Ruby.py (9593:9441ca79f3c8) Ruby.py (9594:219ad5fe8c04)
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 # ruby network options
52 parser.add_option("--topology", type="string", default="Crossbar",
53 help="check src/mem/ruby/network/topologies for complete set")
54 parser.add_option("--mesh-rows", type="int", default=1,
55 help="the number of rows in the mesh topology")
56 parser.add_option("--garnet-network", type="choice",
57 choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
58 parser.add_option("--network-fault-model", action="store_true", default=False,
59 help="enable network fault model: see src/mem/ruby/network/fault_model/")
60
61 # ruby mapping options
62 parser.add_option("--numa-high-bit", type="int", default=0,
63 help="high order address bit to use for numa mapping. " \
64 "0 = highest bit, not specified = lowest bit")
65
66 # ruby sparse memory options
67 parser.add_option("--use-map", action="store_true", default=False)
68 parser.add_option("--map-levels", type="int", default=4)
69
70 parser.add_option("--recycle-latency", type="int", default=10,
71 help="Recycle latency for ruby controller input buffers")
72
73 parser.add_option("--random_seed", type="int", default=1234,
74 help="Used for seeding the random number generator")
75
76 parser.add_option("--ruby_stats", type="string", default="ruby.stats")
77
78 protocol = buildEnv['PROTOCOL']
79 exec "import %s" % protocol
80 eval("%s.define_options(parser)" % protocol)
81
82def create_topology(controllers, options):
83 """ Called from create_system in configs/ruby/<protocol>.py
84 Must return an object which is a subclass of BaseTopology
85 found in configs/topologies/BaseTopology.py
86 This is a wrapper for the legacy topologies.
87 """
88 exec "import %s as Topo" % options.topology
89 topology = eval("Topo.%s(controllers)" % options.topology)
90 return topology
91
92def create_system(options, system, piobus = None, dma_ports = []):
93
94 system.ruby = RubySystem(clock = options.clock,
95 stats_filename = options.ruby_stats,
96 no_mem_vec = options.use_map)
97 ruby = system.ruby
98
99 protocol = buildEnv['PROTOCOL']
100 exec "import %s" % protocol
101 try:
102 (cpu_sequencers, dir_cntrls, topology) = \
103 eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
104 % protocol)
105 except:
106 print "Error: could not create sytem for ruby protocol %s" % protocol
107 raise
108
109 # Create a port proxy for connecting the system port. This is
110 # independent of the protocol and kept in the protocol-agnostic
111 # part (i.e. here).
112 sys_port_proxy = RubyPortProxy(ruby_system = ruby)
113 # Give the system port proxy a SimObject parent without creating a
114 # full-fledged controller
115 system.sys_port_proxy = sys_port_proxy
116
117 # Connect the system port for loading of binaries etc
118 system.system_port = system.sys_port_proxy.slave
119
120
121 #
122 # Set the network classes based on the command line options
123 #
124 if options.garnet_network == "fixed":
125 class NetworkClass(GarnetNetwork_d): pass
126 class IntLinkClass(GarnetIntLink_d): pass
127 class ExtLinkClass(GarnetExtLink_d): pass
128 class RouterClass(GarnetRouter_d): pass
129 elif options.garnet_network == "flexible":
130 class NetworkClass(GarnetNetwork): pass
131 class IntLinkClass(GarnetIntLink): pass
132 class ExtLinkClass(GarnetExtLink): pass
133 class RouterClass(GarnetRouter): pass
134 else:
135 class NetworkClass(SimpleNetwork): pass
136 class IntLinkClass(SimpleIntLink): pass
137 class ExtLinkClass(SimpleExtLink): pass
138 class RouterClass(Switch): pass
139
140 #
141 # Important: the topology must be instantiated before the network and after
142 # the controllers. Hence the separation between topology definition and
143 # instantiation.
144 #
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 # ruby network options
52 parser.add_option("--topology", type="string", default="Crossbar",
53 help="check src/mem/ruby/network/topologies for complete set")
54 parser.add_option("--mesh-rows", type="int", default=1,
55 help="the number of rows in the mesh topology")
56 parser.add_option("--garnet-network", type="choice",
57 choices=['fixed', 'flexible'], help="'fixed'|'flexible'")
58 parser.add_option("--network-fault-model", action="store_true", default=False,
59 help="enable network fault model: see src/mem/ruby/network/fault_model/")
60
61 # ruby mapping options
62 parser.add_option("--numa-high-bit", type="int", default=0,
63 help="high order address bit to use for numa mapping. " \
64 "0 = highest bit, not specified = lowest bit")
65
66 # ruby sparse memory options
67 parser.add_option("--use-map", action="store_true", default=False)
68 parser.add_option("--map-levels", type="int", default=4)
69
70 parser.add_option("--recycle-latency", type="int", default=10,
71 help="Recycle latency for ruby controller input buffers")
72
73 parser.add_option("--random_seed", type="int", default=1234,
74 help="Used for seeding the random number generator")
75
76 parser.add_option("--ruby_stats", type="string", default="ruby.stats")
77
78 protocol = buildEnv['PROTOCOL']
79 exec "import %s" % protocol
80 eval("%s.define_options(parser)" % protocol)
81
82def create_topology(controllers, options):
83 """ Called from create_system in configs/ruby/<protocol>.py
84 Must return an object which is a subclass of BaseTopology
85 found in configs/topologies/BaseTopology.py
86 This is a wrapper for the legacy topologies.
87 """
88 exec "import %s as Topo" % options.topology
89 topology = eval("Topo.%s(controllers)" % options.topology)
90 return topology
91
92def create_system(options, system, piobus = None, dma_ports = []):
93
94 system.ruby = RubySystem(clock = options.clock,
95 stats_filename = options.ruby_stats,
96 no_mem_vec = options.use_map)
97 ruby = system.ruby
98
99 protocol = buildEnv['PROTOCOL']
100 exec "import %s" % protocol
101 try:
102 (cpu_sequencers, dir_cntrls, topology) = \
103 eval("%s.create_system(options, system, piobus, dma_ports, ruby)"
104 % protocol)
105 except:
106 print "Error: could not create sytem for ruby protocol %s" % protocol
107 raise
108
109 # Create a port proxy for connecting the system port. This is
110 # independent of the protocol and kept in the protocol-agnostic
111 # part (i.e. here).
112 sys_port_proxy = RubyPortProxy(ruby_system = ruby)
113 # Give the system port proxy a SimObject parent without creating a
114 # full-fledged controller
115 system.sys_port_proxy = sys_port_proxy
116
117 # Connect the system port for loading of binaries etc
118 system.system_port = system.sys_port_proxy.slave
119
120
121 #
122 # Set the network classes based on the command line options
123 #
124 if options.garnet_network == "fixed":
125 class NetworkClass(GarnetNetwork_d): pass
126 class IntLinkClass(GarnetIntLink_d): pass
127 class ExtLinkClass(GarnetExtLink_d): pass
128 class RouterClass(GarnetRouter_d): pass
129 elif options.garnet_network == "flexible":
130 class NetworkClass(GarnetNetwork): pass
131 class IntLinkClass(GarnetIntLink): pass
132 class ExtLinkClass(GarnetExtLink): pass
133 class RouterClass(GarnetRouter): pass
134 else:
135 class NetworkClass(SimpleNetwork): pass
136 class IntLinkClass(SimpleIntLink): pass
137 class ExtLinkClass(SimpleExtLink): pass
138 class RouterClass(Switch): pass
139
140 #
141 # Important: the topology must be instantiated before the network and after
142 # the controllers. Hence the separation between topology definition and
143 # instantiation.
144 #
145 # gem5 SimObject defined in src/mem/ruby/network/Network.py
146 net_topology = Topology()
147 net_topology.description = topology.description
148
149 routers, int_links, ext_links = topology.makeTopology(options,
150 IntLinkClass, ExtLinkClass, RouterClass)
145
146 routers, int_links, ext_links = topology.makeTopology(options,
147 IntLinkClass, ExtLinkClass, RouterClass)
148 network = NetworkClass(ruby_system = ruby, routers = routers,
149 int_links = int_links, ext_links = ext_links,
150 topology = topology.description)
151
151
152 net_topology.num_routers = len(routers)
153 net_topology.int_links = int_links
154 net_topology.ext_links = ext_links
155
156 network = NetworkClass(ruby_system = ruby, topology = net_topology,
157 routers = routers)
158
159 if options.network_fault_model:
160 assert(options.garnet_network == "fixed")
161 network.enable_fault_model = True
162 network.fault_model = FaultModel()
163
164 #
165 # Loop through the directory controlers.
166 # Determine the total memory size of the ruby system and verify it is equal
167 # to physmem. However, if Ruby memory is using sparse memory in SE
168 # mode, then the system should not back-up the memory state with
169 # the Memory Vector and thus the memory size bytes should stay at 0.
170 # Also set the numa bits to the appropriate values.
171 #
172 total_mem_size = MemorySize('0B')
173
174 dir_bits = int(math.log(options.num_dirs, 2))
175 ruby.block_size_bytes = options.cacheline_size
176 block_size_bits = int(math.log(options.cacheline_size, 2))
177
178 if options.numa_high_bit:
179 numa_bit = options.numa_high_bit
180 else:
181 # if the numa_bit is not specified, set the directory bits as the
182 # lowest bits above the block offset bits, and the numa_bit as the
183 # highest of those directory bits
184 numa_bit = block_size_bits + dir_bits - 1
185
186 for dir_cntrl in dir_cntrls:
187 total_mem_size.value += dir_cntrl.directory.size.value
188 dir_cntrl.directory.numa_high_bit = numa_bit
189
190 phys_mem_size = sum(map(lambda mem: mem.range.size(),
191 system.memories.unproxy(system)))
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
152 if options.network_fault_model:
153 assert(options.garnet_network == "fixed")
154 network.enable_fault_model = True
155 network.fault_model = FaultModel()
156
157 #
158 # Loop through the directory controlers.
159 # Determine the total memory size of the ruby system and verify it is equal
160 # to physmem. However, if Ruby memory is using sparse memory in SE
161 # mode, then the system should not back-up the memory state with
162 # the Memory Vector and thus the memory size bytes should stay at 0.
163 # Also set the numa bits to the appropriate values.
164 #
165 total_mem_size = MemorySize('0B')
166
167 dir_bits = int(math.log(options.num_dirs, 2))
168 ruby.block_size_bytes = options.cacheline_size
169 block_size_bits = int(math.log(options.cacheline_size, 2))
170
171 if options.numa_high_bit:
172 numa_bit = options.numa_high_bit
173 else:
174 # if the numa_bit is not specified, set the directory bits as the
175 # lowest bits above the block offset bits, and the numa_bit as the
176 # highest of those directory bits
177 numa_bit = block_size_bits + dir_bits - 1
178
179 for dir_cntrl in dir_cntrls:
180 total_mem_size.value += dir_cntrl.directory.size.value
181 dir_cntrl.directory.numa_high_bit = numa_bit
182
183 phys_mem_size = sum(map(lambda mem: mem.range.size(),
184 system.memories.unproxy(system)))
185 assert(total_mem_size.value == phys_mem_size)
186
187 ruby_profiler = RubyProfiler(ruby_system = ruby,
188 num_of_sequencers = len(cpu_sequencers))
189 ruby.network = network
190 ruby.profiler = ruby_profiler
191 ruby.mem_size = total_mem_size
192 ruby._cpu_ruby_ports = cpu_sequencers
193 ruby.random_seed = options.random_seed