gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
base.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2018-2019 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2003-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
46 #include "mem/cache/base.hh"
47 
48 #include "base/compiler.hh"
49 #include "base/logging.hh"
50 #include "debug/Cache.hh"
51 #include "debug/CacheComp.hh"
52 #include "debug/CachePort.hh"
53 #include "debug/CacheRepl.hh"
54 #include "debug/CacheVerbose.hh"
56 #include "mem/cache/mshr.hh"
58 #include "mem/cache/queue_entry.hh"
61 #include "params/BaseCache.hh"
62 #include "params/WriteAllocator.hh"
63 #include "sim/core.hh"
64 
66  BaseCache *_cache,
67  const std::string &_label)
68  : QueuedResponsePort(_name, _cache, queue),
69  queue(*_cache, *this, true, _label),
70  blocked(false), mustSendRetry(false),
71  sendRetryEvent([this]{ processSendRetry(); }, _name)
72 {
73 }
74 
75 BaseCache::BaseCache(const BaseCacheParams &p, unsigned blk_size)
76  : ClockedObject(p),
77  cpuSidePort (p.name + ".cpu_side_port", this, "CpuSidePort"),
78  memSidePort(p.name + ".mem_side_port", this, "MemSidePort"),
79  mshrQueue("MSHRs", p.mshrs, 0, p.demand_mshr_reserve), // see below
80  writeBuffer("write buffer", p.write_buffers, p.mshrs), // see below
81  tags(p.tags),
84  writeAllocator(p.write_allocator),
85  writebackClean(p.writeback_clean),
86  tempBlockWriteback(nullptr),
88  name(), false,
90  blkSize(blk_size),
91  lookupLatency(p.tag_latency),
92  dataLatency(p.data_latency),
93  forwardLatency(p.tag_latency),
94  fillLatency(p.data_latency),
95  responseLatency(p.response_latency),
96  sequentialAccess(p.sequential_access),
97  numTarget(p.tgts_per_mshr),
98  forwardSnoops(true),
99  clusivity(p.clusivity),
100  isReadOnly(p.is_read_only),
101  replaceExpansions(p.replace_expansions),
102  moveContractions(p.move_contractions),
103  blocked(0),
104  order(0),
105  noTargetMSHR(nullptr),
106  missCount(p.max_miss_count),
107  addrRanges(p.addr_ranges.begin(), p.addr_ranges.end()),
108  system(p.system),
109  stats(*this)
110 {
111  // the MSHR queue has no reserve entries as we check the MSHR
112  // queue on every single allocation, whereas the write queue has
113  // as many reserve entries as we have MSHRs, since every MSHR may
114  // eventually require a writeback, and we do not check the write
115  // buffer before committing to an MSHR
116 
117  // forward snoops is overridden in init() once we can query
118  // whether the connected requestor is actually snooping or not
119 
120  tempBlock = new TempCacheBlk(blkSize);
121 
122  tags->tagsInit();
123  if (prefetcher)
124  prefetcher->setCache(this);
125 
126  fatal_if(compressor && !dynamic_cast<CompressedTags*>(tags),
127  "The tags of compressed cache %s must derive from CompressedTags",
128  name());
129  warn_if(!compressor && dynamic_cast<CompressedTags*>(tags),
130  "Compressed cache %s does not have a compression algorithm", name());
131  if (compressor)
132  compressor->setCache(this);
133 }
134 
136 {
137  delete tempBlock;
138 }
139 
140 void
142 {
143  assert(!blocked);
144  DPRINTF(CachePort, "Port is blocking new requests\n");
145  blocked = true;
146  // if we already scheduled a retry in this cycle, but it has not yet
147  // happened, cancel it
148  if (sendRetryEvent.scheduled()) {
150  DPRINTF(CachePort, "Port descheduled retry\n");
151  mustSendRetry = true;
152  }
153 }
154 
155 void
157 {
158  assert(blocked);
159  DPRINTF(CachePort, "Port is accepting new requests\n");
160  blocked = false;
161  if (mustSendRetry) {
162  // @TODO: need to find a better time (next cycle?)
163  owner.schedule(sendRetryEvent, curTick() + 1);
164  }
165 }
166 
167 void
169 {
170  DPRINTF(CachePort, "Port is sending retry\n");
171 
172  // reset the flag and call retry
173  mustSendRetry = false;
174  sendRetryReq();
175 }
176 
177 Addr
179 {
180  if (blk != tempBlock) {
181  return tags->regenerateBlkAddr(blk);
182  } else {
183  return tempBlock->getAddr();
184  }
185 }
186 
187 void
189 {
191  fatal("Cache ports on %s are not connected\n", name());
194 }
195 
196 Port &
197 BaseCache::getPort(const std::string &if_name, PortID idx)
198 {
199  if (if_name == "mem_side") {
200  return memSidePort;
201  } else if (if_name == "cpu_side") {
202  return cpuSidePort;
203  } else {
204  return ClockedObject::getPort(if_name, idx);
205  }
206 }
207 
208 bool
210 {
211  for (const auto& r : addrRanges) {
212  if (r.contains(addr)) {
213  return true;
214  }
215  }
216  return false;
217 }
218 
219 void
221 {
222  if (pkt->needsResponse()) {
223  // These delays should have been consumed by now
224  assert(pkt->headerDelay == 0);
225  assert(pkt->payloadDelay == 0);
226 
227  pkt->makeTimingResponse();
228 
229  // In this case we are considering request_time that takes
230  // into account the delay of the xbar, if any, and just
231  // lat, neglecting responseLatency, modelling hit latency
232  // just as the value of lat overriden by access(), which calls
233  // the calculateAccessLatency() function.
234  cpuSidePort.schedTimingResp(pkt, request_time);
235  } else {
236  DPRINTF(Cache, "%s satisfied %s, no response needed\n", __func__,
237  pkt->print());
238 
239  // queue the packet for deletion, as the sending cache is
240  // still relying on it; if the block is found in access(),
241  // CleanEvict and Writeback messages will be deleted
242  // here as well
243  pendingDelete.reset(pkt);
244  }
245 }
246 
247 void
249  Tick forward_time, Tick request_time)
250 {
251  if (writeAllocator &&
252  pkt && pkt->isWrite() && !pkt->req->isUncacheable()) {
253  writeAllocator->updateMode(pkt->getAddr(), pkt->getSize(),
254  pkt->getBlockAddr(blkSize));
255  }
256 
257  if (mshr) {
261 
262  //@todo remove hw_pf here
263 
264  // Coalesce unless it was a software prefetch (see above).
265  if (pkt) {
266  assert(!pkt->isWriteback());
267  // CleanEvicts corresponding to blocks which have
268  // outstanding requests in MSHRs are simply sunk here
269  if (pkt->cmd == MemCmd::CleanEvict) {
270  pendingDelete.reset(pkt);
271  } else if (pkt->cmd == MemCmd::WriteClean) {
272  // A WriteClean should never coalesce with any
273  // outstanding cache maintenance requests.
274 
275  // We use forward_time here because there is an
276  // uncached memory write, forwarded to WriteBuffer.
277  allocateWriteBuffer(pkt, forward_time);
278  } else {
279  DPRINTF(Cache, "%s coalescing MSHR for %s\n", __func__,
280  pkt->print());
281 
282  assert(pkt->req->requestorId() < system->maxRequestors());
283  stats.cmdStats(pkt).mshrHits[pkt->req->requestorId()]++;
284 
285  // We use forward_time here because it is the same
286  // considering new targets. We have multiple
287  // requests for the same address here. It
288  // specifies the latency to allocate an internal
289  // buffer and to schedule an event to the queued
290  // port and also takes into account the additional
291  // delay of the xbar.
292  mshr->allocateTarget(pkt, forward_time, order++,
293  allocOnFill(pkt->cmd));
294  if (mshr->getNumTargets() == numTarget) {
295  noTargetMSHR = mshr;
297  // need to be careful with this... if this mshr isn't
298  // ready yet (i.e. time > curTick()), we don't want to
299  // move it ahead of mshrs that are ready
300  // mshrQueue.moveToFront(mshr);
301  }
302  }
303  }
304  } else {
305  // no MSHR
306  assert(pkt->req->requestorId() < system->maxRequestors());
307  stats.cmdStats(pkt).mshrMisses[pkt->req->requestorId()]++;
308 
309  if (pkt->isEviction() || pkt->cmd == MemCmd::WriteClean) {
310  // We use forward_time here because there is an
311  // writeback or writeclean, forwarded to WriteBuffer.
312  allocateWriteBuffer(pkt, forward_time);
313  } else {
314  if (blk && blk->isValid()) {
315  // If we have a write miss to a valid block, we
316  // need to mark the block non-readable. Otherwise
317  // if we allow reads while there's an outstanding
318  // write miss, the read could return stale data
319  // out of the cache block... a more aggressive
320  // system could detect the overlap (if any) and
321  // forward data out of the MSHRs, but we don't do
322  // that yet. Note that we do need to leave the
323  // block valid so that it stays in the cache, in
324  // case we get an upgrade response (and hence no
325  // new data) when the write miss completes.
326  // As long as CPUs do proper store/load forwarding
327  // internally, and have a sufficiently weak memory
328  // model, this is probably unnecessary, but at some
329  // point it must have seemed like we needed it...
330  assert((pkt->needsWritable() &&
331  !blk->isSet(CacheBlk::WritableBit)) ||
332  pkt->req->isCacheMaintenance());
334  }
335  // Here we are using forward_time, modelling the latency of
336  // a miss (outbound) just as forwardLatency, neglecting the
337  // lookupLatency component.
338  allocateMissBuffer(pkt, forward_time);
339  }
340  }
341 }
342 
343 void
345 {
346  // anything that is merely forwarded pays for the forward latency and
347  // the delay provided by the crossbar
348  Tick forward_time = clockEdge(forwardLatency) + pkt->headerDelay;
349 
350  Cycles lat;
351  CacheBlk *blk = nullptr;
352  bool satisfied = false;
353  {
354  PacketList writebacks;
355  // Note that lat is passed by reference here. The function
356  // access() will set the lat value.
357  satisfied = access(pkt, blk, lat, writebacks);
358 
359  // After the evicted blocks are selected, they must be forwarded
360  // to the write buffer to ensure they logically precede anything
361  // happening below
362  doWritebacks(writebacks, clockEdge(lat + forwardLatency));
363  }
364 
365  // Here we charge the headerDelay that takes into account the latencies
366  // of the bus, if the packet comes from it.
367  // The latency charged is just the value set by the access() function.
368  // In case of a hit we are neglecting response latency.
369  // In case of a miss we are neglecting forward latency.
370  Tick request_time = clockEdge(lat);
371  // Here we reset the timing of the packet.
372  pkt->headerDelay = pkt->payloadDelay = 0;
373 
374  if (satisfied) {
375  // notify before anything else as later handleTimingReqHit might turn
376  // the packet in a response
377  ppHit->notify(pkt);
378 
379  if (prefetcher && blk && blk->wasPrefetched()) {
380  blk->clearPrefetched();
381  }
382 
383  handleTimingReqHit(pkt, blk, request_time);
384  } else {
385  handleTimingReqMiss(pkt, blk, forward_time, request_time);
386 
387  ppMiss->notify(pkt);
388  }
389 
390  if (prefetcher) {
391  // track time of availability of next prefetch, if any
392  Tick next_pf_time = prefetcher->nextPrefetchReadyTime();
393  if (next_pf_time != MaxTick) {
394  schedMemSideSendEvent(next_pf_time);
395  }
396  }
397 }
398 
399 void
401 {
402  Tick completion_time = clockEdge(responseLatency) +
403  pkt->headerDelay + pkt->payloadDelay;
404 
405  // Reset the bus additional time as it is now accounted for
406  pkt->headerDelay = pkt->payloadDelay = 0;
407 
408  cpuSidePort.schedTimingResp(pkt, completion_time);
409 }
410 
411 void
413 {
414  assert(pkt->isResponse());
415 
416  // all header delay should be paid for by the crossbar, unless
417  // this is a prefetch response from above
418  panic_if(pkt->headerDelay != 0 && pkt->cmd != MemCmd::HardPFResp,
419  "%s saw a non-zero packet delay\n", name());
420 
421  const bool is_error = pkt->isError();
422 
423  if (is_error) {
424  DPRINTF(Cache, "%s: Cache received %s with error\n", __func__,
425  pkt->print());
426  }
427 
428  DPRINTF(Cache, "%s: Handling response %s\n", __func__,
429  pkt->print());
430 
431  // if this is a write, we should be looking at an uncacheable
432  // write
433  if (pkt->isWrite()) {
434  assert(pkt->req->isUncacheable());
436  return;
437  }
438 
439  // we have dealt with any (uncacheable) writes above, from here on
440  // we know we are dealing with an MSHR due to a miss or a prefetch
441  MSHR *mshr = dynamic_cast<MSHR*>(pkt->popSenderState());
442  assert(mshr);
443 
444  if (mshr == noTargetMSHR) {
445  // we always clear at least one target
447  noTargetMSHR = nullptr;
448  }
449 
450  // Initial target is used just for stats
451  const QueueEntry::Target *initial_tgt = mshr->getTarget();
452  const Tick miss_latency = curTick() - initial_tgt->recvTime;
453  if (pkt->req->isUncacheable()) {
454  assert(pkt->req->requestorId() < system->maxRequestors());
455  stats.cmdStats(initial_tgt->pkt)
456  .mshrUncacheableLatency[pkt->req->requestorId()] += miss_latency;
457  } else {
458  assert(pkt->req->requestorId() < system->maxRequestors());
459  stats.cmdStats(initial_tgt->pkt)
460  .mshrMissLatency[pkt->req->requestorId()] += miss_latency;
461  }
462 
463  PacketList writebacks;
464 
465  bool is_fill = !mshr->isForward &&
466  (pkt->isRead() || pkt->cmd == MemCmd::UpgradeResp ||
467  mshr->wasWholeLineWrite);
468 
469  // make sure that if the mshr was due to a whole line write then
470  // the response is an invalidation
471  assert(!mshr->wasWholeLineWrite || pkt->isInvalidate());
472 
473  CacheBlk *blk = tags->findBlock(pkt->getAddr(), pkt->isSecure());
474 
475  if (is_fill && !is_error) {
476  DPRINTF(Cache, "Block for addr %#llx being updated in Cache\n",
477  pkt->getAddr());
478 
479  const bool allocate = (writeAllocator && mshr->wasWholeLineWrite) ?
480  writeAllocator->allocate() : mshr->allocOnFill();
481  blk = handleFill(pkt, blk, writebacks, allocate);
482  assert(blk != nullptr);
483  ppFill->notify(pkt);
484  }
485 
486  if (blk && blk->isValid() && pkt->isClean() && !pkt->isInvalidate()) {
487  // The block was marked not readable while there was a pending
488  // cache maintenance operation, restore its flag.
490 
491  // This was a cache clean operation (without invalidate)
492  // and we have a copy of the block already. Since there
493  // is no invalidation, we can promote targets that don't
494  // require a writable copy
495  mshr->promoteReadable();
496  }
497 
498  if (blk && blk->isSet(CacheBlk::WritableBit) &&
499  !pkt->req->isCacheInvalidate()) {
500  // If at this point the referenced block is writable and the
501  // response is not a cache invalidate, we promote targets that
502  // were deferred as we couldn't guarrantee a writable copy
503  mshr->promoteWritable();
504  }
505 
506  serviceMSHRTargets(mshr, pkt, blk);
507 
508  if (mshr->promoteDeferredTargets()) {
509  // avoid later read getting stale data while write miss is
510  // outstanding.. see comment in timingAccess()
511  if (blk) {
513  }
514  mshrQueue.markPending(mshr);
516  } else {
517  // while we deallocate an mshr from the queue we still have to
518  // check the isFull condition before and after as we might
519  // have been using the reserved entries already
520  const bool was_full = mshrQueue.isFull();
521  mshrQueue.deallocate(mshr);
522  if (was_full && !mshrQueue.isFull()) {
524  }
525 
526  // Request the bus for a prefetch if this deallocation freed enough
527  // MSHRs for a prefetch to take place
528  if (prefetcher && mshrQueue.canPrefetch() && !isBlocked()) {
529  Tick next_pf_time = std::max(prefetcher->nextPrefetchReadyTime(),
530  clockEdge());
531  if (next_pf_time != MaxTick)
532  schedMemSideSendEvent(next_pf_time);
533  }
534  }
535 
536  // if we used temp block, check to see if its valid and then clear it out
537  if (blk == tempBlock && tempBlock->isValid()) {
538  evictBlock(blk, writebacks);
539  }
540 
541  const Tick forward_time = clockEdge(forwardLatency) + pkt->headerDelay;
542  // copy writebacks to write buffer
543  doWritebacks(writebacks, forward_time);
544 
545  DPRINTF(CacheVerbose, "%s: Leaving with %s\n", __func__, pkt->print());
546  delete pkt;
547 }
548 
549 
550 Tick
552 {
553  // should assert here that there are no outstanding MSHRs or
554  // writebacks... that would mean that someone used an atomic
555  // access in timing mode
556 
557  // We use lookupLatency here because it is used to specify the latency
558  // to access.
559  Cycles lat = lookupLatency;
560 
561  CacheBlk *blk = nullptr;
562  PacketList writebacks;
563  bool satisfied = access(pkt, blk, lat, writebacks);
564 
565  if (pkt->isClean() && blk && blk->isSet(CacheBlk::DirtyBit)) {
566  // A cache clean opearation is looking for a dirty
567  // block. If a dirty block is encountered a WriteClean
568  // will update any copies to the path to the memory
569  // until the point of reference.
570  DPRINTF(CacheVerbose, "%s: packet %s found block: %s\n",
571  __func__, pkt->print(), blk->print());
572  PacketPtr wb_pkt = writecleanBlk(blk, pkt->req->getDest(), pkt->id);
573  writebacks.push_back(wb_pkt);
574  pkt->setSatisfied();
575  }
576 
577  // handle writebacks resulting from the access here to ensure they
578  // logically precede anything happening below
579  doWritebacksAtomic(writebacks);
580  assert(writebacks.empty());
581 
582  if (!satisfied) {
583  lat += handleAtomicReqMiss(pkt, blk, writebacks);
584  }
585 
586  // Note that we don't invoke the prefetcher at all in atomic mode.
587  // It's not clear how to do it properly, particularly for
588  // prefetchers that aggressively generate prefetch candidates and
589  // rely on bandwidth contention to throttle them; these will tend
590  // to pollute the cache in atomic mode since there is no bandwidth
591  // contention. If we ever do want to enable prefetching in atomic
592  // mode, though, this is the place to do it... see timingAccess()
593  // for an example (though we'd want to issue the prefetch(es)
594  // immediately rather than calling requestMemSideBus() as we do
595  // there).
596 
597  // do any writebacks resulting from the response handling
598  doWritebacksAtomic(writebacks);
599 
600  // if we used temp block, check to see if its valid and if so
601  // clear it out, but only do so after the call to recvAtomic is
602  // finished so that any downstream observers (such as a snoop
603  // filter), first see the fill, and only then see the eviction
604  if (blk == tempBlock && tempBlock->isValid()) {
605  // the atomic CPU calls recvAtomic for fetch and load/store
606  // sequentuially, and we may already have a tempBlock
607  // writeback from the fetch that we have not yet sent
608  if (tempBlockWriteback) {
609  // if that is the case, write the prevoius one back, and
610  // do not schedule any new event
612  } else {
613  // the writeback/clean eviction happens after the call to
614  // recvAtomic has finished (but before any successive
615  // calls), so that the response handling from the fill is
616  // allowed to happen first
618  }
619 
621  }
622 
623  if (pkt->needsResponse()) {
624  pkt->makeAtomicResponse();
625  }
626 
627  return lat * clockPeriod();
628 }
629 
630 void
631 BaseCache::functionalAccess(PacketPtr pkt, bool from_cpu_side)
632 {
633  Addr blk_addr = pkt->getBlockAddr(blkSize);
634  bool is_secure = pkt->isSecure();
635  CacheBlk *blk = tags->findBlock(pkt->getAddr(), is_secure);
636  MSHR *mshr = mshrQueue.findMatch(blk_addr, is_secure);
637 
638  pkt->pushLabel(name());
639 
640  CacheBlkPrintWrapper cbpw(blk);
641 
642  // Note that just because an L2/L3 has valid data doesn't mean an
643  // L1 doesn't have a more up-to-date modified copy that still
644  // needs to be found. As a result we always update the request if
645  // we have it, but only declare it satisfied if we are the owner.
646 
647  // see if we have data at all (owned or otherwise)
648  bool have_data = blk && blk->isValid()
649  && pkt->trySatisfyFunctional(&cbpw, blk_addr, is_secure, blkSize,
650  blk->data);
651 
652  // data we have is dirty if marked as such or if we have an
653  // in-service MSHR that is pending a modified line
654  bool have_dirty =
655  have_data && (blk->isSet(CacheBlk::DirtyBit) ||
656  (mshr && mshr->inService && mshr->isPendingModified()));
657 
658  bool done = have_dirty ||
663 
664  DPRINTF(CacheVerbose, "%s: %s %s%s%s\n", __func__, pkt->print(),
665  (blk && blk->isValid()) ? "valid " : "",
666  have_data ? "data " : "", done ? "done " : "");
667 
668  // We're leaving the cache, so pop cache->name() label
669  pkt->popLabel();
670 
671  if (done) {
672  pkt->makeResponse();
673  } else {
674  // if it came as a request from the CPU side then make sure it
675  // continues towards the memory side
676  if (from_cpu_side) {
678  } else if (cpuSidePort.isSnooping()) {
679  // if it came from the memory side, it must be a snoop request
680  // and we should only forward it if we are forwarding snoops
682  }
683  }
684 }
685 
686 void
688  bool has_old_data)
689 {
690  DataUpdate data_update(regenerateBlkAddr(blk), blk->isSecure());
691  if (ppDataUpdate->hasListeners()) {
692  if (has_old_data) {
693  data_update.oldData = std::vector<uint64_t>(blk->data,
694  blk->data + (blkSize / sizeof(uint64_t)));
695  }
696  }
697 
698  // Actually perform the data update
699  if (cpkt) {
700  cpkt->writeDataToBlock(blk->data, blkSize);
701  }
702 
703  if (ppDataUpdate->hasListeners()) {
704  if (cpkt) {
705  data_update.newData = std::vector<uint64_t>(blk->data,
706  blk->data + (blkSize / sizeof(uint64_t)));
707  }
708  ppDataUpdate->notify(data_update);
709  }
710 }
711 
712 void
714 {
715  assert(pkt->isRequest());
716 
717  uint64_t overwrite_val;
718  bool overwrite_mem;
719  uint64_t condition_val64;
720  uint32_t condition_val32;
721 
722  int offset = pkt->getOffset(blkSize);
723  uint8_t *blk_data = blk->data + offset;
724 
725  assert(sizeof(uint64_t) >= pkt->getSize());
726 
727  // Get a copy of the old block's contents for the probe before the update
728  DataUpdate data_update(regenerateBlkAddr(blk), blk->isSecure());
729  if (ppDataUpdate->hasListeners()) {
730  data_update.oldData = std::vector<uint64_t>(blk->data,
731  blk->data + (blkSize / sizeof(uint64_t)));
732  }
733 
734  overwrite_mem = true;
735  // keep a copy of our possible write value, and copy what is at the
736  // memory address into the packet
737  pkt->writeData((uint8_t *)&overwrite_val);
738  pkt->setData(blk_data);
739 
740  if (pkt->req->isCondSwap()) {
741  if (pkt->getSize() == sizeof(uint64_t)) {
742  condition_val64 = pkt->req->getExtraData();
743  overwrite_mem = !std::memcmp(&condition_val64, blk_data,
744  sizeof(uint64_t));
745  } else if (pkt->getSize() == sizeof(uint32_t)) {
746  condition_val32 = (uint32_t)pkt->req->getExtraData();
747  overwrite_mem = !std::memcmp(&condition_val32, blk_data,
748  sizeof(uint32_t));
749  } else
750  panic("Invalid size for conditional read/write\n");
751  }
752 
753  if (overwrite_mem) {
754  std::memcpy(blk_data, &overwrite_val, pkt->getSize());
756 
757  if (ppDataUpdate->hasListeners()) {
758  data_update.newData = std::vector<uint64_t>(blk->data,
759  blk->data + (blkSize / sizeof(uint64_t)));
760  ppDataUpdate->notify(data_update);
761  }
762  }
763 }
764 
765 QueueEntry*
767 {
768  // Check both MSHR queue and write buffer for potential requests,
769  // note that null does not mean there is no request, it could
770  // simply be that it is not ready
771  MSHR *miss_mshr = mshrQueue.getNext();
772  WriteQueueEntry *wq_entry = writeBuffer.getNext();
773 
774  // If we got a write buffer request ready, first priority is a
775  // full write buffer, otherwise we favour the miss requests
776  if (wq_entry && (writeBuffer.isFull() || !miss_mshr)) {
777  // need to search MSHR queue for conflicting earlier miss.
778  MSHR *conflict_mshr = mshrQueue.findPending(wq_entry);
779 
780  if (conflict_mshr && conflict_mshr->order < wq_entry->order) {
781  // Service misses in order until conflict is cleared.
782  return conflict_mshr;
783 
784  // @todo Note that we ignore the ready time of the conflict here
785  }
786 
787  // No conflicts; issue write
788  return wq_entry;
789  } else if (miss_mshr) {
790  // need to check for conflicting earlier writeback
791  WriteQueueEntry *conflict_mshr = writeBuffer.findPending(miss_mshr);
792  if (conflict_mshr) {
793  // not sure why we don't check order here... it was in the
794  // original code but commented out.
795 
796  // The only way this happens is if we are
797  // doing a write and we didn't have permissions
798  // then subsequently saw a writeback (owned got evicted)
799  // We need to make sure to perform the writeback first
800  // To preserve the dirty data, then we can issue the write
801 
802  // should we return wq_entry here instead? I.e. do we
803  // have to flush writes in order? I don't think so... not
804  // for Alpha anyway. Maybe for x86?
805  return conflict_mshr;
806 
807  // @todo Note that we ignore the ready time of the conflict here
808  }
809 
810  // No conflicts; issue read
811  return miss_mshr;
812  }
813 
814  // fall through... no pending requests. Try a prefetch.
815  assert(!miss_mshr && !wq_entry);
816  if (prefetcher && mshrQueue.canPrefetch() && !isBlocked()) {
817  // If we have a miss queue slot, we can try a prefetch
818  PacketPtr pkt = prefetcher->getPacket();
819  if (pkt) {
820  Addr pf_addr = pkt->getBlockAddr(blkSize);
821  if (!tags->findBlock(pf_addr, pkt->isSecure()) &&
822  !mshrQueue.findMatch(pf_addr, pkt->isSecure()) &&
823  !writeBuffer.findMatch(pf_addr, pkt->isSecure())) {
824  // Update statistic on number of prefetches issued
825  // (hwpf_mshr_misses)
826  assert(pkt->req->requestorId() < system->maxRequestors());
827  stats.cmdStats(pkt).mshrMisses[pkt->req->requestorId()]++;
828 
829  // allocate an MSHR and return it, note
830  // that we send the packet straight away, so do not
831  // schedule the send
832  return allocateMissBuffer(pkt, curTick(), false);
833  } else {
834  // free the request and packet
835  delete pkt;
836  }
837  }
838  }
839 
840  return nullptr;
841 }
842 
843 bool
845  PacketList &writebacks)
846 {
847  bool replacement = false;
848  for (const auto& blk : evict_blks) {
849  if (blk->isValid()) {
850  replacement = true;
851 
852  const MSHR* mshr =
853  mshrQueue.findMatch(regenerateBlkAddr(blk), blk->isSecure());
854  if (mshr) {
855  // Must be an outstanding upgrade or clean request on a block
856  // we're about to replace
857  assert((!blk->isSet(CacheBlk::WritableBit) &&
858  mshr->needsWritable()) || mshr->isCleaning());
859  return false;
860  }
861  }
862  }
863 
864  // The victim will be replaced by a new entry, so increase the replacement
865  // counter if a valid block is being replaced
866  if (replacement) {
868 
869  // Evict valid blocks associated to this victim block
870  for (auto& blk : evict_blks) {
871  if (blk->isValid()) {
872  evictBlock(blk, writebacks);
873  }
874  }
875  }
876 
877  return true;
878 }
879 
880 bool
882  PacketList &writebacks)
883 {
884  // tempBlock does not exist in the tags, so don't do anything for it.
885  if (blk == tempBlock) {
886  return true;
887  }
888 
889  // The compressor is called to compress the updated data, so that its
890  // metadata can be updated.
891  Cycles compression_lat = Cycles(0);
892  Cycles decompression_lat = Cycles(0);
893  const auto comp_data =
894  compressor->compress(data, compression_lat, decompression_lat);
895  std::size_t compression_size = comp_data->getSizeBits();
896 
897  // Get previous compressed size
898  CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk);
899  M5_VAR_USED const std::size_t prev_size = compression_blk->getSizeBits();
900 
901  // If compressed size didn't change enough to modify its co-allocatability
902  // there is nothing to do. Otherwise we may be facing a data expansion
903  // (block passing from more compressed to less compressed state), or a
904  // data contraction (less to more).
905  bool is_data_expansion = false;
906  bool is_data_contraction = false;
907  const CompressionBlk::OverwriteType overwrite_type =
908  compression_blk->checkExpansionContraction(compression_size);
909  std::string op_name = "";
910  if (overwrite_type == CompressionBlk::DATA_EXPANSION) {
911  op_name = "expansion";
912  is_data_expansion = true;
913  } else if ((overwrite_type == CompressionBlk::DATA_CONTRACTION) &&
915  op_name = "contraction";
916  is_data_contraction = true;
917  }
918 
919  // If block changed compression state, it was possibly co-allocated with
920  // other blocks and cannot be co-allocated anymore, so one or more blocks
921  // must be evicted to make room for the expanded/contracted block
922  std::vector<CacheBlk*> evict_blks;
923  if (is_data_expansion || is_data_contraction) {
924  std::vector<CacheBlk*> evict_blks;
925  bool victim_itself = false;
926  CacheBlk *victim = nullptr;
927  if (replaceExpansions || is_data_contraction) {
928  victim = tags->findVictim(regenerateBlkAddr(blk),
929  blk->isSecure(), compression_size, evict_blks);
930 
931  // It is valid to return nullptr if there is no victim
932  if (!victim) {
933  return false;
934  }
935 
936  // If the victim block is itself the block won't need to be moved,
937  // and the victim should not be evicted
938  if (blk == victim) {
939  victim_itself = true;
940  auto it = std::find_if(evict_blks.begin(), evict_blks.end(),
941  [&blk](CacheBlk* evict_blk){ return evict_blk == blk; });
942  evict_blks.erase(it);
943  }
944 
945  // Print victim block's information
946  DPRINTF(CacheRepl, "Data %s replacement victim: %s\n",
947  op_name, victim->print());
948  } else {
949  // If we do not move the expanded block, we must make room for
950  // the expansion to happen, so evict every co-allocated block
951  const SuperBlk* superblock = static_cast<const SuperBlk*>(
952  compression_blk->getSectorBlock());
953  for (auto& sub_blk : superblock->blks) {
954  if (sub_blk->isValid() && (blk != sub_blk)) {
955  evict_blks.push_back(sub_blk);
956  }
957  }
958  }
959 
960  // Try to evict blocks; if it fails, give up on update
961  if (!handleEvictions(evict_blks, writebacks)) {
962  return false;
963  }
964 
965  DPRINTF(CacheComp, "Data %s: [%s] from %d to %d bits\n",
966  op_name, blk->print(), prev_size, compression_size);
967 
968  if (!victim_itself && (replaceExpansions || is_data_contraction)) {
969  // Move the block's contents to the invalid block so that it now
970  // co-allocates with the other existing superblock entry
971  tags->moveBlock(blk, victim);
972  blk = victim;
973  compression_blk = static_cast<CompressionBlk*>(blk);
974  }
975  }
976 
977  // Update the number of data expansions/contractions
978  if (is_data_expansion) {
980  } else if (is_data_contraction) {
982  }
983 
984  compression_blk->setSizeBits(compression_size);
985  compression_blk->setDecompressionLatency(decompression_lat);
986 
987  return true;
988 }
989 
990 void
992 {
993  assert(pkt->isRequest());
994 
995  assert(blk && blk->isValid());
996  // Occasionally this is not true... if we are a lower-level cache
997  // satisfying a string of Read and ReadEx requests from
998  // upper-level caches, a Read will mark the block as shared but we
999  // can satisfy a following ReadEx anyway since we can rely on the
1000  // Read requestor(s) to have buffered the ReadEx snoop and to
1001  // invalidate their blocks after receiving them.
1002  // assert(!pkt->needsWritable() || blk->isSet(CacheBlk::WritableBit));
1003  assert(pkt->getOffset(blkSize) + pkt->getSize() <= blkSize);
1004 
1005  // Check RMW operations first since both isRead() and
1006  // isWrite() will be true for them
1007  if (pkt->cmd == MemCmd::SwapReq) {
1008  if (pkt->isAtomicOp()) {
1009  // Get a copy of the old block's contents for the probe before
1010  // the update
1011  DataUpdate data_update(regenerateBlkAddr(blk), blk->isSecure());
1012  if (ppDataUpdate->hasListeners()) {
1013  data_update.oldData = std::vector<uint64_t>(blk->data,
1014  blk->data + (blkSize / sizeof(uint64_t)));
1015  }
1016 
1017  // extract data from cache and save it into the data field in
1018  // the packet as a return value from this atomic op
1019  int offset = tags->extractBlkOffset(pkt->getAddr());
1020  uint8_t *blk_data = blk->data + offset;
1021  pkt->setData(blk_data);
1022 
1023  // execute AMO operation
1024  (*(pkt->getAtomicOp()))(blk_data);
1025 
1026  // Inform of this block's data contents update
1027  if (ppDataUpdate->hasListeners()) {
1028  data_update.newData = std::vector<uint64_t>(blk->data,
1029  blk->data + (blkSize / sizeof(uint64_t)));
1030  ppDataUpdate->notify(data_update);
1031  }
1032 
1033  // set block status to dirty
1035  } else {
1036  cmpAndSwap(blk, pkt);
1037  }
1038  } else if (pkt->isWrite()) {
1039  // we have the block in a writable state and can go ahead,
1040  // note that the line may be also be considered writable in
1041  // downstream caches along the path to memory, but always
1042  // Exclusive, and never Modified
1043  assert(blk->isSet(CacheBlk::WritableBit));
1044  // Write or WriteLine at the first cache with block in writable state
1045  if (blk->checkWrite(pkt)) {
1046  updateBlockData(blk, pkt, true);
1047  }
1048  // Always mark the line as dirty (and thus transition to the
1049  // Modified state) even if we are a failed StoreCond so we
1050  // supply data to any snoops that have appended themselves to
1051  // this cache before knowing the store will fail.
1053  DPRINTF(CacheVerbose, "%s for %s (write)\n", __func__, pkt->print());
1054  } else if (pkt->isRead()) {
1055  if (pkt->isLLSC()) {
1056  blk->trackLoadLocked(pkt);
1057  }
1058 
1059  // all read responses have a data payload
1060  assert(pkt->hasRespData());
1061  pkt->setDataFromBlock(blk->data, blkSize);
1062  } else if (pkt->isUpgrade()) {
1063  // sanity check
1064  assert(!pkt->hasSharers());
1065 
1066  if (blk->isSet(CacheBlk::DirtyBit)) {
1067  // we were in the Owned state, and a cache above us that
1068  // has the line in Shared state needs to be made aware
1069  // that the data it already has is in fact dirty
1070  pkt->setCacheResponding();
1072  }
1073  } else if (pkt->isClean()) {
1075  } else {
1076  assert(pkt->isInvalidate());
1077  invalidateBlock(blk);
1078  DPRINTF(CacheVerbose, "%s for %s (invalidation)\n", __func__,
1079  pkt->print());
1080  }
1081 }
1082 
1084 //
1085 // Access path: requests coming in from the CPU side
1086 //
1088 Cycles
1090  const Cycles lookup_lat) const
1091 {
1092  // A tag-only access has to wait for the packet to arrive in order to
1093  // perform the tag lookup.
1094  return ticksToCycles(delay) + lookup_lat;
1095 }
1096 
1097 Cycles
1098 BaseCache::calculateAccessLatency(const CacheBlk* blk, const uint32_t delay,
1099  const Cycles lookup_lat) const
1100 {
1101  Cycles lat(0);
1102 
1103  if (blk != nullptr) {
1104  // As soon as the access arrives, for sequential accesses first access
1105  // tags, then the data entry. In the case of parallel accesses the
1106  // latency is dictated by the slowest of tag and data latencies.
1107  if (sequentialAccess) {
1108  lat = ticksToCycles(delay) + lookup_lat + dataLatency;
1109  } else {
1110  lat = ticksToCycles(delay) + std::max(lookup_lat, dataLatency);
1111  }
1112 
1113  // Check if the block to be accessed is available. If not, apply the
1114  // access latency on top of when the block is ready to be accessed.
1115  const Tick tick = curTick() + delay;
1116  const Tick when_ready = blk->getWhenReady();
1117  if (when_ready > tick &&
1118  ticksToCycles(when_ready - tick) > lat) {
1119  lat += ticksToCycles(when_ready - tick);
1120  }
1121  } else {
1122  // In case of a miss, we neglect the data access in a parallel
1123  // configuration (i.e., the data access will be stopped as soon as
1124  // we find out it is a miss), and use the tag-only latency.
1125  lat = calculateTagOnlyLatency(delay, lookup_lat);
1126  }
1127 
1128  return lat;
1129 }
1130 
1131 bool
1133  PacketList &writebacks)
1134 {
1135  // sanity check
1136  assert(pkt->isRequest());
1137 
1138  chatty_assert(!(isReadOnly && pkt->isWrite()),
1139  "Should never see a write in a read-only cache %s\n",
1140  name());
1141 
1142  // Access block in the tags
1143  Cycles tag_latency(0);
1144  blk = tags->accessBlock(pkt->getAddr(), pkt->isSecure(), tag_latency);
1145 
1146  DPRINTF(Cache, "%s for %s %s\n", __func__, pkt->print(),
1147  blk ? "hit " + blk->print() : "miss");
1148 
1149  if (pkt->req->isCacheMaintenance()) {
1150  // A cache maintenance operation is always forwarded to the
1151  // memory below even if the block is found in dirty state.
1152 
1153  // We defer any changes to the state of the block until we
1154  // create and mark as in service the mshr for the downstream
1155  // packet.
1156 
1157  // Calculate access latency on top of when the packet arrives. This
1158  // takes into account the bus delay.
1159  lat = calculateTagOnlyLatency(pkt->headerDelay, tag_latency);
1160 
1161  return false;
1162  }
1163 
1164  if (pkt->isEviction()) {
1165  // We check for presence of block in above caches before issuing
1166  // Writeback or CleanEvict to write buffer. Therefore the only
1167  // possible cases can be of a CleanEvict packet coming from above
1168  // encountering a Writeback generated in this cache peer cache and
1169  // waiting in the write buffer. Cases of upper level peer caches
1170  // generating CleanEvict and Writeback or simply CleanEvict and
1171  // CleanEvict almost simultaneously will be caught by snoops sent out
1172  // by crossbar.
1173  WriteQueueEntry *wb_entry = writeBuffer.findMatch(pkt->getAddr(),
1174  pkt->isSecure());
1175  if (wb_entry) {
1176  assert(wb_entry->getNumTargets() == 1);
1177  PacketPtr wbPkt = wb_entry->getTarget()->pkt;
1178  assert(wbPkt->isWriteback());
1179 
1180  if (pkt->isCleanEviction()) {
1181  // The CleanEvict and WritebackClean snoops into other
1182  // peer caches of the same level while traversing the
1183  // crossbar. If a copy of the block is found, the
1184  // packet is deleted in the crossbar. Hence, none of
1185  // the other upper level caches connected to this
1186  // cache have the block, so we can clear the
1187  // BLOCK_CACHED flag in the Writeback if set and
1188  // discard the CleanEvict by returning true.
1189  wbPkt->clearBlockCached();
1190 
1191  // A clean evict does not need to access the data array
1192  lat = calculateTagOnlyLatency(pkt->headerDelay, tag_latency);
1193 
1194  return true;
1195  } else {
1196  assert(pkt->cmd == MemCmd::WritebackDirty);
1197  // Dirty writeback from above trumps our clean
1198  // writeback... discard here
1199  // Note: markInService will remove entry from writeback buffer.
1200  markInService(wb_entry);
1201  delete wbPkt;
1202  }
1203  }
1204  }
1205 
1206  // The critical latency part of a write depends only on the tag access
1207  if (pkt->isWrite()) {
1208  lat = calculateTagOnlyLatency(pkt->headerDelay, tag_latency);
1209  }
1210 
1211  // Writeback handling is special case. We can write the block into
1212  // the cache without having a writeable copy (or any copy at all).
1213  if (pkt->isWriteback()) {
1214  assert(blkSize == pkt->getSize());
1215 
1216  // we could get a clean writeback while we are having
1217  // outstanding accesses to a block, do the simple thing for
1218  // now and drop the clean writeback so that we do not upset
1219  // any ordering/decisions about ownership already taken
1220  if (pkt->cmd == MemCmd::WritebackClean &&
1221  mshrQueue.findMatch(pkt->getAddr(), pkt->isSecure())) {
1222  DPRINTF(Cache, "Clean writeback %#llx to block with MSHR, "
1223  "dropping\n", pkt->getAddr());
1224 
1225  // A writeback searches for the block, then writes the data.
1226  // As the writeback is being dropped, the data is not touched,
1227  // and we just had to wait for the time to find a match in the
1228  // MSHR. As of now assume a mshr queue search takes as long as
1229  // a tag lookup for simplicity.
1230  return true;
1231  }
1232 
1233  const bool has_old_data = blk && blk->isValid();
1234  if (!blk) {
1235  // need to do a replacement
1236  blk = allocateBlock(pkt, writebacks);
1237  if (!blk) {
1238  // no replaceable block available: give up, fwd to next level.
1239  incMissCount(pkt);
1240  return false;
1241  }
1242 
1244  } else if (compressor) {
1245  // This is an overwrite to an existing block, therefore we need
1246  // to check for data expansion (i.e., block was compressed with
1247  // a smaller size, and now it doesn't fit the entry anymore).
1248  // If that is the case we might need to evict blocks.
1249  if (!updateCompressionData(blk, pkt->getConstPtr<uint64_t>(),
1250  writebacks)) {
1251  invalidateBlock(blk);
1252  return false;
1253  }
1254  }
1255 
1256  // only mark the block dirty if we got a writeback command,
1257  // and leave it as is for a clean writeback
1258  if (pkt->cmd == MemCmd::WritebackDirty) {
1259  // TODO: the coherent cache can assert that the dirty bit is set
1261  }
1262  // if the packet does not have sharers, it is passing
1263  // writable, and we got the writeback in Modified or Exclusive
1264  // state, if not we are in the Owned or Shared state
1265  if (!pkt->hasSharers()) {
1267  }
1268  // nothing else to do; writeback doesn't expect response
1269  assert(!pkt->needsResponse());
1270 
1271  updateBlockData(blk, pkt, has_old_data);
1272  DPRINTF(Cache, "%s new state is %s\n", __func__, blk->print());
1273  incHitCount(pkt);
1274 
1275  // When the packet metadata arrives, the tag lookup will be done while
1276  // the payload is arriving. Then the block will be ready to access as
1277  // soon as the fill is done
1279  std::max(cyclesToTicks(tag_latency), (uint64_t)pkt->payloadDelay));
1280 
1281  return true;
1282  } else if (pkt->cmd == MemCmd::CleanEvict) {
1283  // A CleanEvict does not need to access the data array
1284  lat = calculateTagOnlyLatency(pkt->headerDelay, tag_latency);
1285 
1286  if (blk) {
1287  // Found the block in the tags, need to stop CleanEvict from
1288  // propagating further down the hierarchy. Returning true will
1289  // treat the CleanEvict like a satisfied write request and delete
1290  // it.
1291  return true;
1292  }
1293  // We didn't find the block here, propagate the CleanEvict further
1294  // down the memory hierarchy. Returning false will treat the CleanEvict
1295  // like a Writeback which could not find a replaceable block so has to
1296  // go to next level.
1297  return false;
1298  } else if (pkt->cmd == MemCmd::WriteClean) {
1299  // WriteClean handling is a special case. We can allocate a
1300  // block directly if it doesn't exist and we can update the
1301  // block immediately. The WriteClean transfers the ownership
1302  // of the block as well.
1303  assert(blkSize == pkt->getSize());
1304 
1305  const bool has_old_data = blk && blk->isValid();
1306  if (!blk) {
1307  if (pkt->writeThrough()) {
1308  // if this is a write through packet, we don't try to
1309  // allocate if the block is not present
1310  return false;
1311  } else {
1312  // a writeback that misses needs to allocate a new block
1313  blk = allocateBlock(pkt, writebacks);
1314  if (!blk) {
1315  // no replaceable block available: give up, fwd to
1316  // next level.
1317  incMissCount(pkt);
1318  return false;
1319  }
1320 
1322  }
1323  } else if (compressor) {
1324  // This is an overwrite to an existing block, therefore we need
1325  // to check for data expansion (i.e., block was compressed with
1326  // a smaller size, and now it doesn't fit the entry anymore).
1327  // If that is the case we might need to evict blocks.
1328  if (!updateCompressionData(blk, pkt->getConstPtr<uint64_t>(),
1329  writebacks)) {
1330  invalidateBlock(blk);
1331  return false;
1332  }
1333  }
1334 
1335  // at this point either this is a writeback or a write-through
1336  // write clean operation and the block is already in this
1337  // cache, we need to update the data and the block flags
1338  assert(blk);
1339  // TODO: the coherent cache can assert that the dirty bit is set
1340  if (!pkt->writeThrough()) {
1342  }
1343  // nothing else to do; writeback doesn't expect response
1344  assert(!pkt->needsResponse());
1345 
1346  updateBlockData(blk, pkt, has_old_data);
1347  DPRINTF(Cache, "%s new state is %s\n", __func__, blk->print());
1348 
1349  incHitCount(pkt);
1350 
1351  // When the packet metadata arrives, the tag lookup will be done while
1352  // the payload is arriving. Then the block will be ready to access as
1353  // soon as the fill is done
1355  std::max(cyclesToTicks(tag_latency), (uint64_t)pkt->payloadDelay));
1356 
1357  // If this a write-through packet it will be sent to cache below
1358  return !pkt->writeThrough();
1359  } else if (blk && (pkt->needsWritable() ?
1361  blk->isSet(CacheBlk::ReadableBit))) {
1362  // OK to satisfy access
1363  incHitCount(pkt);
1364 
1365  // Calculate access latency based on the need to access the data array
1366  if (pkt->isRead()) {
1367  lat = calculateAccessLatency(blk, pkt->headerDelay, tag_latency);
1368 
1369  // When a block is compressed, it must first be decompressed
1370  // before being read. This adds to the access latency.
1371  if (compressor) {
1372  lat += compressor->getDecompressionLatency(blk);
1373  }
1374  } else {
1375  lat = calculateTagOnlyLatency(pkt->headerDelay, tag_latency);
1376  }
1377 
1378  satisfyRequest(pkt, blk);
1379  maintainClusivity(pkt->fromCache(), blk);
1380 
1381  return true;
1382  }
1383 
1384  // Can't satisfy access normally... either no block (blk == nullptr)
1385  // or have block but need writable
1386 
1387  incMissCount(pkt);
1388 
1389  lat = calculateAccessLatency(blk, pkt->headerDelay, tag_latency);
1390 
1391  if (!blk && pkt->isLLSC() && pkt->isWrite()) {
1392  // complete miss on store conditional... just give up now
1393  pkt->req->setExtraData(0);
1394  return true;
1395  }
1396 
1397  return false;
1398 }
1399 
1400 void
1402 {
1403  if (from_cache && blk && blk->isValid() &&
1404  !blk->isSet(CacheBlk::DirtyBit) && clusivity == Enums::mostly_excl) {
1405  // if we have responded to a cache, and our block is still
1406  // valid, but not dirty, and this cache is mostly exclusive
1407  // with respect to the cache above, drop the block
1408  invalidateBlock(blk);
1409  }
1410 }
1411 
1412 CacheBlk*
1414  bool allocate)
1415 {
1416  assert(pkt->isResponse());
1417  Addr addr = pkt->getAddr();
1418  bool is_secure = pkt->isSecure();
1419  const bool has_old_data = blk && blk->isValid();
1420 #if TRACING_ON
1421  const std::string old_state = blk ? blk->print() : "";
1422 #endif
1423 
1424  // When handling a fill, we should have no writes to this line.
1425  assert(addr == pkt->getBlockAddr(blkSize));
1426  assert(!writeBuffer.findMatch(addr, is_secure));
1427 
1428  if (!blk) {
1429  // better have read new data...
1430  assert(pkt->hasData() || pkt->cmd == MemCmd::InvalidateResp);
1431 
1432  // need to do a replacement if allocating, otherwise we stick
1433  // with the temporary storage
1434  blk = allocate ? allocateBlock(pkt, writebacks) : nullptr;
1435 
1436  if (!blk) {
1437  // No replaceable block or a mostly exclusive
1438  // cache... just use temporary storage to complete the
1439  // current request and then get rid of it
1440  blk = tempBlock;
1441  tempBlock->insert(addr, is_secure);
1442  DPRINTF(Cache, "using temp block for %#llx (%s)\n", addr,
1443  is_secure ? "s" : "ns");
1444  }
1445  } else {
1446  // existing block... probably an upgrade
1447  // don't clear block status... if block is already dirty we
1448  // don't want to lose that
1449  }
1450 
1451  // Block is guaranteed to be valid at this point
1452  assert(blk->isValid());
1453  assert(blk->isSecure() == is_secure);
1454  assert(regenerateBlkAddr(blk) == addr);
1455 
1457 
1458  // sanity check for whole-line writes, which should always be
1459  // marked as writable as part of the fill, and then later marked
1460  // dirty as part of satisfyRequest
1461  if (pkt->cmd == MemCmd::InvalidateResp) {
1462  assert(!pkt->hasSharers());
1463  }
1464 
1465  // here we deal with setting the appropriate state of the line,
1466  // and we start by looking at the hasSharers flag, and ignore the
1467  // cacheResponding flag (normally signalling dirty data) if the
1468  // packet has sharers, thus the line is never allocated as Owned
1469  // (dirty but not writable), and always ends up being either
1470  // Shared, Exclusive or Modified, see Packet::setCacheResponding
1471  // for more details
1472  if (!pkt->hasSharers()) {
1473  // we could get a writable line from memory (rather than a
1474  // cache) even in a read-only cache, note that we set this bit
1475  // even for a read-only cache, possibly revisit this decision
1477 
1478  // check if we got this via cache-to-cache transfer (i.e., from a
1479  // cache that had the block in Modified or Owned state)
1480  if (pkt->cacheResponding()) {
1481  // we got the block in Modified state, and invalidated the
1482  // owners copy
1484 
1485  chatty_assert(!isReadOnly, "Should never see dirty snoop response "
1486  "in read-only cache %s\n", name());
1487 
1488  }
1489  }
1490 
1491  DPRINTF(Cache, "Block addr %#llx (%s) moving from %s to %s\n",
1492  addr, is_secure ? "s" : "ns", old_state, blk->print());
1493 
1494  // if we got new data, copy it in (checking for a read response
1495  // and a response that has data is the same in the end)
1496  if (pkt->isRead()) {
1497  // sanity checks
1498  assert(pkt->hasData());
1499  assert(pkt->getSize() == blkSize);
1500 
1501  updateBlockData(blk, pkt, has_old_data);
1502  }
1503  // The block will be ready when the payload arrives and the fill is done
1505  pkt->payloadDelay);
1506 
1507  return blk;
1508 }
1509 
1510 CacheBlk*
1512 {
1513  // Get address
1514  const Addr addr = pkt->getAddr();
1515 
1516  // Get secure bit
1517  const bool is_secure = pkt->isSecure();
1518 
1519  // Block size and compression related access latency. Only relevant if
1520  // using a compressor, otherwise there is no extra delay, and the block
1521  // is fully sized
1522  std::size_t blk_size_bits = blkSize*8;
1523  Cycles compression_lat = Cycles(0);
1524  Cycles decompression_lat = Cycles(0);
1525 
1526  // If a compressor is being used, it is called to compress data before
1527  // insertion. Although in Gem5 the data is stored uncompressed, even if a
1528  // compressor is used, the compression/decompression methods are called to
1529  // calculate the amount of extra cycles needed to read or write compressed
1530  // blocks.
1531  if (compressor && pkt->hasData()) {
1532  const auto comp_data = compressor->compress(
1533  pkt->getConstPtr<uint64_t>(), compression_lat, decompression_lat);
1534  blk_size_bits = comp_data->getSizeBits();
1535  }
1536 
1537  // Find replacement victim
1538  std::vector<CacheBlk*> evict_blks;
1539  CacheBlk *victim = tags->findVictim(addr, is_secure, blk_size_bits,
1540  evict_blks);
1541 
1542  // It is valid to return nullptr if there is no victim
1543  if (!victim)
1544  return nullptr;
1545 
1546  // Print victim block's information
1547  DPRINTF(CacheRepl, "Replacement victim: %s\n", victim->print());
1548 
1549  // Try to evict blocks; if it fails, give up on allocation
1550  if (!handleEvictions(evict_blks, writebacks)) {
1551  return nullptr;
1552  }
1553 
1554  // Insert new block at victimized entry
1555  tags->insertBlock(pkt, victim);
1556 
1557  // If using a compressor, set compression data. This must be done after
1558  // insertion, as the compression bit may be set.
1559  if (compressor) {
1560  compressor->setSizeBits(victim, blk_size_bits);
1561  compressor->setDecompressionLatency(victim, decompression_lat);
1562  }
1563 
1564  return victim;
1565 }
1566 
1567 void
1569 {
1570  // If block is still marked as prefetched, then it hasn't been used
1571  if (blk->wasPrefetched()) {
1573  }
1574 
1575  // Notify that the data contents for this address are no longer present
1576  updateBlockData(blk, nullptr, blk->isValid());
1577 
1578  // If handling a block present in the Tags, let it do its invalidation
1579  // process, which will update stats and invalidate the block itself
1580  if (blk != tempBlock) {
1581  tags->invalidate(blk);
1582  } else {
1583  tempBlock->invalidate();
1584  }
1585 }
1586 
1587 void
1589 {
1590  PacketPtr pkt = evictBlock(blk);
1591  if (pkt) {
1592  writebacks.push_back(pkt);
1593  }
1594 }
1595 
1596 PacketPtr
1598 {
1600  "Writeback from read-only cache");
1601  assert(blk && blk->isValid() &&
1603 
1605 
1606  RequestPtr req = std::make_shared<Request>(
1608 
1609  if (blk->isSecure())
1610  req->setFlags(Request::SECURE);
1611 
1612  req->taskId(blk->getTaskId());
1613 
1614  PacketPtr pkt =
1615  new Packet(req, blk->isSet(CacheBlk::DirtyBit) ?
1617 
1618  DPRINTF(Cache, "Create Writeback %s writable: %d, dirty: %d\n",
1619  pkt->print(), blk->isSet(CacheBlk::WritableBit),
1620  blk->isSet(CacheBlk::DirtyBit));
1621 
1622  if (blk->isSet(CacheBlk::WritableBit)) {
1623  // not asserting shared means we pass the block in modified
1624  // state, mark our own block non-writeable
1626  } else {
1627  // we are in the Owned state, tell the receiver
1628  pkt->setHasSharers();
1629  }
1630 
1631  // make sure the block is not marked dirty
1633 
1634  pkt->allocate();
1635  pkt->setDataFromBlock(blk->data, blkSize);
1636 
1637  // When a block is compressed, it must first be decompressed before being
1638  // sent for writeback.
1639  if (compressor) {
1641  }
1642 
1643  return pkt;
1644 }
1645 
1646 PacketPtr
1648 {
1649  RequestPtr req = std::make_shared<Request>(
1651 
1652  if (blk->isSecure()) {
1653  req->setFlags(Request::SECURE);
1654  }
1655  req->taskId(blk->getTaskId());
1656 
1657  PacketPtr pkt = new Packet(req, MemCmd::WriteClean, blkSize, id);
1658 
1659  if (dest) {
1660  req->setFlags(dest);
1661  pkt->setWriteThrough();
1662  }
1663 
1664  DPRINTF(Cache, "Create %s writable: %d, dirty: %d\n", pkt->print(),
1666 
1667  if (blk->isSet(CacheBlk::WritableBit)) {
1668  // not asserting shared means we pass the block in modified
1669  // state, mark our own block non-writeable
1671  } else {
1672  // we are in the Owned state, tell the receiver
1673  pkt->setHasSharers();
1674  }
1675 
1676  // make sure the block is not marked dirty
1678 
1679  pkt->allocate();
1680  pkt->setDataFromBlock(blk->data, blkSize);
1681 
1682  // When a block is compressed, it must first be decompressed before being
1683  // sent for writeback.
1684  if (compressor) {
1686  }
1687 
1688  return pkt;
1689 }
1690 
1691 
1692 void
1694 {
1695  tags->forEachBlk([this](CacheBlk &blk) { writebackVisitor(blk); });
1696 }
1697 
1698 void
1700 {
1701  tags->forEachBlk([this](CacheBlk &blk) { invalidateVisitor(blk); });
1702 }
1703 
1704 bool
1706 {
1707  return tags->anyBlk([](CacheBlk &blk) {
1708  return blk.isSet(CacheBlk::DirtyBit); });
1709 }
1710 
1711 bool
1713 {
1714  return writeAllocator && writeAllocator->coalesce();
1715 }
1716 
1717 void
1719 {
1720  if (blk.isSet(CacheBlk::DirtyBit)) {
1721  assert(blk.isValid());
1722 
1723  RequestPtr request = std::make_shared<Request>(
1725 
1726  request->taskId(blk.getTaskId());
1727  if (blk.isSecure()) {
1728  request->setFlags(Request::SECURE);
1729  }
1730 
1731  Packet packet(request, MemCmd::WriteReq);
1732  packet.dataStatic(blk.data);
1733 
1734  memSidePort.sendFunctional(&packet);
1735 
1737  }
1738 }
1739 
1740 void
1742 {
1743  if (blk.isSet(CacheBlk::DirtyBit))
1744  warn_once("Invalidating dirty cache lines. " \
1745  "Expect things to break.\n");
1746 
1747  if (blk.isValid()) {
1748  assert(!blk.isSet(CacheBlk::DirtyBit));
1749  invalidateBlock(&blk);
1750  }
1751 }
1752 
1753 Tick
1755 {
1756  Tick nextReady = std::min(mshrQueue.nextReadyTime(),
1758 
1759  // Don't signal prefetch ready time if no MSHRs available
1760  // Will signal once enoguh MSHRs are deallocated
1761  if (prefetcher && mshrQueue.canPrefetch() && !isBlocked()) {
1762  nextReady = std::min(nextReady,
1764  }
1765 
1766  return nextReady;
1767 }
1768 
1769 
1770 bool
1772 {
1773  assert(mshr);
1774 
1775  // use request from 1st target
1776  PacketPtr tgt_pkt = mshr->getTarget()->pkt;
1777 
1778  DPRINTF(Cache, "%s: MSHR %s\n", __func__, tgt_pkt->print());
1779 
1780  // if the cache is in write coalescing mode or (additionally) in
1781  // no allocation mode, and we have a write packet with an MSHR
1782  // that is not a whole-line write (due to incompatible flags etc),
1783  // then reset the write mode
1784  if (writeAllocator && writeAllocator->coalesce() && tgt_pkt->isWrite()) {
1785  if (!mshr->isWholeLineWrite()) {
1786  // if we are currently write coalescing, hold on the
1787  // MSHR as many cycles extra as we need to completely
1788  // write a cache line
1789  if (writeAllocator->delay(mshr->blkAddr)) {
1790  Tick delay = blkSize / tgt_pkt->getSize() * clockPeriod();
1791  DPRINTF(CacheVerbose, "Delaying pkt %s %llu ticks to allow "
1792  "for write coalescing\n", tgt_pkt->print(), delay);
1793  mshrQueue.delay(mshr, delay);
1794  return false;
1795  } else {
1796  writeAllocator->reset();
1797  }
1798  } else {
1800  }
1801  }
1802 
1803  CacheBlk *blk = tags->findBlock(mshr->blkAddr, mshr->isSecure);
1804 
1805  // either a prefetch that is not present upstream, or a normal
1806  // MSHR request, proceed to get the packet to send downstream
1807  PacketPtr pkt = createMissPacket(tgt_pkt, blk, mshr->needsWritable(),
1808  mshr->isWholeLineWrite());
1809 
1810  mshr->isForward = (pkt == nullptr);
1811 
1812  if (mshr->isForward) {
1813  // not a cache block request, but a response is expected
1814  // make copy of current packet to forward, keep current
1815  // copy for response handling
1816  pkt = new Packet(tgt_pkt, false, true);
1817  assert(!pkt->isWrite());
1818  }
1819 
1820  // play it safe and append (rather than set) the sender state,
1821  // as forwarded packets may already have existing state
1822  pkt->pushSenderState(mshr);
1823 
1824  if (pkt->isClean() && blk && blk->isSet(CacheBlk::DirtyBit)) {
1825  // A cache clean opearation is looking for a dirty block. Mark
1826  // the packet so that the destination xbar can determine that
1827  // there will be a follow-up write packet as well.
1828  pkt->setSatisfied();
1829  }
1830 
1831  if (!memSidePort.sendTimingReq(pkt)) {
1832  // we are awaiting a retry, but we
1833  // delete the packet and will be creating a new packet
1834  // when we get the opportunity
1835  delete pkt;
1836 
1837  // note that we have now masked any requestBus and
1838  // schedSendEvent (we will wait for a retry before
1839  // doing anything), and this is so even if we do not
1840  // care about this packet and might override it before
1841  // it gets retried
1842  return true;
1843  } else {
1844  // As part of the call to sendTimingReq the packet is
1845  // forwarded to all neighbouring caches (and any caches
1846  // above them) as a snoop. Thus at this point we know if
1847  // any of the neighbouring caches are responding, and if
1848  // so, we know it is dirty, and we can determine if it is
1849  // being passed as Modified, making our MSHR the ordering
1850  // point
1851  bool pending_modified_resp = !pkt->hasSharers() &&
1852  pkt->cacheResponding();
1853  markInService(mshr, pending_modified_resp);
1854 
1855  if (pkt->isClean() && blk && blk->isSet(CacheBlk::DirtyBit)) {
1856  // A cache clean opearation is looking for a dirty
1857  // block. If a dirty block is encountered a WriteClean
1858  // will update any copies to the path to the memory
1859  // until the point of reference.
1860  DPRINTF(CacheVerbose, "%s: packet %s found block: %s\n",
1861  __func__, pkt->print(), blk->print());
1862  PacketPtr wb_pkt = writecleanBlk(blk, pkt->req->getDest(),
1863  pkt->id);
1864  PacketList writebacks;
1865  writebacks.push_back(wb_pkt);
1866  doWritebacks(writebacks, 0);
1867  }
1868 
1869  return false;
1870  }
1871 }
1872 
1873 bool
1875 {
1876  assert(wq_entry);
1877 
1878  // always a single target for write queue entries
1879  PacketPtr tgt_pkt = wq_entry->getTarget()->pkt;
1880 
1881  DPRINTF(Cache, "%s: write %s\n", __func__, tgt_pkt->print());
1882 
1883  // forward as is, both for evictions and uncacheable writes
1884  if (!memSidePort.sendTimingReq(tgt_pkt)) {
1885  // note that we have now masked any requestBus and
1886  // schedSendEvent (we will wait for a retry before
1887  // doing anything), and this is so even if we do not
1888  // care about this packet and might override it before
1889  // it gets retried
1890  return true;
1891  } else {
1892  markInService(wq_entry);
1893  return false;
1894  }
1895 }
1896 
1897 void
1899 {
1900  bool dirty(isDirty());
1901 
1902  if (dirty) {
1903  warn("*** The cache still contains dirty data. ***\n");
1904  warn(" Make sure to drain the system using the correct flags.\n");
1905  warn(" This checkpoint will not restore correctly " \
1906  "and dirty data in the cache will be lost!\n");
1907  }
1908 
1909  // Since we don't checkpoint the data in the cache, any dirty data
1910  // will be lost when restoring from a checkpoint of a system that
1911  // wasn't drained properly. Flag the checkpoint as invalid if the
1912  // cache contains dirty data.
1913  bool bad_checkpoint(dirty);
1914  SERIALIZE_SCALAR(bad_checkpoint);
1915 }
1916 
1917 void
1919 {
1920  bool bad_checkpoint;
1921  UNSERIALIZE_SCALAR(bad_checkpoint);
1922  if (bad_checkpoint) {
1923  fatal("Restoring from checkpoints with dirty caches is not "
1924  "supported in the classic memory system. Please remove any "
1925  "caches or drain them properly before taking checkpoints.\n");
1926  }
1927 }
1928 
1929 
1931  const std::string &name)
1932  : Stats::Group(&c, name.c_str()), cache(c),
1933  ADD_STAT(hits, UNIT_COUNT, ("number of " + name + " hits").c_str()),
1934  ADD_STAT(misses, UNIT_COUNT, ("number of " + name + " misses").c_str()),
1935  ADD_STAT(missLatency, UNIT_TICK,
1936  ("number of " + name + " miss ticks").c_str()),
1937  ADD_STAT(accesses, UNIT_COUNT,
1938  ("number of " + name + " accesses(hits+misses)").c_str()),
1939  ADD_STAT(missRate, UNIT_RATIO,
1940  ("miss rate for " + name + " accesses").c_str()),
1941  ADD_STAT(avgMissLatency,
1942  UNIT_RATE(Stats::Units::Tick, Stats::Units::Count),
1943  ("average " + name + " miss latency").c_str()),
1944  ADD_STAT(mshrHits, UNIT_COUNT,
1945  ("number of " + name + " MSHR hits").c_str()),
1946  ADD_STAT(mshrMisses, UNIT_COUNT,
1947  ("number of " + name + " MSHR misses").c_str()),
1948  ADD_STAT(mshrUncacheable, UNIT_COUNT,
1949  ("number of " + name + " MSHR uncacheable").c_str()),
1950  ADD_STAT(mshrMissLatency, UNIT_TICK,
1951  ("number of " + name + " MSHR miss ticks").c_str()),
1952  ADD_STAT(mshrUncacheableLatency, UNIT_TICK,
1953  ("number of " + name + " MSHR uncacheable ticks").c_str()),
1954  ADD_STAT(mshrMissRate, UNIT_RATIO,
1955  ("mshr miss rate for " + name + " accesses").c_str()),
1956  ADD_STAT(avgMshrMissLatency,
1957  UNIT_RATE(Stats::Units::Tick, Stats::Units::Count),
1958  ("average " + name + " mshr miss latency").c_str()),
1959  ADD_STAT(avgMshrUncacheableLatency,
1960  UNIT_RATE(Stats::Units::Tick, Stats::Units::Count),
1961  ("average " + name + " mshr uncacheable latency").c_str())
1962 {
1963 }
1964 
1965 void
1967 {
1968  using namespace Stats;
1969 
1971  System *system = cache.system;
1972  const auto max_requestors = system->maxRequestors();
1973 
1974  hits
1975  .init(max_requestors)
1976  .flags(total | nozero | nonan)
1977  ;
1978  for (int i = 0; i < max_requestors; i++) {
1979  hits.subname(i, system->getRequestorName(i));
1980  }
1981 
1982  // Miss statistics
1983  misses
1984  .init(max_requestors)
1985  .flags(total | nozero | nonan)
1986  ;
1987  for (int i = 0; i < max_requestors; i++) {
1988  misses.subname(i, system->getRequestorName(i));
1989  }
1990 
1991  // Miss latency statistics
1992  missLatency
1993  .init(max_requestors)
1994  .flags(total | nozero | nonan)
1995  ;
1996  for (int i = 0; i < max_requestors; i++) {
1997  missLatency.subname(i, system->getRequestorName(i));
1998  }
1999 
2000  // access formulas
2001  accesses.flags(total | nozero | nonan);
2002  accesses = hits + misses;
2003  for (int i = 0; i < max_requestors; i++) {
2004  accesses.subname(i, system->getRequestorName(i));
2005  }
2006 
2007  // miss rate formulas
2008  missRate.flags(total | nozero | nonan);
2009  missRate = misses / accesses;
2010  for (int i = 0; i < max_requestors; i++) {
2011  missRate.subname(i, system->getRequestorName(i));
2012  }
2013 
2014  // miss latency formulas
2015  avgMissLatency.flags(total | nozero | nonan);
2016  avgMissLatency = missLatency / misses;
2017  for (int i = 0; i < max_requestors; i++) {
2018  avgMissLatency.subname(i, system->getRequestorName(i));
2019  }
2020 
2021  // MSHR statistics
2022  // MSHR hit statistics
2023  mshrHits
2024  .init(max_requestors)
2025  .flags(total | nozero | nonan)
2026  ;
2027  for (int i = 0; i < max_requestors; i++) {
2028  mshrHits.subname(i, system->getRequestorName(i));
2029  }
2030 
2031  // MSHR miss statistics
2032  mshrMisses
2033  .init(max_requestors)
2034  .flags(total | nozero | nonan)
2035  ;
2036  for (int i = 0; i < max_requestors; i++) {
2037  mshrMisses.subname(i, system->getRequestorName(i));
2038  }
2039 
2040  // MSHR miss latency statistics
2041  mshrMissLatency
2042  .init(max_requestors)
2043  .flags(total | nozero | nonan)
2044  ;
2045  for (int i = 0; i < max_requestors; i++) {
2046  mshrMissLatency.subname(i, system->getRequestorName(i));
2047  }
2048 
2049  // MSHR uncacheable statistics
2050  mshrUncacheable
2051  .init(max_requestors)
2052  .flags(total | nozero | nonan)
2053  ;
2054  for (int i = 0; i < max_requestors; i++) {
2055  mshrUncacheable.subname(i, system->getRequestorName(i));
2056  }
2057 
2058  // MSHR miss latency statistics
2059  mshrUncacheableLatency
2060  .init(max_requestors)
2061  .flags(total | nozero | nonan)
2062  ;
2063  for (int i = 0; i < max_requestors; i++) {
2064  mshrUncacheableLatency.subname(i, system->getRequestorName(i));
2065  }
2066 
2067  // MSHR miss rate formulas
2068  mshrMissRate.flags(total | nozero | nonan);
2069  mshrMissRate = mshrMisses / accesses;
2070 
2071  for (int i = 0; i < max_requestors; i++) {
2072  mshrMissRate.subname(i, system->getRequestorName(i));
2073  }
2074 
2075  // mshrMiss latency formulas
2076  avgMshrMissLatency.flags(total | nozero | nonan);
2077  avgMshrMissLatency = mshrMissLatency / mshrMisses;
2078  for (int i = 0; i < max_requestors; i++) {
2079  avgMshrMissLatency.subname(i, system->getRequestorName(i));
2080  }
2081 
2082  // mshrUncacheable latency formulas
2083  avgMshrUncacheableLatency.flags(total | nozero | nonan);
2084  avgMshrUncacheableLatency = mshrUncacheableLatency / mshrUncacheable;
2085  for (int i = 0; i < max_requestors; i++) {
2086  avgMshrUncacheableLatency.subname(i, system->getRequestorName(i));
2087  }
2088 }
2089 
2091  : Stats::Group(&c), cache(c),
2092 
2093  ADD_STAT(demandHits, UNIT_COUNT, "number of demand (read+write) hits"),
2094  ADD_STAT(overallHits, UNIT_COUNT, "number of overall hits"),
2095  ADD_STAT(demandMisses, UNIT_COUNT, "number of demand (read+write) misses"),
2096  ADD_STAT(overallMisses, UNIT_COUNT, "number of overall misses"),
2097  ADD_STAT(demandMissLatency, UNIT_TICK,
2098  "number of demand (read+write) miss ticks"),
2099  ADD_STAT(overallMissLatency, UNIT_TICK, "number of overall miss ticks"),
2100  ADD_STAT(demandAccesses, UNIT_COUNT,
2101  "number of demand (read+write) accesses"),
2102  ADD_STAT(overallAccesses, UNIT_COUNT,
2103  "number of overall (read+write) accesses"),
2104  ADD_STAT(demandMissRate, UNIT_RATIO, "miss rate for demand accesses"),
2105  ADD_STAT(overallMissRate, UNIT_RATIO, "miss rate for overall accesses"),
2106  ADD_STAT(demandAvgMissLatency,
2107  UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2108  "average overall miss latency"),
2109  ADD_STAT(overallAvgMissLatency,
2110  UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2111  "average overall miss latency"),
2112  ADD_STAT(blockedCycles, UNIT_CYCLE, "number of cycles access was blocked"),
2113  ADD_STAT(blockedCauses, UNIT_COUNT, "number of times access was blocked"),
2114  ADD_STAT(avgBlocked, UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2115  "average number of cycles each access was blocked"),
2116  ADD_STAT(unusedPrefetches, UNIT_COUNT,
2117  "number of HardPF blocks evicted w/o reference"),
2118  ADD_STAT(writebacks, UNIT_COUNT, "number of writebacks"),
2119  ADD_STAT(demandMshrHits, UNIT_COUNT,
2120  "number of demand (read+write) MSHR hits"),
2121  ADD_STAT(overallMshrHits, UNIT_COUNT, "number of overall MSHR hits"),
2122  ADD_STAT(demandMshrMisses, UNIT_COUNT,
2123  "number of demand (read+write) MSHR misses"),
2124  ADD_STAT(overallMshrMisses, UNIT_COUNT, "number of overall MSHR misses"),
2125  ADD_STAT(overallMshrUncacheable, UNIT_COUNT,
2126  "number of overall MSHR uncacheable misses"),
2127  ADD_STAT(demandMshrMissLatency, UNIT_TICK,
2128  "number of demand (read+write) MSHR miss ticks"),
2129  ADD_STAT(overallMshrMissLatency, UNIT_TICK,
2130  "number of overall MSHR miss ticks"),
2131  ADD_STAT(overallMshrUncacheableLatency, UNIT_TICK,
2132  "number of overall MSHR uncacheable ticks"),
2133  ADD_STAT(demandMshrMissRate, UNIT_RATIO,
2134  "mshr miss ratio for demand accesses"),
2135  ADD_STAT(overallMshrMissRate, UNIT_RATIO,
2136  "mshr miss ratio for overall accesses"),
2137  ADD_STAT(demandAvgMshrMissLatency,
2138  UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2139  "average overall mshr miss latency"),
2140  ADD_STAT(overallAvgMshrMissLatency,
2141  UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2142  "average overall mshr miss latency"),
2143  ADD_STAT(overallAvgMshrUncacheableLatency,
2144  UNIT_RATE(Stats::Units::Cycle, Stats::Units::Count),
2145  "average overall mshr uncacheable latency"),
2146  ADD_STAT(replacements, UNIT_COUNT, "number of replacements"),
2147  ADD_STAT(dataExpansions, UNIT_COUNT,"number of data expansions"),
2148  ADD_STAT(dataContractions, UNIT_COUNT, "number of data contractions"),
2149  cmd(MemCmd::NUM_MEM_CMDS)
2150 {
2151  for (int idx = 0; idx < MemCmd::NUM_MEM_CMDS; ++idx)
2152  cmd[idx].reset(new CacheCmdStats(c, MemCmd(idx).toString()));
2153 }
2154 
2155 void
2157 {
2158  using namespace Stats;
2159 
2161 
2162  System *system = cache.system;
2163  const auto max_requestors = system->maxRequestors();
2164 
2165  for (auto &cs : cmd)
2166  cs->regStatsFromParent();
2167 
2168 // These macros make it easier to sum the right subset of commands and
2169 // to change the subset of commands that are considered "demand" vs
2170 // "non-demand"
2171 #define SUM_DEMAND(s) \
2172  (cmd[MemCmd::ReadReq]->s + cmd[MemCmd::WriteReq]->s + \
2173  cmd[MemCmd::WriteLineReq]->s + cmd[MemCmd::ReadExReq]->s + \
2174  cmd[MemCmd::ReadCleanReq]->s + cmd[MemCmd::ReadSharedReq]->s)
2175 
2176 // should writebacks be included here? prior code was inconsistent...
2177 #define SUM_NON_DEMAND(s) \
2178  (cmd[MemCmd::SoftPFReq]->s + cmd[MemCmd::HardPFReq]->s + \
2179  cmd[MemCmd::SoftPFExReq]->s)
2180 
2181  demandHits.flags(total | nozero | nonan);
2182  demandHits = SUM_DEMAND(hits);
2183  for (int i = 0; i < max_requestors; i++) {
2184  demandHits.subname(i, system->getRequestorName(i));
2185  }
2186 
2187  overallHits.flags(total | nozero | nonan);
2188  overallHits = demandHits + SUM_NON_DEMAND(hits);
2189  for (int i = 0; i < max_requestors; i++) {
2190  overallHits.subname(i, system->getRequestorName(i));
2191  }
2192 
2193  demandMisses.flags(total | nozero | nonan);
2194  demandMisses = SUM_DEMAND(misses);
2195  for (int i = 0; i < max_requestors; i++) {
2196  demandMisses.subname(i, system->getRequestorName(i));
2197  }
2198 
2199  overallMisses.flags(total | nozero | nonan);
2200  overallMisses = demandMisses + SUM_NON_DEMAND(misses);
2201  for (int i = 0; i < max_requestors; i++) {
2202  overallMisses.subname(i, system->getRequestorName(i));
2203  }
2204 
2205  demandMissLatency.flags(total | nozero | nonan);
2206  demandMissLatency = SUM_DEMAND(missLatency);
2207  for (int i = 0; i < max_requestors; i++) {
2208  demandMissLatency.subname(i, system->getRequestorName(i));
2209  }
2210 
2211  overallMissLatency.flags(total | nozero | nonan);
2212  overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency);
2213  for (int i = 0; i < max_requestors; i++) {
2214  overallMissLatency.subname(i, system->getRequestorName(i));
2215  }
2216 
2217  demandAccesses.flags(total | nozero | nonan);
2218  demandAccesses = demandHits + demandMisses;
2219  for (int i = 0; i < max_requestors; i++) {
2220  demandAccesses.subname(i, system->getRequestorName(i));
2221  }
2222 
2223  overallAccesses.flags(total | nozero | nonan);
2224  overallAccesses = overallHits + overallMisses;
2225  for (int i = 0; i < max_requestors; i++) {
2226  overallAccesses.subname(i, system->getRequestorName(i));
2227  }
2228 
2229  demandMissRate.flags(total | nozero | nonan);
2230  demandMissRate = demandMisses / demandAccesses;
2231  for (int i = 0; i < max_requestors; i++) {
2232  demandMissRate.subname(i, system->getRequestorName(i));
2233  }
2234 
2235  overallMissRate.flags(total | nozero | nonan);
2236  overallMissRate = overallMisses / overallAccesses;
2237  for (int i = 0; i < max_requestors; i++) {
2238  overallMissRate.subname(i, system->getRequestorName(i));
2239  }
2240 
2241  demandAvgMissLatency.flags(total | nozero | nonan);
2242  demandAvgMissLatency = demandMissLatency / demandMisses;
2243  for (int i = 0; i < max_requestors; i++) {
2244  demandAvgMissLatency.subname(i, system->getRequestorName(i));
2245  }
2246 
2247  overallAvgMissLatency.flags(total | nozero | nonan);
2248  overallAvgMissLatency = overallMissLatency / overallMisses;
2249  for (int i = 0; i < max_requestors; i++) {
2250  overallAvgMissLatency.subname(i, system->getRequestorName(i));
2251  }
2252 
2253  blockedCycles.init(NUM_BLOCKED_CAUSES);
2254  blockedCycles
2255  .subname(Blocked_NoMSHRs, "no_mshrs")
2256  .subname(Blocked_NoTargets, "no_targets")
2257  ;
2258 
2259 
2260  blockedCauses.init(NUM_BLOCKED_CAUSES);
2261  blockedCauses
2262  .subname(Blocked_NoMSHRs, "no_mshrs")
2263  .subname(Blocked_NoTargets, "no_targets")
2264  ;
2265 
2266  avgBlocked
2267  .subname(Blocked_NoMSHRs, "no_mshrs")
2268  .subname(Blocked_NoTargets, "no_targets")
2269  ;
2270  avgBlocked = blockedCycles / blockedCauses;
2271 
2272  unusedPrefetches.flags(nozero);
2273 
2274  writebacks
2275  .init(max_requestors)
2276  .flags(total | nozero | nonan)
2277  ;
2278  for (int i = 0; i < max_requestors; i++) {
2279  writebacks.subname(i, system->getRequestorName(i));
2280  }
2281 
2282  demandMshrHits.flags(total | nozero | nonan);
2283  demandMshrHits = SUM_DEMAND(mshrHits);
2284  for (int i = 0; i < max_requestors; i++) {
2285  demandMshrHits.subname(i, system->getRequestorName(i));
2286  }
2287 
2288  overallMshrHits.flags(total | nozero | nonan);
2289  overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshrHits);
2290  for (int i = 0; i < max_requestors; i++) {
2291  overallMshrHits.subname(i, system->getRequestorName(i));
2292  }
2293 
2294  demandMshrMisses.flags(total | nozero | nonan);
2295  demandMshrMisses = SUM_DEMAND(mshrMisses);
2296  for (int i = 0; i < max_requestors; i++) {
2297  demandMshrMisses.subname(i, system->getRequestorName(i));
2298  }
2299 
2300  overallMshrMisses.flags(total | nozero | nonan);
2301  overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshrMisses);
2302  for (int i = 0; i < max_requestors; i++) {
2303  overallMshrMisses.subname(i, system->getRequestorName(i));
2304  }
2305 
2306  demandMshrMissLatency.flags(total | nozero | nonan);
2307  demandMshrMissLatency = SUM_DEMAND(mshrMissLatency);
2308  for (int i = 0; i < max_requestors; i++) {
2309  demandMshrMissLatency.subname(i, system->getRequestorName(i));
2310  }
2311 
2312  overallMshrMissLatency.flags(total | nozero | nonan);
2313  overallMshrMissLatency =
2314  demandMshrMissLatency + SUM_NON_DEMAND(mshrMissLatency);
2315  for (int i = 0; i < max_requestors; i++) {
2316  overallMshrMissLatency.subname(i, system->getRequestorName(i));
2317  }
2318 
2319  overallMshrUncacheable.flags(total | nozero | nonan);
2320  overallMshrUncacheable =
2321  SUM_DEMAND(mshrUncacheable) + SUM_NON_DEMAND(mshrUncacheable);
2322  for (int i = 0; i < max_requestors; i++) {
2323  overallMshrUncacheable.subname(i, system->getRequestorName(i));
2324  }
2325 
2326 
2327  overallMshrUncacheableLatency.flags(total | nozero | nonan);
2328  overallMshrUncacheableLatency =
2329  SUM_DEMAND(mshrUncacheableLatency) +
2330  SUM_NON_DEMAND(mshrUncacheableLatency);
2331  for (int i = 0; i < max_requestors; i++) {
2332  overallMshrUncacheableLatency.subname(i, system->getRequestorName(i));
2333  }
2334 
2335  demandMshrMissRate.flags(total | nozero | nonan);
2336  demandMshrMissRate = demandMshrMisses / demandAccesses;
2337  for (int i = 0; i < max_requestors; i++) {
2338  demandMshrMissRate.subname(i, system->getRequestorName(i));
2339  }
2340 
2341  overallMshrMissRate.flags(total | nozero | nonan);
2342  overallMshrMissRate = overallMshrMisses / overallAccesses;
2343  for (int i = 0; i < max_requestors; i++) {
2344  overallMshrMissRate.subname(i, system->getRequestorName(i));
2345  }
2346 
2347  demandAvgMshrMissLatency.flags(total | nozero | nonan);
2348  demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses;
2349  for (int i = 0; i < max_requestors; i++) {
2350  demandAvgMshrMissLatency.subname(i, system->getRequestorName(i));
2351  }
2352 
2353  overallAvgMshrMissLatency.flags(total | nozero | nonan);
2354  overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses;
2355  for (int i = 0; i < max_requestors; i++) {
2356  overallAvgMshrMissLatency.subname(i, system->getRequestorName(i));
2357  }
2358 
2359  overallAvgMshrUncacheableLatency.flags(total | nozero | nonan);
2360  overallAvgMshrUncacheableLatency =
2361  overallMshrUncacheableLatency / overallMshrUncacheable;
2362  for (int i = 0; i < max_requestors; i++) {
2363  overallAvgMshrUncacheableLatency.subname(i,
2365  }
2366 
2367  dataExpansions.flags(nozero | nonan);
2368  dataContractions.flags(nozero | nonan);
2369 }
2370 
2371 void
2373 {
2374  ppHit = new ProbePointArg<PacketPtr>(this->getProbeManager(), "Hit");
2375  ppMiss = new ProbePointArg<PacketPtr>(this->getProbeManager(), "Miss");
2376  ppFill = new ProbePointArg<PacketPtr>(this->getProbeManager(), "Fill");
2377  ppDataUpdate =
2378  new ProbePointArg<DataUpdate>(this->getProbeManager(), "Data Update");
2379 }
2380 
2382 //
2383 // CpuSidePort
2384 //
2386 bool
2388 {
2389  // Snoops shouldn't happen when bypassing caches
2390  assert(!cache->system->bypassCaches());
2391 
2392  assert(pkt->isResponse());
2393 
2394  // Express snoop responses from requestor to responder, e.g., from L1 to L2
2395  cache->recvTimingSnoopResp(pkt);
2396  return true;
2397 }
2398 
2399 
2400 bool
2402 {
2403  if (cache->system->bypassCaches() || pkt->isExpressSnoop()) {
2404  // always let express snoop packets through even if blocked
2405  return true;
2406  } else if (blocked || mustSendRetry) {
2407  // either already committed to send a retry, or blocked
2408  mustSendRetry = true;
2409  return false;
2410  }
2411  mustSendRetry = false;
2412  return true;
2413 }
2414 
2415 bool
2417 {
2418  assert(pkt->isRequest());
2419 
2420  if (cache->system->bypassCaches()) {
2421  // Just forward the packet if caches are disabled.
2422  // @todo This should really enqueue the packet rather
2423  M5_VAR_USED bool success = cache->memSidePort.sendTimingReq(pkt);
2424  assert(success);
2425  return true;
2426  } else if (tryTiming(pkt)) {
2427  cache->recvTimingReq(pkt);
2428  return true;
2429  }
2430  return false;
2431 }
2432 
2433 Tick
2435 {
2436  if (cache->system->bypassCaches()) {
2437  // Forward the request if the system is in cache bypass mode.
2438  return cache->memSidePort.sendAtomic(pkt);
2439  } else {
2440  return cache->recvAtomic(pkt);
2441  }
2442 }
2443 
2444 void
2446 {
2447  if (cache->system->bypassCaches()) {
2448  // The cache should be flushed if we are in cache bypass mode,
2449  // so we don't need to check if we need to update anything.
2450  cache->memSidePort.sendFunctional(pkt);
2451  return;
2452  }
2453 
2454  // functional request
2455  cache->functionalAccess(pkt, true);
2456 }
2457 
2460 {
2461  return cache->getAddrRanges();
2462 }
2463 
2464 
2466 CpuSidePort::CpuSidePort(const std::string &_name, BaseCache *_cache,
2467  const std::string &_label)
2468  : CacheResponsePort(_name, _cache, _label), cache(_cache)
2469 {
2470 }
2471 
2473 //
2474 // MemSidePort
2475 //
2477 bool
2479 {
2480  cache->recvTimingResp(pkt);
2481  return true;
2482 }
2483 
2484 // Express snooping requests to memside port
2485 void
2487 {
2488  // Snoops shouldn't happen when bypassing caches
2489  assert(!cache->system->bypassCaches());
2490 
2491  // handle snooping requests
2492  cache->recvTimingSnoopReq(pkt);
2493 }
2494 
2495 Tick
2497 {
2498  // Snoops shouldn't happen when bypassing caches
2499  assert(!cache->system->bypassCaches());
2500 
2501  return cache->recvAtomicSnoop(pkt);
2502 }
2503 
2504 void
2506 {
2507  // Snoops shouldn't happen when bypassing caches
2508  assert(!cache->system->bypassCaches());
2509 
2510  // functional snoop (note that in contrast to atomic we don't have
2511  // a specific functionalSnoop method, as they have the same
2512  // behaviour regardless)
2513  cache->functionalAccess(pkt, false);
2514 }
2515 
2516 void
2518 {
2519  // sanity check
2520  assert(!waitingOnRetry);
2521 
2522  // there should never be any deferred request packets in the
2523  // queue, instead we resly on the cache to provide the packets
2524  // from the MSHR queue or write queue
2525  assert(deferredPacketReadyTime() == MaxTick);
2526 
2527  // check for request packets (requests & writebacks)
2528  QueueEntry* entry = cache.getNextQueueEntry();
2529 
2530  if (!entry) {
2531  // can happen if e.g. we attempt a writeback and fail, but
2532  // before the retry, the writeback is eliminated because
2533  // we snoop another cache's ReadEx.
2534  } else {
2535  // let our snoop responses go first if there are responses to
2536  // the same addresses
2537  if (checkConflictingSnoop(entry->getTarget()->pkt)) {
2538  return;
2539  }
2540  waitingOnRetry = entry->sendPacket(cache);
2541  }
2542 
2543  // if we succeeded and are not waiting for a retry, schedule the
2544  // next send considering when the next queue is ready, note that
2545  // snoop responses have their own packet queue and thus schedule
2546  // their own events
2547  if (!waitingOnRetry) {
2548  schedSendEvent(cache.nextQueueReadyTime());
2549  }
2550 }
2551 
2552 BaseCache::MemSidePort::MemSidePort(const std::string &_name,
2553  BaseCache *_cache,
2554  const std::string &_label)
2555  : CacheRequestPort(_name, _cache, _reqQueue, _snoopRespQueue),
2556  _reqQueue(*_cache, *this, _snoopRespQueue, _label),
2557  _snoopRespQueue(*_cache, *this, true, _label), cache(_cache)
2558 {
2559 }
2560 
2561 void
2562 WriteAllocator::updateMode(Addr write_addr, unsigned write_size,
2563  Addr blk_addr)
2564 {
2565  // check if we are continuing where the last write ended
2566  if (nextAddr == write_addr) {
2567  delayCtr[blk_addr] = delayThreshold;
2568  // stop if we have already saturated
2569  if (mode != WriteMode::NO_ALLOCATE) {
2570  byteCount += write_size;
2571  // switch to streaming mode if we have passed the lower
2572  // threshold
2573  if (mode == WriteMode::ALLOCATE &&
2574  byteCount > coalesceLimit) {
2575  mode = WriteMode::COALESCE;
2576  DPRINTF(Cache, "Switched to write coalescing\n");
2577  } else if (mode == WriteMode::COALESCE &&
2578  byteCount > noAllocateLimit) {
2579  // and continue and switch to non-allocating mode if we
2580  // pass the upper threshold
2581  mode = WriteMode::NO_ALLOCATE;
2582  DPRINTF(Cache, "Switched to write-no-allocate\n");
2583  }
2584  }
2585  } else {
2586  // we did not see a write matching the previous one, start
2587  // over again
2588  byteCount = write_size;
2589  mode = WriteMode::ALLOCATE;
2590  resetDelay(blk_addr);
2591  }
2592  nextAddr = write_addr + write_size;
2593 }
CompressionBlk::checkExpansionContraction
OverwriteType checkExpansionContraction(const std::size_t size) const
Determines if changing the size of the block will cause a data expansion (new size is bigger) or cont...
Definition: super_blk.cc:145
BaseCache::setBlocked
void setBlocked(BlockedCause cause)
Marks the access path of the cache as blocked for the given cause.
Definition: base.hh:1223
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
Packet::isError
bool isError() const
Definition: packet.hh:584
BaseCache::Blocked_NoTargets
@ Blocked_NoTargets
Definition: base.hh:107
BaseCache::updateCompressionData
bool updateCompressionData(CacheBlk *&blk, const uint64_t *data, PacketList &writebacks)
When a block is overwriten, its compression information must be updated, and it may need to be recomp...
Definition: base.cc:881
Packet::writeThrough
bool writeThrough() const
Definition: packet.hh:703
BaseCache::ppFill
ProbePointArg< PacketPtr > * ppFill
To probe when a cache fill occurs.
Definition: base.hh:357
BaseCache::DataUpdate::oldData
std::vector< uint64_t > oldData
The stale data contents.
Definition: base.hh:123
Queue::getNext
Entry * getNext() const
Returns the WriteQueueEntry at the head of the readyList.
Definition: queue.hh:215
BaseCache::tempBlock
TempCacheBlk * tempBlock
Temporary cache block for occasional transitory use.
Definition: base.hh:388
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:63
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:462
Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1017
BaseCache::clearBlocked
void clearBlocked(BlockedCause cause)
Marks the cache as unblocked for the given cause.
Definition: base.hh:1242
BaseCache::writeBuffer
WriteQueue writeBuffer
Write/writeback buffer.
Definition: base.hh:339
queue_entry.hh
BaseCache::maintainClusivity
void maintainClusivity(bool from_cache, CacheBlk *blk)
Maintain the clusivity of this cache by potentially invalidating a block.
Definition: base.cc:1401
Packet::isResponse
bool isResponse() const
Definition: packet.hh:561
MemCmd::WritebackClean
@ WritebackClean
Definition: packet.hh:90
BaseCache::calculateAccessLatency
Cycles calculateAccessLatency(const CacheBlk *blk, const uint32_t delay, const Cycles lookup_lat) const
Calculate access latency in ticks given a tag lookup latency, and whether access was a hit or miss.
Definition: base.cc:1098
BaseCache::replaceExpansions
const bool replaceExpansions
when a data expansion of a compressed block happens it will not be able to co-allocate where it is at...
Definition: base.hh:943
warn
#define warn(...)
Definition: logging.hh:239
Request::SECURE
@ SECURE
The request targets the secure memory space.
Definition: request.hh:177
compressed_tags.hh
BaseCache::markInService
void markInService(MSHR *mshr, bool pending_modified_resp)
Mark a request as in service (sent downstream in the memory system), effectively making this MSHR the...
Definition: base.hh:400
BaseCache::CacheReqPacketQueue::sendDeferredPacket
virtual void sendDeferredPacket()
Override the normal sendDeferredPacket and do not only consider the transmit list (used for responses...
Definition: base.cc:2517
base.hh
Packet::makeTimingResponse
void makeTimingResponse()
Definition: packet.hh:1023
BaseCache::CacheResponsePort::sendRetryEvent
EventFunctionWrapper sendRetryEvent
Definition: base.hh:295
Packet::cacheResponding
bool cacheResponding() const
Definition: packet.hh:620
QueueEntry::blkAddr
Addr blkAddr
Block aligned address.
Definition: queue_entry.hh:111
BaseCache::functionalAccess
virtual void functionalAccess(PacketPtr pkt, bool from_cpu_side)
Performs the access specified by the request.
Definition: base.cc:631
data
const char data[]
Definition: circlebuf.test.cc:47
BaseCache::sequentialAccess
const bool sequentialAccess
Whether tags and data are accessed sequentially.
Definition: base.hh:914
Packet::hasSharers
bool hasSharers() const
Definition: packet.hh:647
QueueEntry::Target
A queue entry is holding packets that will be serviced as soon as resources are available.
Definition: queue_entry.hh:83
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
BaseCache::handleFill
CacheBlk * handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks, bool allocate)
Handle a fill operation caused by a received packet.
Definition: base.cc:1413
BaseCache::schedMemSideSendEvent
void schedMemSideSendEvent(Tick time)
Schedule a send event for the memory-side port.
Definition: base.hh:1261
BaseCache::CpuSidePort::recvAtomic
virtual Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the peer.
Definition: base.cc:2434
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
CacheBlk::clearCoherenceBits
void clearCoherenceBits(unsigned bits)
Clear the corresponding coherence bits.
Definition: cache_blk.hh:227
BaseCache::cmpAndSwap
void cmpAndSwap(CacheBlk *blk, PacketPtr pkt)
Handle doing the Compare and Swap function for SPARC.
Definition: base.cc:713
Packet::setCacheResponding
void setCacheResponding()
Snoop flags.
Definition: packet.hh:614
Packet::writeData
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
Definition: packet.hh:1255
CacheBlk::getWhenReady
Tick getWhenReady() const
Get tick at which block's data will be available for access.
Definition: cache_blk.hh:261
Packet::isExpressSnoop
bool isExpressSnoop() const
Definition: packet.hh:663
BaseCache::CacheResponsePort::clearBlocked
void clearBlocked()
Return to normal operation and accept new requests.
Definition: base.cc:156
BaseCache::writebackBlk
PacketPtr writebackBlk(CacheBlk *blk)
Create a writeback request for the given block.
Definition: base.cc:1597
BaseCache::CacheRequestPort
A cache request port is used for the memory-side port of the cache, and in addition to the basic timi...
Definition: base.hh:144
BaseCache::CacheCmdStats::mshrMisses
Stats::Vector mshrMisses
Number of misses that miss in the MSHRs, per command and thread.
Definition: base.hh:1014
Packet::payloadDelay
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:413
MSHR::needsWritable
bool needsWritable() const
The pending* and post* flags are only valid if inService is true.
Definition: mshr.hh:311
warn_once
#define warn_once(...)
Definition: logging.hh:243
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
BaseCache::system
System * system
System we are currently operating in.
Definition: base.hh:978
BaseCache::serviceMSHRTargets
virtual void serviceMSHRTargets(MSHR *mshr, const PacketPtr pkt, CacheBlk *blk)=0
Service non-deferred MSHR targets using the received response.
mshr.hh
Flags< FlagsType >
MSHR::getNumTargets
int getNumTargets() const
Returns the current number of allocated targets.
Definition: mshr.hh:422
BaseCache::CpuSidePort::recvTimingReq
virtual bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the peer.
Definition: base.cc:2416
BaseCache::nextQueueReadyTime
Tick nextQueueReadyTime() const
Find next request ready time from among possible sources.
Definition: base.cc:1754
CacheBlk::clearPrefetched
void clearPrefetched()
Clear the prefetching bit.
Definition: cache_blk.hh:251
Packet::hasRespData
bool hasRespData() const
Definition: packet.hh:578
base.hh
BaseCache::blkSize
const unsigned blkSize
Block size of this cache.
Definition: base.hh:880
Packet::setHasSharers
void setHasSharers()
On fills, the hasSharers flag is used by the caches in combination with the cacheResponding flag,...
Definition: packet.hh:646
SUM_NON_DEMAND
#define SUM_NON_DEMAND(s)
BaseCache::ppDataUpdate
ProbePointArg< DataUpdate > * ppDataUpdate
To probe when the contents of a block are updated.
Definition: base.hh:364
BaseCache::CacheResponsePort::blocked
bool blocked
Definition: base.hh:287
Clocked::tick
Tick tick
Definition: clocked_object.hh:65
Packet::setSatisfied
void setSatisfied()
Set when a request hits in a cache and the cache is not going to respond.
Definition: packet.hh:710
Packet::isRead
bool isRead() const
Definition: packet.hh:557
Packet::fromCache
bool fromCache() const
Definition: packet.hh:575
MemCmd::CleanEvict
@ CleanEvict
Definition: packet.hh:92
MSHRQueue::markPending
void markPending(MSHR *mshr)
Mark an in service entry as pending, used to resend a request.
Definition: mshr_queue.cc:104
ProbePointArg
ProbePointArg generates a point for the class of Arg.
Definition: thermal_domain.hh:51
BaseCache::CacheCmdStats::mshrUncacheableLatency
Stats::Vector mshrUncacheableLatency
Total cycle latency of each MSHR miss, per command and thread.
Definition: base.hh:1020
BaseCache::noTargetMSHR
MSHR * noTargetMSHR
Pointer to the MSHR that has no targets.
Definition: base.hh:966
UNIT_TICK
#define UNIT_TICK
Definition: units.hh:40
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
BaseCache::memSidePort
MemSidePort memSidePort
Definition: base.hh:331
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:243
Packet::isAtomicOp
bool isAtomicOp() const
Definition: packet.hh:794
BaseCache::getNextQueueEntry
QueueEntry * getNextQueueEntry()
Return the next queue entry to service, either a pending miss from the MSHR queue,...
Definition: base.cc:766
Packet::pushLabel
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1394
Stats::Group::Group
Group()=delete
Packet::needsWritable
bool needsWritable() const
Definition: packet.hh:562
Packet::isInvalidate
bool isInvalidate() const
Definition: packet.hh:572
MSHR::allocOnFill
bool allocOnFill() const
Definition: mshr.hh:332
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:86
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:341
BaseCache::writebackTempBlockAtomicEvent
EventFunctionWrapper writebackTempBlockAtomicEvent
An event to writeback the tempBlock after recvAtomic finishes.
Definition: base.hh:695
Packet::isEviction
bool isEviction() const
Definition: packet.hh:573
BaseTags::accessBlock
virtual CacheBlk * accessBlock(Addr addr, bool is_secure, Cycles &lat)=0
Access block and update replacement data.
Packet::isLLSC
bool isLLSC() const
Definition: packet.hh:583
EventManager::deschedule
void deschedule(Event &event)
Definition: eventq.hh:1025
std::vector< uint64_t >
QueueEntry::Target::recvTime
const Tick recvTime
Time when request was received (for stats)
Definition: queue_entry.hh:85
BaseCache::handleTimingReqHit
virtual void handleTimingReqHit(PacketPtr pkt, CacheBlk *blk, Tick request_time)
Definition: base.cc:220
BaseCache::MemSidePort::recvFunctionalSnoop
virtual void recvFunctionalSnoop(PacketPtr pkt)
Receive a functional snoop request packet from the peer.
Definition: base.cc:2505
BaseTags::moveBlock
virtual void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
Move a block's metadata to another location decided by the replacement policy.
Definition: base.cc:127
Packet::getSize
unsigned getSize() const
Definition: packet.hh:765
RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:482
CompressionBlk::DATA_EXPANSION
@ DATA_EXPANSION
New data contents are considered larger than previous contents.
Definition: super_blk.hh:78
MemCmd::HardPFResp
@ HardPFResp
Definition: packet.hh:97
Packet::isRequest
bool isRequest() const
Definition: packet.hh:560
BaseCache::allocateBlock
CacheBlk * allocateBlock(const PacketPtr pkt, PacketList &writebacks)
Allocate a new block and perform any necessary writebacks.
Definition: base.cc:1511
QueuedResponsePort::schedTimingResp
void schedTimingResp(PacketPtr pkt, Tick when)
Schedule the sending of a timing response.
Definition: qport.hh:90
Stats::reset
void reset()
Definition: statistics.cc:299
BaseCache::addrRanges
const AddrRangeList addrRanges
The address range to which the cache responds on the CPU side.
Definition: base.hh:974
Request::wbRequestorId
@ wbRequestorId
This requestor id is used for writeback requests by the caches.
Definition: request.hh:247
BaseCache::DataUpdate::newData
std::vector< uint64_t > newData
The new data contents.
Definition: base.hh:125
BaseCache::clusivity
const Enums::Clusivity clusivity
Clusivity with respect to the upstream cache, determining if we fill into both this cache and the cac...
Definition: base.hh:927
BaseCache::CacheCmdStats::regStatsFromParent
void regStatsFromParent()
Callback to register stats from parent CacheStats::regStats().
Definition: base.cc:1966
EventBase::Delayed_Writeback_Pri
static const Priority Delayed_Writeback_Pri
For some reason "delayed" inter-cluster writebacks are scheduled before regular writebacks (which hav...
Definition: eventq.hh:169
BaseCache::CacheCmdStats::mshrHits
Stats::Vector mshrHits
Number of misses that hit in the MSHRs per command and thread.
Definition: base.hh:1012
BaseCache::numTarget
const int numTarget
The number of targets for each MSHR.
Definition: base.hh:917
BaseCache::MemSidePort::MemSidePort
MemSidePort(const std::string &_name, BaseCache *_cache, const std::string &_label)
Definition: base.cc:2552
Packet::writeDataToBlock
void writeDataToBlock(uint8_t *blk_data, int blkSize) const
Copy data from the packet to the provided block pointer, which is aligned to the given block size.
Definition: packet.hh:1279
MSHR::promoteWritable
void promoteWritable()
Promotes deferred targets that do not require writable.
Definition: mshr.cc:653
BaseCache::invalidateVisitor
void invalidateVisitor(CacheBlk &blk)
Cache block visitor that invalidates all blocks in the cache.
Definition: base.cc:1741
BaseCache::forwardLatency
const Cycles forwardLatency
This is the forward latency of the cache.
Definition: base.hh:899
Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:395
BaseCache::coalesce
bool coalesce() const
Checks if the cache is coalescing writes.
Definition: base.cc:1712
Packet::print
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
Definition: packet.cc:389
BaseCache::ppMiss
ProbePointArg< PacketPtr > * ppMiss
To probe when a cache miss occurs.
Definition: base.hh:354
Packet::isSecure
bool isSecure() const
Definition: packet.hh:784
Packet::setData
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
Definition: packet.hh:1226
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
BaseCache::CacheStats::unusedPrefetches
Stats::Scalar unusedPrefetches
The number of times a HW-prefetched block is evicted w/o reference.
Definition: base.hh:1081
BaseCache::CacheStats::replacements
Stats::Scalar replacements
Number of replacements of valid blocks.
Definition: base.hh:1121
QueueEntry::Target::pkt
const PacketPtr pkt
Pending request packet.
Definition: queue_entry.hh:88
WriteAllocator::coalesce
bool coalesce() const
Should writes be coalesced? This is true if the mode is set to NO_ALLOCATE.
Definition: base.hh:1382
TempCacheBlk::insert
void insert(const Addr addr, const bool is_secure) override
Insert the block by assigning it a tag and marking it valid.
Definition: cache_blk.hh:526
Compressor::Base::compress
virtual std::unique_ptr< CompressionData > compress(const std::vector< Chunk > &chunks, Cycles &comp_lat, Cycles &decomp_lat)=0
Apply the compression process to the cache line.
MSHR::isPendingModified
bool isPendingModified() const
Definition: mshr.hh:318
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:86
BaseTags::extractBlkOffset
int extractBlkOffset(Addr addr) const
Calculate the block offset of an address.
Definition: base.hh:222
BaseCache::CacheResponsePort::setBlocked
void setBlocked()
Do not accept any new requests.
Definition: base.cc:141
BaseCache::Blocked_NoMSHRs
@ Blocked_NoMSHRs
Definition: base.hh:105
BaseTags::invalidate
virtual void invalidate(CacheBlk *blk)
This function updates the tags when a block is invalidated.
Definition: base.hh:251
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
QueueEntry::sendPacket
virtual bool sendPacket(BaseCache &cache)=0
Send this queue entry as a downstream packet, with the exact behaviour depending on the specific entr...
BaseCache::prefetcher
Prefetcher::Base * prefetcher
Prefetcher.
Definition: base.hh:348
BaseCache::CacheStats::writebacks
Stats::Vector writebacks
Number of blocks written back per thread.
Definition: base.hh:1084
CompressionBlk::getSizeBits
std::size_t getSizeBits() const
Definition: super_blk.cc:90
BaseCache::CacheCmdStats
Definition: base.hh:980
QueueEntry::isSecure
bool isSecure
True if the entry targets the secure memory space.
Definition: queue_entry.hh:117
cp
Definition: cprintf.cc:37
Compressor::Base::setDecompressionLatency
static void setDecompressionLatency(CacheBlk *blk, const Cycles lat)
Set the decompression latency of compressed block.
Definition: base.cc:209
SectorBlk::blks
std::vector< SectorSubBlk * > blks
List of blocks associated to this sector.
Definition: sector_blk.hh:144
BaseCache::incMissCount
void incMissCount(PacketPtr pkt)
Definition: base.hh:1283
MemCmd::SwapReq
@ SwapReq
Definition: packet.hh:112
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1016
base.hh
BaseCache::updateBlockData
void updateBlockData(CacheBlk *blk, const PacketPtr cpkt, bool has_old_data)
Update the data contents of a block.
Definition: base.cc:687
BaseCache::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: base.cc:188
BaseCache::allocateWriteBuffer
void allocateWriteBuffer(PacketPtr pkt, Tick time)
Definition: base.hh:1178
Clocked::cyclesToTicks
Tick cyclesToTicks(Cycles c) const
Definition: clocked_object.hh:224
MSHR::promoteDeferredTargets
bool promoteDeferredTargets()
Definition: mshr.cc:570
BaseCache::mshrQueue
MSHRQueue mshrQueue
Miss status registers.
Definition: base.hh:336
Packet::setWriteThrough
void setWriteThrough()
A writeback/writeclean cmd gets propagated further downstream by the receiver when the flag is set.
Definition: packet.hh:696
BaseTags::regenerateBlkAddr
virtual Addr regenerateBlkAddr(const CacheBlk *blk) const =0
Regenerate the block address.
BaseCache::CacheResponsePort::CacheResponsePort
CacheResponsePort(const std::string &_name, BaseCache *_cache, const std::string &_label)
Definition: base.cc:65
MemCmd::WritebackDirty
@ WritebackDirty
Definition: packet.hh:89
BaseCache::regenerateBlkAddr
Addr regenerateBlkAddr(CacheBlk *blk)
Regenerate block address using tags.
Definition: base.cc:178
RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:492
BaseCache::cpuSidePort
CpuSidePort cpuSidePort
Definition: base.hh:330
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:120
System
Definition: system.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
WriteAllocator::delay
bool delay(Addr blk_addr)
Access whether we need to delay the current write.
Definition: base.hh:1413
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:71
BaseCache::allocOnFill
bool allocOnFill(MemCmd cmd) const
Determine whether we should allocate on a fill or not.
Definition: base.hh:433
BaseCache::stats
BaseCache::CacheStats stats
MemCmd
Definition: packet.hh:72
BaseCache::pendingDelete
std::unique_ptr< Packet > pendingDelete
Upstream caches need this packet until true is returned, so hold it for deletion until a subsequent c...
Definition: base.hh:394
Packet::getBlockAddr
Addr getBlockAddr(unsigned int blk_size) const
Definition: packet.hh:779
BaseCache::blocked
uint8_t blocked
Bit vector of the blocking reasons for the access path.
Definition: base.hh:957
TaggedEntry::isSecure
bool isSecure() const
Check if this block holds data from the secure memory space.
Definition: tagged_entry.hh:61
BaseCache::invalidateBlock
void invalidateBlock(CacheBlk *blk)
Invalidate a cache block.
Definition: base.cc:1568
BaseCache::serialize
void serialize(CheckpointOut &cp) const override
Serialize the state of the caches.
Definition: base.cc:1898
BaseCache::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: base.cc:197
MSHRQueue::delay
void delay(MSHR *mshr, Tick delay_ticks)
Adds a delay to the provided MSHR and moves MSHRs that will be ready earlier than this entry to the t...
Definition: mshr_queue.cc:85
BaseCache::handleUncacheableWriteResp
void handleUncacheableWriteResp(PacketPtr pkt)
Handling the special case of uncacheable write responses to make recvTimingResp less cluttered.
Definition: base.cc:400
BaseTags::insertBlock
virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk)
Insert the new block into the cache and update stats.
Definition: base.cc:99
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Packet::needsResponse
bool needsResponse() const
Definition: packet.hh:571
MipsISA::r
r
Definition: pra_constants.hh:95
BaseCache::recvTimingReq
virtual void recvTimingReq(PacketPtr pkt)
Performs the access specified by the request.
Definition: base.cc:344
Compressor::Base::getDecompressionLatency
Cycles getDecompressionLatency(const CacheBlk *blk)
Get the decompression latency if the block is compressed.
Definition: base.cc:191
BaseCache::CacheCmdStats::CacheCmdStats
CacheCmdStats(BaseCache &c, const std::string &name)
Definition: base.cc:1930
BaseTags::anyBlk
virtual bool anyBlk(std::function< bool(CacheBlk &)> visitor)=0
Find if any of the blocks satisfies a condition.
Clocked::clockEdge
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Definition: clocked_object.hh:174
Packet::getAtomicOp
AtomicOpFunctor * getAtomicOp() const
Accessor function to atomic op.
Definition: packet.hh:793
Packet::setDataFromBlock
void setDataFromBlock(const uint8_t *blk_data, int blkSize)
Copy data into the packet from the provided block pointer, which is aligned to the given block size.
Definition: packet.hh:1245
BaseCache::handleAtomicReqMiss
virtual Cycles handleAtomicReqMiss(PacketPtr pkt, CacheBlk *&blk, PacketList &writebacks)=0
Handle a request in atomic mode that missed in this cache.
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
QueueEntry::getTarget
virtual Target * getTarget()=0
Returns a pointer to the first target.
BaseCache::fillLatency
const Cycles fillLatency
The latency to fill a cache block.
Definition: base.hh:902
BaseCache::forwardSnoops
bool forwardSnoops
Do we forward snoops from mem side port through to cpu side port?
Definition: base.hh:920
chatty_assert
#define chatty_assert(cond,...)
The chatty assert macro will function like a normal assert, but will allow the specification of addit...
Definition: logging.hh:292
BaseCache::regProbePoints
void regProbePoints() override
Registers probes.
Definition: base.cc:2372
Queue::deallocate
void deallocate(Entry *entry)
Removes the given entry from the queue.
Definition: queue.hh:234
ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:288
BaseCache::MemSidePort::recvAtomicSnoop
virtual Tick recvAtomicSnoop(PacketPtr pkt)
Receive an atomic snoop request packet from our peer.
Definition: base.cc:2496
BaseCache::CacheStats::dataContractions
Stats::Scalar dataContractions
Number of data contractions (blocks that had their compression factor improved).
Definition: base.hh:1130
BaseCache::writecleanBlk
PacketPtr writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id)
Create a writeclean request for the given block.
Definition: base.cc:1647
BaseCache::access
virtual bool access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, PacketList &writebacks)
Does all the processing necessary to perform the provided request.
Definition: base.cc:1132
BaseCache::NUM_BLOCKED_CAUSES
@ NUM_BLOCKED_CAUSES
Definition: base.hh:108
BaseCache::isReadOnly
const bool isReadOnly
Is this cache read only, for example the instruction cache, or table-walker cache.
Definition: base.hh:935
Packet::getOffset
Addr getOffset(unsigned int blk_size) const
Definition: packet.hh:774
QueuedResponsePort
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
Definition: qport.hh:58
BaseCache::sendMSHRQueuePacket
virtual bool sendMSHRQueuePacket(MSHR *mshr)
Take an MSHR, turn it into a suitable downstream packet, and send it out.
Definition: base.cc:1771
Packet::isUpgrade
bool isUpgrade() const
Definition: packet.hh:559
BaseCache::isBlocked
bool isBlocked() const
Returns true if the cache is blocked for accesses.
Definition: base.hh:1213
BaseCache::doWritebacksAtomic
virtual void doWritebacksAtomic(PacketList &writebacks)=0
Send writebacks down the memory hierarchy in atomic mode.
CacheBlk::print
std::string print() const override
Pretty-print tag, set and way, and interpret state bits to readable form including mapping to a MOESI...
Definition: cache_blk.hh:360
compiler.hh
Queue::findMatch
Entry * findMatch(Addr blk_addr, bool is_secure, bool ignore_uncacheable=true) const
Find the first entry that matches the provided address.
Definition: queue.hh:162
WriteQueueEntry::getNumTargets
int getNumTargets() const
Returns the current number of allocated targets.
Definition: write_queue_entry.hh:137
TaggedEntry::isValid
virtual bool isValid() const
Checks if the entry is valid.
Definition: tagged_entry.hh:54
BaseCache::writebackVisitor
void writebackVisitor(CacheBlk &blk)
Cache block visitor that writes back dirty cache blocks using functional writes.
Definition: base.cc:1718
BaseCache::CpuSidePort::getAddrRanges
virtual AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: base.cc:2459
CacheBlkPrintWrapper
Simple class to provide virtual print() method on cache blocks without allocating a vtable pointer fo...
Definition: cache_blk.hh:549
BaseCache::lookupLatency
const Cycles lookupLatency
The latency of tag lookup of a cache.
Definition: base.hh:886
BaseCache
A basic cache interface.
Definition: base.hh:89
BaseCache::allocateMissBuffer
MSHR * allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send=true)
Definition: base.hh:1160
CacheBlk::checkWrite
bool checkWrite(PacketPtr pkt)
Handle interaction of load-locked operations and stores.
Definition: cache_blk.hh:407
BaseCache::calculateTagOnlyLatency
Cycles calculateTagOnlyLatency(const uint32_t delay, const Cycles lookup_lat) const
Calculate latency of accesses that only touch the tag array.
Definition: base.cc:1089
MSHRQueue::canPrefetch
bool canPrefetch() const
Returns true if sufficient mshrs for prefetch.
Definition: mshr_queue.hh:150
UNIT_COUNT
#define UNIT_COUNT
Definition: units.hh:49
Packet::id
const PacketId id
Definition: packet.hh:338
CacheBlk::getTaskId
uint32_t getTaskId() const
Get the task id associated to this block.
Definition: cache_blk.hh:281
CacheBlk::WritableBit
@ WritableBit
write permission
Definition: cache_blk.hh:77
core.hh
WriteQueueEntry::getTarget
Target * getTarget() override
Returns a reference to the first target.
Definition: write_queue_entry.hh:150
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
BaseCache::createMissPacket
virtual PacketPtr createMissPacket(PacketPtr cpu_pkt, CacheBlk *blk, bool needs_writable, bool is_whole_line_write) const =0
Create an appropriate downstream bus request packet.
Packet::makeResponse
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1005
BaseCache::satisfyRequest
virtual void satisfyRequest(PacketPtr pkt, CacheBlk *blk, bool deferred_response=false, bool pending_downgrade=false)
Perform any necessary updates to the block and perform any data exchange between the packet and the b...
Definition: base.cc:991
Prefetcher::Base::nextPrefetchReadyTime
virtual Tick nextPrefetchReadyTime() const =0
CacheBlk::wasPrefetched
bool wasPrefetched() const
Check if this block was the result of a hardware prefetch, yet to be touched.
Definition: cache_blk.hh:245
name
const std::string & name()
Definition: trace.cc:48
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
QueueEntry::order
Counter order
Order number assigned to disambiguate writes and misses.
Definition: queue_entry.hh:108
Clocked::clockPeriod
Tick clockPeriod() const
Definition: clocked_object.hh:214
Request::funcRequestorId
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition: request.hh:252
QueuedRequestPort::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Check the list of buffered packets against the supplied functional request.
Definition: qport.hh:160
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:58
SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:114
CompressionBlk::setDecompressionLatency
void setDecompressionLatency(const Cycles lat)
Set number of cycles needed to decompress this block.
Definition: super_blk.cc:132
Packet::hasData
bool hasData() const
Definition: packet.hh:577
MSHR::getTarget
QueueEntry::Target * getTarget() override
Returns a reference to the first target.
Definition: mshr.hh:449
CacheBlk::isSet
bool isSet(unsigned bits) const
Checks the given coherence bits are set.
Definition: cache_blk.hh:235
CacheBlk::setCoherenceBits
void setCoherenceBits(unsigned bits)
Sets the corresponding coherence bits.
Definition: cache_blk.hh:216
BaseCache::compressor
Compressor::Base * compressor
Compression method being used.
Definition: base.hh:345
ResponsePort::owner
SimObject & owner
Definition: port.hh:276
Packet::isCleanEviction
bool isCleanEviction() const
Is this packet a clean eviction, including both actual clean evict packets, but also clean writebacks...
Definition: packet.hh:1368
BaseCache::doWritebacks
virtual void doWritebacks(PacketList &writebacks, Tick forward_time)=0
Insert writebacks into the write buffer.
UNIT_RATIO
#define UNIT_RATIO
Definition: units.hh:48
BaseCache::writebackClean
const bool writebackClean
Determine if clean lines should be written back or not.
Definition: base.hh:667
CacheBlk::setWhenReady
void setWhenReady(const Tick tick)
Set tick at which block's data will be available for access.
Definition: cache_blk.hh:274
SectorSubBlk::getSectorBlock
SectorBlk * getSectorBlock() const
Get sector block associated to this block.
Definition: sector_blk.cc:49
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
MSHR::isCleaning
bool isCleaning() const
Definition: mshr.hh:313
Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:336
UNIT_RATE
#define UNIT_RATE(T1, T2)
Definition: units.hh:47
BaseCache::MemSidePort::recvTimingResp
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Definition: base.cc:2478
BaseCache::tags
BaseTags * tags
Tag and data Storage.
Definition: base.hh:342
BaseCache::CacheCmdStats::mshrMissLatency
Stats::Vector mshrMissLatency
Total cycle latency of each MSHR miss, per command and thread.
Definition: base.hh:1018
MSHR::wasWholeLineWrite
bool wasWholeLineWrite
Track if we sent this as a whole line write or not.
Definition: mshr.hh:119
QueueEntry::inService
bool inService
True if the entry has been sent downstream.
Definition: queue_entry.hh:105
warn_if
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:263
super_blk.hh
Copyright (c) 2018 Inria All rights reserved.
MSHR::allocateTarget
void allocateTarget(PacketPtr target, Tick when, Counter order, bool alloc_on_fill)
Add a request to the list of targets.
Definition: mshr.cc:367
Queue::findPending
Entry * findPending(const QueueEntry *entry) const
Find any pending requests that overlap the given request of a different queue.
Definition: queue.hh:201
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
BaseCache::evictBlock
virtual M5_NODISCARD PacketPtr evictBlock(CacheBlk *blk)=0
Evict a cache block.
Packet::pushSenderState
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition: packet.cc:332
BaseCache::DataUpdate
A data contents update is composed of the updated block's address, the old contents,...
Definition: base.hh:116
CacheBlk::data
uint8_t * data
Contains a copy of the data in this block for easy access.
Definition: cache_blk.hh:100
BaseCache::sendWriteQueuePacket
bool sendWriteQueuePacket(WriteQueueEntry *wq_entry)
Similar to sendMSHR, but for a write-queue entry instead.
Definition: base.cc:1874
SuperBlk
A basic compression superblock.
Definition: super_blk.hh:167
CompressionBlk::setSizeBits
void setSizeBits(const std::size_t size)
Set size, in bits, of this compressed block's data.
Definition: super_blk.cc:96
WriteAllocator::resetDelay
void resetDelay(Addr blk_addr)
Clear delay counter for the input block.
Definition: base.hh:1427
CacheBlk
A Basic Cache block.
Definition: cache_blk.hh:67
System::maxRequestors
RequestorID maxRequestors()
Get the number of requestors registered in the system.
Definition: system.hh:498
WriteQueueEntry
Write queue entry.
Definition: write_queue_entry.hh:65
Packet::isClean
bool isClean() const
Definition: packet.hh:574
Clocked::ticksToCycles
Cycles ticksToCycles(Tick t) const
Definition: clocked_object.hh:219
CacheBlk::DirtyBit
@ DirtyBit
dirty (modified)
Definition: cache_blk.hh:84
BaseCache::CacheStats::dataExpansions
Stats::Scalar dataExpansions
Number of data expansions.
Definition: base.hh:1124
BaseCache::CacheResponsePort::processSendRetry
void processSendRetry()
Definition: base.cc:168
Packet::dataStatic
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1108
CacheBlk::trackLoadLocked
void trackLoadLocked(PacketPtr pkt)
Track the fact that a local locked was issued to the block.
Definition: cache_blk.hh:323
BaseCache::handleTimingReqMiss
virtual void handleTimingReqMiss(PacketPtr pkt, CacheBlk *blk, Tick forward_time, Tick request_time)=0
BaseCache::CpuSidePort::recvTimingSnoopResp
virtual bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
Definition: base.cc:2387
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
Stats::Group
Statistics container.
Definition: group.hh:87
BaseCache::writeAllocator
WriteAllocator *const writeAllocator
The writeAllocator drive optimizations for streaming writes.
Definition: base.hh:380
Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:340
CompressionBlk::OverwriteType
OverwriteType
When an overwrite happens, the data size may change an not fit in its current container any longer.
Definition: super_blk.hh:71
WriteAllocator::reset
void reset()
Reset the write allocator state, meaning that it allocates for writes and has not recorded any inform...
Definition: base.hh:1401
ResponsePort::sendFunctionalSnoop
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.hh:343
Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
Queue::isFull
bool isFull() const
Definition: queue.hh:144
WriteAllocator::allocate
bool allocate() const
Should writes allocate?
Definition: base.hh:1391
BaseTags::findBlock
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const
Finds the block in the cache without touching it.
Definition: base.cc:77
BaseCache::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: base.cc:1918
BaseCache::dataLatency
const Cycles dataLatency
The latency of data access of a cache.
Definition: base.hh:892
logging.hh
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
Packet::isWrite
bool isWrite() const
Definition: packet.hh:558
BaseCache::handleEvictions
bool handleEvictions(std::vector< CacheBlk * > &evict_blks, PacketList &writebacks)
Try to evict the given blocks.
Definition: base.cc:844
UNIT_CYCLE
#define UNIT_CYCLE
Convenience macros to declare the unit of a stat.
Definition: units.hh:39
Queue::nextReadyTime
Tick nextReadyTime() const
Definition: queue.hh:223
BaseCache::CacheResponsePort::mustSendRetry
bool mustSendRetry
Definition: base.hh:289
BaseCache::isDirty
bool isDirty() const
Determine if there are any dirty blocks in the cache.
Definition: base.cc:1705
Prefetcher::Base::getPacket
virtual PacketPtr getPacket()=0
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
SUM_DEMAND
#define SUM_DEMAND(s)
BaseCache::CacheStats::cmd
std::vector< std::unique_ptr< CacheCmdStats > > cmd
Per-command statistics.
Definition: base.hh:1133
QueueEntry
A queue entry base class, to be used by both the MSHRs and write-queue entries.
Definition: queue_entry.hh:58
System::getRequestorName
std::string getRequestorName(RequestorID requestor_id)
Get the name of an object for a given request id.
Definition: system.cc:636
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
Stats
Definition: statistics.cc:53
BaseCache::writebackTempBlockAtomic
void writebackTempBlockAtomic()
Send the outstanding tempBlock writeback.
Definition: base.hh:683
MemCmd::InvalidateResp
@ InvalidateResp
Definition: packet.hh:135
BaseCache::moveContractions
const bool moveContractions
Similar to data expansions, after a block improves its compression, it may need to be moved elsewhere...
Definition: base.hh:951
BaseTags::forEachBlk
virtual void forEachBlk(std::function< void(CacheBlk &)> visitor)=0
Visit each block in the tags and apply a visitor.
QueuedResponsePort::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Check the list of buffered packets against the supplied functional request.
Definition: qport.hh:95
TempCacheBlk::invalidate
void invalidate() override
Invalidate the block and clear all state.
Definition: cache_blk.hh:519
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
WriteAllocator::updateMode
void updateMode(Addr write_addr, unsigned write_size, Addr blk_addr)
Update the write mode based on the current write packet.
Definition: base.cc:2562
BaseCache::responseLatency
const Cycles responseLatency
The latency of sending reponse to its upper level cache/core on a linefill.
Definition: base.hh:909
BaseCache::BaseCache
BaseCache(const BaseCacheParams &p, unsigned blk_size)
Definition: base.cc:75
MemCmd::WriteClean
@ WriteClean
Definition: packet.hh:91
PacketId
uint64_t PacketId
Definition: packet.hh:70
Packet::clearBlockCached
void clearBlockCached()
Definition: packet.hh:722
BaseCache::memWriteback
virtual void memWriteback() override
Write back dirty blocks in the cache using functional accesses.
Definition: base.cc:1693
BaseCache::incHitCount
void incHitCount(PacketPtr pkt)
Definition: base.hh:1294
BaseCache::recvTimingResp
virtual void recvTimingResp(PacketPtr pkt)
Handles a response (cache line fill/write ack) from the bus.
Definition: base.cc:412
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MSHR::isWholeLineWrite
bool isWholeLineWrite() const
Check if this MSHR contains only compatible writes, and if they span the entire cache line.
Definition: mshr.hh:382
std::list
STL list class.
Definition: stl.hh:51
TempCacheBlk
Special instance of CacheBlk for use with tempBlk that deals with its block address regeneration.
Definition: cache_blk.hh:495
BaseCache::~BaseCache
~BaseCache()
Definition: base.cc:135
MSHR::isForward
bool isForward
True if the entry is just a simple forward from an upper level.
Definition: mshr.hh:122
Packet::isWriteback
bool isWriteback() const
Definition: packet.hh:576
Packet::allocate
void allocate()
Allocate memory for the packet.
Definition: packet.hh:1300
CacheBlk::ReadableBit
@ ReadableBit
Read permission.
Definition: cache_blk.hh:82
Cache
A coherent cache that can be arranged in flexible topologies.
Definition: cache.hh:63
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
BaseCache::CpuSidePort::tryTiming
virtual bool tryTiming(PacketPtr pkt) override
Availability request from the peer.
Definition: base.cc:2401
BaseCache::recvAtomic
virtual Tick recvAtomic(PacketPtr pkt)
Performs the access specified by the request.
Definition: base.cc:551
Stats::total
const FlagsType total
Print the total.
Definition: info.hh:50
CheckpointIn
Definition: serialize.hh:68
BaseTags::findVictim
virtual CacheBlk * findVictim(Addr addr, const bool is_secure, const std::size_t size, std::vector< CacheBlk * > &evict_blks)=0
Find replacement victim based on address.
ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:293
Packet::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr other)
Check a functional request against a memory value stored in another packet (i.e.
Definition: packet.hh:1332
MSHR::promoteReadable
void promoteReadable()
Promotes deferred targets that do not require writable.
Definition: mshr.cc:632
BaseCache::CacheStats::regStats
void regStats() override
Callback to set stat parameters.
Definition: base.cc:2156
Compressor::Base::setSizeBits
static void setSizeBits(CacheBlk *blk, const std::size_t size_bits)
Set the size of the compressed block, in bits.
Definition: base.cc:219
BaseCache::CacheStats::CacheStats
CacheStats(BaseCache &c)
Definition: base.cc:2090
BaseCache::tempBlockWriteback
PacketPtr tempBlockWriteback
Writebacks from the tempBlock, resulting on the response path in atomic mode, must happen after the c...
Definition: base.hh:676
CompressedTags
A CompressedTags cache tag store.
Definition: compressed_tags.hh:67
Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1167
CompressionBlk
A superblock is composed of sub-blocks, and each sub-block has information regarding its superblock a...
Definition: super_blk.hh:48
BaseCache::CacheStats::cmdStats
CacheCmdStats & cmdStats(const PacketPtr p)
Definition: base.hh:1035
BaseCache::memInvalidate
virtual void memInvalidate() override
Invalidates all blocks in the cache.
Definition: base.cc:1699
MaxTick
const Tick MaxTick
Definition: types.hh:61
BaseCache::CpuSidePort::CpuSidePort
CpuSidePort(const std::string &_name, BaseCache *_cache, const std::string &_label)
Definition: base.cc:2466
BaseCache::CpuSidePort::recvFunctional
virtual void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the peer.
Definition: base.cc:2445
BaseCache::inRange
bool inRange(Addr addr) const
Determine if an address is in the ranges covered by this cache.
Definition: base.cc:209
MemCmd::NUM_MEM_CMDS
@ NUM_MEM_CMDS
Definition: packet.hh:140
CompressionBlk::DATA_CONTRACTION
@ DATA_CONTRACTION
New data contents are considered smaller than previous contents.
Definition: super_blk.hh:74
BaseCache::ppHit
ProbePointArg< PacketPtr > * ppHit
To probe when a cache hit occurs.
Definition: base.hh:351
Queue::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Definition: queue.hh:180
MemCmd::UpgradeResp
@ UpgradeResp
Definition: packet.hh:101
Stats::nonan
const FlagsType nonan
Don't print if this is NAN.
Definition: info.hh:60
BaseCache::MemSidePort::recvTimingSnoopReq
virtual void recvTimingSnoopReq(PacketPtr pkt)
Receive a timing snoop request from the peer.
Definition: base.cc:2486
Packet::popLabel
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1404
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
BaseCache::CacheResponsePort
A cache response port is used for the CPU-side port of the cache, and it is basically a simple timing...
Definition: base.hh:266
MSHR
Miss Status and handling Register.
Definition: mshr.hh:69
TempCacheBlk::getAddr
Addr getAddr() const
Get block's address.
Definition: cache_blk.hh:537
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
BaseCache::order
uint64_t order
Increasing order number assigned to each incoming request.
Definition: base.hh:960

Generated on Tue Mar 23 2021 19:41:24 for gem5 by doxygen 1.8.17