gem5  v22.1.0.0
dram_gen.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2016-2019 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 page_size,
57  unsigned int nbr_of_banks_DRAM,
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), pageSize(page_size),
66  pageBits(floorLog2(page_size / _blocksize)),
67  bankBits(floorLog2(nbr_of_banks_DRAM)),
68  blockBits(floorLog2(_blocksize)),
69  nbrOfBanksDRAM(nbr_of_banks_DRAM),
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_DRAM)
75  fatal("Attempting to use more banks (%d) than "
76  "what is available (%d)\n",
77  nbr_of_banks_util, nbr_of_banks_DRAM);
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  (pageSize / blocksize)) + 1;
123  blockBits + bankBits + rankBits, new_col);
124  }
125  }
126 
127  DPRINTF(TrafficGen, "DramGen::getNextPacket: %c to addr %x, "
128  "size %d, countNumSeqPkts: %d, numSeqPkts: %d\n",
130 
131  // create a new request packet
134 
135  // add the amount of data manipulated to the total
137 
138  // subtract the number of packets remained to be generated
139  --countNumSeqPkts;
140 
141  // return the generated packet
142  return pkt;
143 }
144 
145 void
146 DramGen::genStartAddr(unsigned int new_bank, unsigned int new_rank)
147 {
148  // start by picking a random address in the range
150 
151  // round down to start address of a block, i.e. a DRAM burst
152  addr -= addr % blocksize;
153 
154  // insert the bank bits at the right spot, and align the
155  // address to achieve the required hit length, this involves
156  // finding the appropriate start address such that all
157  // sequential packets target successive columns in the same
158  // page
159 
160  // for example, if we have a stride size of 192B, which means
161  // for LPDDR3 where burstsize = 32B we have numSeqPkts = 6,
162  // the address generated previously can be such that these
163  // 192B cross the page boundary, hence it needs to be aligned
164  // so that they all belong to the same page for page hit
165  unsigned int columns_per_page = pageSize / blocksize;
166 
167  // pick a random column, but ensure that there is room for
168  // numSeqPkts sequential columns in the same page
169  unsigned int new_col =
170  random_mt.random<unsigned int>(0, columns_per_page - numSeqPkts);
171 
172  if (addrMapping == enums::RoRaBaCoCh ||
173  addrMapping == enums::RoRaBaChCo) {
174  // Block bits, then page bits, then bank bits, then rank bits
176  blockBits + pageBits, new_bank);
177  replaceBits(addr, blockBits + pageBits - 1, blockBits, new_col);
178  if (rankBits != 0) {
180  blockBits + pageBits + bankBits, new_rank);
181  }
182  } else if (addrMapping == enums::RoCoRaBaCh) {
183  // Block bits, then bank bits, then rank bits, then page bits
184  replaceBits(addr, blockBits + bankBits - 1, blockBits, new_bank);
186  blockBits + bankBits + rankBits, new_col);
187  if (rankBits != 0) {
189  blockBits + bankBits, new_rank);
190  }
191  }
192 }
193 
194 } // 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
bool isRead
Remember type of requests to be generated in series.
Definition: dram_gen.hh:121
DramGen(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 page_size, unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util, enums::AddrMap addr_mapping, unsigned int nbr_of_ranks)
Create a DRAM address sequence generator.
Definition: dram_gen.cc:50
const unsigned int nbrOfBanksUtil
Number of banks to be utilized for a given configuration.
Definition: dram_gen.hh:139
const unsigned int nbrOfBanksDRAM
Number of banks in DRAM.
Definition: dram_gen.hh:136
const unsigned int blockBits
Number of block bits in DRAM address.
Definition: dram_gen.hh:133
Addr addr
Address of request.
Definition: dram_gen.hh:118
unsigned int countNumSeqPkts
Track number of sequential packets generated for a request
Definition: dram_gen.hh:115
const unsigned int nbrOfRanks
Number of ranks to be utilized for a given configuration.
Definition: dram_gen.hh:148
const unsigned int rankBits
Number of rank bits in DRAM address.
Definition: dram_gen.hh:145
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: dram_gen.cc:146
const unsigned int numSeqPkts
Number of sequential DRAM packets to be generated per cpu request.
Definition: dram_gen.hh:112
enums::AddrMap addrMapping
Address mapping to be used.
Definition: dram_gen.hh:142
PacketPtr getNextPacket()
Get the next generated packet.
Definition: dram_gen.cc:81
const unsigned int pageBits
Number of page bits in DRAM address.
Definition: dram_gen.hh:127
const unsigned int pageSize
Page size of DRAM.
Definition: dram_gen.hh:124
const unsigned int bankBits
Number of bank bits in DRAM address.
Definition: dram_gen.hh:130
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
Declaration of the DRAM generator for issuing variable page hit length requests and bank utilisation.
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

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