Ruby.py revision 13400:cf74d21e948f
16019SN/A# Copyright (c) 2012, 2017-2018 ARM Limited
26019SN/A# All rights reserved.
37102SN/A#
47102SN/A# The license below extends only to copyright in the software and shall
57102SN/A# not be construed as granting a license to any other intellectual
67102SN/A# property including but not limited to intellectual property relating
77102SN/A# to a hardware implementation of the functionality of the software
87102SN/A# licensed hereunder.  You may use the software subject to the license
97102SN/A# terms below provided that you ensure that this notice is replicated
107102SN/A# unmodified and in its entirety in all distributions of the software,
117102SN/A# modified or unmodified, in source code or in binary form.
127102SN/A#
137102SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
147102SN/A# Copyright (c) 2009 Advanced Micro Devices, Inc.
156019SN/A# All rights reserved.
166019SN/A#
176019SN/A# Redistribution and use in source and binary forms, with or without
186019SN/A# modification, are permitted provided that the following conditions are
196019SN/A# met: redistributions of source code must retain the above copyright
206019SN/A# notice, this list of conditions and the following disclaimer;
216019SN/A# redistributions in binary form must reproduce the above copyright
226019SN/A# notice, this list of conditions and the following disclaimer in the
236019SN/A# documentation and/or other materials provided with the distribution;
246019SN/A# neither the name of the copyright holders nor the names of its
256019SN/A# contributors may be used to endorse or promote products derived from
266019SN/A# this software without specific prior written permission.
276019SN/A#
286019SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296019SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306019SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316019SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326019SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336019SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346019SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356019SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366019SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376019SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386019SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396019SN/A#
406019SN/A# Authors: Brad Beckmann
416019SN/A
426019SN/Afrom __future__ import print_function
436019SN/A
446019SN/Aimport math
456019SN/Aimport m5
466019SN/Afrom m5.objects import *
476019SN/Afrom m5.defines import buildEnv
486019SN/Afrom m5.util import addToPath, fatal
496019SN/A
506019SN/AaddToPath('../')
516019SN/A
526310SN/Afrom common import MemConfig
537102SN/A
546268SN/Afrom topologies import *
556268SN/Afrom network import Network
566268SN/A
576268SN/Adef define_options(parser):
586268SN/A    # By default, ruby uses the simple timing cpu
596276SN/A    parser.set_defaults(cpu_type="TimingSimpleCPU")
606280SN/A
616268SN/A    parser.add_option("--ruby-clock", action="store", type="string",
626268SN/A                      default='2GHz',
636268SN/A                      help="Clock for blocks running at Ruby system's speed")
646268SN/A
656268SN/A    parser.add_option("--access-backing-store", action="store_true", default=False,
666741SN/A                      help="Should ruby maintain a second copy of memory")
677102SN/A
687102SN/A    # Options related to cache structure
697102SN/A    parser.add_option("--ports", action="store", type="int", default=4,
706741SN/A                      help="used of transitions per cycle which is a proxy \
716741SN/A                            for the number of ports.")
726741SN/A
736268SN/A    # network options are in network/Network.py
746272SN/A
756272SN/A    # ruby mapping options
766268SN/A    parser.add_option("--numa-high-bit", type="int", default=0,
776268SN/A                      help="high order address bit to use for numa mapping. " \
786741SN/A                           "0 = highest bit, not specified = lowest bit")
796268SN/A
806268SN/A    parser.add_option("--recycle-latency", type="int", default=10,
816268SN/A                      help="Recycle latency for ruby controller input buffers")
826268SN/A
836268SN/A    protocol = buildEnv['PROTOCOL']
846741SN/A    exec "import %s" % protocol
856019SN/A    eval("%s.define_options(parser)" % protocol)
866268SN/A    Network.define_options(parser)
876268SN/A
886268SN/Adef setup_memory_controllers(system, ruby, dir_cntrls, options):
896268SN/A    ruby.block_size_bytes = options.cacheline_size
906268SN/A    ruby.memory_size_bits = 48
916019SN/A
926019SN/A    index = 0
937129Sgblack@eecs.umich.edu    mem_ctrls = []
946019SN/A    crossbars = []
956268SN/A
967139Sgblack@eecs.umich.edu    if options.numa_high_bit:
976268SN/A        dir_bits = int(math.log(options.num_dirs, 2))
986268SN/A        intlv_size = 2 ** (options.numa_high_bit - dir_bits + 1)
996747SN/A    else:
1006747SN/A        # if the numa_bit is not specified, set the directory bits as the
1016747SN/A        # lowest bits above the block offset bits
1026751SN/A        intlv_size = options.cacheline_size
1036751SN/A
1046753SN/A    # Sets bits to be used for interleaving.  Creates memory controllers
1056753SN/A    # attached to a directory controller.  A separate controller is created
1066753SN/A    # for each address range as the abstract memory can handle only one
1076753SN/A    # contiguous address range as of now.
1086753SN/A    for dir_cntrl in dir_cntrls:
1096753SN/A        crossbar = None
1106753SN/A        if len(system.mem_ranges) > 1:
1116753SN/A            crossbar = IOXBar()
1126751SN/A            crossbars.append(crossbar)
1136751SN/A            dir_cntrl.memory = crossbar.slave
1146751SN/A
1156751SN/A        dir_ranges = []
1166751SN/A        for r in system.mem_ranges:
1176751SN/A            mem_ctrl = MemConfig.create_mem_ctrl(
1186751SN/A                MemConfig.get(options.mem_type), r, index, options.num_dirs,
1196747SN/A                int(math.log(options.num_dirs, 2)), intlv_size)
1206751SN/A
1216751SN/A            if options.access_backing_store:
1226753SN/A                mem_ctrl.kvm_map=False
1236753SN/A
1246753SN/A            mem_ctrls.append(mem_ctrl)
1256753SN/A            dir_ranges.append(mem_ctrl.range)
1266751SN/A
1276751SN/A            if crossbar != None:
1286751SN/A                mem_ctrl.port = crossbar.master
1296751SN/A            else:
1306268SN/A                mem_ctrl.port = dir_cntrl.memory
1316268SN/A
1326268SN/A        index += 1
1336268SN/A        dir_cntrl.addr_ranges = dir_ranges
1346402SN/A
1356268SN/A    system.mem_ctrls = mem_ctrls
1366268SN/A
1376268SN/A    if len(crossbars) > 0:
1386268SN/A        ruby.crossbars = crossbars
1396268SN/A
1406268SN/A
1416268SN/Adef create_topology(controllers, options):
1426268SN/A    """ Called from create_system in configs/ruby/<protocol>.py
1436268SN/A        Must return an object which is a subclass of BaseTopology
1446268SN/A        found in configs/topologies/BaseTopology.py
1456268SN/A        This is a wrapper for the legacy topologies.
1466268SN/A    """
1476268SN/A    exec "import topologies.%s as Topo" % options.topology
1486268SN/A    topology = eval("Topo.%s(controllers)" % options.topology)
1496268SN/A    return topology
1506741SN/A
1516268SN/Adef create_system(options, full_system, system, piobus = None, dma_ports = [],
1526268SN/A                  bootmem=None):
1536741SN/A
1546268SN/A    system.ruby = RubySystem()
1556268SN/A    ruby = system.ruby
1566741SN/A
1577102SN/A    # Create the network object
1587102SN/A    (network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass) = \
1596741SN/A        Network.create_network(options, ruby)
1606268SN/A    ruby.network = network
1616741SN/A
1626268SN/A    protocol = buildEnv['PROTOCOL']
1636268SN/A    exec "import %s" % protocol
1646741SN/A    try:
1656268SN/A        (cpu_sequencers, dir_cntrls, topology) = \
1666268SN/A             eval("%s.create_system(options, full_system, system, dma_ports,\
1676741SN/A                                    bootmem, ruby)"
1686268SN/A                  % protocol)
1696268SN/A    except:
1706741SN/A        print("Error: could not create sytem for ruby protocol %s" % protocol)
1717102SN/A        raise
1727102SN/A
1736741SN/A    # Create the network topology
1746268SN/A    topology.makeTopology(options, network, IntLinkClass, ExtLinkClass,
1756741SN/A            RouterClass)
1766268SN/A
1776268SN/A    # Initialize network based on topology
1786268SN/A    Network.init_network(options, network, InterfaceClass)
1796268SN/A
1806268SN/A    # Create a port proxy for connecting the system port. This is
1817139Sgblack@eecs.umich.edu    # independent of the protocol and kept in the protocol-agnostic
1826268SN/A    # part (i.e. here).
1836268SN/A    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
1846741SN/A    if piobus is not None:
1856756SN/A        sys_port_proxy.pio_master_port = piobus.slave
1866756SN/A
1876756SN/A    # Give the system port proxy a SimObject parent without creating a
1886756SN/A    # full-fledged controller
1896756SN/A    system.sys_port_proxy = sys_port_proxy
1906756SN/A
1916756SN/A    # Connect the system port for loading of binaries etc
1926756SN/A    system.system_port = system.sys_port_proxy.slave
1936756SN/A
1946756SN/A    setup_memory_controllers(system, ruby, dir_cntrls, options)
1956756SN/A
1966756SN/A    # Connect the cpu sequencers and the piobus
1976756SN/A    if piobus != None:
1986756SN/A        for cpu_seq in cpu_sequencers:
1996756SN/A            cpu_seq.pio_master_port = piobus.slave
2006756SN/A            cpu_seq.mem_master_port = piobus.slave
2016756SN/A
2026756SN/A            if buildEnv['TARGET_ISA'] == "x86":
2037102SN/A                cpu_seq.pio_slave_port = piobus.master
2046741SN/A
2056019SN/A    ruby.number_of_virtual_networks = ruby.network.number_of_virtual_networks
2066268SN/A    ruby._cpu_ports = cpu_sequencers
2077120Sgblack@eecs.umich.edu    ruby.num_of_sequencers = len(cpu_sequencers)
2086268SN/A
2097120Sgblack@eecs.umich.edu    # Create a backing copy of physical memory in case required
2106269SN/A    if options.access_backing_store:
2116269SN/A        ruby.access_backing_store = True
2126269SN/A        ruby.phys_mem = SimpleMemory(range=system.mem_ranges[0],
2136269SN/A                                     in_addr_map=False)
2146269SN/A
2156269SN/Adef create_directories(options, bootmem, ruby_system, system):
2166269SN/A    dir_cntrl_nodes = []
2176269SN/A    for i in xrange(options.num_dirs):
2186269SN/A        dir_cntrl = Directory_Controller()
2196269SN/A        dir_cntrl.version = i
2206269SN/A        dir_cntrl.directory = RubyDirectoryMemory()
2216269SN/A        dir_cntrl.ruby_system = ruby_system
2226269SN/A
2236269SN/A        exec("ruby_system.dir_cntrl%d = dir_cntrl" % i)
2246269SN/A        dir_cntrl_nodes.append(dir_cntrl)
2256269SN/A
2266269SN/A    if bootmem is not None:
2276269SN/A        rom_dir_cntrl = Directory_Controller()
2286269SN/A        rom_dir_cntrl.directory = RubyDirectoryMemory()
2296269SN/A        rom_dir_cntrl.ruby_system = ruby_system
2306269SN/A        rom_dir_cntrl.version = i + 1
2316269SN/A        rom_dir_cntrl.memory = bootmem.port
2326269SN/A        rom_dir_cntrl.addr_ranges = bootmem.range
2336269SN/A        return (dir_cntrl_nodes, rom_dir_cntrl)
2346269SN/A
2356269SN/A    return (dir_cntrl_nodes, None)
2366269SN/A
2376269SN/Adef send_evicts(options):
2386269SN/A    # currently, 2 scenarios warrant forwarding evictions to the CPU:
2396269SN/A    # 1. The O3 model must keep the LSQ coherent with the caches
2406269SN/A    # 2. The x86 mwait instruction is built on top of coherence invalidations
2416269SN/A    # 3. The local exclusive monitor in ARM systems
2426269SN/A    if options.cpu_type == "DerivO3CPU" or \
2436269SN/A       buildEnv['TARGET_ISA'] in ('x86', 'arm'):
2446269SN/A        return True
2456269SN/A    return False
2466269SN/A