gem5  v20.1.0.0
abstract_mem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2019 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2001-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
46 #ifndef __MEM_ABSTRACT_MEMORY_HH__
47 #define __MEM_ABSTRACT_MEMORY_HH__
48 
49 #include "mem/backdoor.hh"
50 #include "mem/port.hh"
51 #include "params/AbstractMemory.hh"
52 #include "sim/clocked_object.hh"
53 #include "sim/stats.hh"
54 
55 
56 class System;
57 
62 class LockedAddr {
63 
64  private:
65 
66  // on alpha, minimum LL/SC granularity is 16 bytes, so lower
67  // bits need to masked off.
68  static const Addr Addr_Mask = 0xf;
69 
70  public:
71 
72  // locked address
74 
75  // locking hw context
77 
78  static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
79 
80  // check for matching execution context
81  bool matchesContext(const RequestPtr &req) const
82  {
83  assert(contextId != InvalidContextID);
84  assert(req->hasContextId());
85  return (contextId == req->contextId());
86  }
87 
88  LockedAddr(const RequestPtr &req) : addr(mask(req->getPaddr())),
89  contextId(req->contextId())
90  {}
91 
92  // constructor for unserialization use
93  LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
94  {}
95 };
96 
105 {
106  protected:
107 
108  // Address range of this memory
110 
111  // Pointer to host memory used to implement this memory
112  uint8_t* pmemAddr;
113 
114  // Backdoor to access this memory.
116 
117  // Enable specific memories to be reported to the configuration table
118  const bool confTableReported;
119 
120  // Should the memory appear in the global address map
121  const bool inAddrMap;
122 
123  // Should KVM map this memory for the guest
124  const bool kvmMap;
125 
127 
128  // helper function for checkLockedAddrs(): we really want to
129  // inline a quick check for an empty locked addr list (hopefully
130  // the common case), and do the full list search (if necessary) in
131  // this out-of-line function
132  bool checkLockedAddrList(PacketPtr pkt);
133 
134  // Record the address of a load-locked operation so that we can
135  // clear the execution context's lock flag if a matching store is
136  // performed
137  void trackLoadLocked(PacketPtr pkt);
138 
139  // Compare a store address with any locked addresses so we can
140  // clear the lock flag appropriately. Return value set to 'false'
141  // if store operation should be suppressed (because it was a
142  // conditional store and the address was no longer locked by the
143  // requesting execution context), 'true' otherwise. Note that
144  // this method must be called on *all* stores since even
145  // non-conditional stores must clear any matching lock addresses.
146  bool writeOK(PacketPtr pkt) {
147  const RequestPtr &req = pkt->req;
148  if (lockedAddrList.empty()) {
149  // no locked addrs: nothing to check, store_conditional fails
150  bool isLLSC = pkt->isLLSC();
151  if (isLLSC) {
152  req->setExtraData(0);
153  }
154  return !isLLSC; // only do write if not an sc
155  } else {
156  // iterate over list...
157  return checkLockedAddrList(pkt);
158  }
159  }
160 
166 
167  struct MemStats : public Stats::Group {
169 
170  void regStats() override;
171 
173 
194  } stats;
195 
196 
197  private:
198 
199  // Prevent copying
201 
202  // Prevent assignment
204 
205  public:
206 
207  typedef AbstractMemoryParams Params;
208 
209  AbstractMemory(const Params* p);
210  virtual ~AbstractMemory() {}
211 
212  void initState() override;
213 
220  bool isNull() const { return params()->null; }
221 
228  void setBackingStore(uint8_t* pmem_addr);
229 
234  { return lockedAddrList; }
235 
240 
244  System* system() const { return _system; }
245 
252  void system(System *sys) { _system = sys; }
253 
254  const Params *
255  params() const
256  {
257  return dynamic_cast<const Params *>(_params);
258  }
259 
265  AddrRange getAddrRange() const;
266 
274  inline uint8_t *
276  {
277  return pmemAddr + addr - range.start();
278  }
279 
285  uint64_t size() const { return range.size(); }
286 
292  Addr start() const { return range.start(); }
293 
300  bool isConfReported() const { return confTableReported; }
301 
308  bool isInAddrMap() const { return inAddrMap; }
309 
316  bool isKvmMap() const { return kvmMap; }
317 
325  void access(PacketPtr pkt);
326 
335  void functionalAccess(PacketPtr pkt);
336 };
337 
338 #endif //__MEM_ABSTRACT_MEMORY_HH__
AbstractMemory::MemStats::bytesRead
Stats::Vector bytesRead
Number of total bytes read from this memory.
Definition: abstract_mem.hh:175
AbstractMemory::~AbstractMemory
virtual ~AbstractMemory()
Definition: abstract_mem.hh:210
AbstractMemory::checkLockedAddrList
bool checkLockedAddrList(PacketPtr pkt)
Definition: abstract_mem.cc:281
AbstractMemory::toHostAddr
uint8_t * toHostAddr(Addr addr) const
Transform a gem5 address space address into its physical counterpart in the host address space.
Definition: abstract_mem.hh:275
MemBackdoor
Definition: backdoor.hh:38
AbstractMemory::getAddrRange
AddrRange getAddrRange() const
Get the address range.
Definition: abstract_mem.cc:242
AbstractMemory::kvmMap
const bool kvmMap
Definition: abstract_mem.hh:124
AbstractMemory::getLockedAddrList
const std::list< LockedAddr > & getLockedAddrList() const
Get the list of locked addresses to allow checkpointing.
Definition: abstract_mem.hh:233
AbstractMemory::MemStats::bwInstRead
Stats::Formula bwInstRead
Read bandwidth from this memory.
Definition: abstract_mem.hh:189
AbstractMemory::setBackingStore
void setBackingStore(uint8_t *pmem_addr)
Set the host memory backing store to be used by this memory controller.
Definition: abstract_mem.cc:103
LockedAddr
Locked address class that represents a physical address and a context id.
Definition: abstract_mem.hh:62
ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
AbstractMemory::_system
System * _system
Pointer to the System object.
Definition: abstract_mem.hh:165
LockedAddr::addr
Addr addr
Definition: abstract_mem.hh:73
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:340
Packet::isLLSC
bool isLLSC() const
Definition: packet.hh:582
InvalidContextID
const ContextID InvalidContextID
Definition: types.hh:232
AbstractMemory::inAddrMap
const bool inAddrMap
Definition: abstract_mem.hh:121
backdoor.hh
AbstractMemory::addLockedAddr
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
Definition: abstract_mem.hh:239
Stats::Vector
A vector of scalar stats.
Definition: statistics.hh:2575
AbstractMemory::functionalAccess
void functionalAccess(PacketPtr pkt)
Perform an untimed memory read or write without changing anything but the memory itself.
Definition: abstract_mem.cc:475
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
AbstractMemory::MemStats::bwWrite
Stats::Formula bwWrite
Write bandwidth from this memory.
Definition: abstract_mem.hh:191
AbstractMemory::confTableReported
const bool confTableReported
Definition: abstract_mem.hh:118
AbstractMemory
An abstract memory represents a contiguous block of physical memory, with an associated address range...
Definition: abstract_mem.hh:104
stats.hh
AbstractMemory::MemStats::bwRead
Stats::Formula bwRead
Read bandwidth from this memory.
Definition: abstract_mem.hh:187
AbstractMemory::stats
AbstractMemory::MemStats stats
AbstractMemory::isConfReported
bool isConfReported() const
Should this memory be passed to the kernel and part of the OS physical memory layout.
Definition: abstract_mem.hh:300
AbstractMemory::AbstractMemory
AbstractMemory(const AbstractMemory &)
AbstractMemory::access
void access(PacketPtr pkt)
Perform an untimed memory access and update all the state (e.g.
Definition: abstract_mem.cc:373
AbstractMemory::trackLoadLocked
void trackLoadLocked(PacketPtr pkt)
Definition: abstract_mem.cc:250
AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:68
AbstractMemory::MemStats::numWrites
Stats::Vector numWrites
Number of write requests.
Definition: abstract_mem.hh:183
AbstractMemory::size
uint64_t size() const
Get the memory size.
Definition: abstract_mem.hh:285
System
Definition: system.hh:73
AbstractMemory::operator=
AbstractMemory & operator=(const AbstractMemory &)
AbstractMemory::MemStats::numReads
Stats::Vector numReads
Number of read requests.
Definition: abstract_mem.hh:181
port.hh
AbstractMemory::params
const Params * params() const
Definition: abstract_mem.hh:255
AbstractMemory::MemStats
Definition: abstract_mem.hh:167
AbstractMemory::MemStats::bytesInstRead
Stats::Vector bytesInstRead
Number of instruction bytes read from this memory.
Definition: abstract_mem.hh:177
AbstractMemory::MemStats::MemStats
MemStats(AbstractMemory &mem)
Definition: abstract_mem.cc:115
AbstractMemory::MemStats::mem
const AbstractMemory & mem
Definition: abstract_mem.hh:172
AbstractMemory::pmemAddr
uint8_t * pmemAddr
Definition: abstract_mem.hh:112
LockedAddr::contextId
const ContextID contextId
Definition: abstract_mem.hh:76
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
LockedAddr::Addr_Mask
static const Addr Addr_Mask
Definition: abstract_mem.hh:68
LockedAddr::mask
static Addr mask(Addr paddr)
Definition: abstract_mem.hh:78
AbstractMemory::range
AddrRange range
Definition: abstract_mem.hh:109
AbstractMemory::isNull
bool isNull() const
See if this is a null memory that should never store data and always return zero.
Definition: abstract_mem.hh:220
AbstractMemory::isInAddrMap
bool isInAddrMap() const
Some memories are used as shadow memories or should for other reasons not be part of the global addre...
Definition: abstract_mem.hh:308
AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:314
AbstractMemory::lockedAddrList
std::list< LockedAddr > lockedAddrList
Definition: abstract_mem.hh:126
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
AbstractMemory::start
Addr start() const
Get the start address.
Definition: abstract_mem.hh:292
AbstractMemory::writeOK
bool writeOK(PacketPtr pkt)
Definition: abstract_mem.hh:146
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
AbstractMemory::isKvmMap
bool isKvmMap() const
When shadow memories are in use, KVM may want to make one or the other, but cannot map both into the ...
Definition: abstract_mem.hh:316
Stats::Group
Statistics container.
Definition: group.hh:83
addr
ip6_addr_t addr
Definition: inet.hh:423
LockedAddr::matchesContext
bool matchesContext(const RequestPtr &req) const
Definition: abstract_mem.hh:81
AbstractMemory::Params
AbstractMemoryParams Params
Definition: abstract_mem.hh:207
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
AbstractMemory::system
void system(System *sys)
Set the system pointer on this memory This can't be done via a python parameter because the system ne...
Definition: abstract_mem.hh:252
std::list< LockedAddr >
AbstractMemory::backdoor
MemBackdoor backdoor
Definition: abstract_mem.hh:115
AbstractMemory::system
System * system() const
read the system pointer Implemented for completeness with the setter
Definition: abstract_mem.hh:244
AbstractMemory::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: abstract_mem.cc:72
AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:297
AbstractMemory::MemStats::bytesWritten
Stats::Vector bytesWritten
Number of bytes written to this memory.
Definition: abstract_mem.hh:179
LockedAddr::LockedAddr
LockedAddr(Addr _addr, int _cid)
Definition: abstract_mem.hh:93
LockedAddr::LockedAddr
LockedAddr(const RequestPtr &req)
Definition: abstract_mem.hh:88
AbstractMemory::MemStats::numOther
Stats::Vector numOther
Number of other requests.
Definition: abstract_mem.hh:185
AbstractMemory::MemStats::bwTotal
Stats::Formula bwTotal
Total bandwidth from this memory.
Definition: abstract_mem.hh:193
AbstractMemory::MemStats::regStats
void regStats() override
Callback to set stat parameters.
Definition: abstract_mem.cc:141

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