Ruby.py revision 10519
16019Shines@cs.fsu.edu# Copyright (c) 2012 ARM Limited
27111Sgblack@eecs.umich.edu# All rights reserved.
37111Sgblack@eecs.umich.edu#
47111Sgblack@eecs.umich.edu# The license below extends only to copyright in the software and shall
57111Sgblack@eecs.umich.edu# not be construed as granting a license to any other intellectual
67111Sgblack@eecs.umich.edu# property including but not limited to intellectual property relating
77111Sgblack@eecs.umich.edu# to a hardware implementation of the functionality of the software
87111Sgblack@eecs.umich.edu# licensed hereunder.  You may use the software subject to the license
97111Sgblack@eecs.umich.edu# terms below provided that you ensure that this notice is replicated
107111Sgblack@eecs.umich.edu# unmodified and in its entirety in all distributions of the software,
117111Sgblack@eecs.umich.edu# modified or unmodified, in source code or in binary form.
127111Sgblack@eecs.umich.edu#
137111Sgblack@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
146019Shines@cs.fsu.edu# Copyright (c) 2009 Advanced Micro Devices, Inc.
156019Shines@cs.fsu.edu# All rights reserved.
166019Shines@cs.fsu.edu#
176019Shines@cs.fsu.edu# Redistribution and use in source and binary forms, with or without
186019Shines@cs.fsu.edu# modification, are permitted provided that the following conditions are
196019Shines@cs.fsu.edu# met: redistributions of source code must retain the above copyright
206019Shines@cs.fsu.edu# notice, this list of conditions and the following disclaimer;
216019Shines@cs.fsu.edu# redistributions in binary form must reproduce the above copyright
226019Shines@cs.fsu.edu# notice, this list of conditions and the following disclaimer in the
236019Shines@cs.fsu.edu# documentation and/or other materials provided with the distribution;
246019Shines@cs.fsu.edu# neither the name of the copyright holders nor the names of its
256019Shines@cs.fsu.edu# contributors may be used to endorse or promote products derived from
266019Shines@cs.fsu.edu# this software without specific prior written permission.
276019Shines@cs.fsu.edu#
286019Shines@cs.fsu.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296019Shines@cs.fsu.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306019Shines@cs.fsu.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316019Shines@cs.fsu.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326019Shines@cs.fsu.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336019Shines@cs.fsu.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346019Shines@cs.fsu.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356019Shines@cs.fsu.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366019Shines@cs.fsu.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376019Shines@cs.fsu.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386019Shines@cs.fsu.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396019Shines@cs.fsu.edu#
406019Shines@cs.fsu.edu# Authors: Brad Beckmann
416019Shines@cs.fsu.edu
426019Shines@cs.fsu.eduimport math
436019Shines@cs.fsu.eduimport m5
446019Shines@cs.fsu.edufrom m5.objects import *
456019Shines@cs.fsu.edufrom m5.defines import buildEnv
466019Shines@cs.fsu.edufrom m5.util import addToPath, fatal
476019Shines@cs.fsu.edu
487692SAli.Saidi@ARM.comaddToPath('../topologies')
496242Sgblack@eecs.umich.edu
506019Shines@cs.fsu.edudef define_options(parser):
517678Sgblack@eecs.umich.edu    # By default, ruby uses the simple timing cpu
527408Sgblack@eecs.umich.edu    parser.set_defaults(cpu_type="timing")
536216Snate@binkert.org
547720Sgblack@eecs.umich.edu    parser.add_option("--ruby-clock", action="store", type="string",
556019Shines@cs.fsu.edu                      default='2GHz',
566019Shines@cs.fsu.edu                      help="Clock for blocks running at Ruby system's speed")
576019Shines@cs.fsu.edu
586019Shines@cs.fsu.edu    # Options related to cache structure
597751SAli.Saidi@ARM.com    parser.add_option("--ports", action="store", type="int", default=4,
607751SAli.Saidi@ARM.com                      help="used of transitions per cycle which is a proxy \
617751SAli.Saidi@ARM.com                            for the number of ports.")
627751SAli.Saidi@ARM.com
637751SAli.Saidi@ARM.com    # ruby network options
647751SAli.Saidi@ARM.com    parser.add_option("--topology", type="string", default="Crossbar",
657751SAli.Saidi@ARM.com                 help="check src/mem/ruby/network/topologies for complete set")
667751SAli.Saidi@ARM.com    parser.add_option("--mesh-rows", type="int", default=1,
677751SAli.Saidi@ARM.com                      help="the number of rows in the mesh topology")
688303SAli.Saidi@ARM.com    parser.add_option("--garnet-network", type="choice",
697751SAli.Saidi@ARM.com                      choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
708303SAli.Saidi@ARM.com    parser.add_option("--network-fault-model", action="store_true", default=False,
718303SAli.Saidi@ARM.com                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
728303SAli.Saidi@ARM.com
737751SAli.Saidi@ARM.com    # ruby mapping options
747720Sgblack@eecs.umich.edu    parser.add_option("--numa-high-bit", type="int", default=0,
758303SAli.Saidi@ARM.com                      help="high order address bit to use for numa mapping. " \
768303SAli.Saidi@ARM.com                           "0 = highest bit, not specified = lowest bit")
778303SAli.Saidi@ARM.com
788303SAli.Saidi@ARM.com    # ruby sparse memory options
798303SAli.Saidi@ARM.com    parser.add_option("--use-map", action="store_true", default=False)
808303SAli.Saidi@ARM.com    parser.add_option("--map-levels", type="int", default=4)
818303SAli.Saidi@ARM.com
828303SAli.Saidi@ARM.com    parser.add_option("--recycle-latency", type="int", default=10,
838303SAli.Saidi@ARM.com                      help="Recycle latency for ruby controller input buffers")
848303SAli.Saidi@ARM.com
858303SAli.Saidi@ARM.com    parser.add_option("--random_seed", type="int", default=1234,
868303SAli.Saidi@ARM.com                      help="Used for seeding the random number generator")
878303SAli.Saidi@ARM.com
888303SAli.Saidi@ARM.com    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
897751SAli.Saidi@ARM.com
907751SAli.Saidi@ARM.com    protocol = buildEnv['PROTOCOL']
917751SAli.Saidi@ARM.com    exec "import %s" % protocol
927751SAli.Saidi@ARM.com    eval("%s.define_options(parser)" % protocol)
937720Sgblack@eecs.umich.edu
947751SAli.Saidi@ARM.comdef create_topology(controllers, options):
957720Sgblack@eecs.umich.edu    """ Called from create_system in configs/ruby/<protocol>.py
967751SAli.Saidi@ARM.com        Must return an object which is a subclass of BaseTopology
977751SAli.Saidi@ARM.com        found in configs/topologies/BaseTopology.py
987751SAli.Saidi@ARM.com        This is a wrapper for the legacy topologies.
997751SAli.Saidi@ARM.com    """
1007751SAli.Saidi@ARM.com    exec "import %s as Topo" % options.topology
1017751SAli.Saidi@ARM.com    topology = eval("Topo.%s(controllers)" % options.topology)
1026242Sgblack@eecs.umich.edu    return topology
1037751SAli.Saidi@ARM.com
1047751SAli.Saidi@ARM.comdef create_system(options, full_system, system, piobus = None, dma_ports = []):
1057751SAli.Saidi@ARM.com
1067751SAli.Saidi@ARM.com    system.ruby = RubySystem(no_mem_vec = options.use_map)
1076019Shines@cs.fsu.edu    ruby = system.ruby
1087751SAli.Saidi@ARM.com
1096246Sgblack@eecs.umich.edu    # Set the network classes based on the command line options
1107751SAli.Saidi@ARM.com    if options.garnet_network == "fixed":
1117751SAli.Saidi@ARM.com        NetworkClass = GarnetNetwork_d
1127751SAli.Saidi@ARM.com        IntLinkClass = GarnetIntLink_d
1137751SAli.Saidi@ARM.com        ExtLinkClass = GarnetExtLink_d
1147751SAli.Saidi@ARM.com        RouterClass = GarnetRouter_d
1156329Sgblack@eecs.umich.edu        InterfaceClass = GarnetNetworkInterface_d
1167751SAli.Saidi@ARM.com
1176757SAli.Saidi@ARM.com    elif options.garnet_network == "flexible":
1187751SAli.Saidi@ARM.com        NetworkClass = GarnetNetwork
1197751SAli.Saidi@ARM.com        IntLinkClass = GarnetIntLink
1207751SAli.Saidi@ARM.com        ExtLinkClass = GarnetExtLink
1217751SAli.Saidi@ARM.com        RouterClass = GarnetRouter
1227751SAli.Saidi@ARM.com        InterfaceClass = GarnetNetworkInterface
1237638Sgblack@eecs.umich.edu
1247751SAli.Saidi@ARM.com    else:
1257751SAli.Saidi@ARM.com        NetworkClass = SimpleNetwork
1267751SAli.Saidi@ARM.com        IntLinkClass = SimpleIntLink
1277751SAli.Saidi@ARM.com        ExtLinkClass = SimpleExtLink
1287751SAli.Saidi@ARM.com        RouterClass = Switch
1297638Sgblack@eecs.umich.edu        InterfaceClass = None
1307751SAli.Saidi@ARM.com
1317751SAli.Saidi@ARM.com    # Instantiate the network object so that the controllers can connect to it.
1327751SAli.Saidi@ARM.com    network = NetworkClass(ruby_system = ruby, topology = options.topology,
1337751SAli.Saidi@ARM.com            routers = [], ext_links = [], int_links = [], netifs = [])
1347751SAli.Saidi@ARM.com    ruby.network = network
1357638Sgblack@eecs.umich.edu
1367751SAli.Saidi@ARM.com    protocol = buildEnv['PROTOCOL']
1377751SAli.Saidi@ARM.com    exec "import %s" % protocol
1387751SAli.Saidi@ARM.com    try:
1397751SAli.Saidi@ARM.com        (cpu_sequencers, dir_cntrls, topology) = \
1407751SAli.Saidi@ARM.com             eval("%s.create_system(options, full_system, system, dma_ports,\
1416757SAli.Saidi@ARM.com                                    ruby)"
1427751SAli.Saidi@ARM.com                  % protocol)
1437751SAli.Saidi@ARM.com    except:
1447751SAli.Saidi@ARM.com        print "Error: could not create sytem for ruby protocol %s" % protocol
1457751SAli.Saidi@ARM.com        raise
1467751SAli.Saidi@ARM.com
1477751SAli.Saidi@ARM.com    # Create a port proxy for connecting the system port. This is
1487640Sgblack@eecs.umich.edu    # independent of the protocol and kept in the protocol-agnostic
1497751SAli.Saidi@ARM.com    # part (i.e. here).
1507751SAli.Saidi@ARM.com    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
1517751SAli.Saidi@ARM.com
1528206SWilliam.Wang@arm.com    # Give the system port proxy a SimObject parent without creating a
1538206SWilliam.Wang@arm.com    # full-fledged controller
1548206SWilliam.Wang@arm.com    system.sys_port_proxy = sys_port_proxy
1558206SWilliam.Wang@arm.com
1568206SWilliam.Wang@arm.com    # Connect the system port for loading of binaries etc
1578206SWilliam.Wang@arm.com    system.system_port = system.sys_port_proxy.slave
1587751SAli.Saidi@ARM.com
1597640Sgblack@eecs.umich.edu    # Create the network topology
1607751SAli.Saidi@ARM.com    topology.makeTopology(options, network, IntLinkClass, ExtLinkClass,
1617751SAli.Saidi@ARM.com            RouterClass)
1627751SAli.Saidi@ARM.com
1637751SAli.Saidi@ARM.com    if InterfaceClass != None:
1647751SAli.Saidi@ARM.com        netifs = [InterfaceClass(id=i) for (i,n) in enumerate(network.ext_links)]
1657640Sgblack@eecs.umich.edu        network.netifs = netifs
1667707Sgblack@eecs.umich.edu
1676757SAli.Saidi@ARM.com    if options.network_fault_model:
1687693SAli.Saidi@ARM.com        assert(options.garnet_network == "fixed")
1697693SAli.Saidi@ARM.com        network.enable_fault_model = True
1707720Sgblack@eecs.umich.edu        network.fault_model = FaultModel()
1717720Sgblack@eecs.umich.edu
1727720Sgblack@eecs.umich.edu    # Loop through the directory controlers.
1737720Sgblack@eecs.umich.edu    # Determine the total memory size of the ruby system and verify it is equal
1747720Sgblack@eecs.umich.edu    # to physmem.  However, if Ruby memory is using sparse memory in SE
1757720Sgblack@eecs.umich.edu    # mode, then the system should not back-up the memory state with
1767752SWilliam.Wang@arm.com    # the Memory Vector and thus the memory size bytes should stay at 0.
1777752SWilliam.Wang@arm.com    # Also set the numa bits to the appropriate values.
1787752SWilliam.Wang@arm.com    total_mem_size = MemorySize('0B')
1798300Schander.sudanthi@arm.com
1808300Schander.sudanthi@arm.com    ruby.block_size_bytes = options.cacheline_size
1818300Schander.sudanthi@arm.com    block_size_bits = int(math.log(options.cacheline_size, 2))
1828300Schander.sudanthi@arm.com
1838300Schander.sudanthi@arm.com    if options.numa_high_bit:
1848300Schander.sudanthi@arm.com        numa_bit = options.numa_high_bit
1856019Shines@cs.fsu.edu    else:
1866019Shines@cs.fsu.edu        # if the numa_bit is not specified, set the directory bits as the
1876019Shines@cs.fsu.edu        # lowest bits above the block offset bits, and the numa_bit as the
188        # highest of those directory bits
189        dir_bits = int(math.log(options.num_dirs, 2))
190        numa_bit = block_size_bits + dir_bits - 1
191
192    for dir_cntrl in dir_cntrls:
193        total_mem_size.value += dir_cntrl.directory.size.value
194        dir_cntrl.directory.numa_high_bit = numa_bit
195
196    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
197    assert(total_mem_size.value == phys_mem_size)
198    ruby.mem_size = total_mem_size
199
200    # Connect the cpu sequencers and the piobus
201    if piobus != None:
202        for cpu_seq in cpu_sequencers:
203            cpu_seq.pio_master_port = piobus.slave
204            cpu_seq.mem_master_port = piobus.slave
205
206            if buildEnv['TARGET_ISA'] == "x86":
207                cpu_seq.pio_slave_port = piobus.master
208
209    ruby._cpu_ports = cpu_sequencers
210    ruby.num_of_sequencers = len(cpu_sequencers)
211    ruby.random_seed    = options.random_seed
212