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

Generated on Mon Jan 13 2025 04:28:32 for gem5 by doxygen 1.9.8