simulate.py (12563:8d59ed22ae79) simulate.py (13663:9b64aeabf9a5)
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

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

216
217def memInvalidate(root):
218 for obj in root.descendants():
219 obj.memInvalidate()
220
221def checkpoint(dir):
222 root = objects.Root.getInstance()
223 if not isinstance(root, objects.Root):
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

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

216
217def memInvalidate(root):
218 for obj in root.descendants():
219 obj.memInvalidate()
220
221def checkpoint(dir):
222 root = objects.Root.getInstance()
223 if not isinstance(root, objects.Root):
224 raise TypeError, "Checkpoint must be called on a root object."
224 raise TypeError("Checkpoint must be called on a root object.")
225
226 drain()
227 memWriteback(root)
228 print("Writing checkpoint")
229 _m5.core.serializeAll(dir)
230
231def _changeMemoryMode(system, mode):
232 if not isinstance(system, (objects.Root, objects.System)):
225
226 drain()
227 memWriteback(root)
228 print("Writing checkpoint")
229 _m5.core.serializeAll(dir)
230
231def _changeMemoryMode(system, mode):
232 if not isinstance(system, (objects.Root, objects.System)):
233 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \
234 (type(system), objects.Root, objects.System)
233 raise TypeError("Parameter of type '%s'. Must be type %s or %s." % \
234 (type(system), objects.Root, objects.System))
235 if system.getMemoryMode() != mode:
236 system.setMemoryMode(mode)
237 else:
238 print("System already in target mode. Memory mode unchanged.")
239
240def switchCpus(system, cpuList, verbose=True):
241 """Switch CPUs in a system.
242

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

248 system -- Simulated system.
249 cpuList -- (old_cpu, new_cpu) tuples
250 """
251
252 if verbose:
253 print("switching cpus")
254
255 if not isinstance(cpuList, list):
235 if system.getMemoryMode() != mode:
236 system.setMemoryMode(mode)
237 else:
238 print("System already in target mode. Memory mode unchanged.")
239
240def switchCpus(system, cpuList, verbose=True):
241 """Switch CPUs in a system.
242

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

248 system -- Simulated system.
249 cpuList -- (old_cpu, new_cpu) tuples
250 """
251
252 if verbose:
253 print("switching cpus")
254
255 if not isinstance(cpuList, list):
256 raise RuntimeError, "Must pass a list to this function"
256 raise RuntimeError("Must pass a list to this function")
257 for item in cpuList:
258 if not isinstance(item, tuple) or len(item) != 2:
257 for item in cpuList:
258 if not isinstance(item, tuple) or len(item) != 2:
259 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)"
259 raise RuntimeError("List must have tuples of (oldCPU,newCPU)")
260
261 old_cpus = [old_cpu for old_cpu, new_cpu in cpuList]
262 new_cpus = [new_cpu for old_cpu, new_cpu in cpuList]
263 old_cpu_set = set(old_cpus)
264 memory_mode_name = new_cpus[0].memory_mode()
265 for old_cpu, new_cpu in cpuList:
266 if not isinstance(old_cpu, objects.BaseCPU):
260
261 old_cpus = [old_cpu for old_cpu, new_cpu in cpuList]
262 new_cpus = [new_cpu for old_cpu, new_cpu in cpuList]
263 old_cpu_set = set(old_cpus)
264 memory_mode_name = new_cpus[0].memory_mode()
265 for old_cpu, new_cpu in cpuList:
266 if not isinstance(old_cpu, objects.BaseCPU):
267 raise TypeError, "%s is not of type BaseCPU" % old_cpu
267 raise TypeError("%s is not of type BaseCPU" % old_cpu)
268 if not isinstance(new_cpu, objects.BaseCPU):
268 if not isinstance(new_cpu, objects.BaseCPU):
269 raise TypeError, "%s is not of type BaseCPU" % new_cpu
269 raise TypeError("%s is not of type BaseCPU" % new_cpu)
270 if new_cpu in old_cpu_set:
270 if new_cpu in old_cpu_set:
271 raise RuntimeError, \
272 "New CPU (%s) is in the list of old CPUs." % (old_cpu,)
271 raise RuntimeError(
272 "New CPU (%s) is in the list of old CPUs." % (old_cpu,))
273 if not new_cpu.switchedOut():
273 if not new_cpu.switchedOut():
274 raise RuntimeError, \
275 "New CPU (%s) is already active." % (new_cpu,)
274 raise RuntimeError("New CPU (%s) is already active." % (new_cpu,))
276 if not new_cpu.support_take_over():
275 if not new_cpu.support_take_over():
277 raise RuntimeError, \
278 "New CPU (%s) does not support CPU handover." % (old_cpu,)
276 raise RuntimeError(
277 "New CPU (%s) does not support CPU handover." % (old_cpu,))
279 if new_cpu.memory_mode() != memory_mode_name:
278 if new_cpu.memory_mode() != memory_mode_name:
280 raise RuntimeError, \
279 raise RuntimeError(
281 "%s and %s require different memory modes." % (new_cpu,
280 "%s and %s require different memory modes." % (new_cpu,
282 new_cpus[0])
281 new_cpus[0]))
283 if old_cpu.switchedOut():
282 if old_cpu.switchedOut():
284 raise RuntimeError, \
285 "Old CPU (%s) is inactive." % (new_cpu,)
283 raise RuntimeError("Old CPU (%s) is inactive." % (new_cpu,))
286 if not old_cpu.support_take_over():
284 if not old_cpu.support_take_over():
287 raise RuntimeError, \
288 "Old CPU (%s) does not support CPU handover." % (old_cpu,)
285 raise RuntimeError(
286 "Old CPU (%s) does not support CPU handover." % (old_cpu,))
289
290 try:
291 memory_mode = _memory_modes[memory_mode_name]
292 except KeyError:
287
288 try:
289 memory_mode = _memory_modes[memory_mode_name]
290 except KeyError:
293 raise RuntimeError, "Invalid memory mode (%s)" % memory_mode_name
291 raise RuntimeError("Invalid memory mode (%s)" % memory_mode_name)
294
295 drain()
296
297 # Now all of the CPUs are ready to be switched out
298 for old_cpu, new_cpu in cpuList:
299 old_cpu.switchOut()
300
301 # Change the memory mode if required. We check if this is needed

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

338
339 Return Value:
340 pid of the child process or 0 if running in the child.
341 """
342 from m5 import options
343 global fork_count
344
345 if not _m5.core.listenersDisabled():
292
293 drain()
294
295 # Now all of the CPUs are ready to be switched out
296 for old_cpu, new_cpu in cpuList:
297 old_cpu.switchOut()
298
299 # Change the memory mode if required. We check if this is needed

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

336
337 Return Value:
338 pid of the child process or 0 if running in the child.
339 """
340 from m5 import options
341 global fork_count
342
343 if not _m5.core.listenersDisabled():
346 raise RuntimeError, "Can not fork a simulator with listeners enabled"
344 raise RuntimeError("Can not fork a simulator with listeners enabled")
347
348 drain()
349
350 try:
351 pid = os.fork()
345
346 drain()
347
348 try:
349 pid = os.fork()
352 except OSError, e:
350 except OSError as e:
353 raise e
354
355 if pid == 0:
356 # In child, notify objects of the fork
357 root = objects.Root.getInstance()
358 notifyFork(root)
359 # Setup a new output directory
360 parent = options.outdir

--- 14 unchanged lines hidden ---
351 raise e
352
353 if pid == 0:
354 # In child, notify objects of the fork
355 root = objects.Root.getInstance()
356 notifyFork(root)
357 # Setup a new output directory
358 parent = options.outdir

--- 14 unchanged lines hidden ---