52 #ifndef __MEM_CACHE_BASE_HH__ 53 #define __MEM_CACHE_BASE_HH__ 63 #include "debug/Cache.hh" 64 #include "debug/CachePort.hh" 65 #include "enums/Clusivity.hh" 76 #include "params/WriteAllocator.hh" 88 struct BaseCacheParams;
137 DPRINTF(CachePort,
"Scheduling send event at %llu\n", time);
175 const std::string &label) :
177 snoopRespQueue(snoop_resp_queue) { }
184 virtual void sendDeferredPacket();
197 DPRINTF(CachePort,
"Waiting for snoop response to be " 237 const std::string &_label);
264 const std::string &_label);
275 void processSendRetry();
301 virtual void recvFunctional(
PacketPtr pkt)
override;
308 const std::string &_label);
377 bool wasFull = mshrQueue.
isFull();
380 if (wasFull && !mshrQueue.
isFull()) {
387 bool wasFull = writeBuffer.
isFull();
390 if (wasFull && !writeBuffer.
isFull()) {
410 return clusivity == Enums::mostly_incl ||
437 const Cycles lookup_lat)
const;
448 const Cycles lookup_lat)
const;
484 Tick request_time) = 0;
498 Tick forward_time,
Tick request_time);
621 bool is_whole_line_write)
const = 0;
647 assert(tempBlockWriteback !=
nullptr);
650 tempBlockWriteback =
nullptr;
698 bool deferred_response =
false,
699 bool pending_downgrade =
false);
937 void regStatsFromParent();
1081 BaseCache(
const BaseCacheParams *
p,
unsigned blk_size);
1084 void init()
override;
1107 if (mshrQueue.
isFull()) {
1141 writeBuffer.
allocate(blk_addr, blkSize, pkt, time, order++);
1143 if (writeBuffer.
isFull()) {
1156 return blocked != 0;
1166 uint8_t flag = 1 << cause;
1173 DPRINTF(
Cache,
"Blocking for cause %d, mask=%d\n", cause, blocked);
1185 uint8_t flag = 1 << cause;
1187 DPRINTF(
Cache,
"Unblocking for cause %d, mask=%d\n", cause, blocked);
1208 return tags->
findBlock(addr, is_secure);
1221 return mshrQueue.
findMatch(addr, is_secure);
1228 pkt->
req->incAccessDepth();
1232 exitSimLoop(
"A cache reached the maximum miss count");
1310 coalesceLimit(p->coalesce_limit * p->block_size),
1311 noAllocateLimit(p->no_allocate_limit * p->block_size),
1312 delayThreshold(p->delay_threshold)
1324 return mode != WriteMode::ALLOCATE;
1333 return mode != WriteMode::NO_ALLOCATE;
1343 mode = WriteMode::ALLOCATE;
1355 if (delayCtr[blk_addr] > 0) {
1356 --delayCtr[blk_addr];
1369 delayCtr.erase(blk_addr);
1382 void updateMode(
Addr write_addr,
unsigned write_size,
Addr blk_addr);
1423 #endif //__MEM_CACHE_BASE_HH__ A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
virtual bool access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, PacketList &writebacks)
Does all the processing necessary to perform the provided request.
Stats::Formula demandMissLatency
Total number of cycles spent waiting for demand misses.
virtual Cycles handleAtomicReqMiss(PacketPtr pkt, CacheBlk *&blk, PacketList &writebacks)=0
Handle a request in atomic mode that missed in this cache.
bool forwardSnoops
Do we forward snoops from mem side port through to cpu side port?
void regProbePoints() override
Registers probes.
Ports are used to interface objects to each other.
BaseCache(const BaseCacheParams *p, unsigned blk_size)
std::unordered_map< Addr, Counter > delayCtr
Keep track of the number of times the allocator has delayed an WriteReq MSHR.
Special instance of CacheBlk for use with tempBlk that deals with its block address regeneration...
Declaration of a simple PacketQueue that is associated with a port on which it attempts to send packe...
PacketPtr writebackBlk(CacheBlk *blk)
Create a writeback request for the given block.
bool inService
True if the entry has been sent downstream.
Cycles is a wrapper class for representing cycle counts, i.e.
Stats::Formula demandHits
Number of hits for demand accesses.
Tick recvAtomicSnoop(PacketPtr pkt) override
Default implementations.
A Class for maintaining a list of pending and allocated memory requests.
void writebackVisitor(CacheBlk &blk)
Cache block visitor that writes back dirty cache blocks using functional writes.
Stats::Vector missLatency
Total number of cycles per thread/command spent waiting for a miss.
Stats::Formula avgMshrUncacheableLatency
The average latency of an MSHR miss, per command and thread.
const PortID InvalidPortID
The memory-side port extends the base cache master port with access functions for functional...
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.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
WriteQueue writeBuffer
Write/writeback buffer.
Stats::Formula overallMshrMissLatency
Total cycle latency of overall MSHR misses.
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...
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Stats::Vector mshr_miss_latency
Total cycle latency of each MSHR miss, per command and thread.
Stats::Scalar replacements
Number of replacements of valid blocks.
MSHR * noTargetMSHR
Pointer to the MSHR that has no targets.
Stats::Formula overallMshrUncacheableLatency
Total cycle latency of overall MSHR misses.
const Cycles lookupLatency
The latency of tag lookup of a cache.
std::vector< std::unique_ptr< CacheCmdStats > > cmd
Per-command statistics.
A write queue for all eviction packets, i.e.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Stats::Vector mshr_hits
Number of misses that hit in the MSHRs per command and thread.
EventFunctionWrapper writebackTempBlockAtomicEvent
An event to writeback the tempBlock after recvAtomic finishes.
bool tryTiming(PacketPtr pkt) const
Check if the slave can handle a timing request.
const Enums::Clusivity clusivity
Clusivity with respect to the upstream cache, determining if we fill into both this cache and the cac...
Stats::Formula demandMshrMisses
Demand misses that miss in the MSHRs.
The QueuedMasterPort combines two queues, a request queue and a snoop response queue, that both share the same port.
System * system
System we are currently operating in.
const bool isReadOnly
Is this cache read only, for example the instruction cache, or table-walker cache.
ProbePointArg< PacketPtr > * ppMiss
To probe when a cache miss occurs.
virtual void handleTimingReqMiss(PacketPtr pkt, CacheBlk *blk, Tick forward_time, Tick request_time)=0
const AddrRangeList addrRanges
The address range to which the cache responds on the CPU side.
Stats::Formula overallMshrMisses
Total number of misses that miss in the MSHRs.
BaseCache::CacheStats stats
void invalidateBlock(CacheBlk *blk)
Invalidate a cache block.
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...
Stats::Formula overallMshrUncacheable
Total number of misses that miss in the MSHRs.
virtual void regStats()
Callback to set stat parameters.
Definition of a basic cache compressor.
MSHR * allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send=true)
A vector of scalar stats.
bool allocate() const
Should writes allocate?
bool isBlocked() const
Returns true if the cache is blocked for accesses.
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
const Cycles dataLatency
The latency of data access of a cache.
bool coalesce() const
Checks if the cache is coalescing writes.
const Cycles fillLatency
The latency to fill a cache block.
bool handleEvictions(std::vector< CacheBlk *> &evict_blks, PacketList &writebacks)
Try to evict the given blocks.
WriteAllocator *const writeAllocator
The writeAllocator drive optimizations for streaming writes.
void markInService(WriteQueueEntry *entry)
Mark the given entry as in service.
Stats::Formula overallMissLatency
Total number of cycles spent waiting for all misses.
void schedSendEvent(Tick when)
Schedule a send event if we are not already waiting for a retry.
Declaration of a structure to manage MSHRs.
bool sendWriteQueuePacket(WriteQueueEntry *wq_entry)
Similar to sendMSHR, but for a write-queue entry instead.
Stats::Formula overallAvgMshrUncacheableLatency
The average overall latency of an MSHR miss.
const uint32_t noAllocateLimit
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
CacheReqPacketQueue(BaseCache &cache, MasterPort &port, SnoopRespPacketQueue &snoop_resp_queue, const std::string &label)
SnoopRespPacketQueue & snoopRespQueue
Stats::Vector writebacks
Number of blocks written back per thread.
Cycles calculateTagOnlyLatency(const uint32_t delay, const Cycles lookup_lat) const
Calculate latency of accesses that only touch the tag array.
Stats::Scalar dataExpansions
Number of data expansions.
EventFunctionWrapper sendRetryEvent
CacheCmdStats & cmdStats(const PacketPtr p)
CacheBlk * allocateBlock(const PacketPtr pkt, PacketList &writebacks)
Allocate a new block and perform any necessary writebacks.
Addr getBlockAddr(unsigned int blk_size) const
Stats::Vector hits
Number of hits per thread for each type of command.
RequestPtr req
A pointer to the original request.
virtual void memWriteback() override
Write back dirty blocks in the cache using functional accesses.
void markInService(WriteQueueEntry *entry)
const Cycles responseLatency
The latency of sending reponse to its upper level cache/core on a linefill.
Stats::Vector mshr_uncacheable_lat
Total cycle latency of each MSHR miss, per command and thread.
WriteMode
The current mode for write coalescing and allocation, either normal operation (ALLOCATE), write coalescing (COALESCE), or write coalescing without allocation (NO_ALLOCATE).
Stats::Formula demandMshrMissRate
The demand miss rate in the MSHRs.
ProbePointArg< PacketPtr > * ppFill
To probe when a cache fill occurs.
virtual void recvTimingReq(PacketPtr pkt)
Performs the access specified by the request.
void invalidateVisitor(CacheBlk &blk)
Cache block visitor that invalidates all blocks in the cache.
A coherent cache that can be arranged in flexible topologies.
Declaration of the queued port.
virtual Tick recvAtomic(PacketPtr pkt)
Performs the access specified by the request.
Cycles blockedCycle
Stores time the cache blocked for statistics.
const uint32_t coalesceLimit
Limits for when to switch between the different write modes.
A cache master port is used for the memory-side port of the cache, and in addition to the basic timin...
Stats::Vector mshr_misses
Number of misses that miss in the MSHRs, per command and thread.
PacketPtr tempBlockWriteback
Writebacks from the tempBlock, resulting on the response path in atomic mode, must happen after the c...
CacheMasterPort(const std::string &_name, BaseCache *_cache, ReqPacketQueue &_reqQueue, SnoopRespPacketQueue &_snoopRespQueue)
Stats::Vector blocked_causes
The number of times this cache blocked for each blocked cause.
Stats::Formula avg_blocked
The average number of cycles blocked for each blocked cause.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
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.
bool inRange(Addr addr) const
Determine if an address is in the ranges covered by this cache.
const bool sequentialAccess
Whether tags and data are accessed sequentially.
virtual void recvTimingSnoopResp(PacketPtr pkt)=0
Handle a snoop response.
uint64_t Tick
Tick count type.
void incMissCount(PacketPtr pkt)
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
PacketPtr writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id)
Create a writeclean request for the given block.
Miss Status and handling Register.
void markInService(MSHR *mshr, bool pending_modified_resp)
Mark the given MSHR as in service.
ClockedObject declaration and implementation.
Stats::Formula demandMshrHits
Demand misses that hit in the MSHRs.
Stats::Formula overallAvgMissLatency
The average miss latency for all misses.
std::unique_ptr< Packet > pendingDelete
Upstream caches need this packet until true is returned, so hold it for deletion until a subsequent c...
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
void allocateWriteBuffer(PacketPtr pkt, Tick time)
Stats::Vector blocked_cycles
The total number of cycles blocked for each blocked cause.
CacheReqPacketQueue _reqQueue
The cache-specific queue.
void cmpAndSwap(CacheBlk *blk, PacketPtr pkt)
Handle doing the Compare and Swap function for SPARC.
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.
Stats::Formula overallHits
Number of hit for all accesses.
virtual void handleTimingReqHit(PacketPtr pkt, CacheBlk *blk, Tick request_time)
Stats::Formula overallMissRate
The miss rate for all accesses.
Stats::Formula overallAccesses
The number of overall accesses.
bool checkConflictingSnoop(const PacketPtr pkt)
Check if there is a conflicting snoop response about to be send out, and if so simply stall any reque...
virtual void memInvalidate() override
Invalidates all blocks in the cache.
Stats::Formula demandAvgMissLatency
The average miss latency for demand misses.
void reset()
Reset the write allocator state, meaning that it allocates for writes and has not recorded any inform...
void setBlocked()
Do not accept any new requests.
uint8_t blocked
Bit vector of the blocking reasons for the access path.
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.
void schedMemSideSendEvent(Tick time)
Schedule a send event for the memory-side port.
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Base cache compressor interface.
uint32_t byteCount
Bytes written contiguously.
CacheBlk * handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks, bool allocate)
Handle a fill operation caused by a received packet.
const bool writebackClean
Determine if clean lines should be written back or not.
WriteAllocator(const WriteAllocatorParams *p)
const unsigned blkSize
Block size of this cache.
int64_t Counter
Statistics counter type.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
void recvTimingSnoopReq(PacketPtr pkt) override
Receive a timing snoop request from the peer.
Entry * findMatch(Addr blk_addr, bool is_secure, bool ignore_uncacheable=true) const
Find the first entry that matches the provided address.
Stats::Vector misses
Number of misses per thread for each type of command.
uint64_t order
Increasing order number assigned to each incoming request.
Stats::Formula demandMisses
Number of misses for demand accesses.
virtual M5_NODISCARD PacketPtr evictBlock(CacheBlk *blk)=0
Evict a cache block.
MasterID maxMasters()
Get the number of masters registered in the system.
TempCacheBlk * tempBlock
Temporary cache block for occasional transitory use.
int cmdToIndex() const
Return the index of this command.
const uint32_t delayThreshold
The number of times the allocator will delay an WriteReq MSHR.
A queue entry base class, to be used by both the MSHRs and write-queue entries.
virtual void doWritebacksAtomic(PacketList &writebacks)=0
Send writebacks down the memory hierarchy in atomic mode.
Definitions of a simple cache block class.
Override the default behaviour of sendDeferredPacket to enable the memory-side cache port to also sen...
ProbePointArg< PacketPtr > * ppHit
To probe when a cache hit occurs.
const AddrRangeList & getAddrRanges() const
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...
Stats::Formula mshrMissRate
The miss rate in the MSHRs pre command and thread.
ProbePointArg generates a point for the class of Arg.
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 (...
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...
ReqPacketQueue & reqQueue
Packet queue used to store outgoing requests.
Stats::Formula missRate
The miss rate per command and thread.
bool allocOnFill(MemCmd cmd) const
Determine whether we should allocate on a fill or not.
AddrRangeList getAddrRanges() const
Get the address ranges of the connected slave port.
Stats::Formula avgMshrMissLatency
The average latency of an MSHR miss, per command and thread.
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...
std::ostream CheckpointOut
virtual void doWritebacks(PacketList &writebacks, Tick forward_time)=0
Insert writebacks into the write buffer.
void serialize(CheckpointOut &cp) const override
Serialize the state of the caches.
void schedSendEvent(Tick time)
Schedule a send of a request packet (from the MSHR).
void setBlocked(BlockedCause cause)
Marks the access path of the cache as blocked for the given cause.
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
MemCmd cmd
The command field of the packet.
The write allocator inspects write packets and detects streaming patterns.
Stats::Formula avgMissLatency
The average miss latency per command and thread.
RespPacketQueue queue
A normal packet queue used to store responses.
bool inMissQueue(Addr addr, bool is_secure) const
const std::string name() const
Return port name (for DPRINTF).
Stats::Formula accesses
The number of accesses per command and thread.
Tick deferredPacketReadyTime() const
Get the next packet ready time.
BlockedCause
Reasons for caches to be blocked.
bool checkConflict(const PacketPtr pkt, const int blk_size) const
Check if a packet corresponding to the same address exists in the queue.
MSHRQueueIndex
Indexes to enumerate the MSHR queues.
Stats::Formula overallMshrMissRate
The overall miss rate in the MSHRs.
const int numTarget
The number of targets for each MSHR.
virtual bool sendMSHRQueuePacket(MSHR *mshr)
Take an MSHR, turn it into a suitable downstream packet, and send it out.
const Cycles forwardLatency
This is the forward latency of the cache.
unsigned getBlockSize() const
Query block size of a cache.
bool coalesce() const
Should writes be coalesced? This is true if the mode is set to NO_ALLOCATE.
bool inCache(Addr addr, bool is_secure) const
void resetDelay(Addr blk_addr)
Clear delay counter for the input block.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Stats::Formula overallMshrHits
Total number of misses that hit in the MSHRs.
Stats::Formula demandAccesses
The number of demand accesses.
Counter missCount
The number of misses to trigger an exit event.
virtual bool isSnooping() const
Memory-side port always snoops.
Stats::Scalar unusedPrefetches
The number of times a HW-prefetched block is evicted w/o reference.
virtual void serviceMSHRTargets(MSHR *mshr, const PacketPtr pkt, CacheBlk *blk)=0
Service non-deferred MSHR targets using the received response.
Addr regenerateBlkAddr(CacheBlk *blk)
Regenerate block address using tags.
virtual bool recvTimingResp(PacketPtr pkt)=0
Receive a timing response from the peer.
SnoopRespPacketQueue _snoopRespQueue
Tick nextQueueReadyTime() const
Find next request ready time from among possible sources.
BaseCacheCompressor * compressor
Compression method being used.
void writebackTempBlockAtomic()
Send the outstanding tempBlock writeback.
bool wasPrefetched() const
Check if this block was the result of a hardware prefetch, yet to be touched.
Stats::Formula demandMissRate
The miss rate of all demand accesses.
BasePrefetcher * prefetcher
Prefetcher.
Addr nextAddr
Address to match writes against to detect streams.
WriteQueueEntry * allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, Tick when_ready, Counter order)
Allocates a new WriteQueueEntry for the request and size.
void handleUncacheableWriteResp(PacketPtr pkt)
Handling the special case of uncacheable write responses to make recvTimingResp less cluttered...
void incHitCount(PacketPtr pkt)
bool isDirty() const
Determine if there are any dirty blocks in the cache.
bool delay(Addr blk_addr)
Access whether we need to delay the current write.
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Stats::Formula demandAvgMshrMissLatency
The average latency of a demand MSHR miss.
Abstract superclass for simulation objects.
BaseTags * tags
Tag and data Storage.
Stats::Vector mshr_uncacheable
Number of misses that miss in the MSHRs, per command and thread.
void clearBlocked(BlockedCause cause)
Marks the cache as unblocked for the given cause.
virtual void functionalAccess(PacketPtr pkt, bool from_cpu_side)
Performs the access specified by the request.
MSHRQueue mshrQueue
Miss status registers.
The CPU-side port extends the base cache slave port with access functions for functional, atomic and timing requests.
void maintainClusivity(bool from_cache, CacheBlk *blk)
Maintain the clusivity of this cache by potentially invalidating a block.
Stats::Formula demandMshrMissLatency
Total cycle latency of demand MSHR misses.
Stats::Formula overallMisses
Number of misses for all accesses.
Stats::Formula overallAvgMshrMissLatency
The average overall latency of an MSHR miss.
void clearBlocked()
Return to normal operation and accept new requests.