gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
address_manager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef CPU_TESTERS_PROTOCOL_TESTER_ADDRESS_MANAGER_HH_
35 #define CPU_TESTERS_PROTOCOL_TESTER_ADDRESS_MANAGER_HH_
36 
37 #include <unordered_map>
38 #include <unordered_set>
39 #include <utility>
40 #include <vector>
41 
42 #include "base/types.hh"
43 #include "sim/eventq.hh"
44 
45 /*
46  * --- AddressManager has 3 main tasks ---
47  * (1) generate DRF request sequences
48  * (2) maintain internal log table
49  * (3) validate return values against ones in the log table
50  *
51  * A location is an abstract index of a unique real address.
52  * It's used internally within the tester only.
53  * randAddressMap has the mapping between a location and its real address.
54  *
55  * A value is an integer that a location in real memory can store.
56  * for now, we assume a value is 4-byte
57  *
58  * The location range (randAddressMap) has two distinct parts:
59  * Atomic locations: in the 1st part of randAddressMap &
60  * Non-atomic locations (or just locations): in the 2nd part
61  */
62 
63 /*
64  * --- DRF request sequence generation ---
65  * Each lane of an episode starts selecting its location by calling:
66  * (1) getAtomicLoc
67  * (2) getLoadLoc/getStoreLoc
68  * (3) finishLocSelection
69  *
70  * Each lane of an episode completes its executing by calling:
71  * releaseLocation for all locations it selected
72  */
73 
74 /*
75  * --- Internal structures ---
76  * There are multiple atomic structures, each of which corresponds
77  * to an atomic location.
78  *
79  * Each atomic structure manages a distinct range of locations in locArray
80  * This array is partitioned into 3 parts that are used to select locations
81  * for LDs and STs. Here is the location selecting rule:
82  * | (1) | (2) | (3) |
83  * - all locations in (1) cannot be picked for any LD and ST action
84  * - all locations in (2) can be picked for either LD or ST action
85  * - all locations in (3) can be picked for LD action only
86  *
87  * We maintain the 3 parts by 2 indices firstMark and secondMark.
88  * As locations are moved between partitions, both indices are updated
89  * accordingly.
90  * [0 .. firstMark-1] part (1)
91  * [firstMark .. secondMark-1] part (2)
92  * [secondMark .. arraySize-1] part (3)
93  *
94  * Each location has its context/property. locProps maintains
95  * contexts/properties of all locations. Context/property includes
96  * - current index of a location in locArray
97  * - the number of owners who are currently using the location
98  *
99  * To guarantee DRF constraints, the following conditions must hold
100  * - all locations in (1) have exactly 1 owner
101  * - all locations in (2) have exactly 0 owner
102  * - all locations in (3) have at least 1 owner
103  * - A LD request can randomly pick any location in (2) & (3)
104  * - A ST request can randomly pick any location in (2)
105  *
106  * loadStoreMap maintains all locations already selected for LDs/STs so far
107  *
108  * When endLocSelection is called (i.e., we've picked all locations for an
109  * episode), we need to move each selected location to its right partition.
110  * if LD_bit == 1 && ST_bit == 0 (i.e., picked for LDs), then move the
111  * location to (3) -> future LDs can pick it.
112  * if LD_bit == 0 && ST_bit == 1, then move the location to (1) -> NO future
113  * action can pick it until this episode is done.
114  * if LD_bit == 1 && ST_bit == 1, then move the location to (1) -> NO future
115  * action can pick it until this episode is done.
116  * clear the loadStoreMap
117  */
118 
120 {
121  public:
122  AddressManager(int n_atomic_locs, int numNormalLocsPerAtomic);
123  ~AddressManager();
124 
125  typedef int32_t Value;
126  typedef int32_t Location;
127 
128  // return the unique address mapped to a location
129  Addr getAddress(Location loc);
130  // return a unique atomic location & start picking locations
132  // return a random location for LD
133  Location getLoadLoc(Location atomic_loc);
134  // return a random location for ST
135  Location getStoreLoc(Location atomic_loc);
136  // finish picking locations
137  void finishLocSelection(Location atomic_loc);
138  // an episode is done, release location I've picked
139  void releaseLocation(Location atomic_loc, Location loc);
140  // update a log table entry with a given set of values
141  void updateLogTable(Location loc, int threadId, int episodeId,
142  Value new_value, Tick curTick, int cuId = -1);
143  // return the current value in the log table
144  Value getLoggedValue(Location loc) const;
145  // validate atomic response
146  bool validateAtomicResp(Location loc, Value ret_val);
147 
148  std::string printLastWriter(Location loc) const;
149 
150  static const int INVALID_VALUE;
151  static const int INVALID_LOCATION;
152 
153  private:
155  {
156  public:
158  : threadId(-1), cuId(-1), episodeId(-1), value(0),
159  writeTick(0)
160  { }
161 
162  const std::string print() const
163  {
164  return "(TesterThread ID " + std::to_string(threadId) +
165  ", CU ID " + std::to_string(cuId) +
166  ", Episode ID " + std::to_string(episodeId) +
167  ", Value " + std::to_string(value) +
168  ", Tick " + std::to_string(writeTick) +
169  ")";
170  }
171 
172  void update(int _thread, int _cu, int _episode, Value _value,
173  Tick _tick)
174  {
175  threadId = _thread;
176  cuId = _cu;
177  episodeId = _episode;
178  value = _value;
179  writeTick = _tick;
180  }
181 
182  Value getLastStoredValue() const { return value; }
183 
184  private:
185  int threadId;
186  int cuId;
190  };
191 
193  {
194  public:
195  AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end);
196  ~AtomicStruct();
197 
198  // functions picking locations for LD/ST/ATOMIC ops
199  void startLocSelection();
202  void endLocSelection();
203 
204  // an episode completed its actions
205  // return locations to their correct positions
206  void releaseLoc(Location loc);
207  // is the value what we expect?
208  bool isExpectedValue(Value val);
209 
210  private:
213 
214  // array storing all locations this structure is managing
218 
219  // a vector of location's properties
223 
224  // a temporary map of location and its LD/ST selection
226  typedef std::unordered_map<Location, LdStBits> LdStMap;
228 
229  // number of atomic requests at this location so far
231  // a set of expected values
232  // when we request the first n atomic ops, we expect to receive n
233  // return values from [0 .. n-1]
234  typedef std::unordered_set<Value> ExpectedValueSet;
236 
237  // swap two locations in locArray
238  void swap(LocProperty& prop_1, LocProperty& prop_2);
239 
240  bool inFirstRegion(int idx) const
241  {
242  return (idx >= 0 && idx < firstMark);
243  }
244  bool inSecondRegion(int idx) const
245  {
246  return (idx >= firstMark && idx < secondMark);
247  }
248  bool inThirdRegion(int idx) const
249  {
250  return (idx >= secondMark && idx < arraySize);
251  }
252  };
253 
254  // number of atomic locations
256  // number of normal/non-atomic locations per atomic structure
258  // total number of non-atomic locations
260 
261  // location - address mapping
264 
265  // a list of atomic structures
268 
269  // internal log table
272 };
273 
274 #endif /* CPU_TESTERS_PROTOCOL_TESTER_ADDRESS_MANAGER_HH_ */
AddressManager::validateAtomicResp
bool validateAtomicResp(Location loc, Value ret_val)
Definition: address_manager.cc:427
AddressManager::AtomicStruct::LdStBits
std::pair< bool, bool > LdStBits
Definition: address_manager.hh:225
AddressManager::AtomicStruct::inSecondRegion
bool inSecondRegion(int idx) const
Definition: address_manager.hh:244
AddressManager::LastWriter::threadId
int threadId
Definition: address_manager.hh:185
AddressManager::AtomicStruct::swap
void swap(LocProperty &prop_1, LocProperty &prop_2)
Definition: address_manager.cc:395
AddressManager::LastWriter::episodeId
int episodeId
Definition: address_manager.hh:187
AddressManager::Location
int32_t Location
Definition: address_manager.hh:126
AddressManager::getLoadLoc
Location getLoadLoc(Location atomic_loc)
Definition: address_manager.cc:102
AddressManager::AtomicStruct::getStoreLoc
Location getStoreLoc()
Definition: address_manager.cc:221
AddressManager::AtomicStruct::locArray
Location * locArray
Definition: address_manager.hh:215
AddressManager::Value
int32_t Value
Definition: address_manager.hh:125
AddressManager::atomicStructs
AtomicStructTable atomicStructs
Definition: address_manager.hh:267
AddressManager::AtomicStruct::LocPropTable
std::vector< LocProperty > LocPropTable
Definition: address_manager.hh:221
AddressManager::getAddress
Addr getAddress(Location loc)
Definition: address_manager.cc:87
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
AddressManager::AtomicStruct::locationBase
Location locationBase
Definition: address_manager.hh:212
AddressManager::AtomicStruct::firstMark
int firstMark
Definition: address_manager.hh:216
AddressManager::AtomicStruct::AtomicStruct
AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end)
Definition: address_manager.cc:136
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
AddressManager::AtomicStruct::requestCount
int requestCount
Definition: address_manager.hh:230
AddressManager::AtomicStruct::arraySize
int arraySize
Definition: address_manager.hh:217
AddressManager::AtomicStruct::isExpectedValue
bool isExpectedValue(Value val)
Definition: address_manager.cc:373
std::vector< LocProperty >
AddressManager::LastWriter::writeTick
Tick writeTick
Definition: address_manager.hh:189
AddressManager::LastWriter::LastWriter
LastWriter()
Definition: address_manager.hh:157
AddressManager::AtomicStruct::startLocSelection
void startLocSelection()
Definition: address_manager.cc:171
AddressManager::LogTable
std::vector< LastWriter * > LogTable
Definition: address_manager.hh:270
AddressManager::LastWriter::print
const std::string print() const
Definition: address_manager.hh:162
AddressManager::LastWriter::value
Value value
Definition: address_manager.hh:188
AddressManager
Definition: address_manager.hh:119
AddressManager::getLoggedValue
Value getLoggedValue(Location loc) const
Definition: address_manager.cc:420
AddressManager::randAddressMap
AddressMap randAddressMap
Definition: address_manager.hh:263
AddressManager::AtomicStruct::loadStoreMap
LdStMap loadStoreMap
Definition: address_manager.hh:227
AddressManager::AtomicStructTable
std::vector< AtomicStruct * > AtomicStructTable
Definition: address_manager.hh:266
AddressManager::AtomicStruct::endLocSelection
void endLocSelection()
Definition: address_manager.cc:260
AddressManager::AtomicStruct::LocProperty
std::pair< int, int > LocProperty
Definition: address_manager.hh:220
AddressManager::numLocsPerAtomic
int numLocsPerAtomic
Definition: address_manager.hh:257
AddressManager::finishLocSelection
void finishLocSelection(Location atomic_loc)
Definition: address_manager.cc:116
AddressManager::LastWriter
Definition: address_manager.hh:154
AddressManager::AtomicStruct::secondMark
int secondMark
Definition: address_manager.hh:216
AddressManager::releaseLocation
void releaseLocation(Location atomic_loc, Location loc)
Definition: address_manager.cc:123
AddressManager::logTable
LogTable logTable
Definition: address_manager.hh:271
AddressManager::LastWriter::cuId
int cuId
Definition: address_manager.hh:186
AddressManager::LastWriter::getLastStoredValue
Value getLastStoredValue() const
Definition: address_manager.hh:182
std::pair< int, int >
AddressManager::~AddressManager
~AddressManager()
Definition: address_manager.cc:78
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
AddressManager::numNormalLocs
int numNormalLocs
Definition: address_manager.hh:259
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
AddressManager::AddressMap
std::vector< Addr > AddressMap
Definition: address_manager.hh:262
AddressManager::AtomicStruct
Definition: address_manager.hh:192
AddressManager::LastWriter::update
void update(int _thread, int _cu, int _episode, Value _value, Tick _tick)
Definition: address_manager.hh:172
AddressManager::AtomicStruct::inFirstRegion
bool inFirstRegion(int idx) const
Definition: address_manager.hh:240
AddressManager::AddressManager
AddressManager(int n_atomic_locs, int numNormalLocsPerAtomic)
Definition: address_manager.cc:46
AddressManager::AtomicStruct::LdStMap
std::unordered_map< Location, LdStBits > LdStMap
Definition: address_manager.hh:226
types.hh
AddressManager::AtomicStruct::~AtomicStruct
~AtomicStruct()
Definition: address_manager.cc:165
AddressManager::printLastWriter
std::string printLastWriter(Location loc) const
Definition: address_manager.cc:130
AddressManager::AtomicStruct::ExpectedValueSet
std::unordered_set< Value > ExpectedValueSet
Definition: address_manager.hh:234
AddressManager::AtomicStruct::releaseLoc
void releaseLoc(Location loc)
Definition: address_manager.cc:326
AddressManager::getAtomicLoc
Location getAtomicLoc()
Definition: address_manager.cc:94
AddressManager::AtomicStruct::getLoadLoc
Location getLoadLoc()
Definition: address_manager.cc:188
AddressManager::AtomicStruct::atomicLoc
Location atomicLoc
Definition: address_manager.hh:211
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
AddressManager::AtomicStruct::inThirdRegion
bool inThirdRegion(int idx) const
Definition: address_manager.hh:248
AddressManager::getStoreLoc
Location getStoreLoc(Location atomic_loc)
Definition: address_manager.cc:109
AddressManager::updateLogTable
void updateLogTable(Location loc, int threadId, int episodeId, Value new_value, Tick curTick, int cuId=-1)
Definition: address_manager.cc:412
AddressManager::INVALID_LOCATION
static const int INVALID_LOCATION
Definition: address_manager.hh:151
AddressManager::numAtomicLocs
int numAtomicLocs
Definition: address_manager.hh:255
AddressManager::AtomicStruct::expectedValues
ExpectedValueSet expectedValues
Definition: address_manager.hh:235
AddressManager::AtomicStruct::locProps
LocPropTable locProps
Definition: address_manager.hh:222
AddressManager::INVALID_VALUE
static const int INVALID_VALUE
Definition: address_manager.hh:150
eventq.hh

Generated on Tue Mar 23 2021 19:41:25 for gem5 by doxygen 1.8.17