gem5  v20.1.0.0
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 
46 class SimpleCache : public ClockedObject
47 {
48  private:
49 
54  class CPUSidePort : public ResponsePort
55  {
56  private:
58  int id;
59 
62 
64  bool needRetry;
65 
68 
69  public:
73  CPUSidePort(const std::string& name, int id, SimpleCache *owner) :
75  blockedPacket(nullptr)
76  { }
77 
85  void sendPacket(PacketPtr pkt);
86 
94  AddrRangeList getAddrRanges() const override;
95 
100  void trySendRetry();
101 
102  protected:
107  Tick recvAtomic(PacketPtr pkt) override
108  { panic("recvAtomic unimpl."); }
109 
116  void recvFunctional(PacketPtr pkt) override;
117 
126  bool recvTimingReq(PacketPtr pkt) override;
127 
133  void recvRespRetry() override;
134  };
135 
140  class MemSidePort : public RequestPort
141  {
142  private:
145 
148 
149  public:
153  MemSidePort(const std::string& name, SimpleCache *owner) :
155  { }
156 
164  void sendPacket(PacketPtr pkt);
165 
166  protected:
170  bool recvTimingResp(PacketPtr pkt) override;
171 
177  void recvReqRetry() override;
178 
186  void recvRangeChange() override;
187  };
188 
198  bool handleRequest(PacketPtr pkt, int port_id);
199 
208  bool handleResponse(PacketPtr pkt);
209 
218  void sendResponse(PacketPtr pkt);
219 
226  void handleFunctional(PacketPtr pkt);
227 
232  void accessTiming(PacketPtr pkt);
233 
240  bool accessFunctional(PacketPtr pkt);
241 
248  void insert(PacketPtr pkt);
249 
257 
261  void sendRangeChange() const;
262 
265 
267  const unsigned blockSize;
268 
270  const unsigned capacity;
271 
274 
277 
279  bool blocked;
280 
284 
287 
290 
292  std::unordered_map<Addr, uint8_t*> cacheStore;
293 
295  protected:
297  {
303  } stats;
304 
305  public:
306 
309  SimpleCache(SimpleCacheParams *params);
310 
321  Port &getPort(const std::string &if_name,
322  PortID idx=InvalidPortID) override;
323 
324 };
325 
326 
327 #endif // __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
SimpleCache::SimpleCache
SimpleCache(SimpleCacheParams *params)
constructor
Definition: simple_cache.cc:35
SimpleCache::SimpleCacheStats::SimpleCacheStats
SimpleCacheStats(Stats::Group *parent)
Definition: simple_cache.cc:425
SimpleCache::SimpleCacheStats::hits
Stats::Scalar hits
Definition: simple_cache.hh:299
SimpleCache::CPUSidePort::owner
SimpleCache * owner
The object that owns this object (SimpleCache)
Definition: simple_cache.hh:61
ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:265
SimpleCache::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: simple_cache.cc:54
SimpleCache::SimpleCacheStats
Cache statistics.
Definition: simple_cache.hh:296
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:238
SimpleCache::handleFunctional
void handleFunctional(PacketPtr pkt)
Handle a packet functionally.
Definition: simple_cache.cc:271
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
SimpleCache::getAddrRanges
AddrRangeList getAddrRanges() const
Return the address ranges this cache is responsible for.
Definition: simple_cache.cc:410
SimpleCache::MemSidePort::recvRangeChange
void recvRangeChange() override
Called to receive an address range change from the peer response port.
Definition: simple_cache.cc:185
SimpleCache::MemSidePort::sendPacket
void sendPacket(PacketPtr pkt)
Send a packet across this port.
Definition: simple_cache.cc:151
std::vector
STL vector class.
Definition: stl.hh:37
ClockedObject::params
const Params * params() const
Definition: clocked_object.hh:239
SimpleCache::handleResponse
bool handleResponse(PacketPtr pkt)
Handle the respone from the memory side.
Definition: simple_cache.cc:216
SimpleCache::cacheStore
std::unordered_map< Addr, uint8_t * > cacheStore
An incredibly simple cache storage. Maps block addresses to data.
Definition: simple_cache.hh:292
SimpleCache::capacity
const unsigned capacity
Number of blocks in the cache (size of cache / block size)
Definition: simple_cache.hh:270
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Stats::Histogram
A simple histogram stat.
Definition: statistics.hh:2654
SimpleCache::handleRequest
bool handleRequest(PacketPtr pkt, int port_id)
Handle the request from the CPU side.
Definition: simple_cache.cc:191
SimpleCache::SimpleCacheStats::misses
Stats::Scalar misses
Definition: simple_cache.hh:300
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
SimpleCache::sendRangeChange
void sendRangeChange() const
Tell the CPU side to ask for our memory ranges.
Definition: simple_cache.cc:418
SimpleCache::CPUSidePort::blockedPacket
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
Definition: simple_cache.hh:67
SimpleCache::MemSidePort::recvReqRetry
void recvReqRetry() override
Called by the response port if sendTimingReq was called on this request port (causing recvTimingReq t...
Definition: simple_cache.cc:171
SimpleCache::insert
void insert(PacketPtr pkt)
Insert a block into the cache.
Definition: simple_cache.cc:359
SimpleCache::accessTiming
void accessTiming(PacketPtr pkt)
Access the cache for a timing access.
Definition: simple_cache.cc:281
SimpleCache::SimpleCacheStats::hitRatio
Stats::Formula hitRatio
Definition: simple_cache.hh:302
SimpleCache::stats
SimpleCache::SimpleCacheStats stats
SimpleCache::CPUSidePort::trySendRetry
void trySendRetry()
Send a retry to the peer port only if it is needed.
Definition: simple_cache.cc:92
statistics.hh
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
port.hh
SimpleCache::sendResponse
void sendResponse(PacketPtr pkt)
Send the packet to the CPU side.
Definition: simple_cache.cc:246
SimpleCache::CPUSidePort::CPUSidePort
CPUSidePort(const std::string &name, int id, SimpleCache *owner)
Constructor.
Definition: simple_cache.hh:73
SimpleCache::latency
const Cycles latency
Latency to check the cache. Number of cycles for both hit and miss.
Definition: simple_cache.hh:264
SimpleCache::CPUSidePort::id
int id
Since this is a vector port, need to know what number this one is.
Definition: simple_cache.hh:58
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
SimpleCache
A very simple cache object.
Definition: simple_cache.hh:46
Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
SimpleCache::CPUSidePort::sendPacket
void sendPacket(PacketPtr pkt)
Send a packet across this port.
Definition: simple_cache.cc:71
SimpleCache::MemSidePort::recvTimingResp
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the response port.
Definition: simple_cache.cc:164
SimpleCache::missTime
Tick missTime
For tracking the miss latency.
Definition: simple_cache.hh:289
SimpleCache::MemSidePort
Port on the memory-side that receives responses.
Definition: simple_cache.hh:140
SimpleCache::CPUSidePort::needRetry
bool needRetry
True if the port needs to send a retry req.
Definition: simple_cache.hh:64
SimpleCache::originalPacket
PacketPtr originalPacket
Packet that we are currently handling.
Definition: simple_cache.hh:283
clocked_object.hh
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3037
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Stats::Group
Statistics container.
Definition: group.hh:83
SimpleCache::CPUSidePort
Port on the CPU-side that receives requests.
Definition: simple_cache.hh:54
SimpleCache::MemSidePort::MemSidePort
MemSidePort(const std::string &name, SimpleCache *owner)
Constructor.
Definition: simple_cache.hh:153
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
SimpleCache::CPUSidePort::recvTimingReq
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the request port.
Definition: simple_cache.cc:110
SimpleCache::CPUSidePort::getAddrRanges
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: simple_cache.cc:86
SimpleCache::CPUSidePort::recvRespRetry
void recvRespRetry() override
Called by the request port if sendTimingResp was called on this response port (causing recvTimingResp...
Definition: simple_cache.cc:133
SimpleCache::MemSidePort::owner
SimpleCache * owner
The object that owns this object (SimpleCache)
Definition: simple_cache.hh:144
std::list< AddrRange >
SimpleCache::cpuPorts
std::vector< CPUSidePort > cpuPorts
Instantiation of the CPU-side port.
Definition: simple_cache.hh:273
SimpleCache::memPort
MemSidePort memPort
Instantiation of the memory-side port.
Definition: simple_cache.hh:276
SimpleCache::SimpleCacheStats::missLatency
Stats::Histogram missLatency
Definition: simple_cache.hh:301
SimpleCache::MemSidePort::blockedPacket
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
Definition: simple_cache.hh:147
SimpleCache::CPUSidePort::recvAtomic
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the request port.
Definition: simple_cache.hh:107
SimpleCache::waitingPortId
int waitingPortId
The port to send the response when we recieve it back.
Definition: simple_cache.hh:286
SimpleCache::blockSize
const unsigned blockSize
The block size for the cache.
Definition: simple_cache.hh:267
SimpleCache::accessFunctional
bool accessFunctional(PacketPtr pkt)
This is where we actually update / read from the cache.
Definition: simple_cache.cc:339
SimpleCache::CPUSidePort::recvFunctional
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the request port.
Definition: simple_cache.cc:103
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
SimpleCache::blocked
bool blocked
True if this cache is currently blocked waiting for a response.
Definition: simple_cache.hh:279

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17