Ruby.py revision 7566
1955SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
2955SN/A# Copyright (c) 2009 Advanced Micro Devices, Inc.
31762SN/A# All rights reserved.
4955SN/A#
5955SN/A# Redistribution and use in source and binary forms, with or without
6955SN/A# modification, are permitted provided that the following conditions are
7955SN/A# met: redistributions of source code must retain the above copyright
8955SN/A# notice, this list of conditions and the following disclaimer;
9955SN/A# redistributions in binary form must reproduce the above copyright
10955SN/A# notice, this list of conditions and the following disclaimer in the
11955SN/A# documentation and/or other materials provided with the distribution;
12955SN/A# neither the name of the copyright holders nor the names of its
13955SN/A# contributors may be used to endorse or promote products derived from
14955SN/A# this software without specific prior written permission.
15955SN/A#
16955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A#
282665Ssaidi@eecs.umich.edu# Authors: Brad Beckmann
294762Snate@binkert.org
30955SN/Aimport math
315522Snate@binkert.orgimport m5
324762Snate@binkert.orgfrom m5.objects import *
335522Snate@binkert.orgfrom m5.defines import buildEnv
34955SN/A
355522Snate@binkert.orgdef define_options(parser):
36955SN/A    # ruby network options
375522Snate@binkert.org    parser.add_option("--topology", type="string", default="Crossbar",
384202Sbinkertn@umich.edu                 help="check src/mem/ruby/network/topologies for complete set")
395342Sstever@gmail.com    parser.add_option("--mesh-rows", type="int", default=1,
40955SN/A                      help="the number of rows in the mesh topology")
414381Sbinkertn@umich.edu    parser.add_option("--garnet-network", type="string", default=none,
424381Sbinkertn@umich.edu                      help="'fixed'|'flexible'")
43955SN/A
44955SN/A    # ruby mapping options
45955SN/A    parser.add_option("--numa-high-bit", type="int", default=none,
464202Sbinkertn@umich.edu                      help="high order address bit to use for numa mapping. " \
47955SN/A                           "0 = highest bit, not specified = lowest bit")
484382Sbinkertn@umich.edu
494382Sbinkertn@umich.edu    # ruby sparse memory options
504382Sbinkertn@umich.edu    parser.add_option("--use-map", action="store_true", default=False)
515517Snate@binkert.org    parser.add_option("--map-levels", type="int", default=4)
525517Snate@binkert.org
534762Snate@binkert.org    # ruby debug cmd line options
544762Snate@binkert.org    parser.add_option("--ruby-debug", action="store_true", default=False)
554762Snate@binkert.org    parser.add_option("--ruby-debug-cycle", type="int", default=1)
564762Snate@binkert.org
574762Snate@binkert.org    parser.add_option("--recycle-latency", type="int", default=10,
584762Snate@binkert.org                      help="Recycle latency for ruby controller input buffers")
594762Snate@binkert.org
604762Snate@binkert.org    protocol = buildEnv['PROTOCOL']
614762Snate@binkert.org    exec "import %s" % protocol
624762Snate@binkert.org    eval("%s.define_options(parser)" % protocol)
635522Snate@binkert.org
644762Snate@binkert.orgdef create_system(options, system, piobus = None, dma_devices = []):
654762Snate@binkert.org
664762Snate@binkert.org    protocol = buildEnv['PROTOCOL']
674762Snate@binkert.org    exec "import %s" % protocol
684762Snate@binkert.org    try:
695522Snate@binkert.org        (cpu_sequencers, dir_cntrls, all_cntrls) = \
705522Snate@binkert.org             eval("%s.create_system(options, system, piobus, dma_devices)" \
715522Snate@binkert.org                  % protocol)
725522Snate@binkert.org    except:
734762Snate@binkert.org        print "Error: could not create sytem for ruby protocol %s" % protocol
744762Snate@binkert.org        raise
754762Snate@binkert.org
764762Snate@binkert.org    #
774762Snate@binkert.org    # Important: the topology must be created before the network and after the
785522Snate@binkert.org    # controllers.
794762Snate@binkert.org    #
804762Snate@binkert.org    exec "import %s" % options.topology
815522Snate@binkert.org    try:
825522Snate@binkert.org        net_topology = eval("%s.makeTopology(all_cntrls, options)" \
834762Snate@binkert.org                            % options.topology)
844762Snate@binkert.org    except:
854762Snate@binkert.org        print "Error: could not create topology %s" % options.topology
864762Snate@binkert.org        raise
874762Snate@binkert.org
884762Snate@binkert.org    if options.garnet_network == "fixed":
895522Snate@binkert.org        network = GarnetNetwork_d(topology = net_topology)
905522Snate@binkert.org    elif options.garnet_network == "flexible":
915522Snate@binkert.org        network = GarnetNetwork(topology = net_topology)
924762Snate@binkert.org    else:
934382Sbinkertn@umich.edu        network = SimpleNetwork(topology = net_topology)
944762Snate@binkert.org
954382Sbinkertn@umich.edu    #
965522Snate@binkert.org    # Loop through the directory controlers.
974381Sbinkertn@umich.edu    # Determine the total memory size of the ruby system and verify it is equal
985522Snate@binkert.org    # to physmem.  However, if Ruby memory is using sparse memory in SE
994762Snate@binkert.org    # mode, then the system should not back-up the memory state with
1004762Snate@binkert.org    # the Memory Vector and thus the memory size bytes should stay at 0.
1014762Snate@binkert.org    # Also set the numa bits to the appropriate values.
1025522Snate@binkert.org    #
1035522Snate@binkert.org    total_mem_size = MemorySize('0B')
1045522Snate@binkert.org
1055522Snate@binkert.org    dir_bits = int(math.log(options.num_dirs, 2))
1065522Snate@binkert.org
1075522Snate@binkert.org    if options.numa_high_bit:
1085522Snate@binkert.org        numa_bit = options.numa_high_bit
1095522Snate@binkert.org    else:
1105522Snate@binkert.org        # if not specified, use the lowest bits above the block offest
1114762Snate@binkert.org        if options.numa_high_bit == 0:
1124762Snate@binkert.org            if dir_bits > 0:
1134762Snate@binkert.org                # add 5 because bits 0-5 are the block offset
1144762Snate@binkert.org                numa_bit = dir_bits + 5
1154762Snate@binkert.org            else:
1164762Snate@binkert.org                numa_bit = 6
1174762Snate@binkert.org
1184762Snate@binkert.org    for dir_cntrl in dir_cntrls:
1194762Snate@binkert.org        total_mem_size.value += dir_cntrl.directory.size.value
1204762Snate@binkert.org        dir_cntrl.directory.numa_high_bit = numa_bit
1214762Snate@binkert.org
1224762Snate@binkert.org    physmem_size = long(system.physmem.range.second) - \
1234762Snate@binkert.org                     long(system.physmem.range.first) + 1
1244762Snate@binkert.org    assert(total_mem_size.value == physmem_size)
1254762Snate@binkert.org
1264762Snate@binkert.org    ruby_profiler = RubyProfiler(num_of_sequencers = len(cpu_sequencers))
1274762Snate@binkert.org
1284762Snate@binkert.org    ruby = RubySystem(clock = options.clock,
1294762Snate@binkert.org                      network = network,
1304762Snate@binkert.org                      profiler = ruby_profiler,
1314762Snate@binkert.org                      tracer = RubyTracer(),
1324762Snate@binkert.org                      debug = RubyDebug(filter_string = 'none',
1334762Snate@binkert.org                                        verbosity_string = 'none',
1344762Snate@binkert.org                                        protocol_trace = options.ruby_debug,
1354762Snate@binkert.org                                        start_time = options.ruby_debug_cycle),
1364762Snate@binkert.org                      mem_size = total_mem_size)
1374762Snate@binkert.org
1384762Snate@binkert.org    ruby.cpu_ruby_ports = cpu_sequencers
1394762Snate@binkert.org
1404762Snate@binkert.org    return ruby
1414762Snate@binkert.org