def fork(simout="%(parent)s.f%(fork_seq)i"): """Fork the simulator. This function forks the simulator. After forking the simulator, the child process gets its output files redirected to a new output directory. The default name of the output directory is the same as the parent with the suffix ".fN" added where N is the fork sequence number. The name of the output directory can be overridden using the simout keyword argument. Output file formatting dictionary: parent -- Path to the parent process's output directory. fork_seq -- Fork sequence number. pid -- PID of the child process. Keyword Arguments: simout -- New simulation output directory. Return Value: pid of the child process or 0 if running in the child. """ from m5 import options global fork_count if not _m5.core.listenersDisabled(): raise RuntimeError, "Can not fork a simulator with listeners enabled" drain() try: pid = os.fork() except OSError, e: raise e
def checkpoint(dir): root = objects.Root.getInstance() if not isinstance(root, objects.Root): raise TypeError("Checkpoint must be called on a root object.") drain() memWriteback(root) print("Writing checkpoint") _m5.core.serializeAll(dir)
def fork(simout="%(parent)s.f%(fork_seq)i"): """Fork the simulator. This function forks the simulator. After forking the simulator, the child process gets its output files redirected to a new output directory. The default name of the output directory is the same as the parent with the suffix ".fN" added where N is the fork sequence number. The name of the output directory can be overridden using the simout keyword argument. Output file formatting dictionary: parent -- Path to the parent process's output directory. fork_seq -- Fork sequence number. pid -- PID of the child process. Keyword Arguments: simout -- New simulation output directory. Return Value: pid of the child process or 0 if running in the child. """ from m5 import options global fork_count if not _m5.core.listenersDisabled(): raise RuntimeError("Can not fork a simulator with listeners enabled") drain() # Terminate helper threads that service parallel event queues. _m5.event.terminateEventQueueThreads() try: pid = os.fork() except OSError as e: raise e if pid == 0: # In child, notify objects of the fork root = objects.Root.getInstance() notifyFork(root) # Setup a new output directory parent = options.outdir options.outdir = simout % { "parent": parent, "fork_seq": fork_count, "pid": os.getpid(), } _m5.core.setOutputDir(options.outdir) else: fork_count += 1 return pid
def fork(simout="%(parent)s.f%(fork_seq)i"): """Fork the simulator. This function forks the simulator. After forking the simulator, the child process gets its output files redirected to a new output directory. The default name of the output directory is the same as the parent with the suffix ".fN" added where N is the fork sequence number. The name of the output directory can be overridden using the simout keyword argument. Output file formatting dictionary: parent -- Path to the parent process's output directory. fork_seq -- Fork sequence number. pid -- PID of the child process. Keyword Arguments: simout -- New simulation output directory. Return Value: pid of the child process or 0 if running in the child. """ from m5 import options global fork_count if not _m5.core.listenersDisabled(): raise RuntimeError("Can not fork a simulator with listeners enabled") drain() try: pid = os.fork() except OSError as e: raise e if pid == 0: # In child, notify objects of the fork root = objects.Root.getInstance() notifyFork(root) # Setup a new output directory parent = options.outdir options.outdir = simout % { "parent" : parent, "fork_seq" : fork_count, "pid" : os.getpid(), } _m5.core.setOutputDir(options.outdir) else: fork_count += 1 return pid
def switchCpus(system, cpuList, verbose=True): """Switch CPUs in a system. Note: This method may switch the memory mode of the system if that is required by the CPUs. It may also flush all caches in the system. Arguments: system -- Simulated system. cpuList -- (old_cpu, new_cpu) tuples """ if verbose: print("switching cpus") if not isinstance(cpuList, list): raise RuntimeError("Must pass a list to this function") for item in cpuList: if not isinstance(item, tuple) or len(item) != 2: raise RuntimeError("List must have tuples of (oldCPU,newCPU)") old_cpus = [old_cpu for old_cpu, new_cpu in cpuList] new_cpus = [new_cpu for old_cpu, new_cpu in cpuList] old_cpu_set = set(old_cpus) memory_mode_name = new_cpus[0].memory_mode() for old_cpu, new_cpu in cpuList: if not isinstance(old_cpu, objects.BaseCPU): raise TypeError("%s is not of type BaseCPU" % old_cpu) if not isinstance(new_cpu, objects.BaseCPU): raise TypeError("%s is not of type BaseCPU" % new_cpu) if new_cpu in old_cpu_set: raise RuntimeError( "New CPU (%s) is in the list of old CPUs." % (old_cpu,)) if not new_cpu.switchedOut(): raise RuntimeError("New CPU (%s) is already active." % (new_cpu,)) if not new_cpu.support_take_over(): raise RuntimeError( "New CPU (%s) does not support CPU handover." % (old_cpu,)) if new_cpu.memory_mode() != memory_mode_name: raise RuntimeError( "%s and %s require different memory modes." % (new_cpu, new_cpus[0])) if old_cpu.switchedOut(): raise RuntimeError("Old CPU (%s) is inactive." % (new_cpu,)) if not old_cpu.support_take_over(): raise RuntimeError( "Old CPU (%s) does not support CPU handover." % (old_cpu,)) try: memory_mode = _memory_modes[memory_mode_name] except KeyError: raise RuntimeError("Invalid memory mode (%s)" % memory_mode_name) drain() # Now all of the CPUs are ready to be switched out for old_cpu, new_cpu in cpuList: old_cpu.switchOut() # Change the memory mode if required. We check if this is needed # to avoid printing a warning if no switch was performed. if system.getMemoryMode() != memory_mode: # Flush the memory system if we are switching to a memory mode # that disables caches. This typically happens when switching to a # hardware virtualized CPU. if memory_mode == objects.params.atomic_noncaching: memWriteback(system) memInvalidate(system) _changeMemoryMode(system, memory_mode) for old_cpu, new_cpu in cpuList: new_cpu.takeOverFrom(old_cpu)