gem5 v24.0.0.0
Loading...
Searching...
No Matches
simple_cache.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Jason Lowe-Power
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
30#define __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
31
32#include <unordered_map>
33
34#include "base/statistics.hh"
35#include "mem/port.hh"
36#include "params/SimpleCache.hh"
37#include "sim/clocked_object.hh"
38
39namespace gem5
40{
41
50{
51 private:
52
58 {
59 private:
61 int id;
62
65
68
71
72 public:
76 CPUSidePort(const std::string& name, int id, SimpleCache *owner) :
78 blockedPacket(nullptr)
79 { }
80
88 void sendPacket(PacketPtr pkt);
89
97 AddrRangeList getAddrRanges() const override;
98
103 void trySendRetry();
104
105 protected:
111 { panic("recvAtomic unimpl."); }
112
119 void recvFunctional(PacketPtr pkt) override;
120
129 bool recvTimingReq(PacketPtr pkt) override;
130
136 void recvRespRetry() override;
137 };
138
144 {
145 private:
148
151
152 public:
156 MemSidePort(const std::string& name, SimpleCache *owner) :
158 { }
159
167 void sendPacket(PacketPtr pkt);
168
169 protected:
173 bool recvTimingResp(PacketPtr pkt) override;
174
180 void recvReqRetry() override;
181
189 void recvRangeChange() override;
190 };
191
201 bool handleRequest(PacketPtr pkt, int port_id);
202
211 bool handleResponse(PacketPtr pkt);
212
221 void sendResponse(PacketPtr pkt);
222
229 void handleFunctional(PacketPtr pkt);
230
235 void accessTiming(PacketPtr pkt);
236
243 bool accessFunctional(PacketPtr pkt);
244
251 void insert(PacketPtr pkt);
252
260
264 void sendRangeChange() const;
265
268
271
273 const unsigned capacity;
274
277
280
283
287
290
293
295 std::unordered_map<Addr, uint8_t*> cacheStore;
296
298 protected:
307
308 public:
309
312 SimpleCache(const SimpleCacheParams &params);
313
324 Port &getPort(const std::string &if_name,
325 PortID idx=InvalidPortID) override;
326
327};
328
329} // namespace gem5
330
331#endif // __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
const std::string name() const
Return port name (for DPRINTF).
Definition port.hh:111
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
A ResponsePort is a specialization of a port.
Definition port.hh:349
Port on the CPU-side that receives requests.
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.
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the request port.
CPUSidePort(const std::string &name, int id, SimpleCache *owner)
Constructor.
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
int id
Since this is a vector port, need to know what number this one is.
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.
Port on the memory-side that receives responses.
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.
MemSidePort(const std::string &name, SimpleCache *owner)
Constructor.
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...
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 &params)
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.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
A simple histogram stat.
This is a simple scalar statistic, like a counter.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
const Params & params() const
Port Object Declaration.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
Declaration of Statistics objects.
SimpleCacheStats(statistics::Group *parent)

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0