1 # Copyright (c) 2015 ARM Limited
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.
13 # Copyright (c) 2006-2007 The Regents of The University of Michigan
14 # All rights reserved.
16 # Redistribution and use in source and binary forms, with or without
17 # modification, are permitted provided that the following conditions are
18 # met: redistributions of source code must retain the above copyright
19 # notice, this list of conditions and the following disclaimer;
20 # redistributions in binary form must reproduce the above copyright
21 # notice, this list of conditions and the following disclaimer in the
22 # documentation and/or other materials provided with the distribution;
23 # neither the name of the copyright holders nor the names of its
24 # contributors may be used to endorse or promote products derived from
25 # this software without specific prior written permission.
27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 # Authors: Ron Dreslinski
46 from m5
.objects
import *
48 parser
= optparse
.OptionParser()
50 parser
.add_option("-a", "--atomic", action
="store_true",
51 help="Use atomic (non-timing) mode")
52 parser
.add_option("-b", "--blocking", action
="store_true",
53 help="Use blocking caches")
54 parser
.add_option("-l", "--maxloads", metavar
="N", default
=0,
55 help="Stop after N loads")
56 parser
.add_option("-m", "--maxtick", type="int", default
=m5
.MaxTick
,
58 help="Stop after T ticks")
60 # This example script stress tests the memory system by creating false
61 # sharing in a tree topology. At the bottom of the tree is a shared
62 # memory, and then at each level a number of testers are attached,
63 # along with a number of caches that them selves fan out to subtrees
64 # of testers and caches. Thus, it is possible to create a system with
65 # arbitrarily deep cache hierarchies, sharing or no sharing of caches,
66 # and testers not only at the L1s, but also at the L2s, L3s etc.
68 # The tree specification consists of two colon-separated lists of one
69 # or more integers, one for the caches, and one for the testers. The
70 # first integer is the number of caches/testers closest to main
71 # memory. Each cache then fans out to a subtree. The last integer in
72 # the list is the number of caches/testers associated with the
73 # uppermost level of memory. The other integers (if any) specify the
74 # number of caches/testers connected at each level of the crossbar
75 # hierarchy. The tester string should have one element more than the
76 # cache string as there should always be testers attached to the
79 parser
.add_option("-c", "--caches", type="string", default
="2:2:1",
80 help="Colon-separated cache hierarchy specification, "
81 "see script comments for details "
82 "[default: %default]")
83 parser
.add_option("-t", "--testers", type="string", default
="1:1:0:2",
84 help="Colon-separated tester hierarchy specification, "
85 "see script comments for details "
86 "[default: %default]")
87 parser
.add_option("-f", "--functional", type="int", default
=0,
89 help="Target percentage of functional accesses "
90 "[default: %default]")
91 parser
.add_option("-u", "--uncacheable", type="int", default
=0,
93 help="Target percentage of uncacheable accesses "
94 "[default: %default]")
96 parser
.add_option("--progress", type="int", default
=10000,
98 help="Progress message interval "
99 "[default: %default]")
100 parser
.add_option("--sys-clock", action
="store", type="string",
102 help = """Top-level clock for blocks running at system
105 (options
, args
) = parser
.parse_args()
108 print "Error: script doesn't take any positional arguments"
113 # Start by parsing the command line options and do some basic sanity
116 cachespec
= [int(x
) for x
in options
.caches
.split(':')]
117 testerspec
= [int(x
) for x
in options
.testers
.split(':')]
119 print "Error: Unable to parse caches or testers option"
122 if len(cachespec
) < 1:
123 print "Error: Must have at least one level of caches"
126 if len(cachespec
) != len(testerspec
) - 1:
127 print "Error: Testers must have one element more than caches"
130 if testerspec
[-1] == 0:
131 print "Error: Must have testers at the uppermost level"
136 print "Error: Cannot have a negative number of testers"
141 print "Error: Must have 1 or more caches at each level"
144 # Determine the tester multiplier for each level as the string
145 # elements are per subsystem and it fans out
149 print "Error: Must have at least one cache per level"
150 multiplier
.append(multiplier
[-1] * c
)
153 for t
, m
in zip(testerspec
, multiplier
):
156 if numtesters
> block_size
:
157 print "Error: Number of testers limited to %s because of false sharing" \
161 # Define a prototype L1 cache that we scale for all successive levels
162 proto_l1
= BaseCache(size
= '32kB', assoc
= 4,
163 hit_latency
= 1, response_latency
= 1,
164 tgts_per_mshr
= 8, is_top_level
= True)
171 cache_proto
= [proto_l1
]
173 # Now add additional cache levels (if any) by scaling L1 params, the
174 # first element is Ln, and the last element L1
175 for scale
in cachespec
[:-1]:
176 # Clone previous level and update params
177 prev
= cache_proto
[0]
179 next
.size
= prev
.size
* scale
180 next
.hit_latency
= prev
.hit_latency
* 10
181 next
.response_latency
= prev
.response_latency
* 10
182 next
.assoc
= prev
.assoc
* scale
183 next
.mshrs
= prev
.mshrs
* scale
184 next
.is_top_level
= False
185 cache_proto
.insert(0, next
)
187 # Make a prototype for the tester to be used throughout
188 proto_tester
= MemTest(max_loads
= options
.maxloads
,
189 percent_functional
= options
.functional
,
190 percent_uncacheable
= options
.uncacheable
,
191 progress_interval
= options
.progress
)
193 # Set up the system along with a simple memory and reference memory
194 system
= System(physmem
= SimpleMemory(),
195 cache_line_size
= block_size
)
197 system
.voltage_domain
= VoltageDomain(voltage
= '1V')
199 system
.clk_domain
= SrcClockDomain(clock
= options
.sys_clock
,
200 voltage_domain
= system
.voltage_domain
)
202 # For each level, track the next subsys index to use
203 next_subsys_index
= [0] * (len(cachespec
) + 1)
205 # Recursive function to create a sub-tree of the cache and tester
207 def make_cache_level(ncaches
, prototypes
, level
, next_cache
):
208 global next_subsys_index
, proto_l1
, testerspec
, proto_tester
210 index
= next_subsys_index
[level
]
211 next_subsys_index
[level
] += 1
213 # Create a subsystem to contain the crossbar and caches, and
216 setattr(system
, 'l%dsubsys%d' % (level
, index
), subsys
)
218 # The levels are indexing backwards through the list
219 ntesters
= testerspec
[len(cachespec
) - level
]
221 # Scale the progress threshold as testers higher up in the tree
222 # (smaller level) get a smaller portion of the overall bandwidth,
223 # and also make the interval of packet injection longer for the
224 # testers closer to the memory (larger level) to prevent them
225 # hogging all the bandwidth
226 limit
= (len(cachespec
) - level
+ 1) * 10000000
227 testers
= [proto_tester(interval
= 10 * (level
* level
+ 1),
228 progress_check
= limit
) \
229 for i
in xrange(ntesters
)]
231 subsys
.tester
= testers
234 # Create a crossbar and add it to the subsystem, note that
235 # we do this even with a single element on this level
236 xbar
= CoherentXBar(width
= 32)
239 xbar
.master
= next_cache
.cpu_side
241 # Create and connect the caches, both the ones fanning out
242 # to create the tree, and the ones used to connect testers
244 tree_caches
= [prototypes
[0]() for i
in xrange(ncaches
[0])]
245 tester_caches
= [proto_l1() for i
in xrange(ntesters
)]
247 subsys
.cache
= tester_caches
+ tree_caches
248 for cache
in tree_caches
:
249 cache
.mem_side
= xbar
.slave
250 make_cache_level(ncaches
[1:], prototypes
[1:], level
- 1, cache
)
251 for tester
, cache
in zip(testers
, tester_caches
):
252 tester
.port
= cache
.cpu_side
253 cache
.mem_side
= xbar
.slave
256 print "Error: No next-level cache at top level"
260 # Create a crossbar and add it to the subsystem
261 xbar
= CoherentXBar(width
= 32)
263 xbar
.master
= next_cache
.cpu_side
264 for tester
in testers
:
265 tester
.port
= xbar
.slave
268 testers
[0].port
= next_cache
.cpu_side
270 # Top level call to create the cache hierarchy, bottom up
271 make_cache_level(cachespec
, cache_proto
, len(cachespec
), None)
273 # Connect the lowest level crossbar to the memory
274 last_subsys
= getattr(system
, 'l%dsubsys0' % len(cachespec
))
275 last_subsys
.xbar
.master
= system
.physmem
.port
277 root
= Root(full_system
= False, system
= system
)
279 root
.system
.mem_mode
= 'atomic'
281 root
.system
.mem_mode
= 'timing'
283 # The system port is never used in the tester so merely connect it
285 root
.system
.system_port
= last_subsys
.xbar
.slave
287 # Instantiate configuration
290 # Simulate until program terminates
291 exit_event
= m5
.simulate(options
.maxtick
)
293 print 'Exiting @ tick', m5
.curTick(), 'because', exit_event
.getCause()