2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Erik Hallnor
33 * Definition of BaseCache functions.
36 #include "cpu/base.hh"
38 #include "debug/Cache.hh"
39 #include "mem/cache/base.hh"
40 #include "mem/cache/mshr.hh"
44 BaseCache::CachePort::CachePort(const std::string
&_name
, BaseCache
*_cache
,
45 const std::string
&_label
)
46 : SimpleTimingPort(_name
, _cache
), cache(_cache
),
47 label(_label
), otherPort(NULL
),
48 blocked(false), mustSendRetry(false)
53 BaseCache::BaseCache(const Params
*p
)
55 mshrQueue("MSHRs", p
->mshrs
, 4, MSHRQueue_MSHRs
),
56 writeBuffer("write buffer", p
->write_buffers
, p
->mshrs
+1000,
57 MSHRQueue_WriteBuffer
),
58 blkSize(p
->block_size
),
59 hitLatency(p
->latency
),
60 numTarget(p
->tgts_per_mshr
),
61 forwardSnoops(p
->forward_snoops
),
62 isTopLevel(p
->is_top_level
),
65 missCount(p
->max_miss_count
),
67 addrRange(p
->addr_range
),
73 BaseCache::CachePort::recvRangeChange() const
75 otherPort
->sendRangeChange();
80 BaseCache::CachePort::checkFunctional(PacketPtr pkt
)
82 pkt
->pushLabel(label
);
83 bool done
= SimpleTimingPort::checkFunctional(pkt
);
90 BaseCache::CachePort::deviceBlockSize() const
92 return cache
->getBlockSize();
97 BaseCache::CachePort::recvRetryCommon()
99 assert(waitingOnRetry
);
100 waitingOnRetry
= false;
106 BaseCache::CachePort::setBlocked()
109 DPRINTF(Cache
, "Cache Blocking\n");
111 //Clear the retry flag
112 mustSendRetry
= false;
116 BaseCache::CachePort::clearBlocked()
119 DPRINTF(Cache
, "Cache Unblocking\n");
123 DPRINTF(Cache
, "Cache Sending Retry\n");
124 mustSendRetry
= false;
125 SendRetryEvent
*ev
= new SendRetryEvent(this, true);
126 // @TODO: need to find a better time (next bus cycle?)
127 cache
->schedule(ev
, curTick() + 1);
135 if (!cpuSidePort
|| !memSidePort
)
136 panic("Cache not hooked up on both sides\n");
137 cpuSidePort
->sendRangeChange();
142 BaseCache::regStats()
144 using namespace Stats
;
147 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
148 MemCmd
cmd(access_idx
);
149 const string
&cstr
= cmd
.toString();
157 .name(name() + "." + cstr
+ "_hits")
158 .desc("number of " + cstr
+ " hits")
159 .flags(total
| nozero
| nonan
)
163 // These macros make it easier to sum the right subset of commands and
164 // to change the subset of commands that are considered "demand" vs
166 #define SUM_DEMAND(s) \
167 (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::ReadExReq])
169 // should writebacks be included here? prior code was inconsistent...
170 #define SUM_NON_DEMAND(s) \
171 (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq])
174 .name(name() + ".demand_hits")
175 .desc("number of demand (read+write) hits")
178 demandHits
= SUM_DEMAND(hits
);
181 .name(name() + ".overall_hits")
182 .desc("number of overall hits")
185 overallHits
= demandHits
+ SUM_NON_DEMAND(hits
);
188 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
189 MemCmd
cmd(access_idx
);
190 const string
&cstr
= cmd
.toString();
198 .name(name() + "." + cstr
+ "_misses")
199 .desc("number of " + cstr
+ " misses")
200 .flags(total
| nozero
| nonan
)
205 .name(name() + ".demand_misses")
206 .desc("number of demand (read+write) misses")
209 demandMisses
= SUM_DEMAND(misses
);
212 .name(name() + ".overall_misses")
213 .desc("number of overall misses")
216 overallMisses
= demandMisses
+ SUM_NON_DEMAND(misses
);
218 // Miss latency statistics
219 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
220 MemCmd
cmd(access_idx
);
221 const string
&cstr
= cmd
.toString();
223 missLatency
[access_idx
]
224 .init(maxThreadsPerCPU
)
225 .name(name() + "." + cstr
+ "_miss_latency")
226 .desc("number of " + cstr
+ " miss cycles")
227 .flags(total
| nozero
| nonan
)
232 .name(name() + ".demand_miss_latency")
233 .desc("number of demand (read+write) miss cycles")
236 demandMissLatency
= SUM_DEMAND(missLatency
);
239 .name(name() + ".overall_miss_latency")
240 .desc("number of overall miss cycles")
243 overallMissLatency
= demandMissLatency
+ SUM_NON_DEMAND(missLatency
);
246 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
247 MemCmd
cmd(access_idx
);
248 const string
&cstr
= cmd
.toString();
251 .name(name() + "." + cstr
+ "_accesses")
252 .desc("number of " + cstr
+ " accesses(hits+misses)")
253 .flags(total
| nozero
| nonan
)
256 accesses
[access_idx
] = hits
[access_idx
] + misses
[access_idx
];
260 .name(name() + ".demand_accesses")
261 .desc("number of demand (read+write) accesses")
264 demandAccesses
= demandHits
+ demandMisses
;
267 .name(name() + ".overall_accesses")
268 .desc("number of overall (read+write) accesses")
271 overallAccesses
= overallHits
+ overallMisses
;
273 // miss rate formulas
274 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
275 MemCmd
cmd(access_idx
);
276 const string
&cstr
= cmd
.toString();
279 .name(name() + "." + cstr
+ "_miss_rate")
280 .desc("miss rate for " + cstr
+ " accesses")
281 .flags(total
| nozero
| nonan
)
284 missRate
[access_idx
] = misses
[access_idx
] / accesses
[access_idx
];
288 .name(name() + ".demand_miss_rate")
289 .desc("miss rate for demand accesses")
292 demandMissRate
= demandMisses
/ demandAccesses
;
295 .name(name() + ".overall_miss_rate")
296 .desc("miss rate for overall accesses")
299 overallMissRate
= overallMisses
/ overallAccesses
;
301 // miss latency formulas
302 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
303 MemCmd
cmd(access_idx
);
304 const string
&cstr
= cmd
.toString();
306 avgMissLatency
[access_idx
]
307 .name(name() + "." + cstr
+ "_avg_miss_latency")
308 .desc("average " + cstr
+ " miss latency")
309 .flags(total
| nozero
| nonan
)
312 avgMissLatency
[access_idx
] =
313 missLatency
[access_idx
] / misses
[access_idx
];
317 .name(name() + ".demand_avg_miss_latency")
318 .desc("average overall miss latency")
321 demandAvgMissLatency
= demandMissLatency
/ demandMisses
;
323 overallAvgMissLatency
324 .name(name() + ".overall_avg_miss_latency")
325 .desc("average overall miss latency")
328 overallAvgMissLatency
= overallMissLatency
/ overallMisses
;
330 blocked_cycles
.init(NUM_BLOCKED_CAUSES
);
332 .name(name() + ".blocked_cycles")
333 .desc("number of cycles access was blocked")
334 .subname(Blocked_NoMSHRs
, "no_mshrs")
335 .subname(Blocked_NoTargets
, "no_targets")
339 blocked_causes
.init(NUM_BLOCKED_CAUSES
);
341 .name(name() + ".blocked")
342 .desc("number of cycles access was blocked")
343 .subname(Blocked_NoMSHRs
, "no_mshrs")
344 .subname(Blocked_NoTargets
, "no_targets")
348 .name(name() + ".avg_blocked_cycles")
349 .desc("average number of cycles each access was blocked")
350 .subname(Blocked_NoMSHRs
, "no_mshrs")
351 .subname(Blocked_NoTargets
, "no_targets")
354 avg_blocked
= blocked_cycles
/ blocked_causes
;
357 .name(name() + ".fast_writes")
358 .desc("number of fast writes performed")
362 .name(name() + ".cache_copies")
363 .desc("number of cache copies performed")
367 .init(maxThreadsPerCPU
)
368 .name(name() + ".writebacks")
369 .desc("number of writebacks")
374 // MSHR hit statistics
375 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
376 MemCmd
cmd(access_idx
);
377 const string
&cstr
= cmd
.toString();
379 mshr_hits
[access_idx
]
380 .init(maxThreadsPerCPU
)
381 .name(name() + "." + cstr
+ "_mshr_hits")
382 .desc("number of " + cstr
+ " MSHR hits")
383 .flags(total
| nozero
| nonan
)
388 .name(name() + ".demand_mshr_hits")
389 .desc("number of demand (read+write) MSHR hits")
392 demandMshrHits
= SUM_DEMAND(mshr_hits
);
395 .name(name() + ".overall_mshr_hits")
396 .desc("number of overall MSHR hits")
399 overallMshrHits
= demandMshrHits
+ SUM_NON_DEMAND(mshr_hits
);
401 // MSHR miss statistics
402 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
403 MemCmd
cmd(access_idx
);
404 const string
&cstr
= cmd
.toString();
406 mshr_misses
[access_idx
]
407 .init(maxThreadsPerCPU
)
408 .name(name() + "." + cstr
+ "_mshr_misses")
409 .desc("number of " + cstr
+ " MSHR misses")
410 .flags(total
| nozero
| nonan
)
415 .name(name() + ".demand_mshr_misses")
416 .desc("number of demand (read+write) MSHR misses")
419 demandMshrMisses
= SUM_DEMAND(mshr_misses
);
422 .name(name() + ".overall_mshr_misses")
423 .desc("number of overall MSHR misses")
426 overallMshrMisses
= demandMshrMisses
+ SUM_NON_DEMAND(mshr_misses
);
428 // MSHR miss latency statistics
429 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
430 MemCmd
cmd(access_idx
);
431 const string
&cstr
= cmd
.toString();
433 mshr_miss_latency
[access_idx
]
434 .init(maxThreadsPerCPU
)
435 .name(name() + "." + cstr
+ "_mshr_miss_latency")
436 .desc("number of " + cstr
+ " MSHR miss cycles")
437 .flags(total
| nozero
| nonan
)
441 demandMshrMissLatency
442 .name(name() + ".demand_mshr_miss_latency")
443 .desc("number of demand (read+write) MSHR miss cycles")
446 demandMshrMissLatency
= SUM_DEMAND(mshr_miss_latency
);
448 overallMshrMissLatency
449 .name(name() + ".overall_mshr_miss_latency")
450 .desc("number of overall MSHR miss cycles")
453 overallMshrMissLatency
=
454 demandMshrMissLatency
+ SUM_NON_DEMAND(mshr_miss_latency
);
456 // MSHR uncacheable statistics
457 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
458 MemCmd
cmd(access_idx
);
459 const string
&cstr
= cmd
.toString();
461 mshr_uncacheable
[access_idx
]
462 .init(maxThreadsPerCPU
)
463 .name(name() + "." + cstr
+ "_mshr_uncacheable")
464 .desc("number of " + cstr
+ " MSHR uncacheable")
465 .flags(total
| nozero
| nonan
)
469 overallMshrUncacheable
470 .name(name() + ".overall_mshr_uncacheable_misses")
471 .desc("number of overall MSHR uncacheable misses")
474 overallMshrUncacheable
=
475 SUM_DEMAND(mshr_uncacheable
) + SUM_NON_DEMAND(mshr_uncacheable
);
477 // MSHR miss latency statistics
478 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
479 MemCmd
cmd(access_idx
);
480 const string
&cstr
= cmd
.toString();
482 mshr_uncacheable_lat
[access_idx
]
483 .init(maxThreadsPerCPU
)
484 .name(name() + "." + cstr
+ "_mshr_uncacheable_latency")
485 .desc("number of " + cstr
+ " MSHR uncacheable cycles")
486 .flags(total
| nozero
| nonan
)
490 overallMshrUncacheableLatency
491 .name(name() + ".overall_mshr_uncacheable_latency")
492 .desc("number of overall MSHR uncacheable cycles")
495 overallMshrUncacheableLatency
=
496 SUM_DEMAND(mshr_uncacheable_lat
) +
497 SUM_NON_DEMAND(mshr_uncacheable_lat
);
500 // MSHR access formulas
501 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
502 MemCmd
cmd(access_idx
);
503 const string
&cstr
= cmd
.toString();
505 mshrAccesses
[access_idx
]
506 .name(name() + "." + cstr
+ "_mshr_accesses")
507 .desc("number of " + cstr
+ " mshr accesses(hits+misses)")
508 .flags(total
| nozero
| nonan
)
510 mshrAccesses
[access_idx
] =
511 mshr_hits
[access_idx
] + mshr_misses
[access_idx
]
512 + mshr_uncacheable
[access_idx
];
516 .name(name() + ".demand_mshr_accesses")
517 .desc("number of demand (read+write) mshr accesses")
518 .flags(total
| nozero
| nonan
)
520 demandMshrAccesses
= demandMshrHits
+ demandMshrMisses
;
523 .name(name() + ".overall_mshr_accesses")
524 .desc("number of overall (read+write) mshr accesses")
525 .flags(total
| nozero
| nonan
)
527 overallMshrAccesses
= overallMshrHits
+ overallMshrMisses
528 + overallMshrUncacheable
;
531 // MSHR miss rate formulas
532 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
533 MemCmd
cmd(access_idx
);
534 const string
&cstr
= cmd
.toString();
536 mshrMissRate
[access_idx
]
537 .name(name() + "." + cstr
+ "_mshr_miss_rate")
538 .desc("mshr miss rate for " + cstr
+ " accesses")
539 .flags(total
| nozero
| nonan
)
542 mshrMissRate
[access_idx
] =
543 mshr_misses
[access_idx
] / accesses
[access_idx
];
547 .name(name() + ".demand_mshr_miss_rate")
548 .desc("mshr miss rate for demand accesses")
551 demandMshrMissRate
= demandMshrMisses
/ demandAccesses
;
554 .name(name() + ".overall_mshr_miss_rate")
555 .desc("mshr miss rate for overall accesses")
558 overallMshrMissRate
= overallMshrMisses
/ overallAccesses
;
560 // mshrMiss latency formulas
561 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
562 MemCmd
cmd(access_idx
);
563 const string
&cstr
= cmd
.toString();
565 avgMshrMissLatency
[access_idx
]
566 .name(name() + "." + cstr
+ "_avg_mshr_miss_latency")
567 .desc("average " + cstr
+ " mshr miss latency")
568 .flags(total
| nozero
| nonan
)
571 avgMshrMissLatency
[access_idx
] =
572 mshr_miss_latency
[access_idx
] / mshr_misses
[access_idx
];
575 demandAvgMshrMissLatency
576 .name(name() + ".demand_avg_mshr_miss_latency")
577 .desc("average overall mshr miss latency")
580 demandAvgMshrMissLatency
= demandMshrMissLatency
/ demandMshrMisses
;
582 overallAvgMshrMissLatency
583 .name(name() + ".overall_avg_mshr_miss_latency")
584 .desc("average overall mshr miss latency")
587 overallAvgMshrMissLatency
= overallMshrMissLatency
/ overallMshrMisses
;
589 // mshrUncacheable latency formulas
590 for (int access_idx
= 0; access_idx
< MemCmd::NUM_MEM_CMDS
; ++access_idx
) {
591 MemCmd
cmd(access_idx
);
592 const string
&cstr
= cmd
.toString();
594 avgMshrUncacheableLatency
[access_idx
]
595 .name(name() + "." + cstr
+ "_avg_mshr_uncacheable_latency")
596 .desc("average " + cstr
+ " mshr uncacheable latency")
597 .flags(total
| nozero
| nonan
)
600 avgMshrUncacheableLatency
[access_idx
] =
601 mshr_uncacheable_lat
[access_idx
] / mshr_uncacheable
[access_idx
];
604 overallAvgMshrUncacheableLatency
605 .name(name() + ".overall_avg_mshr_uncacheable_latency")
606 .desc("average overall mshr uncacheable latency")
609 overallAvgMshrUncacheableLatency
= overallMshrUncacheableLatency
/ overallMshrUncacheable
;
612 .init(maxThreadsPerCPU
)
613 .name(name() + ".mshr_cap_events")
614 .desc("number of times MSHR cap was activated")
618 //software prefetching stats
619 soft_prefetch_mshr_full
620 .init(maxThreadsPerCPU
)
621 .name(name() + ".soft_prefetch_mshr_full")
622 .desc("number of mshr full events for SW prefetching instrutions")
626 mshr_no_allocate_misses
627 .name(name() +".no_allocate_misses")
628 .desc("Number of misses that were no-allocate")
634 BaseCache::drain(Event
*de
)
636 int count
= memSidePort
->drain(de
) + cpuSidePort
->drain(de
);
642 changeState(SimObject::Draining
);
646 changeState(SimObject::Drained
);