a07bea1bbb720bdf3e9a46e9fee16d45dcaad873
[gem5.git] / configs / ruby / Ruby.py
1 # Copyright (c) 2006-2007 The Regents of The University of Michigan
2 # Copyright (c) 2009 Advanced Micro Devices, Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # Authors: Brad Beckmann
29
30 import math
31 import m5
32 from m5.objects import *
33 from m5.defines import buildEnv
34
35 def define_options(parser):
36 # ruby network options
37 parser.add_option("--topology", type="string", default="Crossbar",
38 help="check src/mem/ruby/network/topologies for complete set")
39 parser.add_option("--mesh-rows", type="int", default=1,
40 help="the number of rows in the mesh topology")
41 parser.add_option("--garnet-network", type="string", default=None,
42 help="'fixed'|'flexible'")
43 parser.add_option("--network-fault-model", action="store_true", default=False,
44 help="enable network fault model: see src/mem/ruby/network/fault_model/")
45
46 # ruby mapping options
47 parser.add_option("--numa-high-bit", type="int", default=0,
48 help="high order address bit to use for numa mapping. " \
49 "0 = highest bit, not specified = lowest bit")
50
51 # ruby sparse memory options
52 parser.add_option("--use-map", action="store_true", default=False)
53 parser.add_option("--map-levels", type="int", default=4)
54
55 parser.add_option("--recycle-latency", type="int", default=10,
56 help="Recycle latency for ruby controller input buffers")
57
58 parser.add_option("--random_seed", type="int", default=1234,
59 help="Used for seeding the random number generator")
60
61 parser.add_option("--ruby_stats", type="string", default="ruby.stats")
62
63 protocol = buildEnv['PROTOCOL']
64 exec "import %s" % protocol
65 eval("%s.define_options(parser)" % protocol)
66
67 def create_system(options, system, piobus = None, dma_devices = []):
68
69 system.ruby = RubySystem(clock = options.clock,
70 stats_filename = options.ruby_stats,
71 no_mem_vec = options.use_map)
72 ruby = system.ruby
73
74 protocol = buildEnv['PROTOCOL']
75 exec "import %s" % protocol
76 try:
77 (cpu_sequencers, dir_cntrls, all_cntrls) = \
78 eval("%s.create_system(options, system, piobus, \
79 dma_devices, ruby)" \
80 % protocol)
81 except:
82 print "Error: could not create sytem for ruby protocol %s" % protocol
83 raise
84
85 #
86 # Set the network classes based on the command line options
87 #
88 if options.garnet_network == "fixed":
89 class NetworkClass(GarnetNetwork_d): pass
90 class IntLinkClass(GarnetIntLink_d): pass
91 class ExtLinkClass(GarnetExtLink_d): pass
92 class RouterClass(GarnetRouter_d): pass
93 elif options.garnet_network == "flexible":
94 class NetworkClass(GarnetNetwork): pass
95 class IntLinkClass(GarnetIntLink): pass
96 class ExtLinkClass(GarnetExtLink): pass
97 class RouterClass(GarnetRouter): pass
98 else:
99 class NetworkClass(SimpleNetwork): pass
100 class IntLinkClass(SimpleIntLink): pass
101 class ExtLinkClass(SimpleExtLink): pass
102 class RouterClass(BasicRouter): pass
103
104 #
105 # Important: the topology must be created before the network and after the
106 # controllers.
107 #
108 exec "import %s" % options.topology
109 try:
110 net_topology = eval("%s.makeTopology(all_cntrls, options, \
111 IntLinkClass, ExtLinkClass, \
112 RouterClass)" \
113 % options.topology)
114 except:
115 print "Error: could not create topology %s" % options.topology
116 raise
117
118 if options.network_fault_model:
119 assert(options.garnet_network == "fixed")
120 fault_model = FaultModel()
121 network = NetworkClass(ruby_system = ruby, topology = net_topology,\
122 enable_fault_model=True, fault_model = fault_model)
123 else:
124 network = NetworkClass(ruby_system = ruby, topology = net_topology)
125
126 #
127 # Loop through the directory controlers.
128 # Determine the total memory size of the ruby system and verify it is equal
129 # to physmem. However, if Ruby memory is using sparse memory in SE
130 # mode, then the system should not back-up the memory state with
131 # the Memory Vector and thus the memory size bytes should stay at 0.
132 # Also set the numa bits to the appropriate values.
133 #
134 total_mem_size = MemorySize('0B')
135
136 dir_bits = int(math.log(options.num_dirs, 2))
137
138 if options.numa_high_bit:
139 numa_bit = options.numa_high_bit
140 else:
141 # if not specified, use the lowest bits above the block offest
142 if dir_bits > 0:
143 # add 5 because bits 0-5 are the block offset
144 numa_bit = dir_bits + 5
145 else:
146 numa_bit = 6
147
148 for dir_cntrl in dir_cntrls:
149 total_mem_size.value += dir_cntrl.directory.size.value
150 dir_cntrl.directory.numa_high_bit = numa_bit
151
152 physmem_size = long(system.physmem.range.second) - \
153 long(system.physmem.range.first) + 1
154 assert(total_mem_size.value == physmem_size)
155
156 ruby_profiler = RubyProfiler(ruby_system = ruby,
157 num_of_sequencers = len(cpu_sequencers))
158 ruby.network = network
159 ruby.profiler = ruby_profiler
160 ruby.mem_size = total_mem_size
161 ruby._cpu_ruby_ports = cpu_sequencers
162 ruby.random_seed = options.random_seed