gem5  v22.1.0.0
nvm_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/random.hh"
43 #include "base/trace.hh"
44 #include "debug/TrafficGen.hh"
45 #include "enums/AddrMap.hh"
46 
47 namespace gem5
48 {
49 
51  RequestorID requestor_id, Tick _duration,
52  Addr start_addr, Addr end_addr,
53  Addr _blocksize, Addr cacheline_size,
54  Tick min_period, Tick max_period,
55  uint8_t read_percent, Addr data_limit,
56  unsigned int num_seq_pkts, unsigned int buffer_size,
57  unsigned int nbr_of_banks,
58  unsigned int nbr_of_banks_util,
59  enums::AddrMap addr_mapping,
60  unsigned int nbr_of_ranks)
61  : RandomGen(obj, requestor_id, _duration, start_addr, end_addr,
62  _blocksize, cacheline_size, min_period, max_period,
63  read_percent, data_limit),
64  numSeqPkts(num_seq_pkts), countNumSeqPkts(0), addr(0),
65  isRead(true), bufferSize(buffer_size),
66  bufferBits(floorLog2(buffer_size / _blocksize)),
67  bankBits(floorLog2(nbr_of_banks)),
68  blockBits(floorLog2(_blocksize)),
69  nbrOfBanksNVM(nbr_of_banks),
70  nbrOfBanksUtil(nbr_of_banks_util), addrMapping(addr_mapping),
71  rankBits(floorLog2(nbr_of_ranks)),
72  nbrOfRanks(nbr_of_ranks)
73 {
74  if (nbr_of_banks_util > nbr_of_banks)
75  fatal("Attempting to use more banks (%d) than "
76  "what is available (%d)\n",
77  nbr_of_banks_util, nbr_of_banks);
78 }
79 
82 {
83  // if this is the first of the packets in series to be generated,
84  // start counting again
85  if (countNumSeqPkts == 0) {
87 
88  // choose if we generate a read or a write here
89  isRead = readPercent != 0 &&
90  (readPercent == 100 || random_mt.random(0, 100) < readPercent);
91 
92  assert((readPercent == 0 && !isRead) ||
93  (readPercent == 100 && isRead) ||
94  readPercent != 100);
95 
96  // pick a random bank
97  unsigned int new_bank =
98  random_mt.random<unsigned int>(0, nbrOfBanksUtil - 1);
99 
100  // pick a random rank
101  unsigned int new_rank =
102  random_mt.random<unsigned int>(0, nbrOfRanks - 1);
103 
104  // Generate the start address of the command series
105  // routine will update addr variable with bank, rank, and col
106  // bits updated for random traffic mode
107  genStartAddr(new_bank, new_rank);
108 
109  } else {
110  // increment the column by one
111  if (addrMapping == enums::RoRaBaCoCh ||
112  addrMapping == enums::RoRaBaChCo)
113  // Simply increment addr by blocksize to increment
114  // the column by one
115  addr += blocksize;
116 
117  else if (addrMapping == enums::RoCoRaBaCh) {
118  // Explicity increment the column bits
119  unsigned int new_col = ((addr / blocksize /
121  (bufferSize / blocksize)) + 1;
123  bufferBits - 1,
124  blockBits + bankBits + rankBits, new_col);
125  }
126  }
127 
128  DPRINTF(TrafficGen, "NvmGen::getNextPacket: %c to addr %x, "
129  "size %d, countNumSeqPkts: %d, numSeqPkts: %d\n",
131 
132  // create a new request packet
135 
136  // add the amount of data manipulated to the total
138 
139  // subtract the number of packets remained to be generated
140  --countNumSeqPkts;
141 
142  // return the generated packet
143  return pkt;
144 }
145 
146 void
147 NvmGen::genStartAddr(unsigned int new_bank, unsigned int new_rank)
148 {
149  // start by picking a random address in the range
151 
152  // round down to start address of a block, i.e. a NVM burst
153  addr -= addr % blocksize;
154 
155  // insert the bank bits at the right spot, and align the
156  // address to achieve the required hit length, this involves
157  // finding the appropriate start address such that all
158  // sequential packets target successive bursts in the same
159  // buffer
160  unsigned int burst_per_buffer = bufferSize / blocksize;
161 
162  // pick a random burst address, but ensure that there is room for
163  // numSeqPkts sequential bursts in the same buffer
164  unsigned int new_col =
165  random_mt.random<unsigned int>(0, burst_per_buffer - numSeqPkts);
166 
167  if (addrMapping == enums::RoRaBaCoCh ||
168  addrMapping == enums::RoRaBaChCo) {
169  // Block bits, then buffer bits, then bank bits, then rank bits
171  blockBits + bufferBits, new_bank);
172  replaceBits(addr, blockBits + bufferBits - 1, blockBits, new_col);
173  if (rankBits != 0) {
176  new_rank);
177  }
178  } else if (addrMapping == enums::RoCoRaBaCh) {
179  // Block bits, then bank bits, then rank bits, then buffer bits
180  replaceBits(addr, blockBits + bankBits - 1, blockBits, new_bank);
182  blockBits + bankBits + rankBits, new_col);
183  if (rankBits != 0) {
185  blockBits + bankBits, new_rank);
186  }
187  }
188 }
189 
190 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
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
const unsigned int blockBits
Number of block bits in NVM address.
Definition: nvm_gen.hh:133
Addr addr
Address of request.
Definition: nvm_gen.hh:118
PacketPtr getNextPacket()
Get the next generated packet.
Definition: nvm_gen.cc:81
enums::AddrMap addrMapping
Address mapping to be used.
Definition: nvm_gen.hh:142
unsigned int countNumSeqPkts
Track number of sequential packets generated for a request
Definition: nvm_gen.hh:115
const unsigned int bufferBits
Number of buffer bits in NVM address.
Definition: nvm_gen.hh:127
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.
Definition: nvm_gen.cc:147
const unsigned int rankBits
Number of rank bits in NVM address.
Definition: nvm_gen.hh:145
const unsigned int bufferSize
Buffer size of NVM.
Definition: nvm_gen.hh:124
bool isRead
Remember type of requests to be generated in series.
Definition: nvm_gen.hh:121
const unsigned int numSeqPkts
Number of sequential NVM packets to be generated per cpu request.
Definition: nvm_gen.hh:112
const unsigned int nbrOfBanksUtil
Number of banks to be utilized for a given configuration.
Definition: nvm_gen.hh:139
const unsigned int bankBits
Number of bank bits in NVM address.
Definition: nvm_gen.hh:130
const unsigned int nbrOfRanks
Number of ranks to be utilized for a given configuration.
Definition: nvm_gen.hh:148
NvmGen(SimObject &obj, RequestorID requestor_id, Tick _duration, Addr start_addr, Addr end_addr, Addr _blocksize, Addr cacheline_size, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit, unsigned int num_seq_pkts, unsigned int buffer_size, unsigned int nbr_of_banks, unsigned int nbr_of_banks_util, enums::AddrMap addr_mapping, unsigned int nbr_of_ranks)
Create a NVM address sequence generator.
Definition: nvm_gen.cc:50
const unsigned int nbrOfBanksNVM
Number of banks in NVM.
Definition: nvm_gen.hh:136
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
The random generator is similar to the linear one, but does not generate sequential addresses.
Definition: random_gen.hh:61
Addr dataManipulated
Counter to determine the amount of data manipulated.
Definition: random_gen.hh:106
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
const Addr startAddr
Start of address range.
Definition: base_gen.hh:151
const Addr endAddr
End of address range.
Definition: base_gen.hh:154
const Addr blocksize
Blocksize and address increment.
Definition: base_gen.hh:157
const uint8_t readPercent
Percent of generated transactions that should be reads.
Definition: base_gen.hh:169
The traffic generator is a module that generates stimuli for the memory system, based on a collection...
Definition: traffic_gen.hh:71
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
Random random_mt
Definition: random.cc:99
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:90
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:197
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
uint16_t RequestorID
Definition: request.hh:95
Declaration of the NVM generator for issuing variable buffer hit length requests and bank utilisation...

Generated on Wed Dec 21 2022 10:22:32 for gem5 by doxygen 1.9.1