Ruby.py revision 9791:39c75548bcd4
1# Copyright (c) 2012 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license 9# terms below provided that you ensure that this notice is replicated 10# unmodified and in its entirety in all distributions of the software, 11# modified or unmodified, in source code or in binary form. 12# 13# Copyright (c) 2006-2007 The Regents of The University of Michigan 14# Copyright (c) 2009 Advanced Micro Devices, Inc. 15# All rights reserved. 16# 17# Redistribution and use in source and binary forms, with or without 18# modification, are permitted provided that the following conditions are 19# met: redistributions of source code must retain the above copyright 20# notice, this list of conditions and the following disclaimer; 21# redistributions in binary form must reproduce the above copyright 22# notice, this list of conditions and the following disclaimer in the 23# documentation and/or other materials provided with the distribution; 24# neither the name of the copyright holders nor the names of its 25# contributors may be used to endorse or promote products derived from 26# this software without specific prior written permission. 27# 28# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39# 40# Authors: Brad Beckmann 41 42import math 43import m5 44from m5.objects import * 45from m5.defines import buildEnv 46 47def define_options(parser): 48 # By default, ruby uses the simple timing cpu 49 parser.set_defaults(cpu_type="timing") 50 51 parser.add_option("--ruby-clock", action="store", type="string", 52 default='2GHz', 53 help="Clock for blocks running at Ruby system's speed") 54 55 # ruby network options 56 parser.add_option("--topology", type="string", default="Crossbar", 57 help="check src/mem/ruby/network/topologies for complete set") 58 parser.add_option("--mesh-rows", type="int", default=1, 59 help="the number of rows in the mesh topology") 60 parser.add_option("--garnet-network", type="choice", 61 choices=['fixed', 'flexible'], help="'fixed'|'flexible'") 62 parser.add_option("--network-fault-model", action="store_true", default=False, 63 help="enable network fault model: see src/mem/ruby/network/fault_model/") 64 65 # ruby mapping options 66 parser.add_option("--numa-high-bit", type="int", default=0, 67 help="high order address bit to use for numa mapping. " \ 68 "0 = highest bit, not specified = lowest bit") 69 70 # ruby sparse memory options 71 parser.add_option("--use-map", action="store_true", default=False) 72 parser.add_option("--map-levels", type="int", default=4) 73 74 parser.add_option("--recycle-latency", type="int", default=10, 75 help="Recycle latency for ruby controller input buffers") 76 77 parser.add_option("--random_seed", type="int", default=1234, 78 help="Used for seeding the random number generator") 79 80 parser.add_option("--ruby_stats", type="string", default="ruby.stats") 81 82 protocol = buildEnv['PROTOCOL'] 83 exec "import %s" % protocol 84 eval("%s.define_options(parser)" % protocol) 85 86def create_topology(controllers, options): 87 """ Called from create_system in configs/ruby/<protocol>.py 88 Must return an object which is a subclass of BaseTopology 89 found in configs/topologies/BaseTopology.py 90 This is a wrapper for the legacy topologies. 91 """ 92 exec "import %s as Topo" % options.topology 93 topology = eval("Topo.%s(controllers)" % options.topology) 94 return topology 95 96def create_system(options, system, piobus = None, dma_ports = []): 97 98 system.ruby = RubySystem(clock = options.ruby_clock, 99 stats_filename = options.ruby_stats, 100 no_mem_vec = options.use_map) 101 ruby = system.ruby 102 103 protocol = buildEnv['PROTOCOL'] 104 exec "import %s" % protocol 105 try: 106 (cpu_sequencers, dir_cntrls, topology) = \ 107 eval("%s.create_system(options, system, piobus, dma_ports, ruby)" 108 % protocol) 109 except: 110 print "Error: could not create sytem for ruby protocol %s" % protocol 111 raise 112 113 # Create a port proxy for connecting the system port. This is 114 # independent of the protocol and kept in the protocol-agnostic 115 # part (i.e. here). 116 sys_port_proxy = RubyPortProxy(ruby_system = ruby) 117 # Give the system port proxy a SimObject parent without creating a 118 # full-fledged controller 119 system.sys_port_proxy = sys_port_proxy 120 121 # Connect the system port for loading of binaries etc 122 system.system_port = system.sys_port_proxy.slave 123 124 125 # 126 # Set the network classes based on the command line options 127 # 128 if options.garnet_network == "fixed": 129 class NetworkClass(GarnetNetwork_d): pass 130 class IntLinkClass(GarnetIntLink_d): pass 131 class ExtLinkClass(GarnetExtLink_d): pass 132 class RouterClass(GarnetRouter_d): pass 133 elif options.garnet_network == "flexible": 134 class NetworkClass(GarnetNetwork): pass 135 class IntLinkClass(GarnetIntLink): pass 136 class ExtLinkClass(GarnetExtLink): pass 137 class RouterClass(GarnetRouter): pass 138 else: 139 class NetworkClass(SimpleNetwork): pass 140 class IntLinkClass(SimpleIntLink): pass 141 class ExtLinkClass(SimpleExtLink): pass 142 class RouterClass(Switch): pass 143 144 # 145 # Important: the topology must be instantiated before the network and after 146 # the controllers. Hence the separation between topology definition and 147 # instantiation. 148 # 149 150 routers, int_links, ext_links = topology.makeTopology(options, 151 IntLinkClass, ExtLinkClass, RouterClass) 152 network = NetworkClass(ruby_system = ruby, routers = routers, 153 int_links = int_links, ext_links = ext_links, 154 topology = topology.description) 155 156 if options.network_fault_model: 157 assert(options.garnet_network == "fixed") 158 network.enable_fault_model = True 159 network.fault_model = FaultModel() 160 161 # 162 # Loop through the directory controlers. 163 # Determine the total memory size of the ruby system and verify it is equal 164 # to physmem. However, if Ruby memory is using sparse memory in SE 165 # mode, then the system should not back-up the memory state with 166 # the Memory Vector and thus the memory size bytes should stay at 0. 167 # Also set the numa bits to the appropriate values. 168 # 169 total_mem_size = MemorySize('0B') 170 171 dir_bits = int(math.log(options.num_dirs, 2)) 172 ruby.block_size_bytes = options.cacheline_size 173 block_size_bits = int(math.log(options.cacheline_size, 2)) 174 175 if options.numa_high_bit: 176 numa_bit = options.numa_high_bit 177 else: 178 # if the numa_bit is not specified, set the directory bits as the 179 # lowest bits above the block offset bits, and the numa_bit as the 180 # highest of those directory bits 181 numa_bit = block_size_bits + dir_bits - 1 182 183 for dir_cntrl in dir_cntrls: 184 total_mem_size.value += dir_cntrl.directory.size.value 185 dir_cntrl.directory.numa_high_bit = numa_bit 186 187 phys_mem_size = sum(map(lambda mem: mem.range.size(), 188 system.memories.unproxy(system))) 189 assert(total_mem_size.value == phys_mem_size) 190 191 ruby_profiler = RubyProfiler(ruby_system = ruby, 192 num_of_sequencers = len(cpu_sequencers)) 193 ruby.network = network 194 ruby.profiler = ruby_profiler 195 ruby.mem_size = total_mem_size 196 ruby._cpu_ruby_ports = cpu_sequencers 197 ruby.random_seed = options.random_seed 198