Ruby.py revision 10004:5d8b72563869
13005Sstever@eecs.umich.edu# Copyright (c) 2012 ARM Limited
23005Sstever@eecs.umich.edu# All rights reserved.
33005Sstever@eecs.umich.edu#
43005Sstever@eecs.umich.edu# The license below extends only to copyright in the software and shall
53005Sstever@eecs.umich.edu# not be construed as granting a license to any other intellectual
63005Sstever@eecs.umich.edu# property including but not limited to intellectual property relating
73005Sstever@eecs.umich.edu# to a hardware implementation of the functionality of the software
83005Sstever@eecs.umich.edu# licensed hereunder.  You may use the software subject to the license
93005Sstever@eecs.umich.edu# terms below provided that you ensure that this notice is replicated
103005Sstever@eecs.umich.edu# unmodified and in its entirety in all distributions of the software,
113005Sstever@eecs.umich.edu# modified or unmodified, in source code or in binary form.
123005Sstever@eecs.umich.edu#
133005Sstever@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
143005Sstever@eecs.umich.edu# Copyright (c) 2009 Advanced Micro Devices, Inc.
153005Sstever@eecs.umich.edu# All rights reserved.
163005Sstever@eecs.umich.edu#
173005Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
183005Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
193005Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
203005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
213005Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
223005Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
233005Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
243005Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
253005Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
263005Sstever@eecs.umich.edu# this software without specific prior written permission.
273005Sstever@eecs.umich.edu#
283005Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292710SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302710SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
313005Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322889SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332667SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
343005Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352856SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362917SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
373395Shsul@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
383448Shsul@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
393394Shsul@eecs.umich.edu#
403444Sktlim@umich.edu# Authors: Brad Beckmann
413444Sktlim@umich.edu
423444Sktlim@umich.eduimport math
433444Sktlim@umich.eduimport m5
442424SN/Afrom m5.objects import *
452957SN/Afrom m5.defines import buildEnv
462957SN/A
473323Shsul@eecs.umich.edudef define_options(parser):
483005Sstever@eecs.umich.edu    # By default, ruby uses the simple timing cpu
493444Sktlim@umich.edu    parser.set_defaults(cpu_type="timing")
502957SN/A
512957SN/A    parser.add_option("--ruby-clock", action="store", type="string",
522957SN/A                      default='2GHz',
532957SN/A                      help="Clock for blocks running at Ruby system's speed")
542957SN/A
552957SN/A    # Options related to cache structure
563323Shsul@eecs.umich.edu    parser.add_option("--ports", action="store", type="int", default=4,
573444Sktlim@umich.edu                      help="used of transitions per cycle which is a proxy \
582957SN/A                            for the number of ports.")
592957SN/A
602957SN/A    # ruby network options
612957SN/A    parser.add_option("--topology", type="string", default="Crossbar",
622957SN/A                 help="check src/mem/ruby/network/topologies for complete set")
632957SN/A    parser.add_option("--mesh-rows", type="int", default=1,
642957SN/A                      help="the number of rows in the mesh topology")
652715SN/A    parser.add_option("--garnet-network", type="choice",
663005Sstever@eecs.umich.edu                      choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
672801SN/A    parser.add_option("--network-fault-model", action="store_true", default=False,
682801SN/A                      help="enable network fault model: see src/mem/ruby/network/fault_model/")
692801SN/A
702418SN/A    # ruby mapping options
712917SN/A    parser.add_option("--numa-high-bit", type="int", default=0,
722833SN/A                      help="high order address bit to use for numa mapping. " \
732833SN/A                           "0 = highest bit, not specified = lowest bit")
742833SN/A
752833SN/A    # ruby sparse memory options
762833SN/A    parser.add_option("--use-map", action="store_true", default=False)
772833SN/A    parser.add_option("--map-levels", type="int", default=4)
782833SN/A
792833SN/A    parser.add_option("--recycle-latency", type="int", default=10,
802833SN/A                      help="Recycle latency for ruby controller input buffers")
812833SN/A
822833SN/A    parser.add_option("--random_seed", type="int", default=1234,
832833SN/A                      help="Used for seeding the random number generator")
843005Sstever@eecs.umich.edu
852833SN/A    parser.add_option("--ruby_stats", type="string", default="ruby.stats")
862833SN/A
872833SN/A    protocol = buildEnv['PROTOCOL']
882833SN/A    exec "import %s" % protocol
892833SN/A    eval("%s.define_options(parser)" % protocol)
902833SN/A
913481Shsul@eecs.umich.edudef create_topology(controllers, options):
922957SN/A    """ Called from create_system in configs/ruby/<protocol>.py
933395Shsul@eecs.umich.edu        Must return an object which is a subclass of BaseTopology
943005Sstever@eecs.umich.edu        found in configs/topologies/BaseTopology.py
953395Shsul@eecs.umich.edu        This is a wrapper for the legacy topologies.
963395Shsul@eecs.umich.edu    """
973395Shsul@eecs.umich.edu    exec "import %s as Topo" % options.topology
983323Shsul@eecs.umich.edu    topology = eval("Topo.%s(controllers)" % options.topology)
993395Shsul@eecs.umich.edu    return topology
1003395Shsul@eecs.umich.edu
1013005Sstever@eecs.umich.edudef create_system(options, system, piobus = None, dma_ports = []):
1023395Shsul@eecs.umich.edu
1033395Shsul@eecs.umich.edu    system.ruby = RubySystem(stats_filename = options.ruby_stats,
1043481Shsul@eecs.umich.edu                             no_mem_vec = options.use_map)
1053395Shsul@eecs.umich.edu    ruby = system.ruby
1063448Shsul@eecs.umich.edu
1073395Shsul@eecs.umich.edu    protocol = buildEnv['PROTOCOL']
1083395Shsul@eecs.umich.edu    exec "import %s" % protocol
1093005Sstever@eecs.umich.edu    try:
1103005Sstever@eecs.umich.edu        (cpu_sequencers, dir_cntrls, topology) = \
1112902SN/A             eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
1123481Shsul@eecs.umich.edu                  % 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    # Create the network topology
150    network = NetworkClass(ruby_system = ruby, topology = topology.description,
151                           routers = [], ext_links = [], int_links = [])
152    topology.makeTopology(options, network, IntLinkClass, ExtLinkClass,
153                          RouterClass)
154
155    if options.network_fault_model:
156        assert(options.garnet_network == "fixed")
157        network.enable_fault_model = True
158        network.fault_model = FaultModel()
159
160    #
161    # Loop through the directory controlers.
162    # Determine the total memory size of the ruby system and verify it is equal
163    # to physmem.  However, if Ruby memory is using sparse memory in SE
164    # mode, then the system should not back-up the memory state with
165    # the Memory Vector and thus the memory size bytes should stay at 0.
166    # Also set the numa bits to the appropriate values.
167    #
168    total_mem_size = MemorySize('0B')
169
170    ruby.block_size_bytes = options.cacheline_size
171    block_size_bits = int(math.log(options.cacheline_size, 2))
172
173    if options.numa_high_bit:
174        numa_bit = options.numa_high_bit
175    else:
176        # if the numa_bit is not specified, set the directory bits as the
177        # lowest bits above the block offset bits, and the numa_bit as the
178        # highest of those directory bits
179        dir_bits = int(math.log(options.num_dirs, 2))
180        numa_bit = block_size_bits + dir_bits - 1
181
182    for dir_cntrl in dir_cntrls:
183        total_mem_size.value += dir_cntrl.directory.size.value
184        dir_cntrl.directory.numa_high_bit = numa_bit
185
186    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
187    assert(total_mem_size.value == phys_mem_size)
188
189    ruby_profiler = RubyProfiler(ruby_system = ruby,
190                                 num_of_sequencers = len(cpu_sequencers))
191    ruby.network = network
192    ruby.profiler = ruby_profiler
193    ruby.mem_size = total_mem_size
194    ruby._cpu_ruby_ports = cpu_sequencers
195    ruby.random_seed    = options.random_seed
196