Ruby.py revision 9841:69c158420c51
14159Sgblack@eecs.umich.edu# Copyright (c) 2012 ARM Limited
24159Sgblack@eecs.umich.edu# All rights reserved.
34159Sgblack@eecs.umich.edu#
44159Sgblack@eecs.umich.edu# The license below extends only to copyright in the software and shall
57087Snate@binkert.org# not be construed as granting a license to any other intellectual
67087Snate@binkert.org# property including but not limited to intellectual property relating
77087Snate@binkert.org# to a hardware implementation of the functionality of the software
87087Snate@binkert.org# licensed hereunder.  You may use the software subject to the license
97087Snate@binkert.org# terms below provided that you ensure that this notice is replicated
107087Snate@binkert.org# unmodified and in its entirety in all distributions of the software,
117087Snate@binkert.org# modified or unmodified, in source code or in binary form.
127087Snate@binkert.org#
134159Sgblack@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
147087Snate@binkert.org# Copyright (c) 2009 Advanced Micro Devices, Inc.
157087Snate@binkert.org# All rights reserved.
167087Snate@binkert.org#
177087Snate@binkert.org# Redistribution and use in source and binary forms, with or without
187087Snate@binkert.org# modification, are permitted provided that the following conditions are
197087Snate@binkert.org# met: redistributions of source code must retain the above copyright
207087Snate@binkert.org# notice, this list of conditions and the following disclaimer;
217087Snate@binkert.org# redistributions in binary form must reproduce the above copyright
224159Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
237087Snate@binkert.org# documentation and/or other materials provided with the distribution;
244159Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
254159Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
264159Sgblack@eecs.umich.edu# this software without specific prior written permission.
274159Sgblack@eecs.umich.edu#
284159Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
294159Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
304159Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
314159Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
324159Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
334159Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
344159Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
354159Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364159Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
374159Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
384159Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
394159Sgblack@eecs.umich.edu#
404159Sgblack@eecs.umich.edu# Authors: Brad Beckmann
418229Snate@binkert.org
424159Sgblack@eecs.umich.eduimport math
434159Sgblack@eecs.umich.eduimport m5
444159Sgblack@eecs.umich.edufrom m5.objects import *
458229Snate@binkert.orgfrom m5.defines import buildEnv
464159Sgblack@eecs.umich.edu
474159Sgblack@eecs.umich.edudef define_options(parser):
484159Sgblack@eecs.umich.edu    # By default, ruby uses the simple timing cpu
494159Sgblack@eecs.umich.edu    parser.set_defaults(cpu_type="timing")
504159Sgblack@eecs.umich.edu
514159Sgblack@eecs.umich.edu    parser.add_option("--ruby-clock", action="store", type="string",
524159Sgblack@eecs.umich.edu                      default='2GHz',
534159Sgblack@eecs.umich.edu                      help="Clock for blocks running at Ruby system's speed")
545567Snate@binkert.org
554159Sgblack@eecs.umich.edu    # Options related to cache structure
564159Sgblack@eecs.umich.edu    parser.add_option("--ports", action="store", type="int", default=4,
574159Sgblack@eecs.umich.edu                      help="used of transitions per cycle which is a proxy \
584159Sgblack@eecs.umich.edu                            for the number of ports.")
594159Sgblack@eecs.umich.edu
604159Sgblack@eecs.umich.edu    # ruby network options
614159Sgblack@eecs.umich.edu    parser.add_option("--topology", type="string", default="Crossbar",
624159Sgblack@eecs.umich.edu                 help="check src/mem/ruby/network/topologies for complete set")
634159Sgblack@eecs.umich.edu    parser.add_option("--mesh-rows", type="int", default=1,
644159Sgblack@eecs.umich.edu                      help="the number of rows in the mesh topology")
654159Sgblack@eecs.umich.edu    parser.add_option("--garnet-network", type="choice",
664159Sgblack@eecs.umich.edu                      choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
674159Sgblack@eecs.umich.edu    parser.add_option("--network-fault-model", action="store_true", default=False,
684159Sgblack@eecs.umich.edu                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
694159Sgblack@eecs.umich.edu
704159Sgblack@eecs.umich.edu    # ruby mapping options
714159Sgblack@eecs.umich.edu    parser.add_option("--numa-high-bit", type="int", default=0,
724159Sgblack@eecs.umich.edu                      help="high order address bit to use for numa mapping. " \
734159Sgblack@eecs.umich.edu                           "0 = highest bit, not specified = lowest bit")
744159Sgblack@eecs.umich.edu
754159Sgblack@eecs.umich.edu    # ruby sparse memory options
764159Sgblack@eecs.umich.edu    parser.add_option("--use-map", action="store_true", default=False)
774159Sgblack@eecs.umich.edu    parser.add_option("--map-levels", type="int", default=4)
784159Sgblack@eecs.umich.edu
794159Sgblack@eecs.umich.edu    parser.add_option("--recycle-latency", type="int", default=10,
804159Sgblack@eecs.umich.edu                      help="Recycle latency for ruby controller input buffers")
814159Sgblack@eecs.umich.edu
824159Sgblack@eecs.umich.edu    parser.add_option("--random_seed", type="int", default=1234,
834159Sgblack@eecs.umich.edu                      help="Used for seeding the random number generator")
84
85    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
86
87    protocol = buildEnv['PROTOCOL']
88    exec "import %s" % protocol
89    eval("%s.define_options(parser)" % protocol)
90
91def create_topology(controllers, options):
92    """ Called from create_system in configs/ruby/<protocol>.py
93        Must return an object which is a subclass of BaseTopology
94        found in configs/topologies/BaseTopology.py
95        This is a wrapper for the legacy topologies.
96    """
97    exec "import %s as Topo" % options.topology
98    topology = eval("Topo.%s(controllers)" % options.topology)
99    return topology
100
101def create_system(options, system, piobus = None, dma_ports = []):
102
103    system.ruby = RubySystem(stats_filename = options.ruby_stats,
104                             no_mem_vec = options.use_map)
105    ruby = system.ruby
106
107    protocol = buildEnv['PROTOCOL']
108    exec "import %s" % protocol
109    try:
110        (cpu_sequencers, dir_cntrls, topology) = \
111             eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
112                  % protocol)
113    except:
114        print "Error: could not create sytem for ruby protocol %s" % protocol
115        raise
116
117    # Create a port proxy for connecting the system port. This is
118    # independent of the protocol and kept in the protocol-agnostic
119    # part (i.e. here).
120    sys_port_proxy = RubyPortProxy(ruby_system = ruby)
121    # Give the system port proxy a SimObject parent without creating a
122    # full-fledged controller
123    system.sys_port_proxy = sys_port_proxy
124
125    # Connect the system port for loading of binaries etc
126    system.system_port = system.sys_port_proxy.slave
127
128
129    #
130    # Set the network classes based on the command line options
131    #
132    if options.garnet_network == "fixed":
133        class NetworkClass(GarnetNetwork_d): pass
134        class IntLinkClass(GarnetIntLink_d): pass
135        class ExtLinkClass(GarnetExtLink_d): pass
136        class RouterClass(GarnetRouter_d): pass
137    elif options.garnet_network == "flexible":
138        class NetworkClass(GarnetNetwork): pass
139        class IntLinkClass(GarnetIntLink): pass
140        class ExtLinkClass(GarnetExtLink): pass
141        class RouterClass(GarnetRouter): pass
142    else:
143        class NetworkClass(SimpleNetwork): pass
144        class IntLinkClass(SimpleIntLink): pass
145        class ExtLinkClass(SimpleExtLink): pass
146        class RouterClass(Switch): pass
147
148    #
149    # Important: the topology must be instantiated before the network and after
150    # the controllers. Hence the separation between topology definition and
151    # instantiation.
152    #
153
154    routers, int_links, ext_links = topology.makeTopology(options,
155                                    IntLinkClass, ExtLinkClass, RouterClass)
156    network = NetworkClass(ruby_system = ruby, routers = routers,
157                           int_links = int_links, ext_links = ext_links,
158                           topology = topology.description)
159
160    if options.network_fault_model:
161        assert(options.garnet_network == "fixed")
162        network.enable_fault_model = True
163        network.fault_model = FaultModel()
164
165    #
166    # Loop through the directory controlers.
167    # Determine the total memory size of the ruby system and verify it is equal
168    # to physmem.  However, if Ruby memory is using sparse memory in SE
169    # mode, then the system should not back-up the memory state with
170    # the Memory Vector and thus the memory size bytes should stay at 0.
171    # Also set the numa bits to the appropriate values.
172    #
173    total_mem_size = MemorySize('0B')
174
175    dir_bits = int(math.log(options.num_dirs, 2))
176    ruby.block_size_bytes = options.cacheline_size
177    block_size_bits = int(math.log(options.cacheline_size, 2))
178
179    if options.numa_high_bit:
180        numa_bit = options.numa_high_bit
181    else:
182        # if the numa_bit is not specified, set the directory bits as the
183        # lowest bits above the block offset bits, and the numa_bit as the
184        # highest of those directory bits
185        numa_bit = block_size_bits + dir_bits - 1
186
187    for dir_cntrl in dir_cntrls:
188        total_mem_size.value += dir_cntrl.directory.size.value
189        dir_cntrl.directory.numa_high_bit = numa_bit
190
191    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
192    assert(total_mem_size.value == phys_mem_size)
193
194    ruby_profiler = RubyProfiler(ruby_system = ruby,
195                                 num_of_sequencers = len(cpu_sequencers))
196    ruby.network = network
197    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