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

Generated on Thu Jul 28 2022 13:32:29 for gem5 by doxygen 1.8.17