sweep.py revision 11125
112855Sgabeblack@google.com# Copyright (c) 2014-2015 ARM Limited
212855Sgabeblack@google.com# All rights reserved.
312855Sgabeblack@google.com#
412855Sgabeblack@google.com# The license below extends only to copyright in the software and shall
512855Sgabeblack@google.com# not be construed as granting a license to any other intellectual
612855Sgabeblack@google.com# property including but not limited to intellectual property relating
712855Sgabeblack@google.com# to a hardware implementation of the functionality of the software
812855Sgabeblack@google.com# licensed hereunder.  You may use the software subject to the license
912855Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated
1012855Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software,
1112855Sgabeblack@google.com# modified or unmodified, in source code or in binary form.
1212855Sgabeblack@google.com#
1312855Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
1412855Sgabeblack@google.com# modification, are permitted provided that the following conditions are
1512855Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
1612855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1712855Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1812855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1912855Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
2012855Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
2112855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
2212855Sgabeblack@google.com# this software without specific prior written permission.
2312855Sgabeblack@google.com#
2412855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2512855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2612855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2712855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2812855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2912855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3012855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3112855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3212855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3312855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3412855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3512855Sgabeblack@google.com#
3612855Sgabeblack@google.com# Authors: Andreas Hansson
3712855Sgabeblack@google.com
3812855Sgabeblack@google.comimport optparse
3912855Sgabeblack@google.com
4012855Sgabeblack@google.comimport m5
4112855Sgabeblack@google.comfrom m5.objects import *
4212855Sgabeblack@google.comfrom m5.util import addToPath
4312855Sgabeblack@google.comfrom m5.internal.stats import periodicStatDump
4412855Sgabeblack@google.com
4512855Sgabeblack@google.comaddToPath('../common')
46
47import MemConfig
48
49# this script is helpful to sweep the efficiency of a specific memory
50# controller configuration, by varying the number of banks accessed,
51# and the sequential stride size (how many bytes per activate), and
52# observe what bus utilisation (bandwidth) is achieved
53
54parser = optparse.OptionParser()
55
56# Use a single-channel DDR3-1600 x64 by default
57parser.add_option("--mem-type", type="choice", default="DDR3_1600_x64",
58                  choices=MemConfig.mem_names(),
59                  help = "type of memory to use")
60
61parser.add_option("--mem-ranks", "-r", type="int", default=1,
62                  help = "Number of ranks to iterate across")
63
64parser.add_option("--rd_perc", type="int", default=100,
65                  help = "Percentage of read commands")
66
67parser.add_option("--mode", type="choice", default="DRAM",
68                  choices=["DRAM", "DRAM_ROTATE"],
69                  help = "DRAM: Random traffic; \
70                          DRAM_ROTATE: Traffic rotating across banks and ranks")
71
72parser.add_option("--addr_map", type="int", default=1,
73                  help = "0: RoCoRaBaCh; 1: RoRaBaCoCh/RoRaBaChCo")
74
75(options, args) = parser.parse_args()
76
77if args:
78    print "Error: script doesn't take any positional arguments"
79    sys.exit(1)
80
81# at the moment we stay with the default open-adaptive page policy,
82# and address mapping
83
84# start with the system itself, using a multi-layer 2.0 GHz
85# crossbar, delivering 64 bytes / 3 cycles (one header cycle)
86# which amounts to 42.7 GByte/s per layer and thus per port
87system = System(membus = IOXBar(width = 32))
88system.clk_domain = SrcClockDomain(clock = '2.0GHz',
89                                   voltage_domain =
90                                   VoltageDomain(voltage = '1V'))
91
92# we are fine with 256 MB memory for now
93mem_range = AddrRange('256MB')
94system.mem_ranges = [mem_range]
95
96# do not worry about reserving space for the backing store
97mmap_using_noreserve = True
98
99# force a single channel to match the assumptions in the DRAM traffic
100# generator
101options.mem_channels = 1
102options.external_memory_system = 0
103options.tlm_memory = 0
104MemConfig.config_mem(options, system)
105
106# the following assumes that we are using the native DRAM
107# controller, check to be sure
108if not isinstance(system.mem_ctrls[0], m5.objects.DRAMCtrl):
109    fatal("This script assumes the memory is a DRAMCtrl subclass")
110
111# there is no point slowing things down by saving any data
112system.mem_ctrls[0].null = True
113
114# Set the address mapping based on input argument
115# Default to RoRaBaCoCh
116if options.addr_map == 0:
117   system.mem_ctrls[0].addr_mapping = "RoCoRaBaCh"
118elif options.addr_map == 1:
119   system.mem_ctrls[0].addr_mapping = "RoRaBaCoCh"
120else:
121    fatal("Did not specify a valid address map argument")
122
123# stay in each state for 0.25 ms, long enough to warm things up, and
124# short enough to avoid hitting a refresh
125period = 250000000
126
127# this is where we go off piste, and print the traffic generator
128# configuration that we will later use, crazy but it works
129cfg_file_name = "configs/dram/sweep.cfg"
130cfg_file = open(cfg_file_name, 'w')
131
132# stay in each state as long as the dump/reset period, use the entire
133# range, issue transactions of the right DRAM burst size, and match
134# the DRAM maximum bandwidth to ensure that it is saturated
135
136# get the number of banks
137nbr_banks = system.mem_ctrls[0].banks_per_rank.value
138
139# determine the burst length in bytes
140burst_size = int((system.mem_ctrls[0].devices_per_rank.value *
141                  system.mem_ctrls[0].device_bus_width.value *
142                  system.mem_ctrls[0].burst_length.value) / 8)
143
144# next, get the page size in bytes
145page_size = system.mem_ctrls[0].devices_per_rank.value * \
146    system.mem_ctrls[0].device_rowbuffer_size.value
147
148# match the maximum bandwidth of the memory, the parameter is in ns
149# and we need it in ticks
150itt = system.mem_ctrls[0].tBURST.value * 1000000000000
151
152# assume we start at 0
153max_addr = mem_range.end
154
155# use min of the page size and 512 bytes as that should be more than
156# enough
157max_stride = min(512, page_size)
158
159# now we create the state by iterating over the stride size from burst
160# size to the max stride, and from using only a single bank up to the
161# number of banks available
162nxt_state = 0
163for bank in range(1, nbr_banks + 1):
164    for stride_size in range(burst_size, max_stride + 1, burst_size):
165        cfg_file.write("STATE %d %d %s %d 0 %d %d "
166                       "%d %d %d %d %d %d %d %d %d\n" %
167                       (nxt_state, period, options.mode, options.rd_perc,
168                        max_addr, burst_size, itt, itt, 0, stride_size,
169                        page_size, nbr_banks, bank, options.addr_map,
170                        options.mem_ranks))
171        nxt_state = nxt_state + 1
172
173cfg_file.write("INIT 0\n")
174
175# go through the states one by one
176for state in range(1, nxt_state):
177    cfg_file.write("TRANSITION %d %d 1\n" % (state - 1, state))
178
179cfg_file.write("TRANSITION %d %d 1\n" % (nxt_state - 1, nxt_state - 1))
180
181cfg_file.close()
182
183# create a traffic generator, and point it to the file we just created
184system.tgen = TrafficGen(config_file = cfg_file_name)
185
186# add a communication monitor
187system.monitor = CommMonitor()
188
189# connect the traffic generator to the bus via a communication monitor
190system.tgen.port = system.monitor.slave
191system.monitor.master = system.membus.slave
192
193# connect the system port even if it is not used in this example
194system.system_port = system.membus.slave
195
196# every period, dump and reset all stats
197periodicStatDump(period)
198
199# run Forrest, run!
200root = Root(full_system = False, system = system)
201root.system.mem_mode = 'timing'
202
203m5.instantiate()
204m5.simulate(nxt_state * period)
205
206print "DRAM sweep with burst: %d, banks: %d, max stride: %d" % \
207    (burst_size, nbr_banks, max_stride)
208