Ruby.py revision 9100
12124SN/A# Copyright (c) 2012 ARM Limited
22124SN/A# All rights reserved.
35268Sksewell@umich.edu#
45268Sksewell@umich.edu# The license below extends only to copyright in the software and shall
55268Sksewell@umich.edu# not be construed as granting a license to any other intellectual
65268Sksewell@umich.edu# property including but not limited to intellectual property relating
75268Sksewell@umich.edu# to a hardware implementation of the functionality of the software
85268Sksewell@umich.edu# licensed hereunder.  You may use the software subject to the license
95268Sksewell@umich.edu# terms below provided that you ensure that this notice is replicated
105268Sksewell@umich.edu# unmodified and in its entirety in all distributions of the software,
115268Sksewell@umich.edu# modified or unmodified, in source code or in binary form.
125268Sksewell@umich.edu#
135268Sksewell@umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
145268Sksewell@umich.edu# Copyright (c) 2009 Advanced Micro Devices, Inc.
155268Sksewell@umich.edu# All rights reserved.
165268Sksewell@umich.edu#
175268Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without
185268Sksewell@umich.edu# modification, are permitted provided that the following conditions are
195268Sksewell@umich.edu# met: redistributions of source code must retain the above copyright
205268Sksewell@umich.edu# notice, this list of conditions and the following disclaimer;
215268Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright
225268Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the
235268Sksewell@umich.edu# documentation and/or other materials provided with the distribution;
245268Sksewell@umich.edu# neither the name of the copyright holders nor the names of its
255268Sksewell@umich.edu# contributors may be used to endorse or promote products derived from
265268Sksewell@umich.edu# this software without specific prior written permission.
275268Sksewell@umich.edu#
285268Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295268Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305268Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312022SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322649Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332649Ssaidi@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342706Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352649Ssaidi@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362649Ssaidi@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372022SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382124SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392124SN/A#
402124SN/A# Authors: Brad Beckmann
412124SN/A
422124SN/Aimport math
432124SN/Aimport m5
442124SN/Afrom m5.objects import *
455736Snate@binkert.orgfrom m5.defines import buildEnv
462239SN/A
472124SN/Adef define_options(parser):
482124SN/A    # By default, ruby uses the simple timing cpu
492124SN/A    parser.set_defaults(cpu_type="timing")
502124SN/A
516207Sksewell@umich.edu    # ruby network options
522124SN/A    parser.add_option("--topology", type="string", default="Crossbar",
532742Sksewell@umich.edu                 help="check src/mem/ruby/network/topologies for complete set")
542022SN/A    parser.add_option("--mesh-rows", type="int", default=1,
552124SN/A                      help="the number of rows in the mesh topology")
562022SN/A    parser.add_option("--garnet-network", type="string", default=None,
5712616Sgabeblack@google.com                      help="'fixed'|'flexible'")
5812616Sgabeblack@google.com    parser.add_option("--network-fault-model", action="store_true", default=False,
592124SN/A                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
602124SN/A
612742Sksewell@umich.edu    # ruby mapping options
622742Sksewell@umich.edu    parser.add_option("--numa-high-bit", type="int", default=0,
632742Sksewell@umich.edu                      help="high order address bit to use for numa mapping. " \
642742Sksewell@umich.edu                           "0 = highest bit, not specified = lowest bit")
652742Sksewell@umich.edu
662742Sksewell@umich.edu    # ruby sparse memory options
672742Sksewell@umich.edu    parser.add_option("--use-map", action="store_true", default=False)
682742Sksewell@umich.edu    parser.add_option("--map-levels", type="int", default=4)
696207Sksewell@umich.edu
706207Sksewell@umich.edu    parser.add_option("--recycle-latency", type="int", default=10,
712742Sksewell@umich.edu                      help="Recycle latency for ruby controller input buffers")
722742Sksewell@umich.edu
732742Sksewell@umich.edu    parser.add_option("--random_seed", type="int", default=1234,
7412616Sgabeblack@google.com                      help="Used for seeding the random number generator")
7512616Sgabeblack@google.com
762742Sksewell@umich.edu    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
772022SN/A
782022SN/A    protocol = buildEnv['PROTOCOL']
792124SN/A    exec "import %s" % protocol
802022SN/A    eval("%s.define_options(parser)" % protocol)
812124SN/A
822124SN/Adef create_topology(controllers, options):
832124SN/A    """ Called from create_system in configs/ruby/<protocol>.py
842742Sksewell@umich.edu        Must return an object which is a subclass of BaseTopology
852239SN/A        found in configs/topologies/BaseTopology.py
862124SN/A        This is a wrapper for the legacy topologies.
872124SN/A    """
882742Sksewell@umich.edu    exec "import %s as Topo" % options.topology
892742Sksewell@umich.edu    topology = eval("Topo.%s(controllers)" % options.topology)
902742Sksewell@umich.edu    return topology
912742Sksewell@umich.edu
922742Sksewell@umich.edudef create_system(options, system, piobus = None, dma_ports = []):
932742Sksewell@umich.edu
942742Sksewell@umich.edu    system.ruby = RubySystem(clock = options.clock,
952742Sksewell@umich.edu                             stats_filename = options.ruby_stats,
964661Sksewell@umich.edu                             no_mem_vec = options.use_map)
974661Sksewell@umich.edu    ruby = system.ruby
984661Sksewell@umich.edu
999554Sandreas.hansson@arm.com    protocol = buildEnv['PROTOCOL']
10012234Sgabeblack@google.com    exec "import %s" % protocol
1019554Sandreas.hansson@arm.com    try:
1029554Sandreas.hansson@arm.com        (cpu_sequencers, dir_cntrls, topology) = \
1039554Sandreas.hansson@arm.com             eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
1044661Sksewell@umich.edu                  % protocol)
1054661Sksewell@umich.edu    except:
1064661Sksewell@umich.edu        print "Error: could not create sytem for ruby protocol %s" % protocol
1074661Sksewell@umich.edu        raise
10812234Sgabeblack@google.com
1094661Sksewell@umich.edu    # Create a port proxy for connecting the system port. This is
1104661Sksewell@umich.edu    # independent of the protocol and kept in the protocol-agnostic
1115222Sksewell@umich.edu    # part (i.e. here).
1124661Sksewell@umich.edu    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
1134661Sksewell@umich.edu    # Give the system port proxy a SimObject parent without creating a
1145222Sksewell@umich.edu    # full-fledged controller
1154661Sksewell@umich.edu    system.sys_port_proxy = sys_port_proxy
1164661Sksewell@umich.edu
1175222Sksewell@umich.edu    # Connect the system port for loading of binaries etc
1184661Sksewell@umich.edu    system.system_port = system.sys_port_proxy.slave
1194661Sksewell@umich.edu
1205222Sksewell@umich.edu
1214661Sksewell@umich.edu    #
1224661Sksewell@umich.edu    # Set the network classes based on the command line options
1234661Sksewell@umich.edu    #
1244661Sksewell@umich.edu    if options.garnet_network == "fixed":
1254661Sksewell@umich.edu        class NetworkClass(GarnetNetwork_d): pass
1264661Sksewell@umich.edu        class IntLinkClass(GarnetIntLink_d): pass
1274661Sksewell@umich.edu        class ExtLinkClass(GarnetExtLink_d): pass
1284661Sksewell@umich.edu        class RouterClass(GarnetRouter_d): pass
1294661Sksewell@umich.edu    elif options.garnet_network == "flexible":
1304661Sksewell@umich.edu        class NetworkClass(GarnetNetwork): pass
1314661Sksewell@umich.edu        class IntLinkClass(GarnetIntLink): pass
1322022SN/A        class ExtLinkClass(GarnetExtLink): pass
1332022SN/A        class RouterClass(GarnetRouter): pass
1342124SN/A    else:
1352124SN/A        class NetworkClass(SimpleNetwork): pass
1362124SN/A        class IntLinkClass(SimpleIntLink): pass
1372124SN/A        class ExtLinkClass(SimpleExtLink): pass
1382124SN/A        class RouterClass(BasicRouter): pass
1392124SN/A
1402124SN/A    #
1412124SN/A    # Important: the topology must be instantiated before the network and after
1422124SN/A    # the controllers. Hence the separation between topology definition and
1434661Sksewell@umich.edu    # instantiation. TopologyCreator is in src/mem/ruby/network/topologies/.
1442124SN/A    #
14512616Sgabeblack@google.com    from TopologyCreator import instantiateTopology
14612616Sgabeblack@google.com    try:
14712616Sgabeblack@google.com        net_topology = instantiateTopology(topology, options, \
14812616Sgabeblack@google.com                                           IntLinkClass, ExtLinkClass, \
1492124SN/A                                           RouterClass)
1502022SN/A    except:
1512022SN/A        print "Error: could not make topology %s" % options.topology
1522124SN/A        raise
1536207Sksewell@umich.edu
15410184SCurtis.Dunham@arm.com    if options.network_fault_model:
1556207Sksewell@umich.edu        assert(options.garnet_network == "fixed")
1562124SN/A        fault_model = FaultModel()
1573953Sstever@eecs.umich.edu        network = NetworkClass(ruby_system = ruby, topology = net_topology,\
1582124SN/A                               enable_fault_model=True, fault_model = fault_model)
1593953Sstever@eecs.umich.edu    else:
1602124SN/A        network = NetworkClass(ruby_system = ruby, topology = net_topology)
1612124SN/A
16212234Sgabeblack@google.com    #
1632124SN/A    # Loop through the directory controlers.
1642124SN/A    # Determine the total memory size of the ruby system and verify it is equal
1652124SN/A    # to physmem.  However, if Ruby memory is using sparse memory in SE
1662132SN/A    # mode, then the system should not back-up the memory state with
1672124SN/A    # the Memory Vector and thus the memory size bytes should stay at 0.
1685222Sksewell@umich.edu    # Also set the numa bits to the appropriate values.
1695222Sksewell@umich.edu    #
1705222Sksewell@umich.edu    total_mem_size = MemorySize('0B')
1715222Sksewell@umich.edu
1725222Sksewell@umich.edu    dir_bits = int(math.log(options.num_dirs, 2))
1735222Sksewell@umich.edu
1745222Sksewell@umich.edu    if options.numa_high_bit:
1752124SN/A        numa_bit = options.numa_high_bit
1762124SN/A    else:
1772124SN/A        # if not specified, use the lowest bits above the block offest
1782124SN/A        if dir_bits > 0:
1792124SN/A            # add 5 because bits 0-5 are the block offset
1808442Sgblack@eecs.umich.edu            numa_bit = dir_bits + 5
1812124SN/A        else:
1822124SN/A            numa_bit = 6
1832124SN/A
1842124SN/A    for dir_cntrl in dir_cntrls:
1852124SN/A        total_mem_size.value += dir_cntrl.directory.size.value
1862124SN/A        dir_cntrl.directory.numa_high_bit = numa_bit
1872124SN/A
1882124SN/A    phys_mem_size = 0
1892124SN/A    for mem in system.memories.unproxy(system):
1902124SN/A        phys_mem_size += long(mem.range.second) - long(mem.range.first) + 1
1912124SN/A    assert(total_mem_size.value == phys_mem_size)
1922124SN/A
1932124SN/A    ruby_profiler = RubyProfiler(ruby_system = ruby,
19412234Sgabeblack@google.com                                 num_of_sequencers = len(cpu_sequencers))
1952124SN/A    ruby.network = network
1962124SN/A    ruby.profiler = ruby_profiler
1972239SN/A    ruby.mem_size = total_mem_size
1982132SN/A    ruby._cpu_ruby_ports = cpu_sequencers
1992239SN/A    ruby.random_seed    = options.random_seed
2005222Sksewell@umich.edu