Ruby.py revision 9318:dec0b284ded9
12SN/A# Copyright (c) 2012 ARM Limited
21762SN/A# All rights reserved.
39983Sstever@gmail.com#
49983Sstever@gmail.com# The license below extends only to copyright in the software and shall
52SN/A# not be construed as granting a license to any other intellectual
62SN/A# property including but not limited to intellectual property relating
72SN/A# to a hardware implementation of the functionality of the software
82SN/A# licensed hereunder.  You may use the software subject to the license
92SN/A# terms below provided that you ensure that this notice is replicated
102SN/A# unmodified and in its entirety in all distributions of the software,
112SN/A# modified or unmodified, in source code or in binary form.
122SN/A#
132SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
142SN/A# Copyright (c) 2009 Advanced Micro Devices, Inc.
152SN/A# All rights reserved.
162SN/A#
172SN/A# Redistribution and use in source and binary forms, with or without
182SN/A# modification, are permitted provided that the following conditions are
192SN/A# met: redistributions of source code must retain the above copyright
202SN/A# notice, this list of conditions and the following disclaimer;
212SN/A# redistributions in binary form must reproduce the above copyright
222SN/A# notice, this list of conditions and the following disclaimer in the
232SN/A# documentation and/or other materials provided with the distribution;
242SN/A# neither the name of the copyright holders nor the names of its
252SN/A# contributors may be used to endorse or promote products derived from
262SN/A# this software without specific prior written permission.
272SN/A#
282SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292665Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302665Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312665Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381354SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
391354SN/A#
402SN/A# Authors: Brad Beckmann
412SN/A
425501Snate@binkert.orgimport math
435546Snate@binkert.orgimport m5
447004Snate@binkert.orgfrom m5.objects import *
4510412Sandreas.hansson@arm.comfrom m5.defines import buildEnv
469983Sstever@gmail.com
472SN/Adef define_options(parser):
482SN/A    # By default, ruby uses the simple timing cpu
495769Snate@binkert.org    parser.set_defaults(cpu_type="timing")
502361SN/A
516216Snate@binkert.org    # ruby network options
528232Snate@binkert.org    parser.add_option("--topology", type="string", default="Crossbar",
5356SN/A                 help="check src/mem/ruby/network/topologies for complete set")
542SN/A    parser.add_option("--mesh-rows", type="int", default=1,
555543Ssaidi@eecs.umich.edu                      help="the number of rows in the mesh topology")
569983Sstever@gmail.com    parser.add_option("--garnet-network", type="string", default=None,
572SN/A                      help="'fixed'|'flexible'")
589983Sstever@gmail.com    parser.add_option("--network-fault-model", action="store_true", default=False,
599983Sstever@gmail.com                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
609983Sstever@gmail.com
619983Sstever@gmail.com    # ruby mapping options
629983Sstever@gmail.com    parser.add_option("--numa-high-bit", type="int", default=0,
639983Sstever@gmail.com                      help="high order address bit to use for numa mapping. " \
641354SN/A                           "0 = highest bit, not specified = lowest bit")
659983Sstever@gmail.com
669983Sstever@gmail.com    # ruby sparse memory options
679983Sstever@gmail.com    parser.add_option("--use-map", action="store_true", default=False)
689983Sstever@gmail.com    parser.add_option("--map-levels", type="int", default=4)
699983Sstever@gmail.com
709983Sstever@gmail.com    parser.add_option("--recycle-latency", type="int", default=10,
719983Sstever@gmail.com                      help="Recycle latency for ruby controller input buffers")
729983Sstever@gmail.com
739983Sstever@gmail.com    parser.add_option("--random_seed", type="int", default=1234,
749983Sstever@gmail.com                      help="Used for seeding the random number generator")
759983Sstever@gmail.com
769983Sstever@gmail.com    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
779983Sstever@gmail.com
789983Sstever@gmail.com    protocol = buildEnv['PROTOCOL']
799983Sstever@gmail.com    exec "import %s" % protocol
809983Sstever@gmail.com    eval("%s.define_options(parser)" % protocol)
819983Sstever@gmail.com
829983Sstever@gmail.comdef create_topology(controllers, options):
839983Sstever@gmail.com    """ Called from create_system in configs/ruby/<protocol>.py
849983Sstever@gmail.com        Must return an object which is a subclass of BaseTopology
859983Sstever@gmail.com        found in configs/topologies/BaseTopology.py
869983Sstever@gmail.com        This is a wrapper for the legacy topologies.
879983Sstever@gmail.com    """
889983Sstever@gmail.com    exec "import %s as Topo" % options.topology
899983Sstever@gmail.com    topology = eval("Topo.%s(controllers)" % options.topology)
909983Sstever@gmail.com    return topology
919983Sstever@gmail.com
929983Sstever@gmail.comdef create_system(options, system, piobus = None, dma_ports = []):
939983Sstever@gmail.com
949983Sstever@gmail.com    system.ruby = RubySystem(clock = options.clock,
952SN/A                             stats_filename = options.ruby_stats,
969983Sstever@gmail.com                             no_mem_vec = options.use_map)
972SN/A    ruby = system.ruby
985769Snate@binkert.org
998902Sandreas.hansson@arm.com    protocol = buildEnv['PROTOCOL']
1005769Snate@binkert.org    exec "import %s" % protocol
1015769Snate@binkert.org    try:
1027059Snate@binkert.org        (cpu_sequencers, dir_cntrls, topology) = \
1037059Snate@binkert.org             eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
1047059Snate@binkert.org                  % protocol)
1057059Snate@binkert.org    except:
1067059Snate@binkert.org        print "Error: could not create sytem for ruby protocol %s" % protocol
1077059Snate@binkert.org        raise
1087059Snate@binkert.org
1097059Snate@binkert.org    # Create a port proxy for connecting the system port. This is
1107059Snate@binkert.org    # independent of the protocol and kept in the protocol-agnostic
1117059Snate@binkert.org    # part (i.e. here).
1127059Snate@binkert.org    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
1137058Snate@binkert.org    # Give the system port proxy a SimObject parent without creating a
1147058Snate@binkert.org    # full-fledged controller
1157058Snate@binkert.org    system.sys_port_proxy = sys_port_proxy
116396SN/A
117396SN/A    # Connect the system port for loading of binaries etc
118396SN/A    system.system_port = system.sys_port_proxy.slave
119396SN/A
1205501Snate@binkert.org
1217058Snate@binkert.org    #
1227058Snate@binkert.org    # Set the network classes based on the command line options
1233329Sstever@eecs.umich.edu    #
1247058Snate@binkert.org    if options.garnet_network == "fixed":
1257058Snate@binkert.org        class NetworkClass(GarnetNetwork_d): pass
1267058Snate@binkert.org        class IntLinkClass(GarnetIntLink_d): pass
1279979Satgutier@umich.edu        class ExtLinkClass(GarnetExtLink_d): pass
128396SN/A        class RouterClass(GarnetRouter_d): pass
1297058Snate@binkert.org    elif options.garnet_network == "flexible":
1307058Snate@binkert.org        class NetworkClass(GarnetNetwork): pass
1317058Snate@binkert.org        class IntLinkClass(GarnetIntLink): pass
1327058Snate@binkert.org        class ExtLinkClass(GarnetExtLink): pass
1333329Sstever@eecs.umich.edu        class RouterClass(GarnetRouter): pass
1347058Snate@binkert.org    else:
1357058Snate@binkert.org        class NetworkClass(SimpleNetwork): pass
1367058Snate@binkert.org        class IntLinkClass(SimpleIntLink): pass
1377058Snate@binkert.org        class ExtLinkClass(SimpleExtLink): pass
1387058Snate@binkert.org        class RouterClass(Switch): pass
139396SN/A
1407058Snate@binkert.org    #
1417058Snate@binkert.org    # Important: the topology must be instantiated before the network and after
1427058Snate@binkert.org    # the controllers. Hence the separation between topology definition and
1437058Snate@binkert.org    # instantiation.
144396SN/A    #
1457058Snate@binkert.org    # gem5 SimObject defined in src/mem/ruby/network/Network.py
1467058Snate@binkert.org    net_topology = Topology()
147396SN/A    net_topology.description = topology.description
14810249Sstephan.diestelhorst@arm.com
14910249Sstephan.diestelhorst@arm.com    routers, int_links, ext_links = topology.makeTopology(options,
15010249Sstephan.diestelhorst@arm.com                                    IntLinkClass, ExtLinkClass, RouterClass)
15110249Sstephan.diestelhorst@arm.com
1527058Snate@binkert.org    net_topology.routers = routers
1537058Snate@binkert.org    net_topology.int_links = int_links
1547058Snate@binkert.org    net_topology.ext_links = ext_links
1557058Snate@binkert.org
156396SN/A
1577058Snate@binkert.org    if options.network_fault_model:
1587058Snate@binkert.org        assert(options.garnet_network == "fixed")
1597058Snate@binkert.org        fault_model = FaultModel()
160396SN/A        network = NetworkClass(ruby_system = ruby, topology = net_topology,\
1617058Snate@binkert.org                               enable_fault_model=True, fault_model = fault_model)
1627058Snate@binkert.org    else:
1637058Snate@binkert.org        network = NetworkClass(ruby_system = ruby, topology = net_topology)
1644075Sbinkertn@umich.edu
1657058Snate@binkert.org    #
1667058Snate@binkert.org    # Loop through the directory controlers.
1675501Snate@binkert.org    # Determine the total memory size of the ruby system and verify it is equal
1687058Snate@binkert.org    # to physmem.  However, if Ruby memory is using sparse memory in SE
1697058Snate@binkert.org    # mode, then the system should not back-up the memory state with
1707058Snate@binkert.org    # the Memory Vector and thus the memory size bytes should stay at 0.
1717058Snate@binkert.org    # Also set the numa bits to the appropriate values.
1727058Snate@binkert.org    #
1737058Snate@binkert.org    total_mem_size = MemorySize('0B')
1749983Sstever@gmail.com
1759983Sstever@gmail.com    dir_bits = int(math.log(options.num_dirs, 2))
1769983Sstever@gmail.com    ruby.block_size_bytes = options.cacheline_size
1779983Sstever@gmail.com    block_size_bits = int(math.log(options.cacheline_size, 2))
1789983Sstever@gmail.com
1799983Sstever@gmail.com    if options.numa_high_bit:
1809983Sstever@gmail.com        numa_bit = options.numa_high_bit
1819983Sstever@gmail.com    else:
1829983Sstever@gmail.com        # if the numa_bit is not specified, set the directory bits as the
1839983Sstever@gmail.com        # lowest bits above the block offset bits, and the numa_bit as the
1849983Sstever@gmail.com        # highest of those directory bits
1859983Sstever@gmail.com        numa_bit = block_size_bits + dir_bits - 1
1869983Sstever@gmail.com
1879983Sstever@gmail.com    for dir_cntrl in dir_cntrls:
1889983Sstever@gmail.com        total_mem_size.value += dir_cntrl.directory.size.value
1899983Sstever@gmail.com        dir_cntrl.directory.numa_high_bit = numa_bit
1909983Sstever@gmail.com
1919983Sstever@gmail.com    phys_mem_size = sum(map(lambda mem: mem.range.size(),
1929983Sstever@gmail.com                            system.memories.unproxy(system)))
1939983Sstever@gmail.com    assert(total_mem_size.value == phys_mem_size)
1949983Sstever@gmail.com
1959983Sstever@gmail.com    ruby_profiler = RubyProfiler(ruby_system = ruby,
1969983Sstever@gmail.com                                 num_of_sequencers = len(cpu_sequencers))
1979983Sstever@gmail.com    ruby.network = network
1989983Sstever@gmail.com    ruby.profiler = ruby_profiler
1999983Sstever@gmail.com    ruby.mem_size = total_mem_size
2009983Sstever@gmail.com    ruby._cpu_ruby_ports = cpu_sequencers
2019983Sstever@gmail.com    ruby.random_seed    = options.random_seed
2029983Sstever@gmail.com