Ruby.py revision 10519
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
4610118Snilay@cs.wisc.edufrom m5.util import addToPath, fatal
4710118Snilay@cs.wisc.edu
4810118Snilay@cs.wisc.eduaddToPath('../topologies')
496892SBrad.Beckmann@amd.com
507538SBrad.Beckmann@amd.comdef define_options(parser):
518939SBrad.Beckmann@amd.com    # By default, ruby uses the simple timing cpu
528939SBrad.Beckmann@amd.com    parser.set_defaults(cpu_type="timing")
538939SBrad.Beckmann@amd.com
549791Sakash.bagdia@arm.com    parser.add_option("--ruby-clock", action="store", type="string",
559791Sakash.bagdia@arm.com                      default='2GHz',
569791Sakash.bagdia@arm.com                      help="Clock for blocks running at Ruby system's speed")
579791Sakash.bagdia@arm.com
589841Snilay@cs.wisc.edu    # Options related to cache structure
599841Snilay@cs.wisc.edu    parser.add_option("--ports", action="store", type="int", default=4,
609841Snilay@cs.wisc.edu                      help="used of transitions per cycle which is a proxy \
619841Snilay@cs.wisc.edu                            for the number of ports.")
629841Snilay@cs.wisc.edu
637538SBrad.Beckmann@amd.com    # ruby network options
647538SBrad.Beckmann@amd.com    parser.add_option("--topology", type="string", default="Crossbar",
657538SBrad.Beckmann@amd.com                 help="check src/mem/ruby/network/topologies for complete set")
667538SBrad.Beckmann@amd.com    parser.add_option("--mesh-rows", type="int", default=1,
677538SBrad.Beckmann@amd.com                      help="the number of rows in the mesh topology")
689576Snilay@cs.wisc.edu    parser.add_option("--garnet-network", type="choice",
699576Snilay@cs.wisc.edu                      choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
708612Stushar@csail.mit.edu    parser.add_option("--network-fault-model", action="store_true", default=False,
718612Stushar@csail.mit.edu                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
727538SBrad.Beckmann@amd.com
737538SBrad.Beckmann@amd.com    # ruby mapping options
747917SBrad.Beckmann@amd.com    parser.add_option("--numa-high-bit", type="int", default=0,
757563SBrad.Beckmann@amd.com                      help="high order address bit to use for numa mapping. " \
767563SBrad.Beckmann@amd.com                           "0 = highest bit, not specified = lowest bit")
777538SBrad.Beckmann@amd.com
787538SBrad.Beckmann@amd.com    # ruby sparse memory options
797538SBrad.Beckmann@amd.com    parser.add_option("--use-map", action="store_true", default=False)
807538SBrad.Beckmann@amd.com    parser.add_option("--map-levels", type="int", default=4)
817538SBrad.Beckmann@amd.com
827566SBrad.Beckmann@amd.com    parser.add_option("--recycle-latency", type="int", default=10,
837566SBrad.Beckmann@amd.com                      help="Recycle latency for ruby controller input buffers")
847809Snilay@cs.wisc.edu
857809Snilay@cs.wisc.edu    parser.add_option("--random_seed", type="int", default=1234,
867809Snilay@cs.wisc.edu                      help="Used for seeding the random number generator")
877809Snilay@cs.wisc.edu
888638Sgloh    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
898638Sgloh
907538SBrad.Beckmann@amd.com    protocol = buildEnv['PROTOCOL']
917538SBrad.Beckmann@amd.com    exec "import %s" % protocol
927538SBrad.Beckmann@amd.com    eval("%s.define_options(parser)" % protocol)
937538SBrad.Beckmann@amd.com
949100SBrad.Beckmann@amd.comdef create_topology(controllers, options):
959100SBrad.Beckmann@amd.com    """ Called from create_system in configs/ruby/<protocol>.py
969100SBrad.Beckmann@amd.com        Must return an object which is a subclass of BaseTopology
979100SBrad.Beckmann@amd.com        found in configs/topologies/BaseTopology.py
989100SBrad.Beckmann@amd.com        This is a wrapper for the legacy topologies.
999100SBrad.Beckmann@amd.com    """
1009100SBrad.Beckmann@amd.com    exec "import %s as Topo" % options.topology
1019100SBrad.Beckmann@amd.com    topology = eval("Topo.%s(controllers)" % options.topology)
1029100SBrad.Beckmann@amd.com    return topology
1039100SBrad.Beckmann@amd.com
10410519Snilay@cs.wisc.edudef create_system(options, full_system, system, piobus = None, dma_ports = []):
1056892SBrad.Beckmann@amd.com
10610012Snilay@cs.wisc.edu    system.ruby = RubySystem(no_mem_vec = options.use_map)
1078436SBrad.Beckmann@amd.com    ruby = system.ruby
1088436SBrad.Beckmann@amd.com
1098257SBrad.Beckmann@amd.com    # Set the network classes based on the command line options
1108257SBrad.Beckmann@amd.com    if options.garnet_network == "fixed":
11110122Snilay@cs.wisc.edu        NetworkClass = GarnetNetwork_d
11210122Snilay@cs.wisc.edu        IntLinkClass = GarnetIntLink_d
11310122Snilay@cs.wisc.edu        ExtLinkClass = GarnetExtLink_d
11410122Snilay@cs.wisc.edu        RouterClass = GarnetRouter_d
11510122Snilay@cs.wisc.edu        InterfaceClass = GarnetNetworkInterface_d
11610122Snilay@cs.wisc.edu
1178257SBrad.Beckmann@amd.com    elif options.garnet_network == "flexible":
11810122Snilay@cs.wisc.edu        NetworkClass = GarnetNetwork
11910122Snilay@cs.wisc.edu        IntLinkClass = GarnetIntLink
12010122Snilay@cs.wisc.edu        ExtLinkClass = GarnetExtLink
12110122Snilay@cs.wisc.edu        RouterClass = GarnetRouter
12210122Snilay@cs.wisc.edu        InterfaceClass = GarnetNetworkInterface
12310122Snilay@cs.wisc.edu
1248257SBrad.Beckmann@amd.com    else:
12510122Snilay@cs.wisc.edu        NetworkClass = SimpleNetwork
12610122Snilay@cs.wisc.edu        IntLinkClass = SimpleIntLink
12710122Snilay@cs.wisc.edu        ExtLinkClass = SimpleExtLink
12810122Snilay@cs.wisc.edu        RouterClass = Switch
12910122Snilay@cs.wisc.edu        InterfaceClass = None
1309148Spowerjg@cs.wisc.edu
13110311Snilay@cs.wisc.edu    # Instantiate the network object so that the controllers can connect to it.
13210311Snilay@cs.wisc.edu    network = NetworkClass(ruby_system = ruby, topology = options.topology,
13310311Snilay@cs.wisc.edu            routers = [], ext_links = [], int_links = [], netifs = [])
13410311Snilay@cs.wisc.edu    ruby.network = network
13510311Snilay@cs.wisc.edu
13610311Snilay@cs.wisc.edu    protocol = buildEnv['PROTOCOL']
13710311Snilay@cs.wisc.edu    exec "import %s" % protocol
13810311Snilay@cs.wisc.edu    try:
13910311Snilay@cs.wisc.edu        (cpu_sequencers, dir_cntrls, topology) = \
14010519Snilay@cs.wisc.edu             eval("%s.create_system(options, full_system, system, dma_ports,\
14110519Snilay@cs.wisc.edu                                    ruby)"
14210311Snilay@cs.wisc.edu                  % protocol)
14310311Snilay@cs.wisc.edu    except:
14410311Snilay@cs.wisc.edu        print "Error: could not create sytem for ruby protocol %s" % protocol
14510311Snilay@cs.wisc.edu        raise
14610311Snilay@cs.wisc.edu
14710311Snilay@cs.wisc.edu    # Create a port proxy for connecting the system port. This is
14810311Snilay@cs.wisc.edu    # independent of the protocol and kept in the protocol-agnostic
14910311Snilay@cs.wisc.edu    # part (i.e. here).
15010311Snilay@cs.wisc.edu    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
15110311Snilay@cs.wisc.edu
15210311Snilay@cs.wisc.edu    # Give the system port proxy a SimObject parent without creating a
15310311Snilay@cs.wisc.edu    # full-fledged controller
15410311Snilay@cs.wisc.edu    system.sys_port_proxy = sys_port_proxy
15510311Snilay@cs.wisc.edu
15610311Snilay@cs.wisc.edu    # Connect the system port for loading of binaries etc
15710311Snilay@cs.wisc.edu    system.system_port = system.sys_port_proxy.slave
1589148Spowerjg@cs.wisc.edu
1599862Snilay@cs.wisc.edu    # Create the network topology
1609862Snilay@cs.wisc.edu    topology.makeTopology(options, network, IntLinkClass, ExtLinkClass,
16110122Snilay@cs.wisc.edu            RouterClass)
16210122Snilay@cs.wisc.edu
16310122Snilay@cs.wisc.edu    if InterfaceClass != None:
16410122Snilay@cs.wisc.edu        netifs = [InterfaceClass(id=i) for (i,n) in enumerate(network.ext_links)]
16510122Snilay@cs.wisc.edu        network.netifs = netifs
1668257SBrad.Beckmann@amd.com
1678612Stushar@csail.mit.edu    if options.network_fault_model:
1688612Stushar@csail.mit.edu        assert(options.garnet_network == "fixed")
1699593Snilay@cs.wisc.edu        network.enable_fault_model = True
1709593Snilay@cs.wisc.edu        network.fault_model = FaultModel()
1716892SBrad.Beckmann@amd.com
1727563SBrad.Beckmann@amd.com    # Loop through the directory controlers.
1737025SBrad.Beckmann@amd.com    # Determine the total memory size of the ruby system and verify it is equal
1749148Spowerjg@cs.wisc.edu    # to physmem.  However, if Ruby memory is using sparse memory in SE
1757025SBrad.Beckmann@amd.com    # mode, then the system should not back-up the memory state with
1767025SBrad.Beckmann@amd.com    # the Memory Vector and thus the memory size bytes should stay at 0.
1777563SBrad.Beckmann@amd.com    # Also set the numa bits to the appropriate values.
1786903SBrad.Beckmann@amd.com    total_mem_size = MemorySize('0B')
1797563SBrad.Beckmann@amd.com
1809318Spower.jg@gmail.com    ruby.block_size_bytes = options.cacheline_size
1819318Spower.jg@gmail.com    block_size_bits = int(math.log(options.cacheline_size, 2))
1827563SBrad.Beckmann@amd.com
1837563SBrad.Beckmann@amd.com    if options.numa_high_bit:
1847563SBrad.Beckmann@amd.com        numa_bit = options.numa_high_bit
1857563SBrad.Beckmann@amd.com    else:
1869318Spower.jg@gmail.com        # if the numa_bit is not specified, set the directory bits as the
1879318Spower.jg@gmail.com        # lowest bits above the block offset bits, and the numa_bit as the
1889318Spower.jg@gmail.com        # highest of those directory bits
18910004Snilay@cs.wisc.edu        dir_bits = int(math.log(options.num_dirs, 2))
1909318Spower.jg@gmail.com        numa_bit = block_size_bits + dir_bits - 1
1919148Spowerjg@cs.wisc.edu
1926903SBrad.Beckmann@amd.com    for dir_cntrl in dir_cntrls:
1936903SBrad.Beckmann@amd.com        total_mem_size.value += dir_cntrl.directory.size.value
1947563SBrad.Beckmann@amd.com        dir_cntrl.directory.numa_high_bit = numa_bit
1959148Spowerjg@cs.wisc.edu
1969826Sandreas.hansson@arm.com    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
1978931Sandreas.hansson@arm.com    assert(total_mem_size.value == phys_mem_size)
1988436SBrad.Beckmann@amd.com    ruby.mem_size = total_mem_size
19910116Snilay@cs.wisc.edu
20010116Snilay@cs.wisc.edu    # Connect the cpu sequencers and the piobus
20110116Snilay@cs.wisc.edu    if piobus != None:
20210116Snilay@cs.wisc.edu        for cpu_seq in cpu_sequencers:
20310116Snilay@cs.wisc.edu            cpu_seq.pio_master_port = piobus.slave
20410116Snilay@cs.wisc.edu            cpu_seq.mem_master_port = piobus.slave
20510116Snilay@cs.wisc.edu
20610116Snilay@cs.wisc.edu            if buildEnv['TARGET_ISA'] == "x86":
20710116Snilay@cs.wisc.edu                cpu_seq.pio_slave_port = piobus.master
20810116Snilay@cs.wisc.edu
20910120Snilay@cs.wisc.edu    ruby._cpu_ports = cpu_sequencers
21010012Snilay@cs.wisc.edu    ruby.num_of_sequencers = len(cpu_sequencers)
2117809Snilay@cs.wisc.edu    ruby.random_seed    = options.random_seed
212