gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cache.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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) 2002-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  * Dave Greene
42  * Steve Reinhardt
43  * Ron Dreslinski
44  * Andreas Hansson
45  */
46 
52 #ifndef __MEM_CACHE_CACHE_HH__
53 #define __MEM_CACHE_CACHE_HH__
54 
55 #include <unordered_set>
56 
57 #include "base/misc.hh" // fatal, panic, and warn
58 #include "enums/Clusivity.hh"
59 #include "mem/cache/base.hh"
60 #include "mem/cache/blk.hh"
61 #include "mem/cache/mshr.hh"
62 #include "mem/cache/tags/base.hh"
63 #include "params/Cache.hh"
64 #include "sim/eventq.hh"
65 
66 //Forward decleration
67 class BasePrefetcher;
68 
74 class Cache : public BaseCache
75 {
76  protected:
77 
82  class CpuSidePort : public CacheSlavePort
83  {
84  private:
85 
86  // a pointer to our specific cache implementation
88 
89  protected:
90 
91  virtual bool recvTimingSnoopResp(PacketPtr pkt);
92 
93  virtual bool recvTimingReq(PacketPtr pkt);
94 
95  virtual Tick recvAtomic(PacketPtr pkt);
96 
97  virtual void recvFunctional(PacketPtr pkt);
98 
99  virtual AddrRangeList getAddrRanges() const;
100 
101  public:
102 
103  CpuSidePort(const std::string &_name, Cache *_cache,
104  const std::string &_label);
105 
106  };
107 
115  {
116 
117  protected:
118 
121 
122  public:
123 
125  SnoopRespPacketQueue &snoop_resp_queue,
126  const std::string &label) :
127  ReqPacketQueue(cache, port, label), cache(cache),
128  snoopRespQueue(snoop_resp_queue) { }
129 
135  virtual void sendDeferredPacket();
136 
144  {
145  if (snoopRespQueue.hasAddr(addr)) {
146  DPRINTF(CachePort, "Waiting for snoop response to be "
147  "sent\n");
149  schedSendEvent(when);
150  return true;
151  }
152  return false;
153  }
154  };
155 
161  {
162  private:
163 
166 
168 
169  // a pointer to our specific cache implementation
171 
172  protected:
173 
174  virtual void recvTimingSnoopReq(PacketPtr pkt);
175 
176  virtual bool recvTimingResp(PacketPtr pkt);
177 
178  virtual Tick recvAtomicSnoop(PacketPtr pkt);
179 
180  virtual void recvFunctionalSnoop(PacketPtr pkt);
181 
182  public:
183 
184  MemSidePort(const std::string &_name, Cache *_cache,
185  const std::string &_label);
186  };
187 
190 
193 
196 
200  const bool doFastWrites;
201 
206 
210  const bool prefetchOnAccess;
211 
217  const Enums::Clusivity clusivity;
218 
226  const bool writebackClean;
227 
232  std::unique_ptr<Packet> pendingDelete;
233 
242 
249  assert(tempBlockWriteback != nullptr);
252  tempBlockWriteback = nullptr;
253  }
254 
262 
268  std::unordered_set<RequestPtr> outstandingSnoop;
269 
278  bool access(PacketPtr pkt, CacheBlk *&blk,
279  Cycles &lat, PacketList &writebacks);
280 
284  void cmpAndSwap(CacheBlk *blk, PacketPtr pkt);
285 
293  CacheBlk *allocateBlock(Addr addr, bool is_secure, PacketList &writebacks);
294 
300  void invalidateBlock(CacheBlk *blk);
301 
311  void maintainClusivity(bool from_cache, CacheBlk *blk);
312 
324  PacketList &writebacks, bool allocate);
325 
339  inline bool allocOnFill(MemCmd cmd) const override
340  {
341  return clusivity == Enums::mostly_incl ||
342  cmd == MemCmd::WriteLineReq ||
343  cmd == MemCmd::ReadReq ||
344  cmd == MemCmd::WriteReq ||
345  cmd.isPrefetch() ||
346  cmd.isLLSC();
347  }
348 
354  bool recvTimingReq(PacketPtr pkt);
355 
359  void doWritebacks(PacketList& writebacks, Tick forward_time);
360 
365 
371 
376  void recvTimingResp(PacketPtr pkt);
377 
382  void recvTimingSnoopReq(PacketPtr pkt);
383 
388  void recvTimingSnoopResp(PacketPtr pkt);
389 
396 
404 
410  void functionalAccess(PacketPtr pkt, bool fromCpuSide);
411 
425  void satisfyRequest(PacketPtr pkt, CacheBlk *blk,
426  bool deferred_response = false,
427  bool pending_downgrade = false);
428 
429  void doTimingSupplyResponse(PacketPtr req_pkt, const uint8_t *blk_data,
430  bool already_copied, bool pending_inval);
431 
444  uint32_t handleSnoop(PacketPtr pkt, CacheBlk *blk,
445  bool is_timing, bool is_deferred, bool pending_inval);
446 
453 
460 
461 
462  void memWriteback() override;
463  void memInvalidate() override;
464  bool isDirty() const override;
465 
472  bool writebackVisitor(CacheBlk &blk);
480  bool invalidateVisitor(CacheBlk &blk);
481 
494  bool needsWritable) const;
495 
503 
508  bool isCachedAbove(PacketPtr pkt, bool is_timing = true) const;
509 
513  bool outstandingMisses() const
514  {
515  return !mshrQueue.isEmpty();
516  }
517 
518  CacheBlk *findBlock(Addr addr, bool is_secure) const {
519  return tags->findBlock(addr, is_secure);
520  }
521 
522  bool inCache(Addr addr, bool is_secure) const override {
523  return (tags->findBlock(addr, is_secure) != 0);
524  }
525 
526  bool inMissQueue(Addr addr, bool is_secure) const override {
527  return (mshrQueue.findMatch(addr, is_secure) != 0);
528  }
529 
533  Tick nextQueueReadyTime() const;
534 
535  public:
537  Cache(const CacheParams *p);
538 
540  virtual ~Cache();
541 
542  void regStats() override;
543 
552  bool sendMSHRQueuePacket(MSHR* mshr);
553 
562  bool sendWriteQueuePacket(WriteQueueEntry* wq_entry);
563 
567  void serialize(CheckpointOut &cp) const override;
568  void unserialize(CheckpointIn &cp) override;
569 };
570 
580 {
581  public:
582  typedef bool (Cache::*VisitorPtr)(CacheBlk &blk);
583 
585  : cache(_cache), visitor(_visitor) {}
586 
587  bool operator()(CacheBlk &blk) override {
588  return (cache.*visitor)(blk);
589  }
590 
591  private:
594 };
595 
604 {
605  public:
607  : _isDirty(false) {}
608 
609  bool operator()(CacheBlk &blk) override {
610  if (blk.isDirty()) {
611  _isDirty = true;
612  return false;
613  } else {
614  return true;
615  }
616  }
617 
623  bool isDirty() const { return _isDirty; };
624 
625  private:
626  bool _isDirty;
627 };
628 
629 #endif // __MEM_CACHE_CACHE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
Entry * findMatch(Addr blk_addr, bool is_secure) const
Find the first WriteQueueEntry that matches the provided address.
Definition: queue.hh:156
Miss Status and Handling Register (MSHR) declaration.
#define DPRINTF(x,...)
Definition: trace.hh:212
bool isDirty() const
Check to see if a block has been written.
Definition: blk.hh:222
virtual void recvTimingSnoopReq(PacketPtr pkt)
Definition: cache.cc:2607
Declares a basic cache interface BaseCache.
virtual void recvFunctional(PacketPtr pkt)
Definition: cache.cc:2572
bool hasAddr(Addr addr) const
Check if a packets address exists in the queue.
Definition: packet_queue.cc:73
QueueEntry * getNextQueueEntry()
Return the next queue entry to service, either a pending miss from the MSHR queue, a buffered write from the write buffer, or something from the prefetcher.
Definition: cache.cc:2226
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Definition: packet.hh:73
CacheBlkVisitorWrapper(Cache &_cache, VisitorPtr _visitor)
Definition: cache.hh:584
bool isDirty() const
Does the array contain a dirty line?
Definition: cache.hh:623
void doWritebacksAtomic(PacketList &writebacks)
Send writebacks down the memory hierarchy in atomic mode.
Definition: cache.cc:501
Cache * cache
Definition: cache.hh:170
void memWriteback() override
Write back dirty blocks in the cache using functional accesses.
Definition: cache.cc:1605
VisitorPtr visitor
Definition: cache.hh:593
void invalidateBlock(CacheBlk *blk)
Invalidate a cache block.
Definition: cache.cc:1710
void functionalAccess(PacketPtr pkt, bool fromCpuSide)
Performs the access specified by the request.
Definition: cache.cc:1139
ip6_addr_t addr
Definition: inet.hh:335
void memInvalidate() override
Invalidates all blocks in the cache.
Definition: cache.cc:1612
PacketPtr writebackBlk(CacheBlk *blk)
Create a writeback request for the given block.
Definition: cache.cc:1539
CpuSidePort(const std::string &_name, Cache *_cache, const std::string &_label)
Definition: cache.cc:2579
BasePrefetcher * prefetcher
Prefetcher.
Definition: cache.hh:192
virtual bool recvTimingReq(PacketPtr pkt)
Definition: cache.cc:2539
Override the default behaviour of sendDeferredPacket to enable the memory-side cache port to also sen...
Definition: cache.hh:114
Cache * cache
Definition: cache.hh:87
void schedSendEvent(Tick when)
Schedule a send event if we are not already waiting for a retry.
bool operator()(CacheBlk &blk) override
Definition: cache.hh:609
void writebackTempBlockAtomic()
Send the outstanding tempBlock writeback.
Definition: cache.hh:248
CacheReqPacketQueue _reqQueue
The cache-specific queue.
Definition: cache.hh:165
bool isCachedAbove(PacketPtr pkt, bool is_timing=true) const
Send up a snoop request and find cached copies.
Definition: cache.cc:2309
virtual void sendDeferredPacket()
Override the normal sendDeferredPacket and do not only consider the transmit list (used for responses...
Definition: cache.cc:2629
virtual AddrRangeList getAddrRanges() const
Definition: cache.cc:2533
bool invalidateVisitor(CacheBlk &blk)
Cache block visitor that invalidates all blocks in the cache.
Definition: cache.cc:1652
Declaration of a common base class for cache tagstore objects.
bool sendMSHRQueuePacket(MSHR *mshr)
Take an MSHR, turn it into a suitable downstream packet, and send it out.
Definition: cache.cc:2353
A template-policy based cache.
Definition: cache.hh:74
bool outstandingMisses() const
Return whether there are any outstanding misses.
Definition: cache.hh:513
const Enums::Clusivity clusivity
Clusivity with respect to the upstream cache, determining if we fill into both this cache and the cac...
Definition: cache.hh:217
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
Cache block visitor that determines if there are dirty blocks in a cache.
Definition: cache.hh:603
A Basic Cache block.
Definition: blk.hh:79
virtual Tick recvAtomic(PacketPtr pkt)
Definition: cache.cc:2566
Stats::Vector writebacks
Number of blocks written back per thread.
Definition: base.hh:396
void serialize(CheckpointOut &cp) const override
serialize the state of the caches We currently don't support checkpointing cache state, so this panics.
Definition: cache.cc:2495
CacheBlk * findBlock(Addr addr, bool is_secure) const
Definition: cache.hh:518
The memory-side port extends the base cache master port with access functions for functional...
Definition: cache.hh:160
PacketPtr cleanEvictBlk(CacheBlk *blk)
Create a CleanEvict request for the given block.
Definition: cache.cc:1582
uint64_t Tick
Tick count type.
Definition: types.hh:63
const bool prefetchOnAccess
Notify the prefetcher on every access, not just misses.
Definition: cache.hh:210
EventWrapper< Cache,&Cache::writebackTempBlockAtomic > writebackTempBlockAtomicEvent
An event to writeback the tempBlock after recvAtomic finishes.
Definition: cache.hh:261
SnoopRespPacketQueue _snoopRespQueue
Definition: cache.hh:167
Miss Status and handling Register.
Definition: mshr.hh:63
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: cache.cc:2515
Tick deferredPacketReadyTime() const
Get the next packet ready time.
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: cache.cc:149
CacheBlk * handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks, bool allocate)
Populates a cache block and handles all outstanding requests for the satisfied fill request...
Definition: cache.cc:1723
bool sendWriteQueuePacket(WriteQueueEntry *wq_entry)
Similar to sendMSHR, but for a write-queue entry instead.
Definition: cache.cc:2471
void handleUncacheableWriteResp(PacketPtr pkt)
Handling the special case of uncacheable write responses to make recvTimingResp less cluttered...
Definition: cache.cc:1214
const bool writebackClean
Determine if clean lines should be written back or not.
Definition: cache.hh:226
A basic cache interface.
Definition: base.hh:79
virtual void recvFunctionalSnoop(PacketPtr pkt)
Definition: cache.cc:2620
virtual bool recvTimingSnoopResp(PacketPtr pkt)
Definition: cache.cc:2201
void recvTimingResp(PacketPtr pkt)
Handles a response (cache line fill/write ack) from the bus.
Definition: cache.cc:1226
Tick recvAtomicSnoop(PacketPtr pkt)
Snoop for the provided request in the cache and return the estimated time taken.
Definition: cache.cc:2209
void doWritebacks(PacketList &writebacks, Tick forward_time)
Insert writebacks into the write buffer.
Definition: cache.cc:461
void promoteWholeLineWrites(PacketPtr pkt)
Turn line-sized writes into WriteInvalidate transactions.
Definition: cache.cc:572
Definitions of a simple cache block class.
virtual ~Cache()
Non-default destructor is needed to deallocate memory.
Definition: cache.cc:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool(Cache::* VisitorPtr)(CacheBlk &blk)
Definition: cache.hh:582
void recvTimingSnoopReq(PacketPtr pkt)
Snoops bus transactions to maintain coherence.
Definition: cache.cc:2080
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
bool isPrefetch() const
Definition: packet.hh:214
void recvTimingSnoopResp(PacketPtr pkt)
Handle a snoop response.
Definition: cache.cc:535
bool inMissQueue(Addr addr, bool is_secure) const override
Definition: cache.hh:526
void cmpAndSwap(CacheBlk *blk, PacketPtr pkt)
Handle doing the Compare and Swap function for SPARC.
Definition: cache.cc:108
virtual bool recvTimingResp(PacketPtr pkt)
Definition: cache.cc:2599
A queue entry base class, to be used by both the MSHRs and write-queue entries.
Definition: queue_entry.hh:60
bool access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, PacketList &writebacks)
Does all the processing necessary to perform the provided request.
Definition: cache.cc:286
Tick nextQueueReadyTime() const
Find next request ready time from among possible sources.
Definition: cache.cc:2337
CacheReqPacketQueue(Cache &cache, MasterPort &port, SnoopRespPacketQueue &snoop_resp_queue, const std::string &label)
Definition: cache.hh:124
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
std::ostream CheckpointOut
Definition: serialize.hh:67
PacketPtr tempBlockWriteback
Writebacks from the tempBlock, resulting on the response path in atomic mode, must happen after the c...
Definition: cache.hh:241
Cache(const CacheParams *p)
Instantiates a basic cache object.
Definition: cache.cc:67
void doTimingSupplyResponse(PacketPtr req_pkt, const uint8_t *blk_data, bool already_copied, bool pending_inval)
Definition: cache.cc:1839
virtual Tick recvAtomicSnoop(PacketPtr pkt)
Definition: cache.cc:2614
PacketPtr createMissPacket(PacketPtr cpu_pkt, CacheBlk *blk, bool needsWritable) const
Create an appropriate downstream bus request packet for the given parameters.
Definition: cache.cc:900
Tick recvAtomic(PacketPtr pkt)
Performs the access specified by the request.
Definition: cache.cc:974
virtual CacheBlk * findBlock(Addr addr, bool is_secure) const =0
Find a block using the memory address.
uint32_t handleSnoop(PacketPtr pkt, CacheBlk *blk, bool is_timing, bool is_deferred, bool pending_inval)
Perform an upward snoop if needed, and update the block state (possibly invalidating the block)...
Definition: cache.cc:1884
const bool doFastWrites
This cache should allocate a block on a line-sized write miss.
Definition: cache.hh:200
SnoopRespPacketQueue & snoopRespQueue
Definition: cache.hh:120
bool checkConflictingSnoop(Addr addr)
Check if there is a conflicting snoop response about to be send out, and if so simply stall any reque...
Definition: cache.hh:143
bool isDirty() const override
Determine if there are any dirty blocks in the cache.
Definition: cache.cc:1619
bool isEmpty() const
Definition: queue.hh:135
bool recvTimingReq(PacketPtr pkt)
Performs the access specified by the request.
Definition: cache.cc:583
bool operator()(CacheBlk &blk) override
Definition: cache.hh:587
bool writebackVisitor(CacheBlk &blk)
Cache block visitor that writes back dirty cache blocks using functional writes.
Definition: cache.cc:1628
bool allocOnFill(MemCmd cmd) const override
Determine whether we should allocate on a fill or not.
Definition: cache.hh:339
CacheBlk * allocateBlock(Addr addr, bool is_secure, PacketList &writebacks)
Find a block frame for new block at address addr targeting the given security space, assuming that the block is not currently in the cache.
Definition: cache.cc:1667
std::unordered_set< RequestPtr > outstandingSnoop
Store the outstanding requests that we are expecting snoop responses from so we can determine which s...
Definition: cache.hh:268
void regStats() override
Register stats for this object.
Definition: cache.cc:102
bool isLLSC() const
Definition: packet.hh:211
The CPU-side port extends the base cache slave port with access functions for functional, atomic and timing requests.
Definition: cache.hh:82
bool inCache(Addr addr, bool is_secure) const override
Definition: cache.hh:522
Write queue entry.
CacheBlk * tempBlock
Temporary cache block for occasional transitory use.
Definition: cache.hh:195
Bitfield< 0 > p
A common base class of Cache tagstore objects.
Definition: base.hh:65
Base class for cache block visitor, operating on the cache block base class (later subclassed for the...
Definition: blk.hh:397
BaseTags * tags
Tag and data Storage.
Definition: cache.hh:189
Wrap a method and present it as a cache block visitor.
Definition: cache.hh:579
void maintainClusivity(bool from_cache, CacheBlk *blk)
Maintain the clusivity of this cache by potentially invalidating a block.
Definition: cache.cc:449
MSHRQueue mshrQueue
Miss status registers.
Definition: base.hh:191
MemSidePort(const std::string &_name, Cache *_cache, const std::string &_label)
Definition: cache.cc:2665
const std::string label
Label to use for print request packets label stack.
std::unique_ptr< Packet > pendingDelete
Upstream caches need this packet until true is returned, so hold it for deletion until a subsequent c...
Definition: cache.hh:232

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