Ruby.py revision 8258
16892SBrad.Beckmann@amd.com# Copyright (c) 2006-2007 The Regents of The University of Michigan
26892SBrad.Beckmann@amd.com# Copyright (c) 2009 Advanced Micro Devices, Inc.
36892SBrad.Beckmann@amd.com# All rights reserved.
46892SBrad.Beckmann@amd.com#
56892SBrad.Beckmann@amd.com# Redistribution and use in source and binary forms, with or without
66892SBrad.Beckmann@amd.com# modification, are permitted provided that the following conditions are
76892SBrad.Beckmann@amd.com# met: redistributions of source code must retain the above copyright
86892SBrad.Beckmann@amd.com# notice, this list of conditions and the following disclaimer;
96892SBrad.Beckmann@amd.com# redistributions in binary form must reproduce the above copyright
106892SBrad.Beckmann@amd.com# notice, this list of conditions and the following disclaimer in the
116892SBrad.Beckmann@amd.com# documentation and/or other materials provided with the distribution;
126892SBrad.Beckmann@amd.com# neither the name of the copyright holders nor the names of its
136892SBrad.Beckmann@amd.com# contributors may be used to endorse or promote products derived from
146892SBrad.Beckmann@amd.com# this software without specific prior written permission.
156892SBrad.Beckmann@amd.com#
166892SBrad.Beckmann@amd.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176892SBrad.Beckmann@amd.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186892SBrad.Beckmann@amd.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196892SBrad.Beckmann@amd.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206892SBrad.Beckmann@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216892SBrad.Beckmann@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226892SBrad.Beckmann@amd.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236892SBrad.Beckmann@amd.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246892SBrad.Beckmann@amd.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256892SBrad.Beckmann@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266892SBrad.Beckmann@amd.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276892SBrad.Beckmann@amd.com#
286892SBrad.Beckmann@amd.com# Authors: Brad Beckmann
296892SBrad.Beckmann@amd.com
307563SBrad.Beckmann@amd.comimport math
316892SBrad.Beckmann@amd.comimport m5
326892SBrad.Beckmann@amd.comfrom m5.objects import *
336892SBrad.Beckmann@amd.comfrom m5.defines import buildEnv
346892SBrad.Beckmann@amd.com
357538SBrad.Beckmann@amd.comdef define_options(parser):
367538SBrad.Beckmann@amd.com    # ruby network options
377538SBrad.Beckmann@amd.com    parser.add_option("--topology", type="string", default="Crossbar",
387538SBrad.Beckmann@amd.com                 help="check src/mem/ruby/network/topologies for complete set")
397538SBrad.Beckmann@amd.com    parser.add_option("--mesh-rows", type="int", default=1,
407538SBrad.Beckmann@amd.com                      help="the number of rows in the mesh topology")
417661Snate@binkert.org    parser.add_option("--garnet-network", type="string", default=None,
427538SBrad.Beckmann@amd.com                      help="'fixed'|'flexible'")
437538SBrad.Beckmann@amd.com
447538SBrad.Beckmann@amd.com    # ruby mapping options
457917SBrad.Beckmann@amd.com    parser.add_option("--numa-high-bit", type="int", default=0,
467563SBrad.Beckmann@amd.com                      help="high order address bit to use for numa mapping. " \
477563SBrad.Beckmann@amd.com                           "0 = highest bit, not specified = lowest bit")
487538SBrad.Beckmann@amd.com
497538SBrad.Beckmann@amd.com    # ruby sparse memory options
507538SBrad.Beckmann@amd.com    parser.add_option("--use-map", action="store_true", default=False)
517538SBrad.Beckmann@amd.com    parser.add_option("--map-levels", type="int", default=4)
527538SBrad.Beckmann@amd.com
537566SBrad.Beckmann@amd.com    parser.add_option("--recycle-latency", type="int", default=10,
547566SBrad.Beckmann@amd.com                      help="Recycle latency for ruby controller input buffers")
557809Snilay@cs.wisc.edu
567809Snilay@cs.wisc.edu    parser.add_option("--random_seed", type="int", default=1234,
577809Snilay@cs.wisc.edu                      help="Used for seeding the random number generator")
587809Snilay@cs.wisc.edu
597538SBrad.Beckmann@amd.com    protocol = buildEnv['PROTOCOL']
607538SBrad.Beckmann@amd.com    exec "import %s" % protocol
617538SBrad.Beckmann@amd.com    eval("%s.define_options(parser)" % protocol)
627538SBrad.Beckmann@amd.com
637541SBrad.Beckmann@amd.comdef create_system(options, system, piobus = None, dma_devices = []):
646892SBrad.Beckmann@amd.com
657032SBrad.Beckmann@amd.com    protocol = buildEnv['PROTOCOL']
667032SBrad.Beckmann@amd.com    exec "import %s" % protocol
676923SBrad.Beckmann@amd.com    try:
686893SBrad.Beckmann@amd.com        (cpu_sequencers, dir_cntrls, all_cntrls) = \
697557SBrad.Beckmann@amd.com             eval("%s.create_system(options, system, piobus, dma_devices)" \
707557SBrad.Beckmann@amd.com                  % protocol)
716923SBrad.Beckmann@amd.com    except:
726923SBrad.Beckmann@amd.com        print "Error: could not create sytem for ruby protocol %s" % protocol
737557SBrad.Beckmann@amd.com        raise
748257SBrad.Beckmann@amd.com
758257SBrad.Beckmann@amd.com    #
768257SBrad.Beckmann@amd.com    # Set the network classes based on the command line options
778257SBrad.Beckmann@amd.com    #
788257SBrad.Beckmann@amd.com    if options.garnet_network == "fixed":
798257SBrad.Beckmann@amd.com        class NetworkClass(GarnetNetwork_d): pass
808257SBrad.Beckmann@amd.com        class IntLinkClass(GarnetIntLink_d): pass
818257SBrad.Beckmann@amd.com        class ExtLinkClass(GarnetExtLink_d): pass
828257SBrad.Beckmann@amd.com        class RouterClass(GarnetRouter_d): pass
838257SBrad.Beckmann@amd.com    elif options.garnet_network == "flexible":
848257SBrad.Beckmann@amd.com        class NetworkClass(GarnetNetwork): pass
858257SBrad.Beckmann@amd.com        class IntLinkClass(GarnetIntLink): pass
868257SBrad.Beckmann@amd.com        class ExtLinkClass(GarnetExtLink): pass
878257SBrad.Beckmann@amd.com        class RouterClass(GarnetRouter): pass
888257SBrad.Beckmann@amd.com    else:
898257SBrad.Beckmann@amd.com        class NetworkClass(SimpleNetwork): pass
908258SBrad.Beckmann@amd.com        class IntLinkClass(SimpleIntLink): pass
918258SBrad.Beckmann@amd.com        class ExtLinkClass(SimpleExtLink): pass
928257SBrad.Beckmann@amd.com        class RouterClass(BasicRouter): pass
938257SBrad.Beckmann@amd.com
946892SBrad.Beckmann@amd.com    #
957032SBrad.Beckmann@amd.com    # Important: the topology must be created before the network and after the
967032SBrad.Beckmann@amd.com    # controllers.
976892SBrad.Beckmann@amd.com    #
987032SBrad.Beckmann@amd.com    exec "import %s" % options.topology
997032SBrad.Beckmann@amd.com    try:
1008257SBrad.Beckmann@amd.com        net_topology = eval("%s.makeTopology(all_cntrls, options, \
1018257SBrad.Beckmann@amd.com                                             IntLinkClass, ExtLinkClass, \
1028257SBrad.Beckmann@amd.com                                             RouterClass)" \
1037557SBrad.Beckmann@amd.com                            % options.topology)
1047032SBrad.Beckmann@amd.com    except:
1057032SBrad.Beckmann@amd.com        print "Error: could not create topology %s" % options.topology
1067557SBrad.Beckmann@amd.com        raise
1078257SBrad.Beckmann@amd.com
1088257SBrad.Beckmann@amd.com    network = NetworkClass(topology = net_topology)
1096892SBrad.Beckmann@amd.com
1106903SBrad.Beckmann@amd.com    #
1117563SBrad.Beckmann@amd.com    # Loop through the directory controlers.
1127025SBrad.Beckmann@amd.com    # Determine the total memory size of the ruby system and verify it is equal
1137025SBrad.Beckmann@amd.com    # to physmem.  However, if Ruby memory is using sparse memory in SE
1147025SBrad.Beckmann@amd.com    # mode, then the system should not back-up the memory state with
1157025SBrad.Beckmann@amd.com    # the Memory Vector and thus the memory size bytes should stay at 0.
1167563SBrad.Beckmann@amd.com    # Also set the numa bits to the appropriate values.
1176903SBrad.Beckmann@amd.com    #
1186903SBrad.Beckmann@amd.com    total_mem_size = MemorySize('0B')
1197563SBrad.Beckmann@amd.com
1207563SBrad.Beckmann@amd.com    dir_bits = int(math.log(options.num_dirs, 2))
1217563SBrad.Beckmann@amd.com
1227563SBrad.Beckmann@amd.com    if options.numa_high_bit:
1237563SBrad.Beckmann@amd.com        numa_bit = options.numa_high_bit
1247563SBrad.Beckmann@amd.com    else:
1257563SBrad.Beckmann@amd.com        # if not specified, use the lowest bits above the block offest
1267663SBrad.Beckmann@amd.com        if dir_bits > 0:
1277663SBrad.Beckmann@amd.com            # add 5 because bits 0-5 are the block offset
1287663SBrad.Beckmann@amd.com            numa_bit = dir_bits + 5
1297663SBrad.Beckmann@amd.com        else:
1307663SBrad.Beckmann@amd.com            numa_bit = 6
1317563SBrad.Beckmann@amd.com
1326903SBrad.Beckmann@amd.com    for dir_cntrl in dir_cntrls:
1336903SBrad.Beckmann@amd.com        total_mem_size.value += dir_cntrl.directory.size.value
1347563SBrad.Beckmann@amd.com        dir_cntrl.directory.numa_high_bit = numa_bit
1357563SBrad.Beckmann@amd.com
1367541SBrad.Beckmann@amd.com    physmem_size = long(system.physmem.range.second) - \
1377541SBrad.Beckmann@amd.com                     long(system.physmem.range.first) + 1
1386905SBrad.Beckmann@amd.com    assert(total_mem_size.value == physmem_size)
1396892SBrad.Beckmann@amd.com
1406897SBrad.Beckmann@amd.com    ruby_profiler = RubyProfiler(num_of_sequencers = len(cpu_sequencers))
1416892SBrad.Beckmann@amd.com
1426893SBrad.Beckmann@amd.com    ruby = RubySystem(clock = options.clock,
1436892SBrad.Beckmann@amd.com                      network = network,
1446892SBrad.Beckmann@amd.com                      profiler = ruby_profiler,
1456892SBrad.Beckmann@amd.com                      tracer = RubyTracer(),
1466903SBrad.Beckmann@amd.com                      mem_size = total_mem_size)
1476892SBrad.Beckmann@amd.com
1486893SBrad.Beckmann@amd.com    ruby.cpu_ruby_ports = cpu_sequencers
1497809Snilay@cs.wisc.edu    ruby.random_seed    = options.random_seed
1506892SBrad.Beckmann@amd.com
1516892SBrad.Beckmann@amd.com    return ruby
152