gem5  v22.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 namespace gem5
56 {
57 
58 class System;
59 
60 namespace memory
61 {
62 
68 {
69 
70  private:
71 
72  // on alpha, minimum LL/SC granularity is 16 bytes, so lower
73  // bits need to masked off.
74  static const Addr Addr_Mask = 0xf;
75 
76  public:
77 
78  // locked address
80 
81  // locking hw context
83 
84  static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
85 
86  // check for matching execution context
87  bool matchesContext(const RequestPtr &req) const
88  {
89  assert(contextId != InvalidContextID);
90  assert(req->hasContextId());
91  return (contextId == req->contextId());
92  }
93 
94  LockedAddr(const RequestPtr &req) : addr(mask(req->getPaddr())),
95  contextId(req->contextId())
96  {}
97 
98  // constructor for unserialization use
99  LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
100  {}
101 };
102 
111 {
112  protected:
113 
114  // Address range of this memory
116 
117  // Pointer to host memory used to implement this memory
118  uint8_t* pmemAddr;
119 
120  // Backdoor to access this memory.
122 
123  // Enable specific memories to be reported to the configuration table
124  const bool confTableReported;
125 
126  // Should the memory appear in the global address map
127  const bool inAddrMap;
128 
129  // Should KVM map this memory for the guest
130  const bool kvmMap;
131 
133 
134  // helper function for checkLockedAddrs(): we really want to
135  // inline a quick check for an empty locked addr list (hopefully
136  // the common case), and do the full list search (if necessary) in
137  // this out-of-line function
138  bool checkLockedAddrList(PacketPtr pkt);
139 
140  // Record the address of a load-locked operation so that we can
141  // clear the execution context's lock flag if a matching store is
142  // performed
143  void trackLoadLocked(PacketPtr pkt);
144 
145  // Compare a store address with any locked addresses so we can
146  // clear the lock flag appropriately. Return value set to 'false'
147  // if store operation should be suppressed (because it was a
148  // conditional store and the address was no longer locked by the
149  // requesting execution context), 'true' otherwise. Note that
150  // this method must be called on *all* stores since even
151  // non-conditional stores must clear any matching lock addresses.
152  bool writeOK(PacketPtr pkt) {
153  const RequestPtr &req = pkt->req;
154  if (lockedAddrList.empty()) {
155  // no locked addrs: nothing to check, store_conditional fails
156  bool isLLSC = pkt->isLLSC();
157  if (isLLSC) {
158  req->setExtraData(0);
159  }
160  return !isLLSC; // only do write if not an sc
161  } else {
162  // iterate over list...
163  return checkLockedAddrList(pkt);
164  }
165  }
166 
172 
173  struct MemStats : public statistics::Group
174  {
176 
177  void regStats() override;
178 
180 
201  } stats;
202 
203 
204  private:
205 
206  // Prevent copying
208 
209  // Prevent assignment
211 
212  public:
213 
215 
216  AbstractMemory(const Params &p);
217  virtual ~AbstractMemory() {}
218 
219  void initState() override;
220 
227  bool isNull() const { return params().null; }
228 
235  void setBackingStore(uint8_t* pmem_addr);
236 
237  void
239  {
240  if (lockedAddrList.empty() && backdoor.ptr())
241  bd_ptr = &backdoor;
242  }
243 
247  const std::list<LockedAddr> &
249  {
250  return lockedAddrList;
251  }
252 
256  void
258  {
260  lockedAddrList.push_back(addr);
261  }
262 
266  System* system() const { return _system; }
267 
274  void system(System *sys) { _system = sys; }
275 
281  AddrRange getAddrRange() const;
282 
290  inline uint8_t *
292  {
293  return pmemAddr + addr - range.start();
294  }
295 
301  uint64_t size() const { return range.size(); }
302 
308  Addr start() const { return range.start(); }
309 
316  bool isConfReported() const { return confTableReported; }
317 
324  bool isInAddrMap() const { return inAddrMap; }
325 
332  bool isKvmMap() const { return kvmMap; }
333 
341  void access(PacketPtr pkt);
342 
351  void functionalAccess(PacketPtr pkt);
352 };
353 
354 } // namespace memory
355 } // namespace gem5
356 
357 #endif //__MEM_ABSTRACT_MEMORY_HH__
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:82
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObjectParams Params
Parameters of ClockedObject.
uint8_t * ptr() const
Definition: backdoor.hh:62
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
RequestPtr req
A pointer to the original request.
Definition: packet.hh:376
bool isLLSC() const
Definition: packet.hh:619
An abstract memory represents a contiguous block of physical memory, with an associated address range...
void access(PacketPtr pkt)
Perform an untimed memory access and update all the state (e.g.
uint64_t size() const
Get the memory size.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: abstract_mem.cc:74
void trackLoadLocked(PacketPtr pkt)
void setBackingStore(uint8_t *pmem_addr)
Set the host memory backing store to be used by this memory controller.
bool isInAddrMap() const
Some memories are used as shadow memories or should for other reasons not be part of the global addre...
void system(System *sys)
Set the system pointer on this memory This can't be done via a python parameter because the system ne...
System * system() const
read the system pointer Implemented for completeness with the setter
AbstractMemory(const AbstractMemory &)
bool isNull() const
See if this is a null memory that should never store data and always return zero.
bool isKvmMap() const
When shadow memories are in use, KVM may want to make one or the other, but cannot map both into the ...
const std::list< LockedAddr > & getLockedAddrList() const
Get the list of locked addresses to allow checkpointing.
bool checkLockedAddrList(PacketPtr pkt)
System * _system
Pointer to the System object.
void functionalAccess(PacketPtr pkt)
Perform an untimed memory read or write without changing anything but the memory itself.
void getBackdoor(MemBackdoorPtr &bd_ptr)
AddrRange getAddrRange() const
Get the address range.
Addr start() const
Get the start address.
std::list< LockedAddr > lockedAddrList
gem5::memory::AbstractMemory::MemStats stats
bool isConfReported() const
Should this memory be passed to the kernel and part of the OS physical memory layout.
uint8_t * toHostAddr(Addr addr) const
Transform a gem5 address space address into its physical counterpart in the host address space.
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
AbstractMemory & operator=(const AbstractMemory &)
bool writeOK(PacketPtr pkt)
Locked address class that represents a physical address and a context id.
Definition: abstract_mem.hh:68
bool matchesContext(const RequestPtr &req) const
Definition: abstract_mem.hh:87
LockedAddr(Addr _addr, int _cid)
Definition: abstract_mem.hh:99
static const Addr Addr_Mask
Definition: abstract_mem.hh:74
LockedAddr(const RequestPtr &req)
Definition: abstract_mem.hh:94
static Addr mask(Addr paddr)
Definition: abstract_mem.hh:84
const ContextID contextId
Definition: abstract_mem.hh:82
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
A vector of scalar stats.
Definition: statistics.hh:2007
STL list class.
Definition: stl.hh:51
ClockedObject declaration and implementation.
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:326
const Params & params() const
Definition: sim_object.hh:176
Port Object Declaration.
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
const ContextID InvalidContextID
Definition: types.hh:240
statistics::Formula bwInstRead
Read bandwidth from this memory.
statistics::Vector bytesRead
Number of total bytes read from this memory.
statistics::Vector bytesInstRead
Number of instruction bytes read from this memory.
statistics::Formula bwTotal
Total bandwidth from this memory.
statistics::Vector numReads
Number of read requests.
void regStats() override
Callback to set stat parameters.
statistics::Vector numOther
Number of other requests.
statistics::Vector bytesWritten
Number of bytes written to this memory.
statistics::Vector numWrites
Number of write requests.
statistics::Formula bwRead
Read bandwidth from this memory.
statistics::Formula bwWrite
Write bandwidth from this memory.
Definition: mem.h:38

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1