Ruby.py revision 12976:125099a94768
12199SN/A# Copyright (c) 2012, 2017-2018 ARM Limited
22199SN/A# All rights reserved.
32199SN/A#
42199SN/A# The license below extends only to copyright in the software and shall
52199SN/A# not be construed as granting a license to any other intellectual
62199SN/A# property including but not limited to intellectual property relating
72199SN/A# to a hardware implementation of the functionality of the software
82199SN/A# licensed hereunder.  You may use the software subject to the license
92199SN/A# terms below provided that you ensure that this notice is replicated
102199SN/A# unmodified and in its entirety in all distributions of the software,
112199SN/A# modified or unmodified, in source code or in binary form.
122199SN/A#
132199SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
142199SN/A# Copyright (c) 2009 Advanced Micro Devices, Inc.
152199SN/A# All rights reserved.
162199SN/A#
172199SN/A# Redistribution and use in source and binary forms, with or without
182199SN/A# modification, are permitted provided that the following conditions are
192199SN/A# met: redistributions of source code must retain the above copyright
202199SN/A# notice, this list of conditions and the following disclaimer;
212199SN/A# redistributions in binary form must reproduce the above copyright
222199SN/A# notice, this list of conditions and the following disclaimer in the
232199SN/A# documentation and/or other materials provided with the distribution;
242199SN/A# neither the name of the copyright holders nor the names of its
252199SN/A# contributors may be used to endorse or promote products derived from
262199SN/A# this software without specific prior written permission.
272665Ssaidi@eecs.umich.edu#
282665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292199SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302199SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312202SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322202SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332199SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342584SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352980Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362474SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372199SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382199SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392474SN/A#
402199SN/A# Authors: Brad Beckmann
414111Sgblack@eecs.umich.edu
424111Sgblack@eecs.umich.edufrom __future__ import print_function
434111Sgblack@eecs.umich.edu
444111Sgblack@eecs.umich.eduimport math
454111Sgblack@eecs.umich.eduimport m5
464111Sgblack@eecs.umich.edufrom m5.objects import *
474111Sgblack@eecs.umich.edufrom m5.defines import buildEnv
484111Sgblack@eecs.umich.edufrom m5.util import addToPath, fatal
494111Sgblack@eecs.umich.edu
504111Sgblack@eecs.umich.edufrom common import MemConfig
514111Sgblack@eecs.umich.edu
524188Sgblack@eecs.umich.edufrom topologies import *
534188Sgblack@eecs.umich.edufrom network import Network
544188Sgblack@eecs.umich.edu
554188Sgblack@eecs.umich.edudef define_options(parser):
564111Sgblack@eecs.umich.edu    # By default, ruby uses the simple timing cpu
574188Sgblack@eecs.umich.edu    parser.set_defaults(cpu_type="TimingSimpleCPU")
584111Sgblack@eecs.umich.edu
594111Sgblack@eecs.umich.edu    parser.add_option("--ruby-clock", action="store", type="string",
604188Sgblack@eecs.umich.edu                      default='2GHz',
614111Sgblack@eecs.umich.edu                      help="Clock for blocks running at Ruby system's speed")
624111Sgblack@eecs.umich.edu
632202SN/A    parser.add_option("--access-backing-store", action="store_true", default=False,
644111Sgblack@eecs.umich.edu                      help="Should ruby maintain a second copy of memory")
652199SN/A
662199SN/A    # Options related to cache structure
672199SN/A    parser.add_option("--ports", action="store", type="int", default=4,
685154Sgblack@eecs.umich.edu                      help="used of transitions per cycle which is a proxy \
692199SN/A                            for the number of ports.")
704111Sgblack@eecs.umich.edu
714111Sgblack@eecs.umich.edu    # network options are in network/Network.py
724188Sgblack@eecs.umich.edu
734111Sgblack@eecs.umich.edu    # ruby mapping options
742199SN/A    parser.add_option("--numa-high-bit", type="int", default=0,
754111Sgblack@eecs.umich.edu                      help="high order address bit to use for numa mapping. " \
764111Sgblack@eecs.umich.edu                           "0 = highest bit, not specified = lowest bit")
772199SN/A
784111Sgblack@eecs.umich.edu    parser.add_option("--recycle-latency", type="int", default=10,
794111Sgblack@eecs.umich.edu                      help="Recycle latency for ruby controller input buffers")
804111Sgblack@eecs.umich.edu
814111Sgblack@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
824111Sgblack@eecs.umich.edu    exec "import %s" % protocol
835154Sgblack@eecs.umich.edu    eval("%s.define_options(parser)" % protocol)
842199SN/A    Network.define_options(parser)
854111Sgblack@eecs.umich.edu
864111Sgblack@eecs.umich.edudef setup_memory_controllers(system, ruby, dir_cntrls, options):
874111Sgblack@eecs.umich.edu    ruby.block_size_bytes = options.cacheline_size
884111Sgblack@eecs.umich.edu    ruby.memory_size_bits = 48
894111Sgblack@eecs.umich.edu
904111Sgblack@eecs.umich.edu    index = 0
912199SN/A    mem_ctrls = []
922199SN/A    crossbars = []
932561SN/A
943114Sgblack@eecs.umich.edu    if options.numa_high_bit:
952561SN/A        dir_bits = int(math.log(options.num_dirs, 2))
962474SN/A        intlv_size = 2 ** (options.numa_high_bit - dir_bits + 1)
974111Sgblack@eecs.umich.edu    else:
98        # if the numa_bit is not specified, set the directory bits as the
99        # lowest bits above the block offset bits
100        intlv_size = options.cacheline_size
101
102    # Sets bits to be used for interleaving.  Creates memory controllers
103    # attached to a directory controller.  A separate controller is created
104    # for each address range as the abstract memory can handle only one
105    # contiguous address range as of now.
106    for dir_cntrl in dir_cntrls:
107        crossbar = None
108        if len(system.mem_ranges) > 1:
109            crossbar = IOXBar()
110            crossbars.append(crossbar)
111            dir_cntrl.memory = crossbar.slave
112
113        dir_ranges = []
114        for r in system.mem_ranges:
115            mem_ctrl = MemConfig.create_mem_ctrl(
116                MemConfig.get(options.mem_type), r, index, options.num_dirs,
117                int(math.log(options.num_dirs, 2)), intlv_size)
118
119            if options.access_backing_store:
120                mem_ctrl.kvm_map=False
121
122            mem_ctrls.append(mem_ctrl)
123            dir_ranges.append(mem_ctrl.range)
124
125            if crossbar != None:
126                mem_ctrl.port = crossbar.master
127            else:
128                mem_ctrl.port = dir_cntrl.memory
129
130        index += 1
131        dir_cntrl.addr_ranges = dir_ranges
132
133    system.mem_ctrls = mem_ctrls
134
135    if len(crossbars) > 0:
136        ruby.crossbars = crossbars
137
138
139def create_topology(controllers, options):
140    """ Called from create_system in configs/ruby/<protocol>.py
141        Must return an object which is a subclass of BaseTopology
142        found in configs/topologies/BaseTopology.py
143        This is a wrapper for the legacy topologies.
144    """
145    exec "import topologies.%s as Topo" % options.topology
146    topology = eval("Topo.%s(controllers)" % options.topology)
147    return topology
148
149def create_system(options, full_system, system, piobus = None, dma_ports = [],
150                  bootmem=None):
151
152    system.ruby = RubySystem()
153    ruby = system.ruby
154
155    # Create the network object
156    (network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass) = \
157        Network.create_network(options, ruby)
158    ruby.network = network
159
160    protocol = buildEnv['PROTOCOL']
161    exec "import %s" % protocol
162    try:
163        (cpu_sequencers, dir_cntrls, topology) = \
164             eval("%s.create_system(options, full_system, system, dma_ports,\
165                                    bootmem, ruby)"
166                  % protocol)
167    except:
168        print("Error: could not create sytem for ruby protocol %s" % protocol)
169        raise
170
171    # Create the network topology
172    topology.makeTopology(options, network, IntLinkClass, ExtLinkClass,
173            RouterClass)
174
175    # Initialize network based on topology
176    Network.init_network(options, network, InterfaceClass)
177
178    # Create a port proxy for connecting the system port. This is
179    # independent of the protocol and kept in the protocol-agnostic
180    # part (i.e. here).
181    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
182    if piobus is not None:
183        sys_port_proxy.pio_master_port = piobus.slave
184
185    # Give the system port proxy a SimObject parent without creating a
186    # full-fledged controller
187    system.sys_port_proxy = sys_port_proxy
188
189    # Connect the system port for loading of binaries etc
190    system.system_port = system.sys_port_proxy.slave
191
192    setup_memory_controllers(system, ruby, dir_cntrls, options)
193
194    # Connect the cpu sequencers and the piobus
195    if piobus != None:
196        for cpu_seq in cpu_sequencers:
197            cpu_seq.pio_master_port = piobus.slave
198            cpu_seq.mem_master_port = piobus.slave
199
200            if buildEnv['TARGET_ISA'] == "x86":
201                cpu_seq.pio_slave_port = piobus.master
202
203    ruby.number_of_virtual_networks = ruby.network.number_of_virtual_networks
204    ruby._cpu_ports = cpu_sequencers
205    ruby.num_of_sequencers = len(cpu_sequencers)
206
207    # Create a backing copy of physical memory in case required
208    if options.access_backing_store:
209        ruby.access_backing_store = True
210        ruby.phys_mem = SimpleMemory(range=system.mem_ranges[0],
211                                     in_addr_map=False)
212
213def create_directories(options, bootmem, ruby_system, system):
214    dir_cntrl_nodes = []
215    for i in xrange(options.num_dirs):
216        dir_cntrl = Directory_Controller()
217        dir_cntrl.version = i
218        dir_cntrl.directory = RubyDirectoryMemory()
219        dir_cntrl.ruby_system = ruby_system
220
221        exec("ruby_system.dir_cntrl%d = dir_cntrl" % i)
222        dir_cntrl_nodes.append(dir_cntrl)
223
224    if bootmem is not None:
225        rom_dir_cntrl = Directory_Controller()
226        rom_dir_cntrl.directory = RubyDirectoryMemory()
227        rom_dir_cntrl.ruby_system = ruby_system
228        rom_dir_cntrl.version = i + 1
229        rom_dir_cntrl.memory = bootmem.port
230        rom_dir_cntrl.addr_ranges = bootmem.range
231        return (dir_cntrl_nodes, rom_dir_cntrl)
232
233    return (dir_cntrl_nodes, None)
234
235def send_evicts(options):
236    # currently, 2 scenarios warrant forwarding evictions to the CPU:
237    # 1. The O3 model must keep the LSQ coherent with the caches
238    # 2. The x86 mwait instruction is built on top of coherence invalidations
239    # 3. The local exclusive monitor in ARM systems
240    if options.cpu_type == "DerivO3CPU" or \
241       buildEnv['TARGET_ISA'] in ('x86', 'arm'):
242        return True
243    return False
244