46#ifndef __MEM_CACHE_BASE_HH__
47#define __MEM_CACHE_BASE_HH__
58#include "debug/Cache.hh"
59#include "debug/CachePort.hh"
60#include "enums/Clusivity.hh"
72#include "params/WriteAllocator.hh"
87namespace partitioning_policy
94struct BaseCacheParams;
145 DPRINTF(CachePort,
"Scheduling send event at %llu\n", time);
183 const std::string &
label) :
205 DPRINTF(CachePort,
"Waiting for snoop response to be "
245 const std::string &_label);
272 const std::string &_label);
313 const std::string &_label);
449 return clusivity == enums::mostly_incl ||
476 const Cycles lookup_lat)
const;
487 const Cycles lookup_lat)
const;
523 Tick request_time) = 0;
537 Tick forward_time,
Tick request_time);
672 bool is_whole_line_write)
const = 0;
749 bool deferred_response =
false,
750 bool pending_downgrade =
false);
1055 return *
cmd[
p->cmdToIndex()];
1159 BaseCache(
const BaseCacheParams &
p,
unsigned blk_size);
1162 void init()
override;
1244 uint8_t flag = 1 << cause;
1263 uint8_t flag = 1 << cause;
1309 pkt->
req->incAccessDepth();
1313 exitSimLoop(
"A cache reached the maximum miss count");
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Definitions of a simple cache block class.
Override the default behaviour of sendDeferredPacket to enable the memory-side cache port to also sen...
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...
CacheReqPacketQueue(BaseCache &cache, RequestPort &port, SnoopRespPacketQueue &snoop_resp_queue, const std::string &label)
virtual void sendDeferredPacket()
Override the normal sendDeferredPacket and do not only consider the transmit list (used for responses...
SnoopRespPacketQueue & snoopRespQueue
A cache request port is used for the memory-side port of the cache, and in addition to the basic timi...
CacheRequestPort(const std::string &_name, ReqPacketQueue &_reqQueue, SnoopRespPacketQueue &_snoopRespQueue)
void schedSendEvent(Tick time)
Schedule a send of a request packet (from the MSHR).
virtual bool isSnooping() const
Memory-side port always snoops.
A cache response port is used for the CPU-side port of the cache, and it is basically a simple timing...
CacheResponsePort(const std::string &_name, BaseCache &_cache, const std::string &_label)
void clearBlocked()
Return to normal operation and accept new requests.
EventFunctionWrapper sendRetryEvent
void setBlocked()
Do not accept any new requests.
RespPacketQueue queue
A normal packet queue used to store responses.
The CPU-side port extends the base cache response port with access functions for functional,...
virtual bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
virtual Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the peer.
CpuSidePort(const std::string &_name, BaseCache &_cache, const std::string &_label)
virtual bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the peer.
virtual bool tryTiming(PacketPtr pkt) override
Availability request from the peer.
virtual void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the peer.
virtual AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
The memory-side port extends the base cache request port with access functions for functional,...
virtual Tick recvAtomicSnoop(PacketPtr pkt)
Receive an atomic snoop request packet from our peer.
virtual void recvFunctionalSnoop(PacketPtr pkt)
Receive a functional snoop request packet from the peer.
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
virtual void recvTimingSnoopReq(PacketPtr pkt)
Receive a timing snoop request from the peer.
CacheReqPacketQueue _reqQueue
The cache-specific queue.
SnoopRespPacketQueue _snoopRespQueue
MemSidePort(const std::string &_name, BaseCache *_cache, const std::string &_label)
virtual void serviceMSHRTargets(MSHR *mshr, const PacketPtr pkt, CacheBlk *blk)=0
Service non-deferred MSHR targets using the received response.
virtual void functionalAccess(PacketPtr pkt, bool from_cpu_side)
Performs the access specified by the request.
const bool isReadOnly
Is this cache read only, for example the instruction cache, or table-walker cache.
virtual void recvTimingReq(PacketPtr pkt)
Performs the access specified by the request.
virtual void recvTimingSnoopReq(PacketPtr pkt)=0
Snoops bus transactions to maintain coherence.
gem5::BaseCache::CacheAccessorImpl accessor
virtual void doWritebacks(PacketList &writebacks, Tick forward_time)=0
Insert writebacks into the write buffer.
const Cycles fillLatency
The latency to fill a cache block.
const Cycles dataLatency
The latency of data access of a cache.
void invalidateVisitor(CacheBlk &blk)
Cache block visitor that invalidates all blocks in the cache.
virtual Cycles handleAtomicReqMiss(PacketPtr pkt, CacheBlk *&blk, PacketList &writebacks)=0
Handle a request in atomic mode that missed in this cache.
virtual void doWritebacksAtomic(PacketList &writebacks)=0
Send writebacks down the memory hierarchy in atomic mode.
bool hasBeenPrefetched(Addr addr, bool is_secure, RequestorID requestor) const
void updateBlockData(CacheBlk *blk, const PacketPtr cpkt, bool has_old_data)
Update the data contents of a block.
PacketPtr tempBlockWriteback
Writebacks from the tempBlock, resulting on the response path in atomic mode, must happen after the c...
MSHR * allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send=true)
bool isDirty() const
Determine if there are any dirty blocks in the cache.
void invalidateBlock(CacheBlk *blk)
Invalidate a cache block.
MSHR * noTargetMSHR
Pointer to the MSHR that has no targets.
const bool writebackClean
Determine if clean lines should be written back or not.
bool sendWriteQueuePacket(WriteQueueEntry *wq_entry)
Similar to sendMSHR, but for a write-queue entry instead.
bool inRange(Addr addr) const
Determine if an address is in the ranges covered by this cache.
virtual void handleTimingReqMiss(PacketPtr pkt, CacheBlk *blk, Tick forward_time, Tick request_time)=0
bool allocOnFill(MemCmd cmd) const
Determine whether we should allocate on a fill or not.
bool forwardSnoops
Do we forward snoops from mem side port through to cpu side port?
uint64_t order
Increasing order number assigned to each incoming request.
void incHitCount(PacketPtr pkt)
MSHRQueueIndex
Indexes to enumerate the MSHR queues.
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...
virtual void memWriteback() override
Write back dirty blocks in the cache using functional accesses.
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...
bool isBlocked() const
Returns true if the cache is blocked for accesses.
gem5::BaseCache::CacheStats stats
bool inMissQueue(Addr addr, bool is_secure) const
const Cycles lookupLatency
The latency of tag lookup of a cache.
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.
Tick nextQueueReadyTime() const
Find next request ready time from among possible sources.
void regProbePoints() override
Registers probes.
virtual void memInvalidate() override
Invalidates all blocks in the cache.
MSHRQueue mshrQueue
Miss status registers.
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.
bool hasBeenPrefetched(Addr addr, bool is_secure) const
void markInService(WriteQueueEntry *entry)
ProbePointArg< CacheAccessProbeArg > * ppFill
To probe when a cache fill occurs.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
QueueEntry * getNextQueueEntry()
Return the next queue entry to service, either a pending miss from the MSHR queue,...
unsigned getBlockSize() const
Query block size of a cache.
bool inCache(Addr addr, bool is_secure) const
void handleUncacheableWriteResp(PacketPtr pkt)
Handling the special case of uncacheable write responses to make recvTimingResp less cluttered.
const unsigned blkSize
Block size of this cache.
void writebackTempBlockAtomic()
Send the outstanding tempBlock writeback.
BlockedCause
Reasons for caches to be blocked.
const Cycles forwardLatency
This is the forward latency of the cache.
compression::Base * compressor
Compression method being used.
const Cycles responseLatency
The latency of sending reponse to its upper level cache/core on a linefill.
PacketPtr writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id)
Create a writeclean request for the given block.
void schedMemSideSendEvent(Tick time)
Schedule a send event for the memory-side port.
virtual void handleTimingReqHit(PacketPtr pkt, CacheBlk *blk, Tick request_time)
virtual Tick recvAtomic(PacketPtr pkt)
Performs the access specified by the request.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Counter missCount
The number of misses to trigger an exit event.
void cmpAndSwap(CacheBlk *blk, PacketPtr pkt)
Handle doing the Compare and Swap function for SPARC.
virtual void recvTimingResp(PacketPtr pkt)
Handles a response (cache line fill/write ack) from the bus.
virtual void recvTimingSnoopResp(PacketPtr pkt)=0
Handle a snoop response.
virtual bool access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, PacketList &writebacks)
Does all the processing necessary to perform the provided request.
void setBlocked(BlockedCause cause)
Marks the access path of the cache as blocked for the given cause.
BaseCache(const BaseCacheParams &p, unsigned blk_size)
Addr regenerateBlkAddr(CacheBlk *blk)
Regenerate block address using tags.
std::unique_ptr< Packet > pendingDelete
Upstream caches need this packet until true is returned, so hold it for deletion until a subsequent c...
CacheBlk * allocateBlock(const PacketPtr pkt, PacketList &writebacks)
Allocate a new block and perform any necessary writebacks.
ProbePointArg< CacheDataUpdateProbeArg > * ppDataUpdate
To probe when the contents of a block are updated.
prefetch::Base * prefetcher
Prefetcher.
uint8_t blocked
Bit vector of the blocking reasons for the access path.
virtual Tick recvAtomicSnoop(PacketPtr pkt)=0
Snoop for the provided request in the cache and return the estimated time taken.
TempCacheBlk * tempBlock
Temporary cache block for occasional transitory use.
const AddrRangeList addrRanges
The address range to which the cache responds on the CPU side.
ProbePointArg< CacheAccessProbeArg > * ppHit
To probe when a cache hit occurs.
const int numTarget
The number of targets for each MSHR.
const bool moveContractions
Similar to data expansions, after a block improves its compression, it may need to be moved elsewhere...
WriteAllocator *const writeAllocator
The writeAllocator drive optimizations for streaming writes.
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...
void allocateWriteBuffer(PacketPtr pkt, Tick time)
Cycles calculateTagOnlyLatency(const uint32_t delay, const Cycles lookup_lat) const
Calculate latency of accesses that only touch the tag array.
CacheBlk * handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks, bool allocate)
Handle a fill operation caused by a received packet.
void incMissCount(PacketPtr pkt)
WriteQueue writeBuffer
Write/writeback buffer.
const bool replaceExpansions
when a data expansion of a compressed block happens it will not be able to co-allocate where it is at...
void serialize(CheckpointOut &cp) const override
Serialize the state of the caches.
bool coalesce() const
Checks if the cache is coalescing writes.
Cycles blockedCycle
Stores time the cache blocked for statistics.
const bool sequentialAccess
Whether tags and data are accessed sequentially.
bool handleEvictions(std::vector< CacheBlk * > &evict_blks, PacketList &writebacks)
Try to evict the given blocks.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
PacketPtr writebackBlk(CacheBlk *blk)
Create a writeback request for the given block.
void clearBlocked(BlockedCause cause)
Marks the cache as unblocked for the given cause.
const AddrRangeList & getAddrRanges() const
virtual PacketPtr evictBlock(CacheBlk *blk)=0
Evict a cache block.
void writebackVisitor(CacheBlk &blk)
Cache block visitor that writes back dirty cache blocks using functional writes.
EventFunctionWrapper writebackTempBlockAtomicEvent
An event to writeback the tempBlock after recvAtomic finishes.
BaseTags * tags
Tag and data Storage.
const enums::Clusivity clusivity
Clusivity with respect to the upstream cache, determining if we fill into both this cache and the cac...
ProbePointArg< CacheAccessProbeArg > * ppMiss
To probe when a cache miss occurs.
virtual bool sendMSHRQueuePacket(MSHR *mshr)
Take an MSHR, turn it into a suitable downstream packet, and send it out.
void maintainClusivity(bool from_cache, CacheBlk *blk)
Maintain the clusivity of this cache by potentially invalidating a block.
System * system
System we are currently operating in.
partitioning_policy::PartitionManager * partitionManager
Partitioning manager.
uint32_t getSrcRequestorId() const
Get the requestor id associated to this block.
bool wasPrefetched() const
Check if this block was the result of a hardware prefetch, yet to be touched.
A coherent cache that can be arranged in flexible topologies.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Cycles is a wrapper class for representing cycle counts, i.e.
A Class for maintaining a list of pending and allocated memory requests.
void markInService(MSHR *mshr, bool pending_modified_resp)
Mark the given MSHR as in service.
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.
Miss Status and handling Register.
virtual std::string name() const
const std::string label
Label to use for print request packets label stack.
bool checkConflict(const PacketPtr pkt, const int blk_size) const
Check if a packet corresponding to the same address exists in the queue.
void schedSendEvent(Tick when)
Schedule a send event if we are not already waiting for a retry.
Tick deferredPacketReadyTime() const
Get the next packet ready time.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Addr getBlockAddr(unsigned int blk_size) const
RequestPtr req
A pointer to the original request.
MemCmd cmd
The command field of the packet.
Ports are used to interface objects to each other.
ProbePointArg generates a point for the class of Arg.
A queue entry base class, to be used by both the MSHRs and write-queue entries.
bool inService
True if the entry has been sent downstream.
Entry * findMatch(Addr blk_addr, bool is_secure, bool ignore_uncacheable=true) const
Find the first entry that matches the provided address.
The QueuedRequestPort combines two queues, a request queue and a snoop response queue,...
ReqPacketQueue & reqQueue
Packet queue used to store outgoing requests.
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Abstract superclass for simulation objects.
RequestorID maxRequestors()
Get the number of requestors registered in the system.
Special instance of CacheBlk for use with tempBlk that deals with its block address regeneration.
The write allocator inspects write packets and detects streaming patterns.
const uint32_t noAllocateLimit
bool coalesce() const
Should writes be coalesced? This is true if the mode is set to NO_ALLOCATE.
bool delay(Addr blk_addr)
Access whether we need to delay the current write.
WriteAllocator(const WriteAllocatorParams &p)
const uint32_t delayThreshold
The number of times the allocator will delay an WriteReq MSHR.
std::unordered_map< Addr, Counter > delayCtr
Keep track of the number of times the allocator has delayed an WriteReq MSHR.
WriteMode
The current mode for write coalescing and allocation, either normal operation (ALLOCATE),...
void reset()
Reset the write allocator state, meaning that it allocates for writes and has not recorded any inform...
bool allocate() const
Should writes allocate?
void updateMode(Addr write_addr, unsigned write_size, Addr blk_addr)
Update the write mode based on the current write packet.
const uint32_t coalesceLimit
Limits for when to switch between the different write modes.
uint32_t byteCount
Bytes written contiguously.
void resetDelay(Addr blk_addr)
Clear delay counter for the input block.
Addr nextAddr
Address to match writes against to detect streams.
A write queue for all eviction packets, i.e.
void markInService(WriteQueueEntry *entry)
Mark the given entry as in service.
WriteQueueEntry * allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, Tick when_ready, Counter order)
Allocates a new WriteQueueEntry for the request and size.
Base cache compressor interface.
This is a simple scalar statistic, like a counter.
A vector of scalar stats.
ClockedObject declaration and implementation.
Definition of a basic cache compressor.
Declaration of a structure to manage MSHRs.
double Counter
All counters are of 64-bit values.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
const PortID InvalidPortID
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
uint64_t Tick
Tick count type.
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 (...
Declaration of the Packet class.
Declaration of a simple PacketQueue that is associated with a port on which it attempts to send packe...
Declaration of the queued port.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.
bool hasBeenPrefetched(Addr addr, bool is_secure) const override
Determine if address has been prefetched.
bool hasBeenPrefetched(Addr addr, bool is_secure, RequestorID requestor) const override
Determine if address has been prefetched by the requestor.
bool inCache(Addr addr, bool is_secure) const override
Determine if address is in cache.
bool coalesce() const override
Determine if cache is coalescing writes.
bool inMissQueue(Addr addr, bool is_secure) const override
Determine if address is in cache miss queue.
CacheAccessorImpl(BaseCache &_cache)
statistics::Formula accesses
The number of accesses per command and thread.
statistics::Formula avgMshrMissLatency
The average latency of an MSHR miss, per command and thread.
void regStatsFromParent()
Callback to register stats from parent CacheStats::regStats().
statistics::Formula avgMshrUncacheableLatency
The average latency of an MSHR miss, per command and thread.
statistics::Vector misses
Number of misses per thread for each type of command.
statistics::Formula missRate
The miss rate per command and thread.
statistics::Vector missLatency
Total number of ticks per thread/command spent waiting for a miss.
statistics::Formula mshrMissRate
The miss rate in the MSHRs pre command and thread.
statistics::Vector mshrUncacheableLatency
Total tick latency of each MSHR miss, per command and thread.
statistics::Vector hitLatency
Total number of ticks per thread/command spent waiting for a hit.
statistics::Vector mshrHits
Number of misses that hit in the MSHRs per command and thread.
statistics::Vector mshrUncacheable
Number of misses that miss in the MSHRs, per command and thread.
CacheCmdStats(BaseCache &c, const std::string &name)
statistics::Formula avgMissLatency
The average miss latency per command and thread.
statistics::Vector mshrMisses
Number of misses that miss in the MSHRs, per command and thread.
statistics::Vector mshrMissLatency
Total tick latency of each MSHR miss, per command and thread.
statistics::Vector hits
Number of hits per thread for each type of command.
statistics::Formula overallMshrMissLatency
Total tick latency of overall MSHR misses.
statistics::Formula demandMshrMissLatency
Total tick latency of demand MSHR misses.
statistics::Formula overallAvgMshrUncacheableLatency
The average overall latency of an MSHR miss.
statistics::Formula demandHits
Number of hits for demand accesses.
statistics::Formula demandHitLatency
Total number of ticks spent waiting for demand hits.
statistics::Formula demandAccesses
The number of demand accesses.
statistics::Scalar replacements
Number of replacements of valid blocks.
statistics::Formula overallAvgMshrMissLatency
The average overall latency of an MSHR miss.
statistics::Formula demandMissRate
The miss rate of all demand accesses.
statistics::Formula overallMissRate
The miss rate for all accesses.
statistics::Formula demandAvgMshrMissLatency
The average latency of a demand MSHR miss.
statistics::Formula demandMshrMisses
Demand misses that miss in the MSHRs.
statistics::Formula overallMshrMisses
Total number of misses that miss in the MSHRs.
statistics::Formula overallMshrHits
Total number of misses that hit in the MSHRs.
statistics::Formula overallHitLatency
Total number of ticks spent waiting for all hits.
statistics::Scalar dataContractions
Number of data contractions (blocks that had their compression factor improved).
void regStats() override
Callback to set stat parameters.
statistics::Scalar dataExpansions
Number of data expansions.
statistics::Formula overallMshrUncacheable
Total number of misses that miss in the MSHRs.
statistics::Formula demandMissLatency
Total number of ticks spent waiting for demand misses.
statistics::Formula overallMisses
Number of misses for all accesses.
statistics::Formula overallMshrMissRate
The overall miss rate in the MSHRs.
statistics::Formula overallAccesses
The number of overall accesses.
std::vector< std::unique_ptr< CacheCmdStats > > cmd
Per-command statistics.
statistics::Formula demandMshrMissRate
The demand miss rate in the MSHRs.
statistics::Formula avgBlocked
The average number of cycles blocked for each blocked cause.
statistics::Formula overallMshrUncacheableLatency
Total tick latency of overall MSHR misses.
statistics::Formula demandMisses
Number of misses for demand accesses.
statistics::Formula demandAvgMissLatency
The average miss latency for demand misses.
statistics::Formula overallMissLatency
Total number of ticks spent waiting for all misses.
statistics::Formula demandMshrHits
Demand misses that hit in the MSHRs.
statistics::Formula overallAvgMissLatency
The average miss latency for all misses.
statistics::Vector blockedCauses
The number of times this cache blocked for each blocked cause.
statistics::Vector writebacks
Number of blocks written back per thread.
statistics::Vector blockedCycles
The total number of cycles blocked for each blocked cause.
statistics::Formula overallHits
Number of hit for all accesses.
CacheCmdStats & cmdStats(const PacketPtr p)
Provides generic cache lookup functions.