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) {
57 if (if_name ==
"mem_side") {
59 "Mem side of simple cache not a vector port");
61 }
else if (if_name ==
"cpu_side" && idx <
cpuPorts.size()) {
88 return owner->getAddrRanges();
94 if (needRetry && blockedPacket ==
nullptr) {
106 return owner->handleFunctional(pkt);
114 if (blockedPacket || needRetry) {
121 if (!owner->handleRequest(pkt,
id)) {
136 assert(blockedPacket !=
nullptr);
140 blockedPacket =
nullptr;
155 panic_if(blockedPacket !=
nullptr,
"Should never try to send if blocked!");
158 if (!sendTimingReq(pkt)) {
167 return owner->handleResponse(pkt);
174 assert(blockedPacket !=
nullptr);
178 blockedPacket =
nullptr;
187 owner->sendRangeChange();
209 name() +
".accessEvent",
true),
234 panic_if(!hit,
"Should always hit after inserting");
302 unsigned size = pkt->
getSize();
310 "Cannot handle accesses that span multiple cache lines");
319 panic(
"Unknown packet type in upgrade size");
347 }
else if (pkt->
isRead()) {
351 panic(
"Unknown packet type!");
371 int bucket, bucket_size;
374 }
while ( (bucket_size =
cacheStore.bucket_size(bucket)) == 0 );
375 auto block = std::next(
cacheStore.begin(bucket),
421 port.sendRangeChange();
428 ADD_STAT(misses,
"Number of misses"),
429 ADD_STAT(missLatency,
"Ticks for misses to the cache"),
430 ADD_STAT(hitRatio,
"The ratio of hits to the total"
431 "accesses to the cache", hits / (hits + misses))
438 SimpleCacheParams::create()
SimpleCache(SimpleCacheParams *params)
constructor
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...
const Params * params() const
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 ...
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.
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
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.
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.
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.
Tick curTick()
The current simulated tick.
Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17