Ruby.py revision 9593:9441ca79f3c8
111723Sar4jc@virginia.edu# Copyright (c) 2012 ARM Limited 211723Sar4jc@virginia.edu# All rights reserved. 311723Sar4jc@virginia.edu# 412808Srobert.scheffel1@tu-dresden.de# The license below extends only to copyright in the software and shall 511723Sar4jc@virginia.edu# not be construed as granting a license to any other intellectual 611723Sar4jc@virginia.edu# property including but not limited to intellectual property relating 711723Sar4jc@virginia.edu# to a hardware implementation of the functionality of the software 811723Sar4jc@virginia.edu# licensed hereunder. You may use the software subject to the license 911723Sar4jc@virginia.edu# terms below provided that you ensure that this notice is replicated 1011723Sar4jc@virginia.edu# unmodified and in its entirety in all distributions of the software, 1111723Sar4jc@virginia.edu# modified or unmodified, in source code or in binary form. 1211723Sar4jc@virginia.edu# 1311723Sar4jc@virginia.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan 1411723Sar4jc@virginia.edu# Copyright (c) 2009 Advanced Micro Devices, Inc. 1511723Sar4jc@virginia.edu# All rights reserved. 1611723Sar4jc@virginia.edu# 1711723Sar4jc@virginia.edu# Redistribution and use in source and binary forms, with or without 1811723Sar4jc@virginia.edu# modification, are permitted provided that the following conditions are 1911723Sar4jc@virginia.edu# met: redistributions of source code must retain the above copyright 2011723Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer; 2111723Sar4jc@virginia.edu# redistributions in binary form must reproduce the above copyright 2211723Sar4jc@virginia.edu# notice, this list of conditions and the following disclaimer in the 2311723Sar4jc@virginia.edu# documentation and/or other materials provided with the distribution; 2411723Sar4jc@virginia.edu# neither the name of the copyright holders nor the names of its 2511723Sar4jc@virginia.edu# contributors may be used to endorse or promote products derived from 2611723Sar4jc@virginia.edu# this software without specific prior written permission. 2711723Sar4jc@virginia.edu# 2811723Sar4jc@virginia.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2911723Sar4jc@virginia.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3011723Sar4jc@virginia.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3112808Srobert.scheffel1@tu-dresden.de# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3211723Sar4jc@virginia.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3311723Sar4jc@virginia.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3411723Sar4jc@virginia.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3512848Sar4jc@virginia.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3612848Sar4jc@virginia.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3712808Srobert.scheffel1@tu-dresden.de# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3811723Sar4jc@virginia.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3912808Srobert.scheffel1@tu-dresden.de# 4011723Sar4jc@virginia.edu# Authors: Brad Beckmann 4111723Sar4jc@virginia.edu 4211723Sar4jc@virginia.eduimport math 4311723Sar4jc@virginia.eduimport m5 4412848Sar4jc@virginia.edufrom m5.objects import * 4512848Sar4jc@virginia.edufrom m5.defines import buildEnv 4611723Sar4jc@virginia.edu 4711723Sar4jc@virginia.edudef define_options(parser): 4812848Sar4jc@virginia.edu # By default, ruby uses the simple timing cpu 4911723Sar4jc@virginia.edu parser.set_defaults(cpu_type="timing") 5011723Sar4jc@virginia.edu 5111723Sar4jc@virginia.edu # ruby network options 5211723Sar4jc@virginia.edu parser.add_option("--topology", type="string", default="Crossbar", 5311723Sar4jc@virginia.edu help="check src/mem/ruby/network/topologies for complete set") 5411723Sar4jc@virginia.edu parser.add_option("--mesh-rows", type="int", default=1, 5511723Sar4jc@virginia.edu help="the number of rows in the mesh topology") 5612848Sar4jc@virginia.edu parser.add_option("--garnet-network", type="choice", 5712848Sar4jc@virginia.edu choices=['fixed', 'flexible'], help="'fixed'|'flexible'") 5811723Sar4jc@virginia.edu parser.add_option("--network-fault-model", action="store_true", default=False, 5912848Sar4jc@virginia.edu help="enable network fault model: see src/mem/ruby/network/fault_model/") 6012848Sar4jc@virginia.edu 6112848Sar4jc@virginia.edu # ruby mapping options 6212848Sar4jc@virginia.edu parser.add_option("--numa-high-bit", type="int", default=0, 6312848Sar4jc@virginia.edu help="high order address bit to use for numa mapping. " \ 6413548Salec.roelke@gmail.com "0 = highest bit, not specified = lowest bit") 6513548Salec.roelke@gmail.com 6613548Salec.roelke@gmail.com # ruby sparse memory options 6713548Salec.roelke@gmail.com parser.add_option("--use-map", action="store_true", default=False) 6813548Salec.roelke@gmail.com parser.add_option("--map-levels", type="int", default=4) 6913548Salec.roelke@gmail.com 7013548Salec.roelke@gmail.com parser.add_option("--recycle-latency", type="int", default=10, 7113548Salec.roelke@gmail.com help="Recycle latency for ruby controller input buffers") 7213548Salec.roelke@gmail.com 7313548Salec.roelke@gmail.com parser.add_option("--random_seed", type="int", default=1234, 7413548Salec.roelke@gmail.com help="Used for seeding the random number generator") 7513548Salec.roelke@gmail.com 7613548Salec.roelke@gmail.com parser.add_option("--ruby_stats", type="string", default="ruby.stats") 7713548Salec.roelke@gmail.com 7813548Salec.roelke@gmail.com protocol = buildEnv['PROTOCOL'] 7913548Salec.roelke@gmail.com exec "import %s" % protocol 8013548Salec.roelke@gmail.com eval("%s.define_options(parser)" % protocol) 8113548Salec.roelke@gmail.com 8212848Sar4jc@virginia.edudef create_topology(controllers, options): 8312848Sar4jc@virginia.edu """ Called from create_system in configs/ruby/<protocol>.py 8412848Sar4jc@virginia.edu Must return an object which is a subclass of BaseTopology 8512849Sar4jc@virginia.edu found in configs/topologies/BaseTopology.py 8612848Sar4jc@virginia.edu This is a wrapper for the legacy topologies. 8712848Sar4jc@virginia.edu """ 8812848Sar4jc@virginia.edu exec "import %s as Topo" % options.topology 8912848Sar4jc@virginia.edu topology = eval("Topo.%s(controllers)" % options.topology) 9012848Sar4jc@virginia.edu return topology 9112849Sar4jc@virginia.edu 9212848Sar4jc@virginia.edudef create_system(options, system, piobus = None, dma_ports = []): 9312848Sar4jc@virginia.edu 9412848Sar4jc@virginia.edu system.ruby = RubySystem(clock = options.clock, 9512848Sar4jc@virginia.edu stats_filename = options.ruby_stats, 9612848Sar4jc@virginia.edu no_mem_vec = options.use_map) 9712848Sar4jc@virginia.edu ruby = system.ruby 9812848Sar4jc@virginia.edu 9912848Sar4jc@virginia.edu protocol = buildEnv['PROTOCOL'] 10012849Sar4jc@virginia.edu exec "import %s" % protocol 10112848Sar4jc@virginia.edu try: 10212848Sar4jc@virginia.edu (cpu_sequencers, dir_cntrls, topology) = \ 10312848Sar4jc@virginia.edu eval("%s.create_system(options, system, piobus, dma_ports, ruby)" 10412848Sar4jc@virginia.edu % protocol) 10512848Sar4jc@virginia.edu except: 10612848Sar4jc@virginia.edu print "Error: could not create sytem for ruby protocol %s" % protocol 10712848Sar4jc@virginia.edu raise 10812848Sar4jc@virginia.edu 10912848Sar4jc@virginia.edu # Create a port proxy for connecting the system port. This is 11012849Sar4jc@virginia.edu # independent of the protocol and kept in the protocol-agnostic 11112848Sar4jc@virginia.edu # part (i.e. here). 11212848Sar4jc@virginia.edu sys_port_proxy = RubyPortProxy(ruby_system = ruby) 11312848Sar4jc@virginia.edu # Give the system port proxy a SimObject parent without creating a 11412848Sar4jc@virginia.edu # full-fledged controller 11512848Sar4jc@virginia.edu system.sys_port_proxy = sys_port_proxy 11612848Sar4jc@virginia.edu 11712848Sar4jc@virginia.edu # Connect the system port for loading of binaries etc 11812848Sar4jc@virginia.edu system.system_port = system.sys_port_proxy.slave 11912848Sar4jc@virginia.edu 12012848Sar4jc@virginia.edu 12112848Sar4jc@virginia.edu # 12212848Sar4jc@virginia.edu # Set the network classes based on the command line options 12313612Sgabeblack@google.com # 12412848Sar4jc@virginia.edu if options.garnet_network == "fixed": 12512849Sar4jc@virginia.edu class NetworkClass(GarnetNetwork_d): pass 12612848Sar4jc@virginia.edu class IntLinkClass(GarnetIntLink_d): pass 12712848Sar4jc@virginia.edu class ExtLinkClass(GarnetExtLink_d): pass 12812848Sar4jc@virginia.edu class RouterClass(GarnetRouter_d): pass 12912848Sar4jc@virginia.edu elif options.garnet_network == "flexible": 13013548Salec.roelke@gmail.com class NetworkClass(GarnetNetwork): pass 13113548Salec.roelke@gmail.com class IntLinkClass(GarnetIntLink): pass 13213548Salec.roelke@gmail.com class ExtLinkClass(GarnetExtLink): pass 13313548Salec.roelke@gmail.com class RouterClass(GarnetRouter): pass 13411723Sar4jc@virginia.edu else: 13512848Sar4jc@virginia.edu class NetworkClass(SimpleNetwork): pass 13611723Sar4jc@virginia.edu class IntLinkClass(SimpleIntLink): pass 13711723Sar4jc@virginia.edu class ExtLinkClass(SimpleExtLink): pass 13812848Sar4jc@virginia.edu class RouterClass(Switch): pass 13911723Sar4jc@virginia.edu 14011723Sar4jc@virginia.edu # 14112808Srobert.scheffel1@tu-dresden.de # Important: the topology must be instantiated before the network and after 14212808Srobert.scheffel1@tu-dresden.de # the controllers. Hence the separation between topology definition and 14313547Sar4jc@virginia.edu # instantiation. 14413547Sar4jc@virginia.edu # 14513547Sar4jc@virginia.edu # gem5 SimObject defined in src/mem/ruby/network/Network.py 14613547Sar4jc@virginia.edu net_topology = Topology() 14713547Sar4jc@virginia.edu net_topology.description = topology.description 14813547Sar4jc@virginia.edu 14913547Sar4jc@virginia.edu routers, int_links, ext_links = topology.makeTopology(options, 15012808Srobert.scheffel1@tu-dresden.de IntLinkClass, ExtLinkClass, RouterClass) 15112808Srobert.scheffel1@tu-dresden.de 15212808Srobert.scheffel1@tu-dresden.de net_topology.num_routers = len(routers) 15312808Srobert.scheffel1@tu-dresden.de net_topology.int_links = int_links 15412808Srobert.scheffel1@tu-dresden.de net_topology.ext_links = ext_links 15511723Sar4jc@virginia.edu 15612848Sar4jc@virginia.edu network = NetworkClass(ruby_system = ruby, topology = net_topology, 15711723Sar4jc@virginia.edu routers = routers) 15811723Sar4jc@virginia.edu 15911723Sar4jc@virginia.edu if options.network_fault_model: 16011723Sar4jc@virginia.edu assert(options.garnet_network == "fixed") 16111723Sar4jc@virginia.edu network.enable_fault_model = True 16211723Sar4jc@virginia.edu network.fault_model = FaultModel() 16312848Sar4jc@virginia.edu 16412136Sar4jc@virginia.edu # 16512136Sar4jc@virginia.edu # Loop through the directory controlers. 16612136Sar4jc@virginia.edu # Determine the total memory size of the ruby system and verify it is equal 16712136Sar4jc@virginia.edu # to physmem. However, if Ruby memory is using sparse memory in SE 16812136Sar4jc@virginia.edu # mode, then the system should not back-up the memory state with 16912136Sar4jc@virginia.edu # the Memory Vector and thus the memory size bytes should stay at 0. 17012848Sar4jc@virginia.edu # Also set the numa bits to the appropriate values. 17111723Sar4jc@virginia.edu # 17211723Sar4jc@virginia.edu total_mem_size = MemorySize('0B') 17311723Sar4jc@virginia.edu 17411723Sar4jc@virginia.edu dir_bits = int(math.log(options.num_dirs, 2)) 17511723Sar4jc@virginia.edu ruby.block_size_bytes = options.cacheline_size 17611723Sar4jc@virginia.edu block_size_bits = int(math.log(options.cacheline_size, 2)) 17711723Sar4jc@virginia.edu 17812848Sar4jc@virginia.edu if options.numa_high_bit: 17911725Sar4jc@virginia.edu numa_bit = options.numa_high_bit 18011725Sar4jc@virginia.edu else: 18111725Sar4jc@virginia.edu # if the numa_bit is not specified, set the directory bits as the 18211725Sar4jc@virginia.edu # lowest bits above the block offset bits, and the numa_bit as the 18311725Sar4jc@virginia.edu # highest of those directory bits 18411725Sar4jc@virginia.edu numa_bit = block_size_bits + dir_bits - 1 18512848Sar4jc@virginia.edu 18611723Sar4jc@virginia.edu for dir_cntrl in dir_cntrls: 18711723Sar4jc@virginia.edu total_mem_size.value += dir_cntrl.directory.size.value 18811723Sar4jc@virginia.edu dir_cntrl.directory.numa_high_bit = numa_bit 18911723Sar4jc@virginia.edu 19011723Sar4jc@virginia.edu phys_mem_size = sum(map(lambda mem: mem.range.size(), 19112848Sar4jc@virginia.edu system.memories.unproxy(system))) 19211723Sar4jc@virginia.edu assert(total_mem_size.value == phys_mem_size) 19311877Sbrandon.potter@amd.com 19411877Sbrandon.potter@amd.com ruby_profiler = RubyProfiler(ruby_system = ruby, 19511723Sar4jc@virginia.edu num_of_sequencers = len(cpu_sequencers)) 19612848Sar4jc@virginia.edu ruby.network = network 19713612Sgabeblack@google.com ruby.profiler = ruby_profiler 198 ruby.mem_size = total_mem_size 199 ruby._cpu_ruby_ports = cpu_sequencers 200 ruby.random_seed = options.random_seed 201