33#include "debug/SimpleCache.hh"
41 latency(params.latency),
42 blockSize(params.
system->cacheLineSize()),
43 capacity(params.size / blockSize),
44 memPort(params.
name +
".mem_side", this),
45 blocked(false), originalPacket(nullptr), waitingPortId(-1), stats(this)
51 for (
int i = 0;
i <
params.port_cpu_side_connection_count; ++
i) {
60 if (if_name ==
"mem_side") {
62 "Mem side of simple cache not a vector port");
64 }
else if (if_name ==
"cpu_side" && idx <
cpuPorts.size()) {
91 return owner->getAddrRanges();
97 if (needRetry && blockedPacket ==
nullptr) {
109 return owner->handleFunctional(pkt);
117 if (blockedPacket || needRetry) {
124 if (!owner->handleRequest(pkt,
id)) {
139 assert(blockedPacket !=
nullptr);
143 blockedPacket =
nullptr;
158 panic_if(blockedPacket !=
nullptr,
"Should never try to send if blocked!");
161 if (!sendTimingReq(pkt)) {
170 return owner->handleResponse(pkt);
177 assert(blockedPacket !=
nullptr);
181 blockedPacket =
nullptr;
190 owner->sendRangeChange();
212 name() +
".accessEvent",
true),
237 panic_if(!hit,
"Should always hit after inserting");
305 unsigned size = pkt->
getSize();
313 "Cannot handle accesses that span multiple cache lines");
322 panic(
"Unknown packet type in upgrade size");
350 }
else if (pkt->
isRead()) {
354 panic(
"Unknown packet type!");
374 int bucket, bucket_size;
377 }
while ( (bucket_size =
cacheStore.bucket_size(bucket)) == 0 );
378 auto block = std::next(
cacheStore.begin(bucket),
424 port.sendRangeChange();
429 : statistics::
Group(parent),
430 ADD_STAT(hits, statistics::units::Count::get(),
"Number of hits"),
431 ADD_STAT(misses, statistics::units::Count::get(),
"Number of misses"),
433 "Ticks for misses to the cache"),
434 ADD_STAT(hitRatio, statistics::units::Ratio::get(),
435 "The ratio of hits to the total accesses to the cache",
436 hits / (hits + misses))
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
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.
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
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...
void sendPacket(PacketPtr pkt)
Send a packet across this port.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the response port.
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...
A very simple cache object.
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.
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Histogram & init(size_type size)
Set the parameters of this histogram.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
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 - Pranith Kumar Copyright (c) 2020 Inria 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
SimpleCacheStats(statistics::Group *parent)
statistics::Histogram missLatency
const std::string & name()