32#include "debug/SimpleCache.hh"
50 for (
int i = 0;
i <
params.port_cpu_side_connection_count; ++
i) {
59 if (if_name ==
"mem_side") {
61 "Mem side of simple cache not a vector port");
63 }
else if (if_name ==
"cpu_side" && idx <
cpuPorts.size()) {
90 return owner->getAddrRanges();
108 return owner->handleFunctional(pkt);
123 if (!
owner->handleRequest(pkt,
id)) {
169 return owner->handleResponse(pkt);
189 owner->sendRangeChange();
211 name() +
".accessEvent",
true),
236 panic_if(!hit,
"Should always hit after inserting");
304 unsigned size = pkt->
getSize();
312 "Cannot handle accesses that span multiple cache lines");
321 panic(
"Unknown packet type in upgrade size");
349 }
else if (pkt->
isRead()) {
353 panic(
"Unknown packet type!");
373 int bucket, bucket_size;
376 }
while ( (bucket_size =
cacheStore.bucket_size(bucket)) == 0 );
377 auto block = std::next(
cacheStore.begin(bucket),
378 rng->random(0, bucket_size - 1));
416 return memPort.getAddrRanges();
423 port.sendRangeChange();
432 "Ticks for misses to the cache"),
434 "The ratio of hits to the total accesses to the cache",
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
ClockedObject(const ClockedObjectParams &p)
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...
virtual std::string name() const
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
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.
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
bool needsResponse() const
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
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.
Addr getBlockAddr(unsigned int blk_size) const
RequestPtr req
A pointer to the original request.
const T * getConstPtr() const
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
void allocate()
Allocate memory for the packet.
Ports are used to interface objects to each other.
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
SimpleCache * owner
The object that owns this object (SimpleCache)
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the request port.
void sendPacket(PacketPtr pkt)
Send a packet across this port.
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the request port.
void trySendRetry()
Send a retry to the peer port only if it is needed.
void recvRespRetry() override
Called by the request port if sendTimingResp was called on this response port (causing recvTimingResp...
bool needRetry
True if the port needs to send a retry req.
SimpleCache * owner
The object that owns this object (SimpleCache)
void sendPacket(PacketPtr pkt)
Send a packet across this port.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the response port.
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
void recvRangeChange() override
Called to receive an address range change from the peer response port.
void recvReqRetry() override
Called by the response port if sendTimingReq was called on this request port (causing recvTimingReq t...
const unsigned capacity
Number of blocks in the cache (size of cache / block size)
void handleFunctional(PacketPtr pkt)
Handle a packet functionally.
PacketPtr originalPacket
Packet that we are currently handling.
bool blocked
True if this cache is currently blocked waiting for a response.
const Addr blockSize
The block size for the cache.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
bool handleResponse(PacketPtr pkt)
Handle the respone from the memory side.
void sendRangeChange() const
Tell the CPU side to ask for our memory ranges.
SimpleCache(const SimpleCacheParams ¶ms)
constructor
void insert(PacketPtr pkt)
Insert a block into the cache.
gem5::SimpleCache::SimpleCacheStats stats
AddrRangeList getAddrRanges() const
Return the address ranges this cache is responsible for.
bool handleRequest(PacketPtr pkt, int port_id)
Handle the request from the CPU side.
MemSidePort memPort
Instantiation of the memory-side port.
Tick missTime
For tracking the miss latency.
std::unordered_map< Addr, uint8_t * > cacheStore
An incredibly simple cache storage. Maps block addresses to data.
std::vector< CPUSidePort > cpuPorts
Instantiation of the CPU-side port.
void accessTiming(PacketPtr pkt)
Access the cache for a timing access.
void sendResponse(PacketPtr pkt)
Send the packet to the CPU side.
bool accessFunctional(PacketPtr pkt)
This is where we actually update / read from the cache.
const Cycles latency
Latency to check the cache. Number of cycles for both hit and miss.
int waitingPortId
The port to send the response when we recieve it back.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
void schedule(Event &event, Tick when)
#define panic(...)
This implements a cprintf based panic() function.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
const Params & params() const
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Copyright (c) 2024 Arm Limited All rights reserved.
std::shared_ptr< Request > RequestPtr
const PortID InvalidPortID
Tick curTick()
The universal simulation clock.
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.
std::string csprintf(const char *format, const Args &...args)
statistics::Scalar misses
statistics::Formula hitRatio
SimpleCacheStats(statistics::Group *parent)
statistics::Histogram missLatency