7e0bd9e7fa523a3c7ae42b36747cbd1f97b1bcee
[gem5.git] / configs / nvm / sweep.py
1 # Copyright (c) 2020 ARM Limited
2 # All rights reserved.
3 #
4 # The license below extends only to copyright in the software and shall
5 # not be construed as granting a license to any other intellectual
6 # property including but not limited to intellectual property relating
7 # to a hardware implementation of the functionality of the software
8 # licensed hereunder. You may use the software subject to the license
9 # terms below provided that you ensure that this notice is replicated
10 # unmodified and in its entirety in all distributions of the software,
11 # modified or unmodified, in source code or in binary form.
12 #
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are
15 # met: redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer;
17 # redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution;
20 # neither the name of the copyright holders nor the names of its
21 # contributors may be used to endorse or promote products derived from
22 # this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Authors: Andreas Hansson
37
38 from __future__ import print_function
39 from __future__ import absolute_import
40
41 import math
42 import optparse
43
44 import m5
45 from m5.objects import *
46 from m5.util import addToPath
47 from m5.stats import periodicStatDump
48
49 addToPath('../')
50
51 from common import ObjectList
52 from common import MemConfig
53
54 # this script is helpful to sweep the efficiency of a specific memory
55 # controller configuration, by varying the number of banks accessed,
56 # and the sequential stride size (how many bytes per activate), and
57 # observe what bus utilisation (bandwidth) is achieved
58
59 parser = optparse.OptionParser()
60
61 nvm_generators = {
62 "NVM" : lambda x: x.createNvm,
63 }
64
65 # Use a single-channel DDR3-1600 x64 (8x8 topology) by default
66 parser.add_option("--nvm-type", type="choice", default="NVM_2400_1x64",
67 choices=ObjectList.mem_list.get_names(),
68 help = "type of memory to use")
69
70 parser.add_option("--nvm-ranks", "-r", type="int", default=1,
71 help = "Number of ranks to iterate across")
72
73 parser.add_option("--rd_perc", type="int", default=100,
74 help = "Percentage of read commands")
75
76 parser.add_option("--mode", type="choice", default="NVM",
77 choices=nvm_generators.keys(),
78 help = "NVM: Random traffic")
79
80 parser.add_option("--addr-map", type="choice",
81 choices=ObjectList.dram_addr_map_list.get_names(),
82 default="RoRaBaCoCh", help = "NVM address map policy")
83
84 (options, args) = parser.parse_args()
85
86 if args:
87 print("Error: script doesn't take any positional arguments")
88 sys.exit(1)
89
90 # at the moment we stay with the default open-adaptive page policy,
91 # and address mapping
92
93 # start with the system itself, using a multi-layer 2.0 GHz
94 # crossbar, delivering 64 bytes / 3 cycles (one header cycle)
95 # which amounts to 42.7 GByte/s per layer and thus per port
96 system = System(membus = IOXBar(width = 32))
97 system.clk_domain = SrcClockDomain(clock = '2.0GHz',
98 voltage_domain =
99 VoltageDomain(voltage = '1V'))
100
101 # we are fine with 256 MB memory for now
102 mem_range = AddrRange('512MB')
103 system.mem_ranges = [mem_range]
104
105 # do not worry about reserving space for the backing store
106 system.mmap_using_noreserve = True
107
108 # force a single channel to match the assumptions in the DRAM traffic
109 # generator
110 options.mem_channels = 1
111 options.external_memory_system = 0
112 MemConfig.config_mem(options, system)
113
114 # the following assumes that we are using the native memory
115 # controller with an NVM interface, check to be sure
116 if not isinstance(system.mem_ctrls[0], m5.objects.MemCtrl):
117 fatal("This script assumes the controller is a MemCtrl subclass")
118 if not isinstance(system.mem_ctrls[0].nvm, m5.objects.NVMInterface):
119 fatal("This script assumes the memory is a NVMInterface class")
120
121 # there is no point slowing things down by saving any data
122 system.mem_ctrls[0].nvm.null = True
123
124 # Set the address mapping based on input argument
125 system.mem_ctrls[0].nvm.addr_mapping = options.addr_map
126
127 # stay in each state for 0.25 ms, long enough to warm things up, and
128 # short enough to avoid hitting a refresh
129 period = 250000000
130
131 # stay in each state as long as the dump/reset period, use the entire
132 # range, issue transactions of the right DRAM burst size, and match
133 # the DRAM maximum bandwidth to ensure that it is saturated
134
135 # get the number of regions
136 nbr_banks = system.mem_ctrls[0].nvm.banks_per_rank.value
137
138 # determine the burst length in bytes
139 burst_size = int((system.mem_ctrls[0].nvm.devices_per_rank.value *
140 system.mem_ctrls[0].nvm.device_bus_width.value *
141 system.mem_ctrls[0].nvm.burst_length.value) / 8)
142
143
144 # next, get the page size in bytes
145 buffer_size = system.mem_ctrls[0].nvm.devices_per_rank.value * \
146 system.mem_ctrls[0].nvm.device_rowbuffer_size.value
147
148 # match the maximum bandwidth of the memory, the parameter is in seconds
149 # and we need it in ticks (ps)
150 itt = system.mem_ctrls[0].nvm.tBURST.value * 1000000000000
151
152 # assume we start at 0
153 max_addr = mem_range.end
154
155 # use min of the page size and 512 bytes as that should be more than
156 # enough
157 max_stride = min(256, buffer_size)
158
159 # create a traffic generator, and point it to the file we just created
160 system.tgen = PyTrafficGen()
161
162 # add a communication monitor
163 system.monitor = CommMonitor()
164
165 # connect the traffic generator to the bus via a communication monitor
166 system.tgen.port = system.monitor.slave
167 system.monitor.master = system.membus.slave
168
169 # connect the system port even if it is not used in this example
170 system.system_port = system.membus.slave
171
172 # every period, dump and reset all stats
173 periodicStatDump(period)
174
175 # run Forrest, run!
176 root = Root(full_system = False, system = system)
177 root.system.mem_mode = 'timing'
178
179 m5.instantiate()
180
181 def trace():
182 addr_map = ObjectList.dram_addr_map_list.get(options.addr_map)
183 generator = nvm_generators[options.mode](system.tgen)
184 for stride_size in range(burst_size, max_stride + 1, burst_size):
185 for bank in range(1, nbr_banks + 1):
186 num_seq_pkts = int(math.ceil(float(stride_size) / burst_size))
187 yield generator(period,
188 0, max_addr, burst_size, int(itt), int(itt),
189 options.rd_perc, 0,
190 num_seq_pkts, buffer_size, nbr_banks, bank,
191 addr_map, options.nvm_ranks)
192 yield system.tgen.createExit(0)
193
194 system.tgen.start(trace())
195
196 m5.simulate()
197
198 print("NVM sweep with burst: %d, banks: %d, max stride: %d" %
199 (burst_size, nbr_banks, max_stride))