gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Ron Dreslinski
41  * Andreas Hansson
42  */
43 
49 #ifndef __MEM_ABSTRACT_MEMORY_HH__
50 #define __MEM_ABSTRACT_MEMORY_HH__
51 
52 #include "mem/backdoor.hh"
53 #include "mem/port.hh"
54 #include "params/AbstractMemory.hh"
55 #include "sim/clocked_object.hh"
56 #include "sim/stats.hh"
57 
58 
59 class System;
60 
65 class LockedAddr {
66 
67  private:
68 
69  // on alpha, minimum LL/SC granularity is 16 bytes, so lower
70  // bits need to masked off.
71  static const Addr Addr_Mask = 0xf;
72 
73  public:
74 
75  // locked address
77 
78  // locking hw context
80 
81  static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
82 
83  // check for matching execution context
84  bool matchesContext(const RequestPtr &req) const
85  {
86  assert(contextId != InvalidContextID);
87  assert(req->hasContextId());
88  return (contextId == req->contextId());
89  }
90 
91  LockedAddr(const RequestPtr &req) : addr(mask(req->getPaddr())),
92  contextId(req->contextId())
93  {}
94 
95  // constructor for unserialization use
96  LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
97  {}
98 };
99 
108 {
109  protected:
110 
111  // Address range of this memory
113 
114  // Pointer to host memory used to implement this memory
115  uint8_t* pmemAddr;
116 
117  // Backdoor to access this memory.
119 
120  // Enable specific memories to be reported to the configuration table
121  const bool confTableReported;
122 
123  // Should the memory appear in the global address map
124  const bool inAddrMap;
125 
126  // Should KVM map this memory for the guest
127  const bool kvmMap;
128 
130 
131  // helper function for checkLockedAddrs(): we really want to
132  // inline a quick check for an empty locked addr list (hopefully
133  // the common case), and do the full list search (if necessary) in
134  // this out-of-line function
135  bool checkLockedAddrList(PacketPtr pkt);
136 
137  // Record the address of a load-locked operation so that we can
138  // clear the execution context's lock flag if a matching store is
139  // performed
140  void trackLoadLocked(PacketPtr pkt);
141 
142  // Compare a store address with any locked addresses so we can
143  // clear the lock flag appropriately. Return value set to 'false'
144  // if store operation should be suppressed (because it was a
145  // conditional store and the address was no longer locked by the
146  // requesting execution context), 'true' otherwise. Note that
147  // this method must be called on *all* stores since even
148  // non-conditional stores must clear any matching lock addresses.
149  bool writeOK(PacketPtr pkt) {
150  const RequestPtr &req = pkt->req;
151  if (lockedAddrList.empty()) {
152  // no locked addrs: nothing to check, store_conditional fails
153  bool isLLSC = pkt->isLLSC();
154  if (isLLSC) {
155  req->setExtraData(0);
156  }
157  return !isLLSC; // only do write if not an sc
158  } else {
159  // iterate over list...
160  return checkLockedAddrList(pkt);
161  }
162  }
163 
169 
170  struct MemStats : public Stats::Group {
172 
173  void regStats() override;
174 
176 
197  } stats;
198 
199 
200  private:
201 
202  // Prevent copying
204 
205  // Prevent assignment
206  AbstractMemory& operator=(const AbstractMemory&);
207 
208  public:
209 
210  typedef AbstractMemoryParams Params;
211 
212  AbstractMemory(const Params* p);
213  virtual ~AbstractMemory() {}
214 
218  void init() override;
219 
226  bool isNull() const { return params()->null; }
227 
234  void setBackingStore(uint8_t* pmem_addr);
235 
240  { return lockedAddrList; }
241 
245  void addLockedAddr(LockedAddr addr) { lockedAddrList.push_back(addr); }
246 
250  System* system() const { return _system; }
251 
258  void system(System *sys) { _system = sys; }
259 
260  const Params *
261  params() const
262  {
263  return dynamic_cast<const Params *>(_params);
264  }
265 
271  AddrRange getAddrRange() const;
272 
280  inline uint8_t *
282  {
283  return pmemAddr + addr - range.start();
284  }
285 
291  uint64_t size() const { return range.size(); }
292 
298  Addr start() const { return range.start(); }
299 
306  bool isConfReported() const { return confTableReported; }
307 
314  bool isInAddrMap() const { return inAddrMap; }
315 
322  bool isKvmMap() const { return kvmMap; }
323 
331  void access(PacketPtr pkt);
332 
341  void functionalAccess(PacketPtr pkt);
342 };
343 
344 #endif //__MEM_ABSTRACT_MEMORY_HH__
const bool kvmMap
bool matchesContext(const RequestPtr &req) const
Definition: abstract_mem.hh:84
virtual ~AbstractMemory()
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
LockedAddr(Addr _addr, int _cid)
Definition: abstract_mem.hh:96
Locked address class that represents a physical address and a context id.
Definition: abstract_mem.hh:65
bool writeOK(PacketPtr pkt)
bool isConfReported() const
Should this memory be passed to the kernel and part of the OS physical memory layout.
Definition: system.hh:77
A vector of scalar stats.
Definition: statistics.hh:2550
const ContextID contextId
Definition: abstract_mem.hh:79
RequestPtr req
A pointer to the original request.
Definition: packet.hh:327
Stats::Vector bytesWritten
Number of bytes written to this memory.
Stats::Vector numOther
Number of other requests.
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
static Addr mask(Addr paddr)
Definition: abstract_mem.hh:81
const std::list< LockedAddr > & getLockedAddrList() const
Get the list of locked addresses to allow checkpointing.
AbstractMemoryParams Params
const bool inAddrMap
uint8_t * pmemAddr
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
bool isNull() const
See if this is a null memory that should never store data and always return zero. ...
ClockedObject declaration and implementation.
Port Object Declaration.
std::list< LockedAddr > lockedAddrList
LockedAddr(const RequestPtr &req)
Definition: abstract_mem.hh:91
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Stats::Formula bwTotal
Total bandwidth from this memory.
Stats::Vector bytesRead
Number of total bytes read from this memory.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Statistics container.
Definition: group.hh:85
Stats::Vector bytesInstRead
Number of instruction bytes read from this memory.
Addr start() const
Get the start address.
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
bool isLLSC() const
Definition: packet.hh:554
AddrRange range
const Params * params() const
Stats::Vector numWrites
Number of write requests.
System * system() const
read the system pointer Implemented for completeness with the setter
uint8_t * toHostAddr(Addr addr) const
Transform a gem5 address space address into its physical counterpart in the host address space...
const AbstractMemory & mem
Stats::Formula bwRead
Read bandwidth from this memory.
uint64_t size() const
Get the memory size.
System * _system
Pointer to the System object.
const ContextID InvalidContextID
Definition: types.hh:232
MemBackdoor backdoor
An abstract memory represents a contiguous block of physical memory, with an associated address range...
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:297
bool isInAddrMap() const
Some memories are used as shadow memories or should for other reasons not be part of the global addre...
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:284
bool isKvmMap() const
When shadow memories are in use, KVM may want to make one or the other, but cannot map both into the ...
bool_vector8 mem[]
Definition: reset_stim.h:43
void system(System *sys)
Set the system pointer on this memory This can&#39;t be done via a python parameter because the system ne...
Stats::Formula bwWrite
Write bandwidth from this memory.
Bitfield< 0 > p
Stats::Formula bwInstRead
Read bandwidth from this memory.
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
const FlagsType init
This Stat is Initialized.
Definition: info.hh:47
const bool confTableReported
static const Addr Addr_Mask
Definition: abstract_mem.hh:71
Stats::Vector numReads
Number of read requests.

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