gem5  v20.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 
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
203  AbstractMemory& operator=(const AbstractMemory&);
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 
239  void addLockedAddr(LockedAddr addr) { lockedAddrList.push_back(addr); }
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__
const bool kvmMap
bool matchesContext(const RequestPtr &req) const
Definition: abstract_mem.hh:81
virtual ~AbstractMemory()
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
std::shared_ptr< Request > RequestPtr
Definition: request.hh:81
LockedAddr(Addr _addr, int _cid)
Definition: abstract_mem.hh:93
Locked address class that represents a physical address and a context id.
Definition: abstract_mem.hh:62
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:72
A vector of scalar stats.
Definition: statistics.hh:2547
const ContextID contextId
Definition: abstract_mem.hh:76
RequestPtr req
A pointer to the original request.
Definition: packet.hh:321
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:68
static Addr mask(Addr paddr)
Definition: abstract_mem.hh:78
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:88
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
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:249
Statistics container.
Definition: group.hh:83
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:3009
bool isLLSC() const
Definition: packet.hh:548
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:230
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:293
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:280
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:229
const bool confTableReported
static const Addr Addr_Mask
Definition: abstract_mem.hh:68
Stats::Vector numReads
Number of read requests.

Generated on Thu May 28 2020 16:21:33 for gem5 by doxygen 1.8.13