Ruby.py revision 8638
15443Sgblack@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
25443Sgblack@eecs.umich.edu# Copyright (c) 2009 Advanced Micro Devices, Inc.
35443Sgblack@eecs.umich.edu# All rights reserved.
45443Sgblack@eecs.umich.edu#
55443Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
65443Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
75443Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
85443Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
95443Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
105443Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
115443Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
125443Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
135443Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
145443Sgblack@eecs.umich.edu# this software without specific prior written permission.
155443Sgblack@eecs.umich.edu#
165443Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175443Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185443Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195443Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205443Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215443Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225443Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235443Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245443Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255443Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265443Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275443Sgblack@eecs.umich.edu#
285443Sgblack@eecs.umich.edu# Authors: Brad Beckmann
295443Sgblack@eecs.umich.edu
305443Sgblack@eecs.umich.eduimport math
315443Sgblack@eecs.umich.eduimport m5
325443Sgblack@eecs.umich.edufrom m5.objects import *
335443Sgblack@eecs.umich.edufrom m5.defines import buildEnv
345443Sgblack@eecs.umich.edu
355443Sgblack@eecs.umich.edudef define_options(parser):
365443Sgblack@eecs.umich.edu    # ruby network options
375443Sgblack@eecs.umich.edu    parser.add_option("--topology", type="string", default="Crossbar",
385635Sgblack@eecs.umich.edu                 help="check src/mem/ruby/network/topologies for complete set")
395635Sgblack@eecs.umich.edu    parser.add_option("--mesh-rows", type="int", default=1,
405635Sgblack@eecs.umich.edu                      help="the number of rows in the mesh topology")
415443Sgblack@eecs.umich.edu    parser.add_option("--garnet-network", type="string", default=None,
425635Sgblack@eecs.umich.edu                      help="'fixed'|'flexible'")
435635Sgblack@eecs.umich.edu    parser.add_option("--network-fault-model", action="store_true", default=False,
445635Sgblack@eecs.umich.edu                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
455635Sgblack@eecs.umich.edu
465635Sgblack@eecs.umich.edu    # ruby mapping options
475635Sgblack@eecs.umich.edu    parser.add_option("--numa-high-bit", type="int", default=0,
485635Sgblack@eecs.umich.edu                      help="high order address bit to use for numa mapping. " \
495635Sgblack@eecs.umich.edu                           "0 = highest bit, not specified = lowest bit")
505642Sgblack@eecs.umich.edu
515642Sgblack@eecs.umich.edu    # ruby sparse memory options
525642Sgblack@eecs.umich.edu    parser.add_option("--use-map", action="store_true", default=False)
535443Sgblack@eecs.umich.edu    parser.add_option("--map-levels", type="int", default=4)
545443Sgblack@eecs.umich.edu
555443Sgblack@eecs.umich.edu    parser.add_option("--recycle-latency", type="int", default=10,
565443Sgblack@eecs.umich.edu                      help="Recycle latency for ruby controller input buffers")
575443Sgblack@eecs.umich.edu
585443Sgblack@eecs.umich.edu    parser.add_option("--random_seed", type="int", default=1234,
595443Sgblack@eecs.umich.edu                      help="Used for seeding the random number generator")
605443Sgblack@eecs.umich.edu
615443Sgblack@eecs.umich.edu    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
625443Sgblack@eecs.umich.edu
635443Sgblack@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
645443Sgblack@eecs.umich.edu    exec "import %s" % protocol
655443Sgblack@eecs.umich.edu    eval("%s.define_options(parser)" % protocol)
665443Sgblack@eecs.umich.edu
675443Sgblack@eecs.umich.edudef create_system(options, system, piobus = None, dma_devices = []):
685443Sgblack@eecs.umich.edu
695443Sgblack@eecs.umich.edu    system.ruby = RubySystem(clock = options.clock,
705443Sgblack@eecs.umich.edu                             stats_filename = options.ruby_stats)
715443Sgblack@eecs.umich.edu    ruby = system.ruby
725443Sgblack@eecs.umich.edu
735443Sgblack@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
745443Sgblack@eecs.umich.edu    exec "import %s" % protocol
755443Sgblack@eecs.umich.edu    try:
765635Sgblack@eecs.umich.edu        (cpu_sequencers, dir_cntrls, all_cntrls) = \
775635Sgblack@eecs.umich.edu             eval("%s.create_system(options, system, piobus, \
785635Sgblack@eecs.umich.edu                                    dma_devices, ruby)" \
795443Sgblack@eecs.umich.edu                  % protocol)
805443Sgblack@eecs.umich.edu    except:
815443Sgblack@eecs.umich.edu        print "Error: could not create sytem for ruby protocol %s" % protocol
825443Sgblack@eecs.umich.edu        raise
835443Sgblack@eecs.umich.edu
845443Sgblack@eecs.umich.edu    #
855443Sgblack@eecs.umich.edu    # Set the network classes based on the command line options
865635Sgblack@eecs.umich.edu    #
875635Sgblack@eecs.umich.edu    if options.garnet_network == "fixed":
885635Sgblack@eecs.umich.edu        class NetworkClass(GarnetNetwork_d): pass
895443Sgblack@eecs.umich.edu        class IntLinkClass(GarnetIntLink_d): pass
905443Sgblack@eecs.umich.edu        class ExtLinkClass(GarnetExtLink_d): pass
915642Sgblack@eecs.umich.edu        class RouterClass(GarnetRouter_d): pass
925642Sgblack@eecs.umich.edu    elif options.garnet_network == "flexible":
936067Sgblack@eecs.umich.edu        class NetworkClass(GarnetNetwork): pass
945642Sgblack@eecs.umich.edu        class IntLinkClass(GarnetIntLink): pass
955642Sgblack@eecs.umich.edu        class ExtLinkClass(GarnetExtLink): pass
965443Sgblack@eecs.umich.edu        class RouterClass(GarnetRouter): pass
975443Sgblack@eecs.umich.edu    else:
985443Sgblack@eecs.umich.edu        class NetworkClass(SimpleNetwork): pass
995443Sgblack@eecs.umich.edu        class IntLinkClass(SimpleIntLink): pass
1005443Sgblack@eecs.umich.edu        class ExtLinkClass(SimpleExtLink): pass
1015443Sgblack@eecs.umich.edu        class RouterClass(BasicRouter): pass
1025443Sgblack@eecs.umich.edu
1035443Sgblack@eecs.umich.edu    #
1045443Sgblack@eecs.umich.edu    # Important: the topology must be created before the network and after the
1055443Sgblack@eecs.umich.edu    # controllers.
1065443Sgblack@eecs.umich.edu    #
1076067Sgblack@eecs.umich.edu    exec "import %s" % options.topology
1085443Sgblack@eecs.umich.edu    try:
1095443Sgblack@eecs.umich.edu        net_topology = eval("%s.makeTopology(all_cntrls, options, \
1105443Sgblack@eecs.umich.edu                                             IntLinkClass, ExtLinkClass, \
1116067Sgblack@eecs.umich.edu                                             RouterClass)" \
1126067Sgblack@eecs.umich.edu                            % options.topology)
1136067Sgblack@eecs.umich.edu    except:
1146067Sgblack@eecs.umich.edu        print "Error: could not create topology %s" % options.topology
1156067Sgblack@eecs.umich.edu        raise
1166067Sgblack@eecs.umich.edu
1176067Sgblack@eecs.umich.edu    if options.network_fault_model:
1186067Sgblack@eecs.umich.edu        assert(options.garnet_network == "fixed")
1196067Sgblack@eecs.umich.edu        fault_model = FaultModel()
1206067Sgblack@eecs.umich.edu        network = NetworkClass(ruby_system = ruby, topology = net_topology,\
1216067Sgblack@eecs.umich.edu                               enable_fault_model=True, fault_model = fault_model)
1226067Sgblack@eecs.umich.edu    else:
1236067Sgblack@eecs.umich.edu        network = NetworkClass(ruby_system = ruby, topology = net_topology)
1246067Sgblack@eecs.umich.edu
1255443Sgblack@eecs.umich.edu    #
1265443Sgblack@eecs.umich.edu    # Loop through the directory controlers.
1275443Sgblack@eecs.umich.edu    # Determine the total memory size of the ruby system and verify it is equal
1285443Sgblack@eecs.umich.edu    # to physmem.  However, if Ruby memory is using sparse memory in SE
1295443Sgblack@eecs.umich.edu    # mode, then the system should not back-up the memory state with
1305443Sgblack@eecs.umich.edu    # the Memory Vector and thus the memory size bytes should stay at 0.
1315443Sgblack@eecs.umich.edu    # Also set the numa bits to the appropriate values.
1325443Sgblack@eecs.umich.edu    #
1335443Sgblack@eecs.umich.edu    total_mem_size = MemorySize('0B')
1345443Sgblack@eecs.umich.edu
1355443Sgblack@eecs.umich.edu    dir_bits = int(math.log(options.num_dirs, 2))
1365443Sgblack@eecs.umich.edu
1375443Sgblack@eecs.umich.edu    if options.numa_high_bit:
1385443Sgblack@eecs.umich.edu        numa_bit = options.numa_high_bit
1395443Sgblack@eecs.umich.edu    else:
1405443Sgblack@eecs.umich.edu        # if not specified, use the lowest bits above the block offest
1415443Sgblack@eecs.umich.edu        if dir_bits > 0:
1425443Sgblack@eecs.umich.edu            # add 5 because bits 0-5 are the block offset
1436067Sgblack@eecs.umich.edu            numa_bit = dir_bits + 5
1445443Sgblack@eecs.umich.edu        else:
1455443Sgblack@eecs.umich.edu            numa_bit = 6
1465443Sgblack@eecs.umich.edu
1475443Sgblack@eecs.umich.edu    for dir_cntrl in dir_cntrls:
1485443Sgblack@eecs.umich.edu        total_mem_size.value += dir_cntrl.directory.size.value
1495443Sgblack@eecs.umich.edu        dir_cntrl.directory.numa_high_bit = numa_bit
1505443Sgblack@eecs.umich.edu
1515443Sgblack@eecs.umich.edu    physmem_size = long(system.physmem.range.second) - \
1525443Sgblack@eecs.umich.edu                     long(system.physmem.range.first) + 1
1535443Sgblack@eecs.umich.edu    assert(total_mem_size.value == physmem_size)
1545443Sgblack@eecs.umich.edu
1555443Sgblack@eecs.umich.edu    ruby_profiler = RubyProfiler(ruby_system = ruby,
1565443Sgblack@eecs.umich.edu                                 num_of_sequencers = len(cpu_sequencers))
1575443Sgblack@eecs.umich.edu    ruby_tracer   = RubyTracer(ruby_system = ruby)
1585443Sgblack@eecs.umich.edu
1595443Sgblack@eecs.umich.edu    ruby.network = network
1605443Sgblack@eecs.umich.edu    ruby.profiler = ruby_profiler
1615443Sgblack@eecs.umich.edu    ruby.tracer = ruby_tracer
1625443Sgblack@eecs.umich.edu    ruby.mem_size = total_mem_size
1635443Sgblack@eecs.umich.edu    ruby._cpu_ruby_ports = cpu_sequencers
1646067Sgblack@eecs.umich.edu    ruby.random_seed    = options.random_seed
1655443Sgblack@eecs.umich.edu