memcheck.py revision 11451
1955SN/A# Copyright (c) 2015 ARM Limited
2955SN/A# All rights reserved.
37816Ssteve.reinhardt@amd.com#
45871Snate@binkert.org# The license below extends only to copyright in the software and shall
51762SN/A# not be construed as granting a license to any other intellectual
6955SN/A# property including but not limited to intellectual property relating
7955SN/A# to a hardware implementation of the functionality of the software
8955SN/A# licensed hereunder.  You may use the software subject to the license
9955SN/A# terms below provided that you ensure that this notice is replicated
10955SN/A# unmodified and in its entirety in all distributions of the software,
11955SN/A# modified or unmodified, in source code or in binary form.
12955SN/A#
13955SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
14955SN/A# All rights reserved.
15955SN/A#
16955SN/A# Redistribution and use in source and binary forms, with or without
17955SN/A# modification, are permitted provided that the following conditions are
18955SN/A# met: redistributions of source code must retain the above copyright
19955SN/A# notice, this list of conditions and the following disclaimer;
20955SN/A# redistributions in binary form must reproduce the above copyright
21955SN/A# notice, this list of conditions and the following disclaimer in the
22955SN/A# documentation and/or other materials provided with the distribution;
23955SN/A# neither the name of the copyright holders nor the names of its
24955SN/A# contributors may be used to endorse or promote products derived from
25955SN/A# this software without specific prior written permission.
26955SN/A#
27955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
302665Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
312665Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
325863Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
388878Ssteve.reinhardt@amd.com#
392632Sstever@eecs.umich.edu# Authors: Ron Dreslinski
408878Ssteve.reinhardt@amd.com#          Andreas Hansson
412632Sstever@eecs.umich.edu
42955SN/Aimport optparse
438878Ssteve.reinhardt@amd.comimport sys
442632Sstever@eecs.umich.edu
452761Sstever@eecs.umich.eduimport m5
462632Sstever@eecs.umich.edufrom m5.objects import *
472632Sstever@eecs.umich.edu
482632Sstever@eecs.umich.eduparser = optparse.OptionParser()
492761Sstever@eecs.umich.edu
502761Sstever@eecs.umich.eduparser.add_option("-a", "--atomic", action="store_true",
512761Sstever@eecs.umich.edu                  help="Use atomic (non-timing) mode")
528878Ssteve.reinhardt@amd.comparser.add_option("-b", "--blocking", action="store_true",
538878Ssteve.reinhardt@amd.com                  help="Use blocking caches")
542761Sstever@eecs.umich.eduparser.add_option("-m", "--maxtick", type="int", default=m5.MaxTick,
552761Sstever@eecs.umich.edu                  metavar="T",
562761Sstever@eecs.umich.edu                  help="Stop after T ticks")
572761Sstever@eecs.umich.eduparser.add_option("-p", "--prefetchers", action="store_true",
582761Sstever@eecs.umich.edu                  help="Use prefetchers")
598878Ssteve.reinhardt@amd.comparser.add_option("-s", "--stridepref", action="store_true",
608878Ssteve.reinhardt@amd.com                  help="Use strided prefetchers")
612632Sstever@eecs.umich.edu
622632Sstever@eecs.umich.edu# This example script has a lot in common with the memtest.py in that
638878Ssteve.reinhardt@amd.com# it is designed to stress tests the memory system. However, this
648878Ssteve.reinhardt@amd.com# script uses oblivious traffic generators to create the stimuli, and
652632Sstever@eecs.umich.edu# couples them with memcheckers to verify that the data read matches
66955SN/A# the allowed outcomes. Just like memtest.py, the traffic generators
67955SN/A# and checkers are placed in a tree topology. At the bottom of the
68955SN/A# tree is a shared memory, and then at each level a number of
695863Snate@binkert.org# generators and checkers are attached, along with a number of caches
705863Snate@binkert.org# that them selves fan out to subtrees of generators and caches. Thus,
715863Snate@binkert.org# it is possible to create a system with arbitrarily deep cache
725863Snate@binkert.org# hierarchies, sharing or no sharing of caches, and generators not
735863Snate@binkert.org# only at the L1s, but also at the L2s, L3s etc.
745863Snate@binkert.org#
755863Snate@binkert.org# The tree specification consists of two colon-separated lists of one
765863Snate@binkert.org# or more integers, one for the caches, and one for the
775863Snate@binkert.org# testers/generators. The first integer is the number of
785863Snate@binkert.org# caches/testers closest to main memory. Each cache then fans out to a
795863Snate@binkert.org# subtree. The last integer in the list is the number of
808878Ssteve.reinhardt@amd.com# caches/testers associated with the uppermost level of memory. The
815863Snate@binkert.org# other integers (if any) specify the number of caches/testers
825863Snate@binkert.org# connected at each level of the crossbar hierarchy. The tester string
835863Snate@binkert.org# should have one element more than the cache string as there should
845863Snate@binkert.org# always be testers attached to the uppermost caches.
855863Snate@binkert.org#
865863Snate@binkert.org# Since this script tests actual sharing, there is also a possibility
875863Snate@binkert.org# to stress prefetching and the interaction between prefetchers and
885863Snate@binkert.org# caches. The traffic generators switch between random address streams
895863Snate@binkert.org# and linear address streams to ensure that the prefetchers will
905863Snate@binkert.org# trigger. By default prefetchers are off.
915863Snate@binkert.org
925863Snate@binkert.orgparser.add_option("-c", "--caches", type="string", default="3:2",
935863Snate@binkert.org                  help="Colon-separated cache hierarchy specification, "
945863Snate@binkert.org                  "see script comments for details "
955863Snate@binkert.org                  "[default: %default]")
968878Ssteve.reinhardt@amd.comparser.add_option("-t", "--testers", type="string", default="1:0:2",
975863Snate@binkert.org                  help="Colon-separated tester hierarchy specification, "
985863Snate@binkert.org                  "see script comments for details "
995863Snate@binkert.org                  "[default: %default]")
1006654Snate@binkert.orgparser.add_option("--sys-clock", action="store", type="string",
101955SN/A                  default='1GHz',
1025396Ssaidi@eecs.umich.edu                  help = """Top-level clock for blocks running at system
1035863Snate@binkert.org                  speed""")
1045863Snate@binkert.org
1054202Sbinkertn@umich.edu(options, args) = parser.parse_args()
1065863Snate@binkert.org
1075863Snate@binkert.orgif args:
1085863Snate@binkert.org     print "Error: script doesn't take any positional arguments"
1095863Snate@binkert.org     sys.exit(1)
110955SN/A
1116654Snate@binkert.org# Start by parsing the command line options and do some basic sanity
1125273Sstever@gmail.com# checking
1135871Snate@binkert.orgtry:
1145273Sstever@gmail.com     cachespec = [int(x) for x in options.caches.split(':')]
1156655Snate@binkert.org     testerspec = [int(x) for x in options.testers.split(':')]
1168878Ssteve.reinhardt@amd.comexcept:
1176655Snate@binkert.org     print "Error: Unable to parse caches or testers option"
1186655Snate@binkert.org     sys.exit(1)
1199219Spower.jg@gmail.com
1206655Snate@binkert.orgif len(cachespec) < 1:
1215871Snate@binkert.org     print "Error: Must have at least one level of caches"
1226654Snate@binkert.org     sys.exit(1)
1238947Sandreas.hansson@arm.com
1245396Ssaidi@eecs.umich.eduif len(cachespec) != len(testerspec) - 1:
1258120Sgblack@eecs.umich.edu     print "Error: Testers must have one element more than caches"
1268120Sgblack@eecs.umich.edu     sys.exit(1)
1278120Sgblack@eecs.umich.edu
1288120Sgblack@eecs.umich.eduif testerspec[-1] == 0:
1298120Sgblack@eecs.umich.edu     print "Error: Must have testers at the uppermost level"
1308120Sgblack@eecs.umich.edu     sys.exit(1)
1318120Sgblack@eecs.umich.edu
1328120Sgblack@eecs.umich.edufor t in testerspec:
1338879Ssteve.reinhardt@amd.com     if t < 0:
1348879Ssteve.reinhardt@amd.com          print "Error: Cannot have a negative number of testers"
1358879Ssteve.reinhardt@amd.com          sys.exit(1)
1368879Ssteve.reinhardt@amd.com
1378879Ssteve.reinhardt@amd.comfor c in cachespec:
1388879Ssteve.reinhardt@amd.com     if c < 1:
1398879Ssteve.reinhardt@amd.com          print "Error: Must have 1 or more caches at each level"
1408879Ssteve.reinhardt@amd.com          sys.exit(1)
1418879Ssteve.reinhardt@amd.com
1428879Ssteve.reinhardt@amd.com# Determine the tester multiplier for each level as the string
1438879Ssteve.reinhardt@amd.com# elements are per subsystem and it fans out
1448879Ssteve.reinhardt@amd.commultiplier = [1]
1458879Ssteve.reinhardt@amd.comfor c in cachespec:
1468120Sgblack@eecs.umich.edu     if c < 1:
1478120Sgblack@eecs.umich.edu          print "Error: Must have at least one cache per level"
1488120Sgblack@eecs.umich.edu     multiplier.append(multiplier[-1] * c)
1498120Sgblack@eecs.umich.edu
1508120Sgblack@eecs.umich.edunumtesters = 0
1518120Sgblack@eecs.umich.edufor t, m in zip(testerspec, multiplier):
1528120Sgblack@eecs.umich.edu     numtesters += t * m
1538120Sgblack@eecs.umich.edu
1548120Sgblack@eecs.umich.edu# Define a prototype L1 cache that we scale for all successive levels
1558120Sgblack@eecs.umich.eduproto_l1 = Cache(size = '32kB', assoc = 4,
1568120Sgblack@eecs.umich.edu                 hit_latency = 1, response_latency = 1,
1578120Sgblack@eecs.umich.edu                 tgts_per_mshr = 8)
1588120Sgblack@eecs.umich.edu
1598120Sgblack@eecs.umich.eduif options.blocking:
1608879Ssteve.reinhardt@amd.com     proto_l1.mshrs = 1
1618879Ssteve.reinhardt@amd.comelse:
1628879Ssteve.reinhardt@amd.com     proto_l1.mshrs = 4
1638879Ssteve.reinhardt@amd.com
1648879Ssteve.reinhardt@amd.comif options.prefetchers:
1658879Ssteve.reinhardt@amd.com     proto_l1.prefetcher = TaggedPrefetcher()
1668879Ssteve.reinhardt@amd.comelif options.stridepref:
1678879Ssteve.reinhardt@amd.com     proto_l1.prefetcher = StridePrefetcher()
1689227Sandreas.hansson@arm.com
1699227Sandreas.hansson@arm.comcache_proto = [proto_l1]
1708879Ssteve.reinhardt@amd.com
1718879Ssteve.reinhardt@amd.com# Now add additional cache levels (if any) by scaling L1 params, the
1728879Ssteve.reinhardt@amd.com# first element is Ln, and the last element L1
1738879Ssteve.reinhardt@amd.comfor scale in cachespec[:-1]:
1748120Sgblack@eecs.umich.edu     # Clone previous level and update params
1758947Sandreas.hansson@arm.com     prev = cache_proto[0]
1767816Ssteve.reinhardt@amd.com     next = prev()
1775871Snate@binkert.org     next.size = prev.size * scale
1785871Snate@binkert.org     next.hit_latency = prev.hit_latency * 10
1796121Snate@binkert.org     next.response_latency = prev.response_latency * 10
1805871Snate@binkert.org     next.assoc = prev.assoc * scale
1815871Snate@binkert.org     next.mshrs = prev.mshrs * scale
1829119Sandreas.hansson@arm.com     cache_proto.insert(0, next)
1839396Sandreas.hansson@arm.com
1849396Sandreas.hansson@arm.com# Create a config to be used by all the traffic generators
185955SN/Acfg_file_name = "configs/example/memcheck.cfg"
1869416SAndreas.Sandberg@ARM.comcfg_file = open(cfg_file_name, 'w')
1879416SAndreas.Sandberg@ARM.com
1889416SAndreas.Sandberg@ARM.com# Three states, with random, linear and idle behaviours. The random
1899416SAndreas.Sandberg@ARM.com# and linear states access memory in the range [0 : 16 Mbyte] with 8
1909416SAndreas.Sandberg@ARM.com# byte accesses.
1919416SAndreas.Sandberg@ARM.comcfg_file.write("STATE 0 10000000 RANDOM 65 0 16777216 8 50000 150000 0\n")
1929416SAndreas.Sandberg@ARM.comcfg_file.write("STATE 1 10000000 LINEAR 65 0 16777216 8 50000 150000 0\n")
1935871Snate@binkert.orgcfg_file.write("STATE 2 10000000 IDLE\n")
1945871Snate@binkert.orgcfg_file.write("INIT 0\n")
1959416SAndreas.Sandberg@ARM.comcfg_file.write("TRANSITION 0 1 0.5\n")
1969416SAndreas.Sandberg@ARM.comcfg_file.write("TRANSITION 0 2 0.5\n")
1975871Snate@binkert.orgcfg_file.write("TRANSITION 1 0 0.5\n")
198955SN/Acfg_file.write("TRANSITION 1 2 0.5\n")
1996121Snate@binkert.orgcfg_file.write("TRANSITION 2 0 0.5\n")
2008881Smarc.orr@gmail.comcfg_file.write("TRANSITION 2 1 0.5\n")
2016121Snate@binkert.orgcfg_file.close()
2026121Snate@binkert.org
2031533SN/A# Make a prototype for the tester to be used throughout
2049239Sandreas.hansson@arm.comproto_tester = TrafficGen(config_file = cfg_file_name)
2059239Sandreas.hansson@arm.com
2069239Sandreas.hansson@arm.com# Set up the system along with a DRAM controller
2079239Sandreas.hansson@arm.comsystem = System(physmem = DDR3_1600_x64())
2089239Sandreas.hansson@arm.com
2099239Sandreas.hansson@arm.comsystem.voltage_domain = VoltageDomain(voltage = '1V')
2109239Sandreas.hansson@arm.com
2119239Sandreas.hansson@arm.comsystem.clk_domain = SrcClockDomain(clock =  options.sys_clock,
2129239Sandreas.hansson@arm.com                        voltage_domain = system.voltage_domain)
2139239Sandreas.hansson@arm.com
2149239Sandreas.hansson@arm.comsystem.memchecker = MemChecker()
2159239Sandreas.hansson@arm.com
2166655Snate@binkert.org# For each level, track the next subsys index to use
2176655Snate@binkert.orgnext_subsys_index = [0] * (len(cachespec) + 1)
2186655Snate@binkert.org
2196655Snate@binkert.org# Recursive function to create a sub-tree of the cache and tester
2205871Snate@binkert.org# hierarchy
2215871Snate@binkert.orgdef make_cache_level(ncaches, prototypes, level, next_cache):
2225863Snate@binkert.org     global next_subsys_index, proto_l1, testerspec, proto_tester
2235871Snate@binkert.org
2248878Ssteve.reinhardt@amd.com     index = next_subsys_index[level]
2255871Snate@binkert.org     next_subsys_index[level] += 1
2265871Snate@binkert.org
2275871Snate@binkert.org     # Create a subsystem to contain the crossbar and caches, and
2285863Snate@binkert.org     # any testers
2296121Snate@binkert.org     subsys = SubSystem()
2305863Snate@binkert.org     setattr(system, 'l%dsubsys%d' % (level, index), subsys)
2315871Snate@binkert.org
2328336Ssteve.reinhardt@amd.com     # The levels are indexing backwards through the list
2338336Ssteve.reinhardt@amd.com     ntesters = testerspec[len(cachespec) - level]
2348336Ssteve.reinhardt@amd.com
2358336Ssteve.reinhardt@amd.com     testers = [proto_tester() for i in xrange(ntesters)]
2364678Snate@binkert.org     checkers = [MemCheckerMonitor(memchecker = system.memchecker) \
2378336Ssteve.reinhardt@amd.com                      for i in xrange(ntesters)]
2388336Ssteve.reinhardt@amd.com     if ntesters:
2398336Ssteve.reinhardt@amd.com          subsys.tester = testers
2404678Snate@binkert.org          subsys.checkers = checkers
2414678Snate@binkert.org
2424678Snate@binkert.org     if level != 0:
2434678Snate@binkert.org          # Create a crossbar and add it to the subsystem, note that
2447827Snate@binkert.org          # we do this even with a single element on this level
2457827Snate@binkert.org          xbar = L2XBar(width = 32)
2468336Ssteve.reinhardt@amd.com          subsys.xbar = xbar
2474678Snate@binkert.org          if next_cache:
2488336Ssteve.reinhardt@amd.com               xbar.master = next_cache.cpu_side
2498336Ssteve.reinhardt@amd.com
2508336Ssteve.reinhardt@amd.com          # Create and connect the caches, both the ones fanning out
2518336Ssteve.reinhardt@amd.com          # to create the tree, and the ones used to connect testers
2528336Ssteve.reinhardt@amd.com          # on this level
2538336Ssteve.reinhardt@amd.com          tree_caches = [prototypes[0]() for i in xrange(ncaches[0])]
2545871Snate@binkert.org          tester_caches = [proto_l1() for i in xrange(ntesters)]
2555871Snate@binkert.org
2568336Ssteve.reinhardt@amd.com          subsys.cache = tester_caches + tree_caches
2578336Ssteve.reinhardt@amd.com          for cache in tree_caches:
2588336Ssteve.reinhardt@amd.com               cache.mem_side = xbar.slave
2598336Ssteve.reinhardt@amd.com               make_cache_level(ncaches[1:], prototypes[1:], level - 1, cache)
2608336Ssteve.reinhardt@amd.com          for tester, checker, cache in zip(testers, checkers, tester_caches):
2615871Snate@binkert.org               tester.port = checker.slave
2628336Ssteve.reinhardt@amd.com               checker.master = cache.cpu_side
2638336Ssteve.reinhardt@amd.com               cache.mem_side = xbar.slave
2648336Ssteve.reinhardt@amd.com     else:
2658336Ssteve.reinhardt@amd.com          if not next_cache:
2668336Ssteve.reinhardt@amd.com               print "Error: No next-level cache at top level"
2674678Snate@binkert.org               sys.exit(1)
2685871Snate@binkert.org
2694678Snate@binkert.org          if ntesters > 1:
2708336Ssteve.reinhardt@amd.com               # Create a crossbar and add it to the subsystem
2718336Ssteve.reinhardt@amd.com               xbar = L2XBar(width = 32)
2728336Ssteve.reinhardt@amd.com               subsys.xbar = xbar
2738336Ssteve.reinhardt@amd.com               xbar.master = next_cache.cpu_side
2748336Ssteve.reinhardt@amd.com               for tester, checker in zip(testers, checkers):
2758336Ssteve.reinhardt@amd.com                    tester.port = checker.slave
2768336Ssteve.reinhardt@amd.com                    checker.master = xbar.slave
2778336Ssteve.reinhardt@amd.com          else:
2788336Ssteve.reinhardt@amd.com               # Single tester
2798336Ssteve.reinhardt@amd.com               testers[0].port = checkers[0].slave
2808336Ssteve.reinhardt@amd.com               checkers[0].master = next_cache.cpu_side
2818336Ssteve.reinhardt@amd.com
2828336Ssteve.reinhardt@amd.com# Top level call to create the cache hierarchy, bottom up
2838336Ssteve.reinhardt@amd.commake_cache_level(cachespec, cache_proto, len(cachespec), None)
2848336Ssteve.reinhardt@amd.com
2858336Ssteve.reinhardt@amd.com# Connect the lowest level crossbar to the memory
2868336Ssteve.reinhardt@amd.comlast_subsys = getattr(system, 'l%dsubsys0' % len(cachespec))
2875871Snate@binkert.orglast_subsys.xbar.master = system.physmem.port
2886121Snate@binkert.orglast_subsys.xbar.point_of_coherency = True
289955SN/A
290955SN/Aroot = Root(full_system = False, system = system)
2912632Sstever@eecs.umich.eduif options.atomic:
2922632Sstever@eecs.umich.edu    root.system.mem_mode = 'atomic'
293955SN/Aelse:
294955SN/A    root.system.mem_mode = 'timing'
295955SN/A
296955SN/A# The system port is never used in the tester so merely connect it
2978878Ssteve.reinhardt@amd.com# to avoid problems
298955SN/Aroot.system.system_port = last_subsys.xbar.slave
2992632Sstever@eecs.umich.edu
3002632Sstever@eecs.umich.edu# Instantiate configuration
3012632Sstever@eecs.umich.edum5.instantiate()
3022632Sstever@eecs.umich.edu
3032632Sstever@eecs.umich.edu# Simulate until program terminates
3042632Sstever@eecs.umich.eduexit_event = m5.simulate(options.maxtick)
3052632Sstever@eecs.umich.edu
3068268Ssteve.reinhardt@amd.comprint 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
3078268Ssteve.reinhardt@amd.com