Deleted Added
sdiff udiff text old ( 9430:a113f27b68bd ) new ( 9521:1cd02decbfd3 )
full compact
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

--- 46 unchanged lines hidden (view full) ---

55from m5.internal.stats import updateEvents as updateStatEvents
56
57from util import fatal
58from util import attrdict
59
60# define a MaxTick parameter
61MaxTick = 2**63 - 1
62
63_memory_modes = {
64 "atomic" : objects.params.atomic,
65 "timing" : objects.params.timing,
66 }
67
68# The final hook to generate .ini files. Called from the user script
69# once the config is built.
70def instantiate(ckpt_dir=None):
71 from m5 import options
72
73 root = objects.Root.getInstance()
74
75 if not root:

--- 126 unchanged lines hidden (view full) ---

202 if not isinstance(root, objects.Root):
203 raise TypeError, "Checkpoint must be called on a root object."
204 drain(root)
205 memWriteback(root)
206 print "Writing checkpoint"
207 internal.core.serializeAll(dir)
208 resume(root)
209
210def _changeMemoryMode(system, mode):
211 if not isinstance(system, (objects.Root, objects.System)):
212 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \
213 (type(system), objects.Root, objects.System)
214 if system.getMemoryMode() != mode:
215 drain(system)
216 system.setMemoryMode(mode)
217 else:
218 print "System already in target mode. Memory mode unchanged."
219
220def switchCpus(system, cpuList, do_drain=True):
221 """Switch CPUs in a system.
222
223 By default, this method drains and resumes the system. This
224 behavior can be disabled by setting the keyword argument
225 'do_drain' to false, which might be desirable if multiple
226 operations requiring a drained system are going to be performed in
227 sequence.
228
229 Note: This method may switch the memory mode of the system if that
230 is required by the CPUs. It may also flush all caches in the
231 system.
232
233 Arguments:
234 system -- Simulated system.
235 cpuList -- (old_cpu, new_cpu) tuples
236
237 Keyword Arguments:
238 do_drain -- Perform a drain/resume of the system when switching.
239 """
240 print "switching cpus"
241 if not isinstance(cpuList, list):
242 raise RuntimeError, "Must pass a list to this function"
243 for item in cpuList:
244 if not isinstance(item, tuple) or len(item) != 2:
245 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)"
246
247 old_cpus = [old_cpu for old_cpu, new_cpu in cpuList]
248 new_cpus = [new_cpu for old_cpu, new_cpu in cpuList]
249 old_cpu_set = set(old_cpus)
250 memory_mode_name = new_cpus[0].memory_mode()
251 for old_cpu, new_cpu in cpuList:
252 if not isinstance(old_cpu, objects.BaseCPU):
253 raise TypeError, "%s is not of type BaseCPU" % old_cpu
254 if not isinstance(new_cpu, objects.BaseCPU):
255 raise TypeError, "%s is not of type BaseCPU" % new_cpu
256 if new_cpu in old_cpu_set:
257 raise RuntimeError, \
258 "New CPU (%s) is in the list of old CPUs." % (old_cpu,)
259 if not new_cpu.switchedOut():
260 raise RuntimeError, \
261 "New CPU (%s) is already active." % (new_cpu,)
262 if not new_cpu.support_take_over():
263 raise RuntimeError, \
264 "New CPU (%s) does not support CPU handover." % (old_cpu,)
265 if new_cpu.memory_mode() != memory_mode_name:
266 raise RuntimeError, \
267 "%s and %s require different memory modes." % (new_cpu,
268 new_cpus[0])
269 if old_cpu.switchedOut():
270 raise RuntimeError, \
271 "Old CPU (%s) is inactive." % (new_cpu,)
272 if not old_cpu.support_take_over():
273 raise RuntimeError, \
274 "Old CPU (%s) does not support CPU handover." % (old_cpu,)
275
276 try:
277 memory_mode = _memory_modes[memory_mode_name]
278 except KeyError:
279 raise RuntimeError, "Invalid memory mode (%s)" % memory_mode_name
280
281 if do_drain:
282 drain(system)
283
284 # Now all of the CPUs are ready to be switched out
285 for old_cpu, new_cpu in cpuList:
286 old_cpu.switchOut()
287
288 # Change the memory mode if required. We check if this is needed
289 # to avoid printing a warning if no switch was performed.
290 if system.getMemoryMode() != memory_mode:
291 _changeMemoryMode(system, memory_mode)
292
293 for old_cpu, new_cpu in cpuList:
294 new_cpu.takeOverFrom(old_cpu)
295
296 if do_drain:
297 resume(system)
298
299from internal.core import disableAllListeners