gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Thomas Grass
38  * Andreas Hansson
39  * Sascha Bischoff
40  * Neha Agarwal
41  */
42 
44 
45 #include <algorithm>
46 
47 #include "base/random.hh"
48 #include "base/trace.hh"
49 #include "debug/TrafficGen.hh"
50 #include "enums/AddrMap.hh"
51 
53  MasterID master_id, Tick _duration,
54  Addr start_addr, Addr end_addr,
55  Addr _blocksize, Addr cacheline_size,
56  Tick min_period, Tick max_period,
57  uint8_t read_percent, Addr data_limit,
58  unsigned int num_seq_pkts, unsigned int page_size,
59  unsigned int nbr_of_banks_DRAM,
60  unsigned int nbr_of_banks_util,
61  Enums::AddrMap addr_mapping,
62  unsigned int nbr_of_ranks)
63  : RandomGen(obj, master_id, _duration, start_addr, end_addr,
64  _blocksize, cacheline_size, min_period, max_period,
65  read_percent, data_limit),
66  numSeqPkts(num_seq_pkts), countNumSeqPkts(0), addr(0),
67  isRead(true), pageSize(page_size),
68  pageBits(floorLog2(page_size / _blocksize)),
69  bankBits(floorLog2(nbr_of_banks_DRAM)),
70  blockBits(floorLog2(_blocksize)),
71  nbrOfBanksDRAM(nbr_of_banks_DRAM),
72  nbrOfBanksUtil(nbr_of_banks_util), addrMapping(addr_mapping),
73  rankBits(floorLog2(nbr_of_ranks)),
74  nbrOfRanks(nbr_of_ranks)
75 {
76  if (nbr_of_banks_util > nbr_of_banks_DRAM)
77  fatal("Attempting to use more banks (%d) than "
78  "what is available (%d)\n",
79  nbr_of_banks_util, nbr_of_banks_DRAM);
80 }
81 
84 {
85  // if this is the first of the packets in series to be generated,
86  // start counting again
87  if (countNumSeqPkts == 0) {
89 
90  // choose if we generate a read or a write here
91  isRead = readPercent != 0 &&
92  (readPercent == 100 || random_mt.random(0, 100) < readPercent);
93 
94  assert((readPercent == 0 && !isRead) ||
95  (readPercent == 100 && isRead) ||
96  readPercent != 100);
97 
98  // pick a random bank
99  unsigned int new_bank =
100  random_mt.random<unsigned int>(0, nbrOfBanksUtil - 1);
101 
102  // pick a random rank
103  unsigned int new_rank =
104  random_mt.random<unsigned int>(0, nbrOfRanks - 1);
105 
106  // Generate the start address of the command series
107  // routine will update addr variable with bank, rank, and col
108  // bits updated for random traffic mode
109  genStartAddr(new_bank, new_rank);
110 
111  } else {
112  // increment the column by one
113  if (addrMapping == Enums::RoRaBaCoCh ||
114  addrMapping == Enums::RoRaBaChCo)
115  // Simply increment addr by blocksize to increment
116  // the column by one
117  addr += blocksize;
118 
119  else if (addrMapping == Enums::RoCoRaBaCh) {
120  // Explicity increment the column bits
121  unsigned int new_col = ((addr / blocksize /
123  (pageSize / blocksize)) + 1;
125  blockBits + bankBits + rankBits, new_col);
126  }
127  }
128 
129  DPRINTF(TrafficGen, "DramGen::getNextPacket: %c to addr %x, "
130  "size %d, countNumSeqPkts: %d, numSeqPkts: %d\n",
132 
133  // create a new request packet
136 
137  // add the amount of data manipulated to the total
139 
140  // subtract the number of packets remained to be generated
141  --countNumSeqPkts;
142 
143  // return the generated packet
144  return pkt;
145 }
146 
147 void
148 DramGen::genStartAddr(unsigned int new_bank, unsigned int new_rank)
149 {
150  // start by picking a random address in the range
152 
153  // round down to start address of a block, i.e. a DRAM burst
154  addr -= addr % blocksize;
155 
156  // insert the bank bits at the right spot, and align the
157  // address to achieve the required hit length, this involves
158  // finding the appropriate start address such that all
159  // sequential packets target successive columns in the same
160  // page
161 
162  // for example, if we have a stride size of 192B, which means
163  // for LPDDR3 where burstsize = 32B we have numSeqPkts = 6,
164  // the address generated previously can be such that these
165  // 192B cross the page boundary, hence it needs to be aligned
166  // so that they all belong to the same page for page hit
167  unsigned int columns_per_page = pageSize / blocksize;
168 
169  // pick a random column, but ensure that there is room for
170  // numSeqPkts sequential columns in the same page
171  unsigned int new_col =
172  random_mt.random<unsigned int>(0, columns_per_page - numSeqPkts);
173 
174  if (addrMapping == Enums::RoRaBaCoCh ||
175  addrMapping == Enums::RoRaBaChCo) {
176  // Block bits, then page bits, then bank bits, then rank bits
177  replaceBits(addr, blockBits + pageBits + bankBits - 1,
178  blockBits + pageBits, new_bank);
179  replaceBits(addr, blockBits + pageBits - 1, blockBits, new_col);
180  if (rankBits != 0) {
182  blockBits + pageBits + bankBits, new_rank);
183  }
184  } else if (addrMapping == Enums::RoCoRaBaCh) {
185  // Block bits, then bank bits, then rank bits, then page bits
186  replaceBits(addr, blockBits + bankBits - 1, blockBits, new_bank);
188  blockBits + bankBits + rankBits, new_col);
189  if (rankBits != 0) {
190  replaceBits(addr, blockBits + bankBits + rankBits - 1,
191  blockBits + bankBits, new_rank);
192  }
193  }
194 }
#define DPRINTF(x,...)
Definition: trace.hh:229
const unsigned int numSeqPkts
Number of sequential DRAM packets to be generated per cpu request.
Definition: dram_gen.hh:114
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
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:148
PacketPtr getPacket(Addr addr, unsigned size, const MemCmd &cmd, Request::FlagsType flags=0)
Generate a new request and associated packet.
Definition: base_gen.cc:61
unsigned int countNumSeqPkts
Track number of sequential packets generated for a request.
Definition: dram_gen.hh:117
ip6_addr_t addr
Definition: inet.hh:335
const unsigned int nbrOfBanksDRAM
Number of banks in DRAM.
Definition: dram_gen.hh:138
bool isRead
Remember type of requests to be generated in series.
Definition: dram_gen.hh:123
const unsigned int bankBits
Number of bank bits in DRAM address.
Definition: dram_gen.hh:132
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:83
const unsigned int blockBits
Number of block bits in DRAM address.
Definition: dram_gen.hh:135
The traffic generator is a master module that generates stimuli for the memory system, based on a collection of simple behaviours that are either probabilistic or based on traces.
Definition: traffic_gen.hh:71
uint64_t Tick
Tick count type.
Definition: types.hh:63
const uint8_t readPercent
Percent of generated transactions that should be reads.
Definition: base_gen.hh:167
void replaceBits(T &val, int first, int last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition: bitfield.hh:157
const unsigned int nbrOfBanksUtil
Number of banks to be utilized for a given configuration.
Definition: dram_gen.hh:141
DramGen(SimObject &obj, MasterID master_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:52
const unsigned int pageBits
Number of page bits in DRAM address.
Definition: dram_gen.hh:129
const Addr startAddr
Start of address range.
Definition: base_gen.hh:149
const unsigned int rankBits
Number of rank bits in DRAM address.
Definition: dram_gen.hh:147
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint16_t MasterID
Definition: request.hh:86
const unsigned int nbrOfRanks
Number of ranks to be utilized for a given configuration.
Definition: dram_gen.hh:150
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Declaration of the DRAM generator for issuing variable page hit length requests and bank utilisation...
PacketPtr getNextPacket()
Get the next generated packet.
Definition: dram_gen.cc:83
int floorLog2(unsigned x)
Definition: intmath.hh:61
Addr addr
Address of request.
Definition: dram_gen.hh:120
const Addr blocksize
Blocksize and address increment.
Definition: base_gen.hh:155
Random random_mt
Definition: random.cc:100
The random generator is similar to the linear one, but does not generate sequential addresses...
Definition: random_gen.hh:62
const unsigned int pageSize
Page size of DRAM.
Definition: dram_gen.hh:126
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
Enums::AddrMap addrMapping
Address mapping to be used.
Definition: dram_gen.hh:144
const Addr endAddr
End of address range.
Definition: base_gen.hh:152
Addr dataManipulated
Counter to determine the amount of data manipulated.
Definition: random_gen.hh:106

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13