Go to the documentation of this file.
32 #include "debug/SimpleCache.hh"
37 latency(params.latency),
38 blockSize(params.
system->cacheLineSize()),
39 capacity(params.size / blockSize),
40 memPort(params.
name +
".mem_side", this),
41 blocked(false), originalPacket(nullptr), waitingPortId(-1), stats(this)
47 for (
int i = 0;
i <
params.port_cpu_side_connection_count; ++
i) {
56 if (if_name ==
"mem_side") {
58 "Mem side of simple cache not a vector port");
60 }
else if (if_name ==
"cpu_side" && idx <
cpuPorts.size()) {
87 return owner->getAddrRanges();
93 if (needRetry && blockedPacket ==
nullptr) {
105 return owner->handleFunctional(pkt);
113 if (blockedPacket || needRetry) {
120 if (!owner->handleRequest(pkt,
id)) {
135 assert(blockedPacket !=
nullptr);
139 blockedPacket =
nullptr;
154 panic_if(blockedPacket !=
nullptr,
"Should never try to send if blocked!");
157 if (!sendTimingReq(pkt)) {
166 return owner->handleResponse(pkt);
173 assert(blockedPacket !=
nullptr);
177 blockedPacket =
nullptr;
186 owner->sendRangeChange();
208 name() +
".accessEvent",
true),
233 panic_if(!hit,
"Should always hit after inserting");
301 unsigned size = pkt->
getSize();
309 "Cannot handle accesses that span multiple cache lines");
318 panic(
"Unknown packet type in upgrade size");
346 }
else if (pkt->
isRead()) {
350 panic(
"Unknown packet type!");
370 int bucket, bucket_size;
373 }
while ( (bucket_size =
cacheStore.bucket_size(bucket)) == 0 );
374 auto block = std::next(
cacheStore.begin(bucket),
420 port.sendRangeChange();
430 "The ratio of hits to the total accesses to the cache",
431 hits / (hits + misses))
SimpleCacheStats(Stats::Group *parent)
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
const PortID InvalidPortID
void handleFunctional(PacketPtr pkt)
Handle a packet functionally.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
AddrRangeList getAddrRanges() const
Return the address ranges this cache is responsible for.
AddrRangeList getAddrRanges() const
Get the address ranges of the connected responder port.
std::shared_ptr< Request > RequestPtr
RequestPtr req
A pointer to the original request.
void recvRangeChange() override
Called to receive an address range change from the peer response port.
void sendPacket(PacketPtr pkt)
Send a packet across this port.
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
bool handleResponse(PacketPtr pkt)
Handle the respone from the memory side.
std::unordered_map< Addr, uint8_t * > cacheStore
An incredibly simple cache storage. Maps block addresses to data.
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
const unsigned capacity
Number of blocks in the cache (size of cache / block size)
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
std::enable_if_t< std::is_integral< T >::value, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
bool handleRequest(PacketPtr pkt, int port_id)
Handle the request from the CPU side.
void schedule(Event &event, Tick when)
void sendRangeChange() const
Tell the CPU side to ask for our memory ranges.
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
void recvReqRetry() override
Called by the response port if sendTimingReq was called on this request port (causing recvTimingReq t...
void insert(PacketPtr pkt)
Insert a block into the cache.
void accessTiming(PacketPtr pkt)
Access the cache for a timing access.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Addr getBlockAddr(unsigned int blk_size) const
SimpleCache::SimpleCacheStats stats
void trySendRetry()
Send a retry to the peer port only if it is needed.
Ports are used to interface objects to each other.
bool needsResponse() const
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...
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.
void sendResponse(PacketPtr pkt)
Send the packet to the CPU side.
const Cycles latency
Latency to check the cache. Number of cycles for both hit and miss.
A very simple cache object.
ProbePointArg< PacketInfo > Packet
Packet probe point.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
const std::string & name()
void sendPacket(PacketPtr pkt)
Send a packet across this port.
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
virtual const std::string name() const
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the response port.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Tick missTime
For tracking the miss latency.
PacketPtr originalPacket
Packet that we are currently handling.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the request port.
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Tick curTick()
The universal simulation clock.
void recvRespRetry() override
Called by the request port if sendTimingResp was called on this response port (causing recvTimingResp...
Histogram & init(size_type size)
Set the parameters of this histogram.
const Params & params() const
SimpleCache(const SimpleCacheParams ¶ms)
constructor
void allocate()
Allocate memory for the packet.
std::vector< CPUSidePort > cpuPorts
Instantiation of the CPU-side port.
MemSidePort memPort
Instantiation of the memory-side port.
Stats::Histogram missLatency
const T * getConstPtr() const
std::string csprintf(const char *format, const Args &...args)
int waitingPortId
The port to send the response when we recieve it back.
const unsigned blockSize
The block size for the cache.
bool accessFunctional(PacketPtr pkt)
This is where we actually update / read from the cache.
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the request port.
#define panic(...)
This implements a cprintf based panic() function.
bool blocked
True if this cache is currently blocked waiting for a response.
Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17