gem5 v24.1.0.1
Loading...
Searching...
No Matches
hybrid_gen.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed here under. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
39
40#include <algorithm>
41
42#include "base/trace.hh"
43#include "debug/TrafficGen.hh"
44#include "enums/AddrMap.hh"
45
46namespace gem5
47{
48
50 RequestorID requestor_id, Tick _duration,
51 Addr start_addr_dram, Addr end_addr_dram,
52 Addr blocksize_dram,
53 Addr start_addr_nvm, Addr end_addr_nvm,
54 Addr blocksize_nvm,
55 Addr cacheline_size,
56 Tick min_period, Tick max_period,
57 uint8_t read_percent, Addr data_limit,
58 unsigned int num_seq_pkts_dram, unsigned int page_size_dram,
59 unsigned int nbr_of_banks_dram,
60 unsigned int nbr_of_banks_util_dram,
61 unsigned int num_seq_pkts_nvm, unsigned int buffer_size_nvm,
62 unsigned int nbr_of_banks_nvm,
63 unsigned int nbr_of_banks_util_nvm,
64 enums::AddrMap addr_mapping,
65 unsigned int nbr_of_ranks_dram,
66 unsigned int nbr_of_ranks_nvm,
67 uint8_t nvm_percent)
68 : BaseGen(obj, requestor_id, _duration),
69 startAddrDram(start_addr_dram),
70 endAddrDram(end_addr_dram),
71 blocksizeDram(blocksize_dram),
72 startAddrNvm(start_addr_nvm),
73 endAddrNvm(end_addr_nvm),
74 blocksizeNvm(blocksize_nvm),
75 cacheLineSize(cacheline_size),
76 minPeriod(min_period), maxPeriod(max_period),
77 readPercent(read_percent), dataLimit(data_limit),
78 numSeqPktsDram(num_seq_pkts_dram),
79 numSeqPktsNvm(num_seq_pkts_nvm),
80 countNumSeqPkts(0), addr(0),
81 pageSizeDram(page_size_dram),
82 pageBitsDram(floorLog2(pageSizeDram / blocksizeDram)),
83 bankBitsDram(floorLog2(nbr_of_banks_dram)),
84 blockBitsDram(floorLog2(blocksizeDram)),
85 nbrOfBanksDram(nbr_of_banks_dram),
86 nbrOfBanksUtilDram(nbr_of_banks_util_dram),
87 bufferSizeNvm(buffer_size_nvm),
88 pageBitsNvm(floorLog2(bufferSizeNvm / blocksizeNvm)),
89 bankBitsNvm(floorLog2(nbr_of_banks_nvm)),
90 blockBitsNvm(floorLog2(blocksizeNvm)),
91 nbrOfBanksNvm(nbr_of_banks_nvm),
92 nbrOfBanksUtilNvm(nbr_of_banks_util_nvm),
93 addrMapping(addr_mapping),
94 nbrOfRanksDram(nbr_of_ranks_dram),
95 rankBitsDram(floorLog2(nbrOfRanksDram)),
96 nbrOfRanksNvm(nbr_of_ranks_nvm),
97 rankBitsNvm(floorLog2(nbrOfRanksNvm)),
98 nvmPercent(nvm_percent),
99 isRead(true),
100 isNvm(false),
101 dataManipulated(0)
102{
104 fatal("TrafficGen %s Dram block size (%d) is larger than "
105 "cache line size (%d)\n", name(),
107
109 fatal("TrafficGen %s Nvm block size (%d) is larger than "
110 "cache line size (%d)\n", name(),
112
113 if (readPercent > 100)
114 fatal("%s cannot have more than 100% reads", name());
115
116 if (minPeriod > maxPeriod)
117 fatal("%s cannot have min_period > max_period", name());
118
120 fatal("Attempting to use more Dram banks (%d) than "
121 "what is available (%d)\n",
123
125 fatal("Attempting to use more Nvm banks (%d) than "
126 "what is available (%d)\n",
128}
129
130void
132{
133 // reset the counter to zero
134 dataManipulated = 0;
135}
136
139{
140 // if this is the first of the packets in series to be generated,
141 // start counting again
142 if (countNumSeqPkts == 0) {
143 isNvm = nvmPercent != 0 &&
144 (nvmPercent == 100 || rng->random(0, 100) < nvmPercent);
145
146 // choose if we generate a read or a write here
147 isRead = readPercent != 0 &&
148 (readPercent == 100 || rng->random(0, 100) < readPercent);
149
150 assert((readPercent == 0 && !isRead) ||
151 (readPercent == 100 && isRead) ||
152 readPercent != 100);
153
154 if (isNvm) {
155 // Select the appropriate parameters for this interface
168 } else {
169 // Select the appropriate parameters for this interface
182 }
183
185
186 // pick a random bank
187 unsigned int new_bank =
188 rng->random<unsigned int>(0, nbrOfBanksUtil - 1);
189
190 // pick a random rank
191 unsigned int new_rank =
192 rng->random<unsigned int>(0, nbrOfRanks - 1);
193
194 // Generate the start address of the command series
195 // routine will update addr variable with bank, rank, and col
196 // bits updated for random traffic mode
197 genStartAddr(new_bank, new_rank);
198
199
200 } else {
201 // increment the column by one
202 if (addrMapping == enums::RoRaBaCoCh ||
203 addrMapping == enums::RoRaBaChCo)
204 // Simply increment addr by blocksize to increment
205 // the column by one
206 addr += blocksize;
207
208 else if (addrMapping == enums::RoCoRaBaCh) {
209 // Explicity increment the column bits
210 unsigned int new_col = ((addr / blocksize /
212 (pageSize / blocksize)) + 1;
214 blockBits + bankBits + rankBits, new_col);
215 }
216 }
217
218 DPRINTF(TrafficGen, "HybridGen::getNextPacket: %c to addr %#x, "
219 "size %d, countNumSeqPkts: %d, numSeqPkts: %d\n",
221
222 // create a new request packet
225
226 // add the amount of data manipulated to the total
228
229 // subtract the number of packets remained to be generated
231
232 // return the generated packet
233 return pkt;
234}
235
236void
237HybridGen::genStartAddr(unsigned int new_bank, unsigned int new_rank)
238{
239 // start by picking a random address in the range
240 addr = rng->random<Addr>(startAddr, endAddr - 1);
241
242 // round down to start address of a block, i.e. a DRAM burst
243 addr -= addr % blocksize;
244
245 // insert the bank bits at the right spot, and align the
246 // address to achieve the required hit length, this involves
247 // finding the appropriate start address such that all
248 // sequential packets target successive columns in the same
249 // page
250
251 // for example, if we have a stride size of 192B, which means
252 // for LPDDR3 where burstsize = 32B we have numSeqPkts = 6,
253 // the address generated previously can be such that these
254 // 192B cross the page boundary, hence it needs to be aligned
255 // so that they all belong to the same page for page hit
256 unsigned int burst_per_page = pageSize / blocksize;
257
258 // pick a random column, but ensure that there is room for
259 // numSeqPkts sequential columns in the same page
260 unsigned int new_col =
261 rng->random<unsigned int>(0, burst_per_page - numSeqPkts);
262
263 if (addrMapping == enums::RoRaBaCoCh ||
264 addrMapping == enums::RoRaBaChCo) {
265 // Block bits, then page bits, then bank bits, then rank bits
267 blockBits + pageBits, new_bank);
268 replaceBits(addr, blockBits + pageBits - 1, blockBits, new_col);
269 if (rankBits != 0) {
271 blockBits + pageBits + bankBits, new_rank);
272 }
273 } else if (addrMapping == enums::RoCoRaBaCh) {
274 // Block bits, then bank bits, then rank bits, then page bits
275 replaceBits(addr, blockBits + bankBits - 1, blockBits, new_bank);
277 blockBits + bankBits + rankBits, new_col);
278 if (rankBits != 0) {
280 blockBits + bankBits, new_rank);
281 }
282 }
283}
284
285Tick
286HybridGen::nextPacketTick(bool elastic, Tick delay) const
287{
288 // Check to see if we have reached the data limit. If dataLimit is
289 // zero we do not have a data limit and therefore we will keep
290 // generating requests for the entire residency in this state.
292 {
293 DPRINTF(TrafficGen, "Data limit for RandomGen reached.\n");
294 // No more requests. Return MaxTick.
295 return MaxTick;
296 } else {
297 // return the time when the next request should take place
298 Tick wait = rng->random(minPeriod, maxPeriod);
299
300 // compensate for the delay experienced to not be elastic, by
301 // default the value we generate is from the time we are
302 // asked, so the elasticity happens automatically
303 if (!elastic) {
304 if (wait < delay)
305 wait = 0;
306 else
307 wait -= delay;
308 }
309
310 return curTick() + wait;
311 }
312}
313
314} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Base class for all generators, with the shared functionality and virtual functions for entering,...
Definition base_gen.hh:66
PacketPtr getPacket(Addr addr, unsigned size, const MemCmd &cmd, Request::FlagsType flags=0)
Generate a new request and associated packet.
Definition base_gen.cc:55
Random::RandomPtr rng
Definition base_gen.hh:76
std::string name() const
Get the name, useful for DPRINTFs.
Definition base_gen.hh:110
Tick nextPacketTick(bool elastic, Tick delay) const
Determine the tick when the next packet is available.
const unsigned int bankBitsNvm
Number of bank bits in NVM address.
const Addr startAddrDram
Start of DRAM address range.
unsigned int countNumSeqPkts
Track number of sequential packets generated for a request
unsigned int pageSize
Page size of DRAM.
const Addr dataLimit
Maximum amount of data to manipulate.
unsigned int nbrOfRanks
Number of ranks to be utilized for a given configuration.
const uint8_t readPercent
Percent of generated transactions that should be reads.
void enter()
Enter this generator state.
const unsigned int nbrOfBanksUtilNvm
Number of banks to be utilized for a given configuration.
HybridGen(SimObject &obj, RequestorID requestor_id, Tick _duration, Addr start_addr_dram, Addr end_addr_dram, Addr blocksize_dram, Addr start_addr_nvm, Addr end_addr_nvm, Addr blocksize_nvm, Addr cacheline_size, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit, unsigned int num_seq_pkts_dram, unsigned int page_size_dram, unsigned int nbr_of_banks_dram, unsigned int nbr_of_banks_util_dram, unsigned int num_seq_pkts_nvm, unsigned int buffer_size_nvm, unsigned int nbr_of_banks_nvm, unsigned int nbr_of_banks_util_nvm, enums::AddrMap addr_mapping, unsigned int nbr_of_ranks_dram, unsigned int nbr_of_ranks_nvm, uint8_t nvm_percent)
Create a hybrid DRAM + NVM address sequence generator.
Definition hybrid_gen.cc:49
Addr dataManipulated
Counter to determine the amount of data manipulated.
const Addr startAddrNvm
Start of DRAM address range.
const Addr blocksizeNvm
Blocksize and address increment for DRAM.
const unsigned int blockBitsDram
Number of block bits in DRAM address.
PacketPtr getNextPacket()
Get the next generated packet.
const unsigned int pageBitsNvm
Number of buffer bits in NVM address.
const uint8_t nvmPercent
Percent of generated transactions that should go to NVM.
const unsigned int numSeqPktsNvm
const Addr blocksizeDram
Blocksize and address increment for DRAM.
unsigned int numSeqPkts
Number of sequential DRAM packets to be generated per cpu request.
const Addr endAddrDram
End of DRAM address range.
const unsigned int nbrOfBanksNvm
Number of banks in NVM.
Addr startAddr
Start of address range.
const unsigned int bankBitsDram
Number of bank bits in DRAM address.
Addr endAddr
End of address range.
const unsigned int nbrOfBanksUtilDram
Number of banks to be utilized for a given configuration.
const Addr cacheLineSize
Cache line size in the simulated system.
const unsigned int nbrOfBanksDram
Number of banks in DRAM.
const unsigned int rankBitsNvm
Number of rank bits in DRAM address.
const unsigned int rankBitsDram
Number of rank bits in DRAM address.
const Addr endAddrNvm
End of DRAM address range.
const unsigned int nbrOfRanksNvm
Number of ranks to be utilized for a given configuration.
const Tick maxPeriod
unsigned int bankBits
Number of bank bits in DRAM address.
unsigned int nbrOfBanks
Number of banks in DRAM.
bool isRead
Remember type of requests to be generated in series.
enums::AddrMap addrMapping
Address mapping to be used.
Addr blocksize
Blocksize and address increment.
Addr addr
Address of request.
const unsigned int blockBitsNvm
Number of block bits in NVM address.
unsigned int pageBits
Number of page bits in DRAM address.
const unsigned int pageSizeDram
Page size of DRAM.
const unsigned int nbrOfRanksDram
Number of ranks to be utilized for a given configuration.
const unsigned int bufferSizeNvm
Buffer size of NVM.
void genStartAddr(unsigned int new_bank, unsigned int new_rank)
Insert bank, rank, and column bits into packed address to create address for 1st command in a series.
const Tick minPeriod
Request generation period.
unsigned int blockBits
Number of block bits in DRAM address.
const unsigned int numSeqPktsDram
Number of sequential packets to be generated per cpu request.
const unsigned int pageBitsDram
Number of page bits in DRAM address.
bool isNvm
Remember the interface to be generated in series.
unsigned int nbrOfBanksUtil
Number of banks to be utilized for a given configuration.
unsigned int rankBits
Number of rank bits in DRAM address.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Abstract superclass for simulation objects.
The traffic generator is a module that generates stimuli for the memory system, based on a collection...
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition bitfield.hh:216
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Declaration of the NVM generator for issuing variable buffer hit length requests and bank utilisation...
Bitfield< 3 > addr
Definition types.hh:84
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
const Tick MaxTick
Definition types.hh:60
uint16_t RequestorID
Definition request.hh:95

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