1 # Copyright (c) 2012-2013, 2017-2018 ARM Limited
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.
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are
15 # met: redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer;
17 # redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution;
20 # neither the name of the copyright holders nor the names of its
21 # contributors may be used to endorse or promote products derived from
22 # this software without specific prior written permission.
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 from abc
import ABCMeta
, abstractmethod
39 from m5
.objects
import *
40 from m5
.proxy
import *
41 m5
.util
.addToPath('../configs/')
42 from common
import FSConfig
43 from common
import Options
44 from common
.Caches
import *
47 _have_kvm_support
= 'BaseKvmCPU' in globals()
49 class BaseSystem(object):
50 """Base system builder.
52 This class provides some basic functionality for creating an ARM
53 system with the usual peripherals (caches, GIC, etc.). It allows
54 customization by defining separate methods for different parts of
55 the initialization process.
58 __metaclass__
= ABCMeta
60 def __init__(self
, mem_mode
='timing', mem_class
=SimpleMemory
,
61 cpu_class
=TimingSimpleCPU
, num_cpus
=1, num_threads
=1,
62 checker
=False, mem_size
=None, use_ruby
=False):
63 """Initialize a simple base system.
66 mem_mode -- String describing the memory mode (timing or atomic)
67 mem_class -- Memory controller class to use
68 cpu_class -- CPU class to use
69 num_cpus -- Number of CPUs to instantiate
70 checker -- Set to True to add checker CPUs
71 mem_size -- Override the default memory size
72 use_ruby -- Set to True to use ruby memory
74 self
.mem_mode
= mem_mode
75 self
.mem_class
= mem_class
76 self
.cpu_class
= cpu_class
77 self
.num_cpus
= num_cpus
78 self
.num_threads
= num_threads
79 self
.checker
= checker
80 self
.use_ruby
= use_ruby
82 def create_cpus(self
, cpu_clk_domain
):
83 """Return a list of CPU objects to add to a system."""
84 cpus
= [ self
.cpu_class(clk_domain
=cpu_clk_domain
,
85 numThreads
=self
.num_threads
,
87 for i
in range(self
.num_cpus
) ]
93 def create_caches_private(self
, cpu
):
94 """Add private caches to a CPU.
97 cpu -- CPU instance to work on.
99 cpu
.addPrivateSplitL1Caches(L1_ICache(size
='32kB', assoc
=1),
100 L1_DCache(size
='32kB', assoc
=4))
102 def create_caches_shared(self
, system
):
103 """Add shared caches to a system.
106 system -- System to work on.
109 A bus that CPUs should use to connect to the shared cache.
111 system
.toL2Bus
= L2XBar(clk_domain
=system
.cpu_clk_domain
)
112 system
.l2c
= L2Cache(clk_domain
=system
.cpu_clk_domain
,
114 system
.l2c
.cpu_side
= system
.toL2Bus
.master
115 system
.l2c
.mem_side
= system
.membus
.slave
116 return system
.toL2Bus
118 def init_cpu(self
, system
, cpu
, sha_bus
):
122 system -- System to work on.
123 cpu -- CPU to initialize.
125 if not cpu
.switched_out
:
126 self
.create_caches_private(cpu
)
127 cpu
.createInterruptController()
128 cpu
.connectAllPorts(sha_bus
if sha_bus
!= None else system
.membus
,
131 def init_kvm(self
, system
):
132 """Do KVM-specific system initialization.
135 system -- System to work on.
139 def init_system(self
, system
):
140 """Initialize a system.
143 system -- System to initialize.
145 self
.create_clk_src(system
)
146 system
.cpu
= self
.create_cpus(system
.cpu_clk_domain
)
148 if _have_kvm_support
and \
149 any([isinstance(c
, BaseKvmCPU
) for c
in system
.cpu
]):
150 self
.init_kvm(system
)
153 # Add the ruby specific and protocol specific options
154 parser
= optparse
.OptionParser()
155 Options
.addCommonOptions(parser
)
156 Ruby
.define_options(parser
)
157 (options
, args
) = parser
.parse_args()
159 # Set the default cache size and associativity to be very
160 # small to encourage races between requests and writebacks.
161 options
.l1d_size
="32kB"
162 options
.l1i_size
="32kB"
163 options
.l2_size
="4MB"
167 options
.num_cpus
= self
.num_cpus
170 bootmem
= getattr(system
, '_bootmem', None)
171 Ruby
.create_system(options
, True, system
, system
.iobus
,
172 system
._dma
_ports
, bootmem
)
174 # Create a seperate clock domain for Ruby
175 system
.ruby
.clk_domain
= SrcClockDomain(
176 clock
= options
.ruby_clock
,
177 voltage_domain
= system
.voltage_domain
)
178 for i
, cpu
in enumerate(system
.cpu
):
179 if not cpu
.switched_out
:
180 cpu
.createInterruptController()
181 cpu
.connectCachedPorts(system
.ruby
._cpu
_ports
[i
])
183 sha_bus
= self
.create_caches_shared(system
)
184 for cpu
in system
.cpu
:
185 self
.init_cpu(system
, cpu
, sha_bus
)
188 def create_clk_src(self
,system
):
189 # Create system clock domain. This provides clock value to every
190 # clocked object that lies beneath it unless explicitly overwritten
191 # by a different clock domain.
192 system
.voltage_domain
= VoltageDomain()
193 system
.clk_domain
= SrcClockDomain(clock
= '1GHz',
195 system
.voltage_domain
)
197 # Create a seperate clock domain for components that should
198 # run at CPUs frequency
199 system
.cpu_clk_domain
= SrcClockDomain(clock
= '2GHz',
201 system
.voltage_domain
)
204 def create_system(self
):
205 """Create an return an initialized system."""
209 def create_root(self
):
210 """Create and return a simulation root using the system
211 defined by this class."""
214 class BaseSESystem(BaseSystem
):
215 """Basic syscall-emulation builder."""
217 def __init__(self
, **kwargs
):
218 super(BaseSESystem
, self
).__init
__(**kwargs
)
220 def init_system(self
, system
):
221 super(BaseSESystem
, self
).init_system(system
)
223 def create_system(self
):
224 system
= System(physmem
= self
.mem_class(),
225 membus
= SystemXBar(),
226 mem_mode
= self
.mem_mode
,
227 multi_thread
= (self
.num_threads
> 1))
228 if not self
.use_ruby
:
229 system
.system_port
= system
.membus
.slave
230 system
.physmem
.port
= system
.membus
.master
231 self
.init_system(system
)
234 def create_root(self
):
235 system
= self
.create_system()
236 m5
.ticks
.setGlobalFrequency('1THz')
237 return Root(full_system
=False, system
=system
)
239 class BaseSESystemUniprocessor(BaseSESystem
):
240 """Basic syscall-emulation builder for uniprocessor systems.
242 Note: This class is only really needed to provide backwards
243 compatibility in existing test cases.
246 def __init__(self
, **kwargs
):
247 super(BaseSESystemUniprocessor
, self
).__init
__(**kwargs
)
249 def create_caches_private(self
, cpu
):
250 # The atomic SE configurations do not use caches
251 if self
.mem_mode
== "timing":
252 # @todo We might want to revisit these rather enthusiastic L1 sizes
253 cpu
.addTwoLevelCacheHierarchy(L1_ICache(size
='128kB'),
254 L1_DCache(size
='256kB'),
257 def create_caches_shared(self
, system
):
260 class BaseFSSystem(BaseSystem
):
261 """Basic full system builder."""
263 def __init__(self
, **kwargs
):
264 super(BaseFSSystem
, self
).__init
__(**kwargs
)
266 def init_system(self
, system
):
267 super(BaseFSSystem
, self
).init_system(system
)
270 # Connect the ruby io port to the PIO bus,
271 # assuming that there is just one such port.
272 system
.iobus
.master
= system
.ruby
._io
_port
.slave
274 # create the memory controllers and connect them, stick with
275 # the physmem name to avoid bumping all the reference stats
276 system
.physmem
= [self
.mem_class(range = r
)
277 for r
in system
.mem_ranges
]
278 for i
in range(len(system
.physmem
)):
279 system
.physmem
[i
].port
= system
.membus
.master
281 # create the iocache, which by default runs at the system clock
282 system
.iocache
= IOCache(addr_ranges
=system
.mem_ranges
)
283 system
.iocache
.cpu_side
= system
.iobus
.master
284 system
.iocache
.mem_side
= system
.membus
.slave
286 def create_root(self
):
287 system
= self
.create_system()
288 m5
.ticks
.setGlobalFrequency('1THz')
289 return Root(full_system
=True, system
=system
)
291 class BaseFSSystemUniprocessor(BaseFSSystem
):
292 """Basic full system builder for uniprocessor systems.
294 Note: This class is only really needed to provide backwards
295 compatibility in existing test cases.
298 def __init__(self
, **kwargs
):
299 super(BaseFSSystemUniprocessor
, self
).__init
__(**kwargs
)
301 def create_caches_private(self
, cpu
):
302 cpu
.addTwoLevelCacheHierarchy(L1_ICache(size
='32kB', assoc
=1),
303 L1_DCache(size
='32kB', assoc
=4),
304 L2Cache(size
='4MB', assoc
=8))
306 def create_caches_shared(self
, system
):
309 class BaseFSSwitcheroo(BaseFSSystem
):
310 """Uniprocessor system prepared for CPU switching"""
312 def __init__(self
, cpu_classes
, **kwargs
):
313 super(BaseFSSwitcheroo
, self
).__init
__(**kwargs
)
314 self
.cpu_classes
= tuple(cpu_classes
)
316 def create_cpus(self
, cpu_clk_domain
):
317 cpus
= [ cclass(clk_domain
= cpu_clk_domain
,
320 for cclass
in self
.cpu_classes
]
321 cpus
[0].switched_out
= False