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

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17