gem5  v20.0.0.2
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 
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 SlavePort
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) :
74  SlavePort(name, owner), id(id), owner(owner), needRetry(false),
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 MasterPort
141  {
142  private:
145 
148 
149  public:
153  MemSidePort(const std::string& name, SimpleCache *owner) :
154  MasterPort(name, owner), owner(owner), blockedPacket(nullptr)
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 
299 
300  public:
301 
304  SimpleCache(SimpleCacheParams *params);
305 
316  Port &getPort(const std::string &if_name,
317  PortID idx=InvalidPortID) override;
318 
322  void regStats() override;
323 };
324 
325 
326 #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:71
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: simple_cache.cc:53
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
Stats::Scalar hits
Cache statistics.
Ports are used to interface objects to each other.
Definition: port.hh:56
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:282
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
const PortID InvalidPortID
Definition: types.hh:236
A very simple cache object.
Definition: simple_cache.hh:46
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:35
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:54
A SlavePort is a specialisation of a port.
Definition: port.hh:254
Stats::Scalar misses
Declaration of Statistics objects.
const Params * params() const
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2505
STL vector class.
Definition: stl.hh:37
CPUSidePort(const std::string &name, int id, SimpleCache *owner)
Constructor.
Definition: simple_cache.hh:73
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:91
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:61
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:67
ClockedObject declaration and implementation.
int id
Since this is a vector port, need to know what number this one is.
Definition: simple_cache.hh:58
A simple histogram stat.
Definition: statistics.hh:2626
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:249
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:3009
Tick missTime
For tracking the miss latency.
SimpleCache * owner
The object that owns this object (SimpleCache)
Definition: simple_cache.hh:61
MemSidePort memPort
Instantiation of the memory-side port.
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:102
PacketPtr originalPacket
Packet that we are currently handling.
bool needRetry
True if the port needs to send a retry req.
Definition: simple_cache.hh:64
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:235
void sendPacket(PacketPtr pkt)
Send a packet across this port.
Definition: simple_cache.cc:70
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: simple_cache.cc:85
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 Mon Jun 8 2020 15:45:11 for gem5 by doxygen 1.8.13