gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Jason Lowe-Power
29  */
30 
31 #ifndef __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
32 #define __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
33 
34 #include <unordered_map>
35 
36 #include "base/statistics.hh"
37 #include "mem/port.hh"
38 #include "params/SimpleCache.hh"
39 #include "sim/clocked_object.hh"
40 
48 class SimpleCache : public ClockedObject
49 {
50  private:
51 
56  class CPUSidePort : public SlavePort
57  {
58  private:
60  int id;
61 
64 
66  bool needRetry;
67 
70 
71  public:
75  CPUSidePort(const std::string& name, int id, SimpleCache *owner) :
76  SlavePort(name, owner), id(id), owner(owner), needRetry(false),
77  blockedPacket(nullptr)
78  { }
79 
87  void sendPacket(PacketPtr pkt);
88 
96  AddrRangeList getAddrRanges() const override;
97 
102  void trySendRetry();
103 
104  protected:
109  Tick recvAtomic(PacketPtr pkt) override
110  { panic("recvAtomic unimpl."); }
111 
118  void recvFunctional(PacketPtr pkt) override;
119 
128  bool recvTimingReq(PacketPtr pkt) override;
129 
135  void recvRespRetry() override;
136  };
137 
142  class MemSidePort : public MasterPort
143  {
144  private:
147 
150 
151  public:
155  MemSidePort(const std::string& name, SimpleCache *owner) :
156  MasterPort(name, owner), owner(owner), blockedPacket(nullptr)
157  { }
158 
166  void sendPacket(PacketPtr pkt);
167 
168  protected:
172  bool recvTimingResp(PacketPtr pkt) override;
173 
179  void recvReqRetry() override;
180 
188  void recvRangeChange() override;
189  };
190 
200  bool handleRequest(PacketPtr pkt, int port_id);
201 
210  bool handleResponse(PacketPtr pkt);
211 
220  void sendResponse(PacketPtr pkt);
221 
228  void handleFunctional(PacketPtr pkt);
229 
234  void accessTiming(PacketPtr pkt);
235 
242  bool accessFunctional(PacketPtr pkt);
243 
250  void insert(PacketPtr pkt);
251 
259 
263  void sendRangeChange() const;
264 
267 
269  const unsigned blockSize;
270 
272  const unsigned capacity;
273 
276 
279 
281  bool blocked;
282 
286 
289 
292 
294  std::unordered_map<Addr, uint8_t*> cacheStore;
295 
301 
302  public:
303 
306  SimpleCache(SimpleCacheParams *params);
307 
318  Port &getPort(const std::string &if_name,
319  PortID idx=InvalidPortID) override;
320 
324  void regStats() override;
325 };
326 
327 
328 #endif // __LEARNING_GEM5_SIMPLE_CACHE_SIMPLE_CACHE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: simple_cache.cc:55
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Stats::Scalar hits
Cache statistics.
Ports are used to interface objects to each other.
Definition: port.hh:60
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the master port.
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:286
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
const PortID InvalidPortID
Definition: types.hh:238
A very simple cache object.
Definition: simple_cache.hh:48
void handleFunctional(PacketPtr pkt)
Handle a packet functionally.
int waitingPortId
The port to send the response when we recieve it back.
const unsigned blockSize
The block size for the cache.
SimpleCache(SimpleCacheParams *params)
constructor
Definition: simple_cache.cc:37
const unsigned capacity
Number of blocks in the cache (size of cache / block size)
Port on the memory-side that receives responses.
bool handleRequest(PacketPtr pkt, int port_id)
Handle the request from the CPU side.
Port on the CPU-side that receives requests.
Definition: simple_cache.hh:56
A SlavePort is a specialisation of a port.
Definition: port.hh:258
Stats::Scalar misses
Declaration of Statistics objects.
const Params * params() const
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
STL vector class.
Definition: stl.hh:40
CPUSidePort(const std::string &name, int id, SimpleCache *owner)
Constructor.
Definition: simple_cache.hh:75
Stats::Formula hitRatio
void sendResponse(PacketPtr pkt)
Send the packet to the CPU side.
void accessTiming(PacketPtr pkt)
Access the cache for a timing access.
void trySendRetry()
Send a retry to the peer port only if it is needed.
Definition: simple_cache.cc:93
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.
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the master port.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
MemSidePort(const std::string &name, SimpleCache *owner)
Constructor.
void insert(PacketPtr pkt)
Insert a block into the cache.
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
Definition: simple_cache.hh:69
ClockedObject declaration and implementation.
int id
Since this is a vector port, need to know what number this one is.
Definition: simple_cache.hh:60
A simple histogram stat.
Definition: statistics.hh:2629
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the master port.
Port Object Declaration.
void regStats() override
Register the stats.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
const Cycles latency
Latency to check the cache. Number of cycles for both hit and miss.
SimpleCache * owner
The object that owns this object (SimpleCache)
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
Tick missTime
For tracking the miss latency.
SimpleCache * owner
The object that owns this object (SimpleCache)
Definition: simple_cache.hh:63
MemSidePort memPort
Instantiation of the memory-side port.
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
PacketPtr originalPacket
Packet that we are currently handling.
bool needRetry
True if the port needs to send a retry req.
Definition: simple_cache.hh:66
std::vector< CPUSidePort > cpuPorts
Instantiation of the CPU-side port.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
void sendPacket(PacketPtr pkt)
Send a packet across this port.
Definition: simple_cache.cc:72
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: simple_cache.cc:87
PacketPtr blockedPacket
If we tried to send a packet and it was blocked, store it here.
Stats::Histogram missLatency
bool accessFunctional(PacketPtr pkt)
This is where we actually update / read from the cache.
void recvRespRetry() override
Called by the master port if sendTimingResp was called on this slave port (causing recvTimingResp to ...
bool blocked
True if this cache is currently blocked waiting for a response.

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13