Ruby.py revision 8436
17639Sgblack@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
27639Sgblack@eecs.umich.edu# Copyright (c) 2009 Advanced Micro Devices, Inc.
37639Sgblack@eecs.umich.edu# All rights reserved.
47639Sgblack@eecs.umich.edu#
57639Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
67639Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
77639Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
87639Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
97639Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
107639Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
117639Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
127639Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
137639Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
147639Sgblack@eecs.umich.edu# this software without specific prior written permission.
157639Sgblack@eecs.umich.edu#
167639Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177639Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187639Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197639Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207639Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217639Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227639Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237639Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247639Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257639Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267639Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277639Sgblack@eecs.umich.edu#
287639Sgblack@eecs.umich.edu# Authors: Brad Beckmann
297639Sgblack@eecs.umich.edu
307639Sgblack@eecs.umich.eduimport math
317639Sgblack@eecs.umich.eduimport m5
327639Sgblack@eecs.umich.edufrom m5.objects import *
337639Sgblack@eecs.umich.edufrom m5.defines import buildEnv
347639Sgblack@eecs.umich.edu
357639Sgblack@eecs.umich.edudef define_options(parser):
367639Sgblack@eecs.umich.edu    # ruby network options
377639Sgblack@eecs.umich.edu    parser.add_option("--topology", type="string", default="Crossbar",
387639Sgblack@eecs.umich.edu                 help="check src/mem/ruby/network/topologies for complete set")
397639Sgblack@eecs.umich.edu    parser.add_option("--mesh-rows", type="int", default=1,
407639Sgblack@eecs.umich.edu                      help="the number of rows in the mesh topology")
417639Sgblack@eecs.umich.edu    parser.add_option("--garnet-network", type="string", default=None,
427639Sgblack@eecs.umich.edu                      help="'fixed'|'flexible'")
437639Sgblack@eecs.umich.edu
447639Sgblack@eecs.umich.edu    # ruby mapping options
457639Sgblack@eecs.umich.edu    parser.add_option("--numa-high-bit", type="int", default=0,
467639Sgblack@eecs.umich.edu                      help="high order address bit to use for numa mapping. " \
477639Sgblack@eecs.umich.edu                           "0 = highest bit, not specified = lowest bit")
487639Sgblack@eecs.umich.edu
497639Sgblack@eecs.umich.edu    # ruby sparse memory options
507639Sgblack@eecs.umich.edu    parser.add_option("--use-map", action="store_true", default=False)
517639Sgblack@eecs.umich.edu    parser.add_option("--map-levels", type="int", default=4)
527639Sgblack@eecs.umich.edu
537639Sgblack@eecs.umich.edu    parser.add_option("--recycle-latency", type="int", default=10,
547639Sgblack@eecs.umich.edu                      help="Recycle latency for ruby controller input buffers")
557639Sgblack@eecs.umich.edu
567639Sgblack@eecs.umich.edu    parser.add_option("--random_seed", type="int", default=1234,
577639Sgblack@eecs.umich.edu                      help="Used for seeding the random number generator")
587639Sgblack@eecs.umich.edu
597639Sgblack@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
607639Sgblack@eecs.umich.edu    exec "import %s" % protocol
617639Sgblack@eecs.umich.edu    eval("%s.define_options(parser)" % protocol)
627639Sgblack@eecs.umich.edu
637639Sgblack@eecs.umich.edudef create_system(options, system, piobus = None, dma_devices = []):
647639Sgblack@eecs.umich.edu
657639Sgblack@eecs.umich.edu    system.ruby = RubySystem(clock = options.clock)
667639Sgblack@eecs.umich.edu    ruby = system.ruby
677639Sgblack@eecs.umich.edu
687639Sgblack@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
697639Sgblack@eecs.umich.edu    exec "import %s" % protocol
707639Sgblack@eecs.umich.edu    try:
717639Sgblack@eecs.umich.edu        (cpu_sequencers, dir_cntrls, all_cntrls) = \
727639Sgblack@eecs.umich.edu             eval("%s.create_system(options, system, piobus, \
737639Sgblack@eecs.umich.edu                                    dma_devices, ruby)" \
747639Sgblack@eecs.umich.edu                  % protocol)
757639Sgblack@eecs.umich.edu    except:
767639Sgblack@eecs.umich.edu        print "Error: could not create sytem for ruby protocol %s" % protocol
777639Sgblack@eecs.umich.edu        raise
787639Sgblack@eecs.umich.edu
797639Sgblack@eecs.umich.edu    #
807639Sgblack@eecs.umich.edu    # Set the network classes based on the command line options
817639Sgblack@eecs.umich.edu    #
827639Sgblack@eecs.umich.edu    if options.garnet_network == "fixed":
837639Sgblack@eecs.umich.edu        class NetworkClass(GarnetNetwork_d): pass
847639Sgblack@eecs.umich.edu        class IntLinkClass(GarnetIntLink_d): pass
857639Sgblack@eecs.umich.edu        class ExtLinkClass(GarnetExtLink_d): pass
867639Sgblack@eecs.umich.edu        class RouterClass(GarnetRouter_d): pass
877639Sgblack@eecs.umich.edu    elif options.garnet_network == "flexible":
887639Sgblack@eecs.umich.edu        class NetworkClass(GarnetNetwork): pass
897639Sgblack@eecs.umich.edu        class IntLinkClass(GarnetIntLink): pass
907639Sgblack@eecs.umich.edu        class ExtLinkClass(GarnetExtLink): pass
917639Sgblack@eecs.umich.edu        class RouterClass(GarnetRouter): pass
927639Sgblack@eecs.umich.edu    else:
937639Sgblack@eecs.umich.edu        class NetworkClass(SimpleNetwork): pass
947639Sgblack@eecs.umich.edu        class IntLinkClass(SimpleIntLink): pass
957639Sgblack@eecs.umich.edu        class ExtLinkClass(SimpleExtLink): pass
967639Sgblack@eecs.umich.edu        class RouterClass(BasicRouter): pass
977639Sgblack@eecs.umich.edu
987639Sgblack@eecs.umich.edu    #
997639Sgblack@eecs.umich.edu    # Important: the topology must be created before the network and after the
1007639Sgblack@eecs.umich.edu    # controllers.
1017639Sgblack@eecs.umich.edu    #
1027639Sgblack@eecs.umich.edu    exec "import %s" % options.topology
1037639Sgblack@eecs.umich.edu    try:
1047639Sgblack@eecs.umich.edu        net_topology = eval("%s.makeTopology(all_cntrls, options, \
1057639Sgblack@eecs.umich.edu                                             IntLinkClass, ExtLinkClass, \
1067639Sgblack@eecs.umich.edu                                             RouterClass)" \
1077639Sgblack@eecs.umich.edu                            % options.topology)
1087639Sgblack@eecs.umich.edu    except:
1097639Sgblack@eecs.umich.edu        print "Error: could not create topology %s" % options.topology
1107639Sgblack@eecs.umich.edu        raise
1117639Sgblack@eecs.umich.edu
1127639Sgblack@eecs.umich.edu    network = NetworkClass(ruby_system = ruby, topology = net_topology)
1137639Sgblack@eecs.umich.edu
1147639Sgblack@eecs.umich.edu    #
1157639Sgblack@eecs.umich.edu    # Loop through the directory controlers.
1167639Sgblack@eecs.umich.edu    # Determine the total memory size of the ruby system and verify it is equal
1177639Sgblack@eecs.umich.edu    # to physmem.  However, if Ruby memory is using sparse memory in SE
1187639Sgblack@eecs.umich.edu    # mode, then the system should not back-up the memory state with
1197639Sgblack@eecs.umich.edu    # the Memory Vector and thus the memory size bytes should stay at 0.
1207639Sgblack@eecs.umich.edu    # Also set the numa bits to the appropriate values.
1217639Sgblack@eecs.umich.edu    #
1227639Sgblack@eecs.umich.edu    total_mem_size = MemorySize('0B')
1237639Sgblack@eecs.umich.edu
1247639Sgblack@eecs.umich.edu    dir_bits = int(math.log(options.num_dirs, 2))
1257639Sgblack@eecs.umich.edu
1267639Sgblack@eecs.umich.edu    if options.numa_high_bit:
1277639Sgblack@eecs.umich.edu        numa_bit = options.numa_high_bit
1287639Sgblack@eecs.umich.edu    else:
1297639Sgblack@eecs.umich.edu        # if not specified, use the lowest bits above the block offest
1307639Sgblack@eecs.umich.edu        if dir_bits > 0:
1317639Sgblack@eecs.umich.edu            # add 5 because bits 0-5 are the block offset
1327639Sgblack@eecs.umich.edu            numa_bit = dir_bits + 5
1337639Sgblack@eecs.umich.edu        else:
1347639Sgblack@eecs.umich.edu            numa_bit = 6
1357639Sgblack@eecs.umich.edu
1367639Sgblack@eecs.umich.edu    for dir_cntrl in dir_cntrls:
1377639Sgblack@eecs.umich.edu        total_mem_size.value += dir_cntrl.directory.size.value
1387639Sgblack@eecs.umich.edu        dir_cntrl.directory.numa_high_bit = numa_bit
1397639Sgblack@eecs.umich.edu
1407639Sgblack@eecs.umich.edu    physmem_size = long(system.physmem.range.second) - \
1417639Sgblack@eecs.umich.edu                     long(system.physmem.range.first) + 1
1427639Sgblack@eecs.umich.edu    assert(total_mem_size.value == physmem_size)
1437639Sgblack@eecs.umich.edu
1447639Sgblack@eecs.umich.edu    ruby_profiler = RubyProfiler(ruby_system = ruby,
1457639Sgblack@eecs.umich.edu                                 num_of_sequencers = len(cpu_sequencers))
1467639Sgblack@eecs.umich.edu    ruby_tracer   = RubyTracer(ruby_system = ruby)
1477639Sgblack@eecs.umich.edu
1487639Sgblack@eecs.umich.edu    ruby.network = network
1497639Sgblack@eecs.umich.edu    ruby.profiler = ruby_profiler
1507639Sgblack@eecs.umich.edu    ruby.tracer = ruby_tracer
1517639Sgblack@eecs.umich.edu    ruby.mem_size = total_mem_size
1527639Sgblack@eecs.umich.edu    ruby._cpu_ruby_ports = cpu_sequencers
1537639Sgblack@eecs.umich.edu    ruby.random_seed    = options.random_seed
1547639Sgblack@eecs.umich.edu