gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015-2016 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  * Authors: Erik Hallnor
41  * Steve Reinhardt
42  * Ron Dreslinski
43  */
44 
50 #ifndef __MEM_CACHE_BASE_HH__
51 #define __MEM_CACHE_BASE_HH__
52 
53 #include <algorithm>
54 #include <list>
55 #include <string>
56 #include <vector>
57 
58 #include "base/misc.hh"
59 #include "base/statistics.hh"
60 #include "base/trace.hh"
61 #include "base/types.hh"
62 #include "debug/Cache.hh"
63 #include "debug/CachePort.hh"
64 #include "mem/cache/mshr_queue.hh"
65 #include "mem/cache/write_queue.hh"
66 #include "mem/mem_object.hh"
67 #include "mem/packet.hh"
68 #include "mem/qport.hh"
69 #include "mem/request.hh"
70 #include "params/BaseCache.hh"
71 #include "sim/eventq.hh"
72 #include "sim/full_system.hh"
73 #include "sim/sim_exit.hh"
74 #include "sim/system.hh"
75 
79 class BaseCache : public MemObject
80 {
81  protected:
88  };
89 
90  public:
94  enum BlockedCause {
99  };
100 
101  protected:
102 
113  {
114 
115  public:
116 
121  void schedSendEvent(Tick time)
122  {
123  DPRINTF(CachePort, "Scheduling send event at %llu\n", time);
124  reqQueue.schedSendEvent(time);
125  }
126 
127  protected:
128 
129  CacheMasterPort(const std::string &_name, BaseCache *_cache,
130  ReqPacketQueue &_reqQueue,
131  SnoopRespPacketQueue &_snoopRespQueue) :
132  QueuedMasterPort(_name, _cache, _reqQueue, _snoopRespQueue)
133  { }
134 
140  virtual bool isSnooping() const { return true; }
141  };
142 
152  {
153 
154  public:
155 
157  void setBlocked();
158 
160  void clearBlocked();
161 
162  bool isBlocked() const { return blocked; }
163 
164  protected:
165 
166  CacheSlavePort(const std::string &_name, BaseCache *_cache,
167  const std::string &_label);
168 
171 
172  bool blocked;
173 
175 
176  private:
177 
178  void processSendRetry();
179 
182 
183  };
184 
187 
188  protected:
189 
192 
195 
200  void markInService(MSHR *mshr, bool pending_modified_resp)
201  {
202  bool wasFull = mshrQueue.isFull();
203  mshrQueue.markInService(mshr, pending_modified_resp);
204 
205  if (wasFull && !mshrQueue.isFull()) {
207  }
208  }
209 
211  {
212  bool wasFull = writeBuffer.isFull();
213  writeBuffer.markInService(entry);
214 
215  if (wasFull && !writeBuffer.isFull()) {
217  }
218  }
219 
227  virtual bool allocOnFill(MemCmd cmd) const = 0;
228 
232  virtual void memWriteback() = 0;
240  virtual void memInvalidate() = 0;
246  virtual bool isDirty() const = 0;
247 
256  bool inRange(Addr addr) const;
257 
259  const unsigned blkSize;
260 
266 
272 
279 
282 
289 
291  const int numTarget;
292 
295 
302  const bool isReadOnly;
303 
308  uint8_t blocked;
309 
311  uint64_t order;
312 
315 
318 
321 
326 
327  public:
330 
331  // Statistics
344 
352 
362 
369 
376 
383 
388 
391 
394 
397 
404 
411 
416 
423 
428 
429 #if 0
430 
431  Stats::Formula mshrAccesses[MemCmd::NUM_MEM_CMDS];
433  Stats::Formula demandMshrAccesses;
435  Stats::Formula overallMshrAccesses;
436 #endif
437 
444 
451 
456 
464  virtual void regStats();
465 
466  public:
467  BaseCache(const BaseCacheParams *p, unsigned blk_size);
469 
470  virtual void init();
471 
472  virtual BaseMasterPort &getMasterPort(const std::string &if_name,
473  PortID idx = InvalidPortID);
474  virtual BaseSlavePort &getSlavePort(const std::string &if_name,
475  PortID idx = InvalidPortID);
476 
481  unsigned
482  getBlockSize() const
483  {
484  return blkSize;
485  }
486 
487  const AddrRangeList &getAddrRanges() const { return addrRanges; }
488 
489  MSHR *allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send = true)
490  {
492  pkt, time, order++,
493  allocOnFill(pkt->cmd));
494 
495  if (mshrQueue.isFull()) {
497  }
498 
499  if (sched_send) {
500  // schedule the send
501  schedMemSideSendEvent(time);
502  }
503 
504  return mshr;
505  }
506 
508  {
509  // should only see writes or clean evicts here
510  assert(pkt->isWrite() || pkt->cmd == MemCmd::CleanEvict);
511 
512  Addr blk_addr = pkt->getBlockAddr(blkSize);
513 
514  WriteQueueEntry *wq_entry =
515  writeBuffer.findMatch(blk_addr, pkt->isSecure());
516  if (wq_entry && !wq_entry->inService) {
517  DPRINTF(Cache, "Potential to merge writeback %s", pkt->print());
518  }
519 
520  writeBuffer.allocate(blk_addr, blkSize, pkt, time, order++);
521 
522  if (writeBuffer.isFull()) {
524  }
525 
526  // schedule the send
527  schedMemSideSendEvent(time);
528  }
529 
533  bool isBlocked() const
534  {
535  return blocked != 0;
536  }
537 
544  {
545  uint8_t flag = 1 << cause;
546  if (blocked == 0) {
547  blocked_causes[cause]++;
550  }
551  blocked |= flag;
552  DPRINTF(Cache,"Blocking for cause %d, mask=%d\n", cause, blocked);
553  }
554 
563  {
564  uint8_t flag = 1 << cause;
565  blocked &= ~flag;
566  DPRINTF(Cache,"Unblocking for cause %d, mask=%d\n", cause, blocked);
567  if (blocked == 0) {
568  blocked_cycles[cause] += curCycle() - blockedCycle;
570  }
571  }
572 
582  {
584  }
585 
586  virtual bool inCache(Addr addr, bool is_secure) const = 0;
587 
588  virtual bool inMissQueue(Addr addr, bool is_secure) const = 0;
589 
591  {
592  assert(pkt->req->masterId() < system->maxMasters());
593  misses[pkt->cmdToIndex()][pkt->req->masterId()]++;
594  pkt->req->incAccessDepth();
595  if (missCount) {
596  --missCount;
597  if (missCount == 0)
598  exitSimLoop("A cache reached the maximum miss count");
599  }
600  }
602  {
603  assert(pkt->req->masterId() < system->maxMasters());
604  hits[pkt->cmdToIndex()][pkt->req->masterId()]++;
605 
606  }
607 
608 };
609 
610 #endif //__MEM_CACHE_BASE_HH__
Entry * findMatch(Addr blk_addr, bool is_secure) const
Find the first WriteQueueEntry that matches the provided address.
Definition: queue.hh:156
bool isSecure() const
Definition: packet.hh:661
Stats::Formula demandMshrMissRate
The demand miss rate in the MSHRs.
Definition: base.hh:441
#define DPRINTF(x,...)
Definition: trace.hh:212
virtual void regStats()
Register stats for this object.
Definition: base.cc:178
bool forwardSnoops
Do we forward snoops from mem side port through to cpu side port?
Definition: base.hh:294
BaseCache(const BaseCacheParams *p, unsigned blk_size)
Definition: base.cc:69
Stats::Formula overallMisses
Number of misses for all accesses.
Definition: base.hh:351
bool inService
True if the entry has been sent downstream.
Definition: queue_entry.hh:80
virtual bool allocOnFill(MemCmd cmd) const =0
Determine if we should allocate on a fill or not.
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
A Class for maintaining a list of pending and allocated memory requests.
Definition: mshr_queue.hh:59
Definition: packet.hh:73
bool isBlocked() const
Returns true if the cache is blocked for accesses.
Definition: base.hh:533
Stats::Formula demandMissRate
The miss rate of all demand accesses.
Definition: base.hh:373
const PortID InvalidPortID
Definition: types.hh:182
WriteQueue writeBuffer
Write/writeback buffer.
Definition: base.hh:194
bool isBlocked() const
Definition: base.hh:162
MSHR * noTargetMSHR
Pointer to the MSHR that has no targets.
Definition: base.hh:317
Stats::Formula demandMshrMisses
Demand misses that miss in the MSHRs.
Definition: base.hh:408
const Cycles lookupLatency
The latency of tag lookup of a cache.
Definition: base.hh:265
Stats::Scalar unusedPrefetches
The number of times a HW-prefetched block is evicted w/o reference.
Definition: base.hh:393
Stats::Formula demandAvgMshrMissLatency
The average latency of a demand MSHR miss.
Definition: base.hh:448
A write queue for all eviction packets, i.e.
Definition: write_queue.hh:57
Stats::Formula avgMshrMissLatency[MemCmd::NUM_MEM_CMDS]
The average latency of an MSHR miss, per command and thread.
Definition: base.hh:446
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
bool isFull() const
Definition: queue.hh:140
virtual BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
Definition: base.cc:157
Addr getBlockAddr(unsigned int blk_size) const
Definition: packet.hh:656
The QueuedMasterPort combines two queues, a request queue and a snoop response queue, that both share the same port.
Definition: qport.hh:107
ip6_addr_t addr
Definition: inet.hh:335
MemObject declaration.
bool isWrite() const
Definition: packet.hh:503
System * system
System we are currently operating in.
Definition: base.hh:329
Stats::Formula demandHits
Number of hits for demand accesses.
Definition: base.hh:341
const bool isReadOnly
Is this cache read only, for example the instruction cache, or table-walker cache.
Definition: base.hh:302
CacheSlavePort * cpuSidePort
Definition: base.hh:185
const AddrRangeList addrRanges
The address range to which the cache responds on the CPU side.
Definition: base.hh:325
bool inRange(Addr addr) const
Determine if an address is in the ranges covered by this cache.
Definition: base.cc:167
MSHR * allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send=true)
Definition: base.hh:489
Definition: system.hh:83
A vector of scalar stats.
Definition: statistics.hh:2499
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
Definition: qport.hh:59
const Cycles dataLatency
The latency of data access of a cache.
Definition: base.hh:271
virtual void memWriteback()=0
Write back dirty blocks in the cache using functional accesses.
int cmdToIndex() const
Return the index of this command.
Definition: packet.hh:500
Stats::Formula accesses[MemCmd::NUM_MEM_CMDS]
The number of accesses per command and thread.
Definition: base.hh:364
const Cycles fillLatency
The latency to fill a cache block.
Definition: base.hh:281
void markInService(WriteQueueEntry *entry)
Mark the given entry as in service.
Definition: write_queue.cc:76
void schedSendEvent(Tick when)
Schedule a send event if we are not already waiting for a retry.
Declaration of a structure to manage MSHRs.
virtual bool inMissQueue(Addr addr, bool is_secure) const =0
Stats::Formula overallMshrMisses
Total number of misses that miss in the MSHRs.
Definition: base.hh:410
A BaseSlavePort is a protocol-agnostic slave port, responsible only for the structural connection to ...
Definition: port.hh:139
Declaration of Statistics objects.
Stats::Formula demandAccesses
The number of demand accesses.
Definition: base.hh:366
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
Stats::Vector blocked_cycles
The total number of cycles blocked for each blocked cause.
Definition: base.hh:385
Stats::Vector blocked_causes
The number of times this cache blocked for each blocked cause.
Definition: base.hh:387
Stats::Vector hits[MemCmd::NUM_MEM_CMDS]
Number of hits per thread for each type of command.
Definition: base.hh:339
Stats::Vector mshr_uncacheable_lat[MemCmd::NUM_MEM_CMDS]
Total cycle latency of each MSHR miss, per command and thread.
Definition: base.hh:425
Stats::Formula overallAvgMshrUncacheableLatency
The average overall latency of an MSHR miss.
Definition: base.hh:455
void markInService(WriteQueueEntry *entry)
Definition: base.hh:210
const Cycles responseLatency
The latency of sending reponse to its upper level cache/core on a linefill.
Definition: base.hh:288
Stats::Formula overallMissLatency
Total number of cycles spent waiting for all misses.
Definition: base.hh:361
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Stats::Formula avgMissLatency[MemCmd::NUM_MEM_CMDS]
The average miss latency per command and thread.
Definition: base.hh:378
A template-policy based cache.
Definition: cache.hh:74
Declaration of the queued port.
Cycles blockedCycle
Stores time the cache blocked for statistics.
Definition: base.hh:314
Stats::Formula demandAvgMissLatency
The average miss latency for demand misses.
Definition: base.hh:380
EventWrapper< CacheSlavePort,&CacheSlavePort::processSendRetry > sendRetryEvent
Definition: base.hh:181
Stats::Formula overallMshrUncacheable
Total number of misses that miss in the MSHRs.
Definition: base.hh:415
A cache master port is used for the memory-side port of the cache, and in addition to the basic timin...
Definition: base.hh:112
CacheSlavePort(const std::string &_name, BaseCache *_cache, const std::string &_label)
Definition: base.cc:61
CacheMasterPort(const std::string &_name, BaseCache *_cache, ReqPacketQueue &_reqQueue, SnoopRespPacketQueue &_snoopRespQueue)
Definition: base.hh:129
Stats::Formula demandMshrHits
Demand misses that hit in the MSHRs.
Definition: base.hh:401
Stats::Formula overallAvgMissLatency
The average miss latency for all misses.
Definition: base.hh:382
const AddrRangeList & getAddrRanges() const
Definition: base.hh:487
Stats::Vector writebacks
Number of blocks written back per thread.
Definition: base.hh:396
MSHR * allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, Tick when_ready, Counter order, bool alloc_on_fill)
Allocates a new MSHR for the request and size.
Definition: mshr_queue.cc:59
Stats::Formula overallMshrHits
Total number of misses that hit in the MSHRs.
Definition: base.hh:403
virtual void memInvalidate()=0
Invalidates all blocks in the cache.
uint64_t Tick
Tick count type.
Definition: types.hh:63
void incMissCount(PacketPtr pkt)
Definition: base.hh:590
Stats::Formula demandMisses
Number of misses for demand accesses.
Definition: base.hh:349
CacheMasterPort * memSidePort
Definition: base.hh:186
Stats::Formula missRate[MemCmd::NUM_MEM_CMDS]
The miss rate per command and thread.
Definition: base.hh:371
Miss Status and handling Register.
Definition: mshr.hh:63
void markInService(MSHR *mshr, bool pending_modified_resp)
Mark the given MSHR as in service.
Definition: mshr_queue.cc:86
const RequestPtr req
A pointer to the original request.
Definition: packet.hh:304
void allocateWriteBuffer(PacketPtr pkt, Tick time)
Definition: base.hh:507
A basic cache interface.
Definition: base.hh:79
Stats::Vector missLatency[MemCmd::NUM_MEM_CMDS]
Total number of cycles per thread/command spent waiting for a miss.
Definition: base.hh:357
Stats::Formula overallMshrMissLatency
Total cycle latency of overall MSHR misses.
Definition: base.hh:422
virtual bool inCache(Addr addr, bool is_secure) const =0
void setBlocked()
Do not accept any new requests.
Definition: base.cc:101
Stats::Formula overallMshrUncacheableLatency
Total cycle latency of overall MSHR misses.
Definition: base.hh:427
uint8_t blocked
Bit vector of the blocking reasons for the access path.
Definition: base.hh:308
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
void schedMemSideSendEvent(Tick time)
Schedule a send event for the memory-side port.
Definition: base.hh:581
Stats::Vector mshr_misses[MemCmd::NUM_MEM_CMDS]
Number of misses that miss in the MSHRs, per command and thread.
Definition: base.hh:406
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
const unsigned blkSize
Block size of this cache.
Definition: base.hh:259
int64_t Counter
Statistics counter type.
Definition: types.hh:58
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
virtual BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
Definition: base.cc:147
Stats::Vector mshr_hits[MemCmd::NUM_MEM_CMDS]
Number of misses that hit in the MSHRs per command and thread.
Definition: base.hh:399
uint64_t order
Increasing order number assigned to each incoming request.
Definition: base.hh:311
Stats::Formula avgMshrUncacheableLatency[MemCmd::NUM_MEM_CMDS]
The average latency of an MSHR miss, per command and thread.
Definition: base.hh:453
Stats::Formula avg_blocked
The average number of cycles blocked for each blocked cause.
Definition: base.hh:390
MasterID maxMasters()
Get the number of masters registered in the system.
Definition: system.hh:344
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
MasterID masterId() const
Accesssor for the requestor id.
Definition: request.hh:624
Stats::Formula mshrMissRate[MemCmd::NUM_MEM_CMDS]
The miss rate in the MSHRs pre command and thread.
Definition: base.hh:439
Stats::Vector misses[MemCmd::NUM_MEM_CMDS]
Number of misses per thread for each type of command.
Definition: base.hh:347
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
Definition: sim_events.cc:83
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:200
Stats::Vector mshr_miss_latency[MemCmd::NUM_MEM_CMDS]
Total cycle latency of each MSHR miss, per command and thread.
Definition: base.hh:418
ReqPacketQueue & reqQueue
Packet queue used to store outgoing requests.
Definition: qport.hh:113
Declaration of the Packet class.
A cache slave port is used for the CPU-side port of the cache, and it is basically a simple timing po...
Definition: base.hh:151
Stats::Formula overallAvgMshrMissLatency
The average overall latency of an MSHR miss.
Definition: base.hh:450
void schedSendEvent(Tick time)
Schedule a send of a request packet (from the MSHR).
Definition: base.hh:121
void setBlocked(BlockedCause cause)
Marks the access path of the cache as blocked for the given cause.
Definition: base.hh:543
virtual bool isDirty() const =0
Determine if there are any dirty blocks in the cache.
MemCmd cmd
The command field of the packet.
Definition: packet.hh:301
virtual bool isSnooping() const
Memory-side port always snoops.
Definition: base.hh:140
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
RespPacketQueue queue
A normal packet queue used to store responses.
Definition: base.hh:170
Stats::Vector mshr_uncacheable[MemCmd::NUM_MEM_CMDS]
Number of misses that miss in the MSHRs, per command and thread.
Definition: base.hh:413
BlockedCause
Reasons for caches to be blocked.
Definition: base.hh:94
MSHRQueueIndex
Indexes to enumerate the MSHR queues.
Definition: base.hh:85
unsigned getBlockSize() const
Query block size of a cache.
Definition: base.hh:482
~BaseCache()
Definition: base.hh:468
const int numTarget
The number of targets for each MSHR.
Definition: base.hh:291
const Cycles forwardLatency
This is the forward latency of the cache.
Definition: base.hh:278
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
Stats::Formula overallMshrMissRate
The overall miss rate in the MSHRs.
Definition: base.hh:443
Counter missCount
The number of misses to trigger an exit event.
Definition: base.hh:320
Stats::Formula demandMissLatency
Total number of cycles spent waiting for demand misses.
Definition: base.hh:359
Write queue entry.
Stats::Formula overallAccesses
The number of overall accesses.
Definition: base.hh:368
Stats::Formula demandMshrMissLatency
Total cycle latency of demand MSHR misses.
Definition: base.hh:420
Bitfield< 0 > p
WriteQueueEntry * allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, Tick when_ready, Counter order)
Allocates a new WriteQueueEntry for the request and size.
Definition: write_queue.cc:59
Stats::Formula overallHits
Number of hit for all accesses.
Definition: base.hh:343
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: base.cc:138
void incHitCount(PacketPtr pkt)
Definition: base.hh:601
void incAccessDepth() const
Increment/Get the depth at which this request is responded to.
Definition: request.hh:725
Stats::Formula overallMissRate
The miss rate for all accesses.
Definition: base.hh:375
void clearBlocked(BlockedCause cause)
Marks the cache as unblocked for the given cause.
Definition: base.hh:562
MSHRQueue mshrQueue
Miss status registers.
Definition: base.hh:191
void clearBlocked()
Return to normal operation and accept new requests.
Definition: base.cc:116

Generated on Fri Jun 9 2017 13:03:41 for gem5 by doxygen 1.8.6