Ruby.py revision 9593
18706Sandreas.hansson@arm.com# Copyright (c) 2012 ARM Limited
28706Sandreas.hansson@arm.com# All rights reserved.
38706Sandreas.hansson@arm.com#
48706Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall
58706Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual
68706Sandreas.hansson@arm.com# property including but not limited to intellectual property relating
78706Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software
88706Sandreas.hansson@arm.com# licensed hereunder.  You may use the software subject to the license
98706Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated
108706Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software,
118706Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form.
128706Sandreas.hansson@arm.com#
136892SBrad.Beckmann@amd.com# Copyright (c) 2006-2007 The Regents of The University of Michigan
146892SBrad.Beckmann@amd.com# Copyright (c) 2009 Advanced Micro Devices, Inc.
156892SBrad.Beckmann@amd.com# All rights reserved.
166892SBrad.Beckmann@amd.com#
176892SBrad.Beckmann@amd.com# Redistribution and use in source and binary forms, with or without
186892SBrad.Beckmann@amd.com# modification, are permitted provided that the following conditions are
196892SBrad.Beckmann@amd.com# met: redistributions of source code must retain the above copyright
206892SBrad.Beckmann@amd.com# notice, this list of conditions and the following disclaimer;
216892SBrad.Beckmann@amd.com# redistributions in binary form must reproduce the above copyright
226892SBrad.Beckmann@amd.com# notice, this list of conditions and the following disclaimer in the
236892SBrad.Beckmann@amd.com# documentation and/or other materials provided with the distribution;
246892SBrad.Beckmann@amd.com# neither the name of the copyright holders nor the names of its
256892SBrad.Beckmann@amd.com# contributors may be used to endorse or promote products derived from
266892SBrad.Beckmann@amd.com# this software without specific prior written permission.
276892SBrad.Beckmann@amd.com#
286892SBrad.Beckmann@amd.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296892SBrad.Beckmann@amd.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306892SBrad.Beckmann@amd.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316892SBrad.Beckmann@amd.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326892SBrad.Beckmann@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336892SBrad.Beckmann@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346892SBrad.Beckmann@amd.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356892SBrad.Beckmann@amd.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366892SBrad.Beckmann@amd.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376892SBrad.Beckmann@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386892SBrad.Beckmann@amd.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396892SBrad.Beckmann@amd.com#
406892SBrad.Beckmann@amd.com# Authors: Brad Beckmann
416892SBrad.Beckmann@amd.com
427563SBrad.Beckmann@amd.comimport math
436892SBrad.Beckmann@amd.comimport m5
446892SBrad.Beckmann@amd.comfrom m5.objects import *
456892SBrad.Beckmann@amd.comfrom m5.defines import buildEnv
466892SBrad.Beckmann@amd.com
477538SBrad.Beckmann@amd.comdef define_options(parser):
488939SBrad.Beckmann@amd.com    # By default, ruby uses the simple timing cpu
498939SBrad.Beckmann@amd.com    parser.set_defaults(cpu_type="timing")
508939SBrad.Beckmann@amd.com
517538SBrad.Beckmann@amd.com    # ruby network options
527538SBrad.Beckmann@amd.com    parser.add_option("--topology", type="string", default="Crossbar",
537538SBrad.Beckmann@amd.com                 help="check src/mem/ruby/network/topologies for complete set")
547538SBrad.Beckmann@amd.com    parser.add_option("--mesh-rows", type="int", default=1,
557538SBrad.Beckmann@amd.com                      help="the number of rows in the mesh topology")
569576Snilay@cs.wisc.edu    parser.add_option("--garnet-network", type="choice",
579576Snilay@cs.wisc.edu                      choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
588612Stushar@csail.mit.edu    parser.add_option("--network-fault-model", action="store_true", default=False,
598612Stushar@csail.mit.edu                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
607538SBrad.Beckmann@amd.com
617538SBrad.Beckmann@amd.com    # ruby mapping options
627917SBrad.Beckmann@amd.com    parser.add_option("--numa-high-bit", type="int", default=0,
637563SBrad.Beckmann@amd.com                      help="high order address bit to use for numa mapping. " \
647563SBrad.Beckmann@amd.com                           "0 = highest bit, not specified = lowest bit")
657538SBrad.Beckmann@amd.com
667538SBrad.Beckmann@amd.com    # ruby sparse memory options
677538SBrad.Beckmann@amd.com    parser.add_option("--use-map", action="store_true", default=False)
687538SBrad.Beckmann@amd.com    parser.add_option("--map-levels", type="int", default=4)
697538SBrad.Beckmann@amd.com
707566SBrad.Beckmann@amd.com    parser.add_option("--recycle-latency", type="int", default=10,
717566SBrad.Beckmann@amd.com                      help="Recycle latency for ruby controller input buffers")
727809Snilay@cs.wisc.edu
737809Snilay@cs.wisc.edu    parser.add_option("--random_seed", type="int", default=1234,
747809Snilay@cs.wisc.edu                      help="Used for seeding the random number generator")
757809Snilay@cs.wisc.edu
768638Sgloh    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
778638Sgloh
787538SBrad.Beckmann@amd.com    protocol = buildEnv['PROTOCOL']
797538SBrad.Beckmann@amd.com    exec "import %s" % protocol
807538SBrad.Beckmann@amd.com    eval("%s.define_options(parser)" % protocol)
817538SBrad.Beckmann@amd.com
829100SBrad.Beckmann@amd.comdef create_topology(controllers, options):
839100SBrad.Beckmann@amd.com    """ Called from create_system in configs/ruby/<protocol>.py
849100SBrad.Beckmann@amd.com        Must return an object which is a subclass of BaseTopology
859100SBrad.Beckmann@amd.com        found in configs/topologies/BaseTopology.py
869100SBrad.Beckmann@amd.com        This is a wrapper for the legacy topologies.
879100SBrad.Beckmann@amd.com    """
889100SBrad.Beckmann@amd.com    exec "import %s as Topo" % options.topology
899100SBrad.Beckmann@amd.com    topology = eval("Topo.%s(controllers)" % options.topology)
909100SBrad.Beckmann@amd.com    return topology
919100SBrad.Beckmann@amd.com
928929Snilay@cs.wisc.edudef create_system(options, system, piobus = None, dma_ports = []):
936892SBrad.Beckmann@amd.com
948638Sgloh    system.ruby = RubySystem(clock = options.clock,
958690Snilay@cs.wisc.edu                             stats_filename = options.ruby_stats,
968690Snilay@cs.wisc.edu                             no_mem_vec = options.use_map)
978436SBrad.Beckmann@amd.com    ruby = system.ruby
988436SBrad.Beckmann@amd.com
997032SBrad.Beckmann@amd.com    protocol = buildEnv['PROTOCOL']
1007032SBrad.Beckmann@amd.com    exec "import %s" % protocol
1016923SBrad.Beckmann@amd.com    try:
1029100SBrad.Beckmann@amd.com        (cpu_sequencers, dir_cntrls, topology) = \
1038929Snilay@cs.wisc.edu             eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
1047557SBrad.Beckmann@amd.com                  % protocol)
1056923SBrad.Beckmann@amd.com    except:
1066923SBrad.Beckmann@amd.com        print "Error: could not create sytem for ruby protocol %s" % protocol
1077557SBrad.Beckmann@amd.com        raise
1088257SBrad.Beckmann@amd.com
1098706Sandreas.hansson@arm.com    # Create a port proxy for connecting the system port. This is
1108706Sandreas.hansson@arm.com    # independent of the protocol and kept in the protocol-agnostic
1118706Sandreas.hansson@arm.com    # part (i.e. here).
1128923Sandreas.hansson@arm.com    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
1138706Sandreas.hansson@arm.com    # Give the system port proxy a SimObject parent without creating a
1148706Sandreas.hansson@arm.com    # full-fledged controller
1158706Sandreas.hansson@arm.com    system.sys_port_proxy = sys_port_proxy
1168706Sandreas.hansson@arm.com
1178732Sandreas.hansson@arm.com    # Connect the system port for loading of binaries etc
1188839Sandreas.hansson@arm.com    system.system_port = system.sys_port_proxy.slave
1198732Sandreas.hansson@arm.com
1208732Sandreas.hansson@arm.com
1218257SBrad.Beckmann@amd.com    #
1228257SBrad.Beckmann@amd.com    # Set the network classes based on the command line options
1238257SBrad.Beckmann@amd.com    #
1248257SBrad.Beckmann@amd.com    if options.garnet_network == "fixed":
1258257SBrad.Beckmann@amd.com        class NetworkClass(GarnetNetwork_d): pass
1268257SBrad.Beckmann@amd.com        class IntLinkClass(GarnetIntLink_d): pass
1278257SBrad.Beckmann@amd.com        class ExtLinkClass(GarnetExtLink_d): pass
1288257SBrad.Beckmann@amd.com        class RouterClass(GarnetRouter_d): pass
1298257SBrad.Beckmann@amd.com    elif options.garnet_network == "flexible":
1308257SBrad.Beckmann@amd.com        class NetworkClass(GarnetNetwork): pass
1318257SBrad.Beckmann@amd.com        class IntLinkClass(GarnetIntLink): pass
1328257SBrad.Beckmann@amd.com        class ExtLinkClass(GarnetExtLink): pass
1338257SBrad.Beckmann@amd.com        class RouterClass(GarnetRouter): pass
1348257SBrad.Beckmann@amd.com    else:
1358257SBrad.Beckmann@amd.com        class NetworkClass(SimpleNetwork): pass
1368258SBrad.Beckmann@amd.com        class IntLinkClass(SimpleIntLink): pass
1378258SBrad.Beckmann@amd.com        class ExtLinkClass(SimpleExtLink): pass
1389274Snilay@cs.wisc.edu        class RouterClass(Switch): pass
1399148Spowerjg@cs.wisc.edu
1406892SBrad.Beckmann@amd.com    #
1419100SBrad.Beckmann@amd.com    # Important: the topology must be instantiated before the network and after
1429100SBrad.Beckmann@amd.com    # the controllers. Hence the separation between topology definition and
1439148Spowerjg@cs.wisc.edu    # instantiation.
1446892SBrad.Beckmann@amd.com    #
1459148Spowerjg@cs.wisc.edu    # gem5 SimObject defined in src/mem/ruby/network/Network.py
1469148Spowerjg@cs.wisc.edu    net_topology = Topology()
1479148Spowerjg@cs.wisc.edu    net_topology.description = topology.description
1489148Spowerjg@cs.wisc.edu
1499148Spowerjg@cs.wisc.edu    routers, int_links, ext_links = topology.makeTopology(options,
1509148Spowerjg@cs.wisc.edu                                    IntLinkClass, ExtLinkClass, RouterClass)
1519148Spowerjg@cs.wisc.edu
1529593Snilay@cs.wisc.edu    net_topology.num_routers = len(routers)
1539148Spowerjg@cs.wisc.edu    net_topology.int_links = int_links
1549148Spowerjg@cs.wisc.edu    net_topology.ext_links = ext_links
1559148Spowerjg@cs.wisc.edu
1569593Snilay@cs.wisc.edu    network = NetworkClass(ruby_system = ruby, topology = net_topology,
1579593Snilay@cs.wisc.edu                           routers = routers)
1588257SBrad.Beckmann@amd.com
1598612Stushar@csail.mit.edu    if options.network_fault_model:
1608612Stushar@csail.mit.edu        assert(options.garnet_network == "fixed")
1619593Snilay@cs.wisc.edu        network.enable_fault_model = True
1629593Snilay@cs.wisc.edu        network.fault_model = FaultModel()
1636892SBrad.Beckmann@amd.com
1646903SBrad.Beckmann@amd.com    #
1657563SBrad.Beckmann@amd.com    # Loop through the directory controlers.
1667025SBrad.Beckmann@amd.com    # Determine the total memory size of the ruby system and verify it is equal
1679148Spowerjg@cs.wisc.edu    # to physmem.  However, if Ruby memory is using sparse memory in SE
1687025SBrad.Beckmann@amd.com    # mode, then the system should not back-up the memory state with
1697025SBrad.Beckmann@amd.com    # the Memory Vector and thus the memory size bytes should stay at 0.
1707563SBrad.Beckmann@amd.com    # Also set the numa bits to the appropriate values.
1716903SBrad.Beckmann@amd.com    #
1726903SBrad.Beckmann@amd.com    total_mem_size = MemorySize('0B')
1737563SBrad.Beckmann@amd.com
1747563SBrad.Beckmann@amd.com    dir_bits = int(math.log(options.num_dirs, 2))
1759318Spower.jg@gmail.com    ruby.block_size_bytes = options.cacheline_size
1769318Spower.jg@gmail.com    block_size_bits = int(math.log(options.cacheline_size, 2))
1777563SBrad.Beckmann@amd.com
1787563SBrad.Beckmann@amd.com    if options.numa_high_bit:
1797563SBrad.Beckmann@amd.com        numa_bit = options.numa_high_bit
1807563SBrad.Beckmann@amd.com    else:
1819318Spower.jg@gmail.com        # if the numa_bit is not specified, set the directory bits as the
1829318Spower.jg@gmail.com        # lowest bits above the block offset bits, and the numa_bit as the
1839318Spower.jg@gmail.com        # highest of those directory bits
1849318Spower.jg@gmail.com        numa_bit = block_size_bits + dir_bits - 1
1859148Spowerjg@cs.wisc.edu
1866903SBrad.Beckmann@amd.com    for dir_cntrl in dir_cntrls:
1876903SBrad.Beckmann@amd.com        total_mem_size.value += dir_cntrl.directory.size.value
1887563SBrad.Beckmann@amd.com        dir_cntrl.directory.numa_high_bit = numa_bit
1899148Spowerjg@cs.wisc.edu
1909232Sandreas.hansson@arm.com    phys_mem_size = sum(map(lambda mem: mem.range.size(),
1919232Sandreas.hansson@arm.com                            system.memories.unproxy(system)))
1928931Sandreas.hansson@arm.com    assert(total_mem_size.value == phys_mem_size)
1936892SBrad.Beckmann@amd.com
1948436SBrad.Beckmann@amd.com    ruby_profiler = RubyProfiler(ruby_system = ruby,
1958436SBrad.Beckmann@amd.com                                 num_of_sequencers = len(cpu_sequencers))
1968436SBrad.Beckmann@amd.com    ruby.network = network
1978436SBrad.Beckmann@amd.com    ruby.profiler = ruby_profiler
1988436SBrad.Beckmann@amd.com    ruby.mem_size = total_mem_size
1998322Ssteve.reinhardt@amd.com    ruby._cpu_ruby_ports = cpu_sequencers
2007809Snilay@cs.wisc.edu    ruby.random_seed    = options.random_seed
201