gem5 v24.0.0.0
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/types.hh"
41#include "sim/eventq.hh"
42
43namespace 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);
125
126 typedef int32_t Value;
127 typedef int32_t Location;
128
129 // return the unique address mapped to a location
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:
187 int cuId;
191 };
192
194 {
195 public:
196 AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end);
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?
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_ */
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
AtomicStruct(Location atom_loc, Location loc_begin, Location loc_end)
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
AddressManager(int n_atomic_locs, int numNormalLocsPerAtomic)
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)
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)
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0