gem5  v21.1.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  * 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 namespace gem5
46 {
47 
48 /*
49  * --- AddressManager has 3 main tasks ---
50  * (1) generate DRF request sequences
51  * (2) maintain internal log table
52  * (3) validate return values against ones in the log table
53  *
54  * A location is an abstract index of a unique real address.
55  * It's used internally within the tester only.
56  * randAddressMap has the mapping between a location and its real address.
57  *
58  * A value is an integer that a location in real memory can store.
59  * for now, we assume a value is 4-byte
60  *
61  * The location range (randAddressMap) has two distinct parts:
62  * Atomic locations: in the 1st part of randAddressMap &
63  * Non-atomic locations (or just locations): in the 2nd part
64  */
65 
66 /*
67  * --- DRF request sequence generation ---
68  * Each lane of an episode starts selecting its location by calling:
69  * (1) getAtomicLoc
70  * (2) getLoadLoc/getStoreLoc
71  * (3) finishLocSelection
72  *
73  * Each lane of an episode completes its executing by calling:
74  * releaseLocation for all locations it selected
75  */
76 
77 /*
78  * --- Internal structures ---
79  * There are multiple atomic structures, each of which corresponds
80  * to an atomic location.
81  *
82  * Each atomic structure manages a distinct range of locations in locArray
83  * This array is partitioned into 3 parts that are used to select locations
84  * for LDs and STs. Here is the location selecting rule:
85  * | (1) | (2) | (3) |
86  * - all locations in (1) cannot be picked for any LD and ST action
87  * - all locations in (2) can be picked for either LD or ST action
88  * - all locations in (3) can be picked for LD action only
89  *
90  * We maintain the 3 parts by 2 indices firstMark and secondMark.
91  * As locations are moved between partitions, both indices are updated
92  * accordingly.
93  * [0 .. firstMark-1] part (1)
94  * [firstMark .. secondMark-1] part (2)
95  * [secondMark .. arraySize-1] part (3)
96  *
97  * Each location has its context/property. locProps maintains
98  * contexts/properties of all locations. Context/property includes
99  * - current index of a location in locArray
100  * - the number of owners who are currently using the location
101  *
102  * To guarantee DRF constraints, the following conditions must hold
103  * - all locations in (1) have exactly 1 owner
104  * - all locations in (2) have exactly 0 owner
105  * - all locations in (3) have at least 1 owner
106  * - A LD request can randomly pick any location in (2) & (3)
107  * - A ST request can randomly pick any location in (2)
108  *
109  * loadStoreMap maintains all locations already selected for LDs/STs so far
110  *
111  * When endLocSelection is called (i.e., we've picked all locations for an
112  * episode), we need to move each selected location to its right partition.
113  * if LD_bit == 1 && ST_bit == 0 (i.e., picked for LDs), then move the
114  * location to (3) -> future LDs can pick it.
115  * if LD_bit == 0 && ST_bit == 1, then move the location to (1) -> NO future
116  * action can pick it until this episode is done.
117  * if LD_bit == 1 && ST_bit == 1, then move the location to (1) -> NO future
118  * action can pick it until this episode is done.
119  * clear the loadStoreMap
120  */
121 
123 {
124  public:
125  AddressManager(int n_atomic_locs, int numNormalLocsPerAtomic);
126  ~AddressManager();
127 
128  typedef int32_t Value;
129  typedef int32_t Location;
130 
131  // return the unique address mapped to a location
132  Addr getAddress(Location loc);
133  // return a unique atomic location & start picking locations
135  // return a random location for LD
136  Location getLoadLoc(Location atomic_loc);
137  // return a random location for ST
138  Location getStoreLoc(Location atomic_loc);
139  // finish picking locations
140  void finishLocSelection(Location atomic_loc);
141  // an episode is done, release location I've picked
142  void releaseLocation(Location atomic_loc, Location loc);
143  // update a log table entry with a given set of values
144  void updateLogTable(Location loc, int threadId, int episodeId,
145  Value new_value, Tick curTick, int cuId = -1);
146  // return the current value in the log table
147  Value getLoggedValue(Location loc) const;
148  // validate atomic response
149  bool validateAtomicResp(Location loc, Value ret_val);
150 
151  std::string printLastWriter(Location loc) const;
152 
153  static const int INVALID_VALUE;
154  static const int INVALID_LOCATION;
155 
156  private:
158  {
159  public:
161  : threadId(-1), cuId(-1), episodeId(-1), value(0),
162  writeTick(0)
163  { }
164 
165  const std::string print() const
166  {
167  return "(TesterThread ID " + std::to_string(threadId) +
168  ", CU ID " + std::to_string(cuId) +
169  ", Episode ID " + std::to_string(episodeId) +
170  ", Value " + std::to_string(value) +
171  ", Tick " + std::to_string(writeTick) +
172  ")";
173  }
174 
175  void update(int _thread, int _cu, int _episode, Value _value,
176  Tick _tick)
177  {
178  threadId = _thread;
179  cuId = _cu;
180  episodeId = _episode;
181  value = _value;
182  writeTick = _tick;
183  }
184 
185  Value getLastStoredValue() const { return value; }
186 
187  private:
188  int threadId;
189  int cuId;
193  };
194 
196  {
197  public:
198  AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end);
199  ~AtomicStruct();
200 
201  // functions picking locations for LD/ST/ATOMIC ops
202  void startLocSelection();
205  void endLocSelection();
206 
207  // an episode completed its actions
208  // return locations to their correct positions
209  void releaseLoc(Location loc);
210  // is the value what we expect?
211  bool isExpectedValue(Value val);
212 
213  private:
216 
217  // array storing all locations this structure is managing
221 
222  // a vector of location's properties
226 
227  // a temporary map of location and its LD/ST selection
229  typedef std::unordered_map<Location, LdStBits> LdStMap;
231 
232  // number of atomic requests at this location so far
234  // a set of expected values
235  // when we request the first n atomic ops, we expect to receive n
236  // return values from [0 .. n-1]
237  typedef std::unordered_set<Value> ExpectedValueSet;
239 
240  // swap two locations in locArray
241  void swap(LocProperty& prop_1, LocProperty& prop_2);
242 
243  bool inFirstRegion(int idx) const
244  {
245  return (idx >= 0 && idx < firstMark);
246  }
247  bool inSecondRegion(int idx) const
248  {
249  return (idx >= firstMark && idx < secondMark);
250  }
251  bool inThirdRegion(int idx) const
252  {
253  return (idx >= secondMark && idx < arraySize);
254  }
255  };
256 
257  // number of atomic locations
259  // number of normal/non-atomic locations per atomic structure
261  // total number of non-atomic locations
263 
264  // location - address mapping
267 
268  // a list of atomic structures
271 
272  // internal log table
275 };
276 
277 } // namespace gem5
278 
279 #endif /* CPU_TESTERS_PROTOCOL_TESTER_ADDRESS_MANAGER_HH_ */
gem5::AddressManager::LastWriter::LastWriter
LastWriter()
Definition: address_manager.hh:160
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::AddressManager::AtomicStruct::requestCount
int requestCount
Definition: address_manager.hh:233
gem5::AddressManager::LastWriter::writeTick
Tick writeTick
Definition: address_manager.hh:192
gem5::AddressManager::AtomicStruct::AtomicStruct
AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end)
Definition: address_manager.cc:139
gem5::AddressManager::AtomicStruct::~AtomicStruct
~AtomicStruct()
Definition: address_manager.cc:168
gem5::AddressManager::AtomicStruct::secondMark
int secondMark
Definition: address_manager.hh:219
gem5::AddressManager::AtomicStruct::firstMark
int firstMark
Definition: address_manager.hh:219
gem5::AddressManager::getLoadLoc
Location getLoadLoc(Location atomic_loc)
Definition: address_manager.cc:105
gem5::AddressManager::getStoreLoc
Location getStoreLoc(Location atomic_loc)
Definition: address_manager.cc:112
gem5::AddressManager::finishLocSelection
void finishLocSelection(Location atomic_loc)
Definition: address_manager.cc:119
gem5::AddressManager::AddressMap
std::vector< Addr > AddressMap
Definition: address_manager.hh:265
gem5::AddressManager::LastWriter::episodeId
int episodeId
Definition: address_manager.hh:190
gem5::AddressManager
Definition: address_manager.hh:122
gem5::AddressManager::AddressManager
AddressManager(int n_atomic_locs, int numNormalLocsPerAtomic)
Definition: address_manager.cc:49
gem5::AddressManager::AtomicStruct::arraySize
int arraySize
Definition: address_manager.hh:220
gem5::AddressManager::AtomicStruct::LdStMap
std::unordered_map< Location, LdStBits > LdStMap
Definition: address_manager.hh:229
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:243
gem5::AddressManager::numNormalLocs
int numNormalLocs
Definition: address_manager.hh:262
gem5::AddressManager::LastWriter::cuId
int cuId
Definition: address_manager.hh:189
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
gem5::AddressManager::AtomicStruct::inThirdRegion
bool inThirdRegion(int idx) const
Definition: address_manager.hh:251
gem5::AddressManager::validateAtomicResp
bool validateAtomicResp(Location loc, Value ret_val)
Definition: address_manager.cc:430
std::vector< LocProperty >
gem5::AddressManager::LastWriter::update
void update(int _thread, int _cu, int _episode, Value _value, Tick _tick)
Definition: address_manager.hh:175
gem5::AddressManager::~AddressManager
~AddressManager()
Definition: address_manager.cc:81
gem5::AddressManager::AtomicStruct::LocProperty
std::pair< int, int > LocProperty
Definition: address_manager.hh:223
gem5::AddressManager::atomicStructs
AtomicStructTable atomicStructs
Definition: address_manager.hh:270
gem5::AddressManager::AtomicStruct::LocPropTable
std::vector< LocProperty > LocPropTable
Definition: address_manager.hh:224
gem5::AddressManager::numLocsPerAtomic
int numLocsPerAtomic
Definition: address_manager.hh:260
gem5::AddressManager::LastWriter::print
const std::string print() const
Definition: address_manager.hh:165
gem5::AddressManager::AtomicStruct::locProps
LocPropTable locProps
Definition: address_manager.hh:225
gem5::AddressManager::AtomicStruct::getLoadLoc
Location getLoadLoc()
Definition: address_manager.cc:191
gem5::AddressManager::AtomicStruct::startLocSelection
void startLocSelection()
Definition: address_manager.cc:174
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::AddressManager::AtomicStruct::loadStoreMap
LdStMap loadStoreMap
Definition: address_manager.hh:230
gem5::AddressManager::LogTable
std::vector< LastWriter * > LogTable
Definition: address_manager.hh:273
gem5::AddressManager::AtomicStruct::getStoreLoc
Location getStoreLoc()
Definition: address_manager.cc:224
gem5::AddressManager::updateLogTable
void updateLogTable(Location loc, int threadId, int episodeId, Value new_value, Tick curTick, int cuId=-1)
Definition: address_manager.cc:415
gem5::AddressManager::getAtomicLoc
Location getAtomicLoc()
Definition: address_manager.cc:97
gem5::AddressManager::AtomicStruct::isExpectedValue
bool isExpectedValue(Value val)
Definition: address_manager.cc:376
gem5::AddressManager::AtomicStruct::inSecondRegion
bool inSecondRegion(int idx) const
Definition: address_manager.hh:247
gem5::AddressManager::Location
int32_t Location
Definition: address_manager.hh:129
gem5::AddressManager::INVALID_VALUE
static const int INVALID_VALUE
Definition: address_manager.hh:153
std::pair< int, int >
gem5::AddressManager::AtomicStruct::atomicLoc
Location atomicLoc
Definition: address_manager.hh:214
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:154
gem5::AddressManager::AtomicStruct::endLocSelection
void endLocSelection()
Definition: address_manager.cc:263
gem5::AddressManager::numAtomicLocs
int numAtomicLocs
Definition: address_manager.hh:258
gem5::AddressManager::LastWriter::getLastStoredValue
Value getLastStoredValue() const
Definition: address_manager.hh:185
gem5::AddressManager::Value
int32_t Value
Definition: address_manager.hh:128
gem5::AddressManager::AtomicStructTable
std::vector< AtomicStruct * > AtomicStructTable
Definition: address_manager.hh:269
gem5::AddressManager::AtomicStruct::locArray
Location * locArray
Definition: address_manager.hh:218
types.hh
gem5::AddressManager::LastWriter::threadId
int threadId
Definition: address_manager.hh:188
gem5::AddressManager::AtomicStruct::locationBase
Location locationBase
Definition: address_manager.hh:215
gem5::AddressManager::LastWriter
Definition: address_manager.hh:157
gem5::AddressManager::LastWriter::value
Value value
Definition: address_manager.hh:191
gem5::AddressManager::AtomicStruct::swap
void swap(LocProperty &prop_1, LocProperty &prop_2)
Definition: address_manager.cc:398
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::AddressManager::getLoggedValue
Value getLoggedValue(Location loc) const
Definition: address_manager.cc:423
gem5::AddressManager::AtomicStruct::expectedValues
ExpectedValueSet expectedValues
Definition: address_manager.hh:238
gem5::AddressManager::logTable
LogTable logTable
Definition: address_manager.hh:274
gem5::AddressManager::AtomicStruct::LdStBits
std::pair< bool, bool > LdStBits
Definition: address_manager.hh:228
gem5::AddressManager::AtomicStruct::releaseLoc
void releaseLoc(Location loc)
Definition: address_manager.cc:329
gem5::AddressManager::AtomicStruct
Definition: address_manager.hh:195
gem5::AddressManager::randAddressMap
AddressMap randAddressMap
Definition: address_manager.hh:266
gem5::AddressManager::printLastWriter
std::string printLastWriter(Location loc) const
Definition: address_manager.cc:133
gem5::AddressManager::releaseLocation
void releaseLocation(Location atomic_loc, Location loc)
Definition: address_manager.cc:126
gem5::AddressManager::getAddress
Addr getAddress(Location loc)
Definition: address_manager.cc:90
gem5::AddressManager::AtomicStruct::ExpectedValueSet
std::unordered_set< Value > ExpectedValueSet
Definition: address_manager.hh:237
eventq.hh

Generated on Tue Sep 21 2021 12:25:09 for gem5 by doxygen 1.8.17