def _run_step(name, restore=None, interval=0.5): """ Instantiate (optionally from a checkpoint if restore is set to the checkpoitn name) the system and run for interval seconds of simulated time. At the end of the simulation interval, create a checkpoint and exit. As this function is intended to run in its own process using the multiprocessing framework, the exit is a true call to exit which terminates the process. Exit codes are used to pass information to the parent. """ if restore is not None: m5.instantiate(restore) else: m5.instantiate() e = m5.simulate(m5.ticks.fromSeconds(interval)) cause = e.getCause() if cause in _exit_limit: m5.checkpoint(name) sys.exit(_exitcode_checkpoint) elif cause in _exit_normal: sys.exit(_exitcode_done) else: print("Test failed: Unknown exit cause: %s" % cause) sys.exit(_exitcode_fail)
def run_test(root, switcher=None, freq=1000): """Test runner for CPU switcheroo tests. The switcheroo test runner is used to switch CPUs in a system that has been prepared for CPU switching. Such systems should have multiple CPUs when they are instantiated, but only one should be switched in. Such configurations can be created using the base_config.BaseFSSwitcheroo class. A CPU switcher object is used to control switching. The default switcher sequentially switches between all CPUs in a system, starting with the CPU that is currently switched in. Unlike most other test runners, this one automatically configures the memory mode of the system based on the first CPU the switcher reports. Keyword Arguments: switcher -- CPU switcher implementation. See Sequential for an example implementation. period -- Switching frequency in Hz. """ if switcher == None: switcher = Sequential(root.system.cpu) current_cpu = switcher.first() system = root.system system.mem_mode = type(current_cpu).memory_mode() # instantiate configuration m5.instantiate() # Determine the switching period, this has to be done after # instantiating the system since the time base must be fixed. period = m5.ticks.fromSeconds(1.0 / freq) while True: exit_event = m5.simulate(period) exit_cause = exit_event.getCause() if exit_cause == "simulate() limit reached": next_cpu = switcher.next() print "Switching CPUs..." print "Next CPU: %s" % type(next_cpu) m5.drain(system) if current_cpu != next_cpu: m5.switchCpus(system, [ (current_cpu, next_cpu) ], do_drain=False) else: print "Source CPU and destination CPU are the same, skipping..." m5.resume(system) current_cpu = next_cpu elif exit_cause == "target called exit()" or \ exit_cause == "m5_exit instruction encountered": sys.exit(0) else: print "Test failed: Unknown exit cause: %s" % exit_cause sys.exit(1)
def run_test(root): """Default run_test implementations. Scripts can override it.""" # instantiate configuration m5.instantiate() # simulate until program terminates exit_event = m5.simulate(maxtick) print('Exiting @ tick', m5.curTick(), 'because', exit_event.getCause())
def run_test(root): """gpu test requires a specialized run_test implementation to set up the mmio space.""" # instantiate configuration m5.instantiate() # Now that the system has been constructed, setup the mmio space root.system.cpu[0].workload[0].map(0x10000000, 0x200000000, 4096) # simulate until program terminates exit_event = m5.simulate(maxtick) print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("commands_to_run", metavar="command(s)", nargs='*', help="Command(s) to run") parser.add_argument("--cpu", type=str, choices=cpu_types.keys(), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=MemConfig.mem_names(), help = "type of memory to use") parser.add_argument("--mem-channels", type=int, default=2, help = "number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help = "number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") args = parser.parse_args() # Create a single root node for gem5's object hierarchy. There can # only exist one root node in the simulator at any given # time. Tell gem5 that we want to use syscall emulation mode # instead of full system mode. root = Root(full_system=False) # Populate the root node with a system. A system corresponds to a # single node with shared memory. root.system = create(args) # Instantiate the C++ object hierarchy. After this point, # SimObjects can't be instantiated anymore. m5.instantiate() # Start the simulator. This gives control to the C++ world and # starts the simulator. The returned event tells the simulation # script why the simulator exited. event = m5.simulate() # Print the reason for the simulation exit. Some exit codes are # requests for service (e.g., checkpoints) from the simulation # script. We'll just ignore them here and exit. print(event.getCause(), " @ ", m5.curTick()) sys.exit(event.getCode())
def run_test(root, interval=0.5, max_checkpoints=5): """ Run the simulated system for a fixed amount of time and take a checkpoint, then restore from the same checkpoint and run until the system calls m5 exit. """ cpt_name = os.path.join(m5.options.outdir, "test.cpt") restore = None for cpt_no in range(max_checkpoints): # Create a checkpoint from a separate child process. This enables # us to get back to a (mostly) pristine state and restart # simulation from the checkpoint. p = Process(target=_run_step, args=(cpt_name, ), kwargs={ "restore" : restore, "interval" : interval, }) p.start() # Wait for the child to return p.join() # Restore from the checkpoint next iteration restore = cpt_name if p.exitcode == _exitcode_done: print("Test done.", file=sys.stderr) sys.exit(0) elif p.exitcode == _exitcode_checkpoint: pass else: print("Test failed.", file=sys.stderr) sys.exit(1) # Maximum number of checkpoints reached. Just run full-speed from # now on. m5.instantiate() e = m5.simulate() cause = e.getCause() if cause in _exit_normal: sys.exit(0) else: print("Test failed: Unknown exit cause: %s" % cause) sys.exit(1)
def main(): parser = argparse.ArgumentParser(description="Simple system using HMC as\ main memory") HMC.add_options(parser) add_options(parser) options = parser.parse_args() # build the system root = build_system(options) # instantiate all of the objects we've created so far m5.instantiate() print("Beginning simulation!") event = m5.simulate(10000000000) m5.stats.dump() print('Exiting @ tick %i because %s (exit code is %i)' % (m5.curTick(), event.getCause(), event.getCode())) print("Done")
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("--dtb", type=str, default=None, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk-image", type=str, default=default_disk, help="Disk to instantiate") parser.add_argument("--script", type=str, default="", help = "Linux bootscript") parser.add_argument("--cpu", type=str, choices=cpu_types.keys(), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=MemConfig.mem_names(), help = "type of memory to use") parser.add_argument("--mem-channels", type=int, default=1, help = "number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help = "number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--restore", type=str, default=None) args = parser.parse_args() root = Root(full_system=True) root.system = create(args) if args.restore is not None: m5.instantiate(args.restore) else: m5.instantiate() run(args)
def instantiate(options, checkpoint_dir=None): # Setup the simulation quantum if we are running in PDES-mode # (e.g., when using KVM) root = Root.getInstance() if root and _using_pdes(root): m5.util.inform("Running in PDES mode with a %s simulation quantum.", options.sim_quantum) root.sim_quantum = _to_ticks(options.sim_quantum) # Get and load from the chkpt or simpoint checkpoint if options.restore_from: if checkpoint_dir and not os.path.isabs(options.restore_from): cpt = os.path.join(checkpoint_dir, options.restore_from) else: cpt = options.restore_from m5.util.inform("Restoring from checkpoint %s", cpt) m5.instantiate(cpt) else: m5.instantiate()
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("--kernel", type=str, default=None, help="Binary to run") parser.add_argument("--disk-image", type=str, default=None, help="Disk to instantiate") parser.add_argument("--readfile", type=str, default="", help="File to return with the m5 readfile command") parser.add_argument("--cpu", type=str, choices=cpu_types.keys(), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=MemConfig.mem_names(), help="type of memory to use") parser.add_argument("--mem-channels", type=int, default=1, help="number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help="number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--restore", type=str, default=None) parser.add_argument("--dtb-gen", action="store_true", help="Doesn't run simulation, it generates a DTB only") args = parser.parse_args() root = Root(full_system=True) root.system = create(args) if args.restore is not None: m5.instantiate(args.restore) else: m5.instantiate() if args.dtb_gen: # No run, autogenerate DTB and exit root.system.generateDtb(m5.options.outdir, 'system.dtb') else: run(args)
def run_test(root, switcher=None, freq=1000, verbose=False): """Test runner for CPU switcheroo tests. The switcheroo test runner is used to switch CPUs in a system that has been prepared for CPU switching. Such systems should have multiple CPUs when they are instantiated, but only one should be switched in. Such configurations can be created using the base_config.BaseFSSwitcheroo class. A CPU switcher object is used to control switching. The default switcher sequentially switches between all CPUs in a system, starting with the CPU that is currently switched in. Unlike most other test runners, this one automatically configures the memory mode of the system based on the first CPU the switcher reports. Keyword Arguments: switcher -- CPU switcher implementation. See Sequential for an example implementation. period -- Switching frequency in Hz. verbose -- Enable output at each switch (suppressed by default). """ if switcher == None: switcher = Sequential(root.system.cpu) current_cpu = switcher.first() system = root.system system.mem_mode = type(current_cpu).memory_mode() # Suppress "Entering event queue" messages since we get tons of them. # Worse yet, they include the timestamp, which makes them highly # variable and unsuitable for comparing as test outputs. if not verbose: _m5.core.setLogLevel(_m5.core.LogLevel.WARN) # instantiate configuration m5.instantiate() # Determine the switching period, this has to be done after # instantiating the system since the time base must be fixed. period = m5.ticks.fromSeconds(1.0 / freq) while True: exit_event = m5.simulate(period) exit_cause = exit_event.getCause() if exit_cause == "simulate() limit reached": next_cpu = switcher.next() if verbose: print("Switching CPUs...") print("Next CPU: %s" % type(next_cpu)) m5.drain() if current_cpu != next_cpu: m5.switchCpus(system, [ (current_cpu, next_cpu) ], verbose=verbose) else: print("Source CPU and destination CPU are the same," " skipping...") current_cpu = next_cpu elif exit_cause == "target called exit()" or \ exit_cause == "m5_exit instruction encountered": sys.exit(0) else: print("Test failed: Unknown exit cause: %s" % exit_cause) sys.exit(1)
def main(): parser = argparse.ArgumentParser() parser.add_argument("--dtb", type=str, default=None, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk-image", type=str, default=default_disk, help="Disk to instantiate") parser.add_argument( "--root-device", type=str, default=default_root_device, help="OS device name for root partition (default: {})".format( default_root_device)) parser.add_argument("--script", type=str, default="", help="Linux bootscript") parser.add_argument("--cpu", choices=list(cpu_types.keys()), default="minor", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("-n", "--num-cpus", type=int, default=1) parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--restore", type=str, default=None) parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=ObjectList.mem_list.get_names(), help="type of memory to use") parser.add_argument("--mem-channels", type=int, default=1, help="number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help="number of memory ranks per channel") parser.add_argument( "--mem-size", action="store", type=str, default="2GiB", help="Specify the physical memory size (single memory)") parser.add_argument("--enable-dram-powerdown", action="store_true", help="Enable low-power states in DRAMInterface") parser.add_argument("--mem-channels-intlv", type=int, default=0, help="Memory channels interleave") parser.add_argument("--num-dirs", type=int, default=1) parser.add_argument("--num-l2caches", type=int, default=1) parser.add_argument("--num-l3caches", type=int, default=1) parser.add_argument("--l1d_size", type=str, default="64kB") parser.add_argument("--l1i_size", type=str, default="32kB") parser.add_argument("--l2_size", type=str, default="2MB") parser.add_argument("--l3_size", type=str, default="16MB") parser.add_argument("--l1d_assoc", type=int, default=2) parser.add_argument("--l1i_assoc", type=int, default=2) parser.add_argument("--l2_assoc", type=int, default=8) parser.add_argument("--l3_assoc", type=int, default=16) parser.add_argument("--cacheline_size", type=int, default=64) Ruby.define_options(parser) args = parser.parse_args() root = Root(full_system=True) root.system = create(args) if args.restore is not None: m5.instantiate(args.restore) else: m5.instantiate() run(args)
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("--kernel", type=str, default=None, help="Binary to run") parser.add_argument("--workload", type=str, default="ArmBaremetal", choices=workloads.workload_list.get_names(), help="Workload type") parser.add_argument("--disk-image", type=str, default=None, help="Disk to instantiate") parser.add_argument("--readfile", type=str, default="", help="File to return with the m5 readfile command") parser.add_argument("--cpu", type=str, choices=list(cpu_types.keys()), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--machine-type", type=str, choices=ObjectList.platform_list.get_names(), default="VExpress_GEM5_V2", help="Hardware platform class") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=ObjectList.mem_list.get_names(), help="type of memory to use") parser.add_argument("--mem-channels", type=int, default=1, help="number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help="number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--restore", type=str, default=None) parser.add_argument("--dtb-gen", action="store_true", help="Doesn't run simulation, it generates a DTB only") parser.add_argument("--semi-enable", action="store_true", help="Enable semihosting support") parser.add_argument("--semi-stdin", type=str, default="stdin", help="Standard input for semihosting " \ "(default: gem5's stdin)") parser.add_argument("--semi-stdout", type=str, default="stdout", help="Standard output for semihosting " \ "(default: gem5's stdout)") parser.add_argument("--semi-stderr", type=str, default="stderr", help="Standard error for semihosting " \ "(default: gem5's stderr)") parser.add_argument('--semi-path', type=str, default="", help=('Search path for files to be loaded through ' 'Arm Semihosting')) parser.add_argument("args", default=[], nargs="*", help="Semihosting arguments to pass to benchmark") parser.add_argument( "-P", "--param", action="append", default=[], help="Set a SimObject parameter relative to the root node. " "An extended Python multi range slicing syntax can be used " "for arrays. For example: " "'system.cpu[0,1,3:8:2].max_insts_all_threads = 42' " "sets max_insts_all_threads for cpus 0, 1, 3, 5 and 7 " "Direct parameters of the root object are not accessible, " "only parameters of its children.") args = parser.parse_args() root = Root(full_system=True) root.system = create(args) root.apply_config(args.param) if args.restore is not None: m5.instantiate(args.restore) else: m5.instantiate() if args.dtb_gen: # No run, autogenerate DTB and exit root.system.generateDtb(os.path.join(m5.options.outdir, 'system.dtb')) else: run(args)
def run(options, root, testsys, cpu_class): # NOTE: this function is called from example from configs/example/ruby_fs.py # like this: "Simulation.run(options, root, system, FutureClass)" # so, "system" is "testsys" here; if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") np = options.num_cpus max_checkpoints = options.max_checkpoints switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [cpu_class(defer_registration=True, cpu_id=(np+i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys if not buildEnv['FULL_SYSTEM']: switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[0].clock # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.standard_switch: if not options.caches: # O3 CPU must have a cache to work. print "O3 CPU must be used with caches" sys.exit(1) switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(np+i)) for i in xrange(np)] switch_cpus_1 = [DerivO3CPU(defer_registration=True, cpu_id=(2*np+i)) for i in xrange(np)] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys if not buildEnv['FULL_SYSTEM']: switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[0].clock switch_cpus_1[i].clock = testsys.cpu[0].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: from os.path import isdir, exists from os import listdir import re if not isdir(cptdir): fatal("checkpoint dir %s does not exist!", cptdir) if options.at_instruction or options.simpoint: inst = options.checkpoint_restore if options.simpoint: # assume workload 0 has the simpoint if testsys.cpu[0].workload[0].simpoint == 0: fatal('Unable to find simpoint') inst += int(testsys.cpu[0].workload[0].simpoint) checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst)) if not exists(checkpoint_dir): fatal("Unable to find checkpoint directory %s", checkpoint_dir) else: dirs = listdir(cptdir) expr = re.compile('cpt\.([0-9]*)') cpts = [] for dir in dirs: match = expr.match(dir) if match: cpts.append(match.group(1)) cpts.sort(lambda a,b: cmp(long(a), long(b))) cpt_num = options.checkpoint_restore if cpt_num > len(cpts): fatal('Checkpoint %d not found', cpt_num) ## Adjust max tick based on our starting tick maxtick = maxtick - int(cpts[cpt_num - 1]) checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) # when you change to Timing (or Atomic), you halt the system # given as argument. When you are finished with the system # changes (including switchCpus), you must resume the system # manually. You DON'T need to resume after just switching # CPUs if you haven't changed anything on the system level. m5.changeToTiming(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.warmup) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.drain(testsys) m5.switchCpus(switch_cpu_list1) m5.resume(testsys) num_checkpoints = 0 exit_cause = '' # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. if options.take_checkpoints != None : if options.at_instruction or options.simpoint: checkpoint_inst = int(options.take_checkpoints) # maintain correct offset if we restored from some instruction if options.checkpoint_restore != None: checkpoint_inst += options.checkpoint_restore print "Creating checkpoint at inst:%d" % (checkpoint_inst) exit_event = m5.simulate() print "exit cause = %s" % (exit_event.getCause()) # skip checkpoint instructions should they exist while exit_event.getCause() == "checkpoint": exit_event = m5.simulate() if exit_event.getCause() == \ "a thread reached the max instruction count": m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ (options.bench, checkpoint_inst))) print "Checkpoint written." num_checkpoints += 1 if exit_event.getCause() == "user interrupt received": exit_cause = exit_event.getCause(); else: when, period = options.take_checkpoints.split(",", 1) when = int(when) period = int(period) exit_event = m5.simulate(when) while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(when - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 sim_ticks = when exit_cause = "maximum %d checkpoints dropped" % max_checkpoints while num_checkpoints < max_checkpoints and \ exit_event.getCause() == "simulate() limit reached": if (sim_ticks + period) > maxtick: exit_event = m5.simulate(maxtick - sim_ticks) exit_cause = exit_event.getCause() break else: exit_event = m5.simulate(period) sim_ticks += period while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(sim_ticks - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if exit_event.getCause() != "simulate() limit reached": exit_cause = exit_event.getCause(); else: # no checkpoints being taken via this script if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" #exit_event = m5.simulate(maxtick) # --Note1: Ruby is created in ruby_fs.py by # "Ruby.create_system(options, system, system.piobus, system._dma_devices)" # which assigned: "stats_filename = options.ruby_stats"; # definition of "create_system" is in configs/ruby/Ruby.py, which # instantiate the ctor of RubySystem: "system.ruby = RubySystem(...)"; #print testsys.ruby._cpu_ruby_ports #print testsys.ruby.network.ni_flit_size #print testsys.ruby.profiler.ruby_system # the ctor of RubySystem is defined in src/mem/ruby/system/RubySystem.py; # which sets some defaults: #print testsys.ruby.stats_filename # i.e., ruby.stats #print testsys.ruby.type #print testsys.ruby.random_seed #print testsys.ruby.clock #print testsys.ruby.block_size_bytes #print testsys.ruby.mem_size #print testsys.ruby.no_mem_vec # () cris: description of changes # --Note2: initially writing into ruby.stats was done with overwriting; # so, for each dump point the file was re-written; to fix that I # changed function "OutputDirectory::create(...)" from src/base/output.cc # which is called by "RubyExitCallback::process()" from src/mem/ruby/system/System.cc # function that is the one called at the end of the gem5 run # as a calback to dump all ruby stats (callback is "registered" in the # ctor of RubySystem::RubySystem() inside the same file...); # --Note3: using doExitCleanup inspired from src/python/m5/simulate.py # (inside which ini and json files are created; you need to rebuild each # time you change that Python file): #m5.internal.core.doExitCleanup( False) #clear callback queue? # --Note4: python/m5/internal/core.py describes "m5.internal.core"; # cris: here I want to dump stats every other delta ticks; # I need these to be able to generate reliability traces; NUM_OF_DUMPS = 100 num_i = 0 delta = maxtick/NUM_OF_DUMPS sim_ticks = m5.curTick() while (m5.curTick() < maxtick): sim_ticks += delta exit_event = m5.simulate(sim_ticks - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": #--Note5: "doExitCleanup()" is described in src/sim/core.cc; # I changed it to be able to call it multiple times; #--Note6: do not dump stats in ruby.stats for last iteration # because it will be repeated once more via the exit callbacks # in src/python/m5/simulate.py... # Note6: next call of doExitCleanup does actually also reset/clear # the stats of ruby system via the RubyExitCallback::process() in # src/mem/ruby/system/System.cc if num_i < (NUM_OF_DUMPS-1): print "Dumping also ruby stats at inst %d to file: ruby.stats" %(num_i) m5.internal.core.doExitCleanup( False) #clear callback queue? print "Dumping gem5 stats at inst %d to file: stats.txt" %(num_i) # --Note7: dump() wites into stats.txt; dump() is defined in # src/python/m5/stats/__init__.py and does its # thing via the functions described in base/stats/text.cc #atexit.register(stats.dump) <--- does not work (from simulate.py) m5.stats.dump() m5.stats.reset() # <--- what does it actually do? num_i += 1 # alex's changes: #while exit_event.getCause() != "m5_exit instruction encountered": # m5.stats.dump() # m5.stats.reset() # exit_event = m5.simulate(maxtick) #while exit_event.getCause() == "checkpoint": # m5.checkpoint(joinpath(cptdir, "cpt.%d")) # num_checkpoints += 1 # if num_checkpoints == max_checkpoints: # exit_cause = "maximum %d checkpoints dropped" % max_checkpoints # break # exit_event = m5.simulate(maxtick - m5.curTick()) # exit_cause = exit_event.getCause() if exit_cause == '': exit_cause = exit_event.getCause() print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d"))
def run(options, root, testsys, cpu_class): if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") np = options.num_cpus max_checkpoints = options.max_checkpoints new = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: new = [cpu_class(defer_registration=True, cpu_id=(np + i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) new[i].system = testsys if not buildEnv["FULL_SYSTEM"]: new[i].workload = testsys.cpu[i].workload new[i].clock = testsys.cpu[0].clock # simulation period if options.maxinsts: new[i].max_insts_any_thread = options.maxinsts testsys.new = new switch_cpu_list = [(testsys.cpu[i], new[i]) for i in xrange(np)] if options.standard_switch: if not options.caches: # O3 CPU must have a cache to work. print "O3 CPU must be used with caches" sys.exit(1) new = [TimingSimpleCPU(defer_registration=True, cpu_id=(np + i)) for i in xrange(np)] new_1 = [DerivO3CPU(defer_registration=True, cpu_id=(2 * np + i)) for i in xrange(np)] for i in xrange(np): new[i].system = testsys new_1[i].system = testsys if not buildEnv["FULL_SYSTEM"]: new[i].workload = testsys.cpu[i].workload new_1[i].workload = testsys.cpu[i].workload new[i].clock = testsys.cpu[0].clock new_1[i].clock = testsys.cpu[0].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal("simpoint not found") testsys.cpu[i].max_insts_any_thread = testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: new[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: new_1[i].max_insts_any_thread = options.maxinsts testsys.new = new testsys.new_1 = new_1 switch_cpu_list = [(testsys.cpu[i], new[i]) for i in xrange(np)] switch_cpu_list1 = [(new[i], new_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal("no simpoint for testsys.cpu[%d].workload[0]", i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: from os.path import isdir, exists from os import listdir import re if not isdir(cptdir): fatal("checkpoint dir %s does not exist!", cptdir) if options.at_instruction or options.simpoint: inst = options.checkpoint_restore if options.simpoint: # assume workload 0 has the simpoint if testsys.cpu[0].workload[0].simpoint == 0: fatal("Unable to find simpoint") inst += int(testsys.cpu[0].workload[0].simpoint) checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst)) if not exists(checkpoint_dir): fatal("Unable to find checkpoint directory %s", checkpoint_dir) else: dirs = listdir(cptdir) expr = re.compile("cpt\.([0-9]*)") cpts = [] for dir in dirs: match = expr.match(dir) if match: cpts.append(match.group(1)) cpts.sort(lambda a, b: cmp(long(a), long(b))) cpt_num = options.checkpoint_restore if cpt_num > len(cpts): fatal("Checkpoint %d not found", cpt_num) ## Adjust max tick based on our starting tick maxtick = maxtick - int(cpts[cpt_num - 1]) checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) # when you change to Timing (or Atomic), you halt the system # given as argument. When you are finished with the system # changes (including switchCpus), you must resume the system # manually. You DON'T need to resume after just switching # CPUs if you haven't changed anything on the system level. m5.changeToTiming(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) if options.standard_switch: print "Switch at instruction count:%d" % (testsys.new[0].max_insts_any_thread) # warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.warmup) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % (testsys.new_1[0].max_insts_any_thread) m5.drain(testsys) m5.switchCpus(switch_cpu_list1) m5.resume(testsys) num_checkpoints = 0 exit_cause = "" # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. if options.take_checkpoints != None: if options.at_instruction or options.simpoint: checkpoint_inst = int(options.take_checkpoints) # maintain correct offset if we restored from some instruction if options.checkpoint_restore != None: checkpoint_inst += options.checkpoint_restore print "Creating checkpoint at inst:%d" % (checkpoint_inst) exit_event = m5.simulate() print "exit cause = %s" % (exit_event.getCause()) # skip checkpoint instructions should they exist while exit_event.getCause() == "checkpoint": exit_event = m5.simulate() if exit_event.getCause() == "a thread reached the max instruction count": m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % (options.bench, checkpoint_inst))) print "Checkpoint written." num_checkpoints += 1 if exit_event.getCause() == "user interrupt received": exit_cause = exit_event.getCause() else: when, period = options.take_checkpoints.split(",", 1) when = int(when) period = int(period) exit_event = m5.simulate(when) while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(when - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 sim_ticks = when exit_cause = "maximum %d checkpoints dropped" % max_checkpoints while num_checkpoints < max_checkpoints and exit_event.getCause() == "simulate() limit reached": if (sim_ticks + period) > maxtick: exit_event = m5.simulate(maxtick - sim_ticks) exit_cause = exit_event.getCause() break else: exit_event = m5.simulate(period) sim_ticks += period while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(sim_ticks - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if exit_event.getCause() != "simulate() limit reached": exit_cause = exit_event.getCause() else: # no checkpoints being taken via this script if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" exit_event = m5.simulate(maxtick) while exit_event.getCause() == "checkpoint": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if num_checkpoints == max_checkpoints: exit_cause = "maximum %d checkpoints dropped" % max_checkpoints break exit_event = m5.simulate(maxtick - m5.curTick()) exit_cause = exit_event.getCause() if exit_cause == "": exit_cause = exit_event.getCause() print "Exiting @ tick %i because %s" % (m5.curTick(), exit_cause) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d"))
def main(): parser = argparse.ArgumentParser( description="Generic ARM big.LITTLE configuration") parser.add_argument("--restore-from", type=str, default=None, help="Restore from checkpoint") parser.add_argument("--dtb", type=str, default=default_dtb, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk", action="append", type=str, default=[], help="Disks to instantiate") parser.add_argument("--bootscript", type=str, default=default_rcs, help="Linux bootscript") parser.add_argument("--atomic", action="store_true", default=False, help="Use atomic CPUs") parser.add_argument("--kernel-init", type=str, default="/sbin/init", help="Override init") parser.add_argument("--big-cpus", type=int, default=1, help="Number of big CPUs to instantiate") parser.add_argument("--little-cpus", type=int, default=1, help="Number of little CPUs to instantiate") parser.add_argument("--caches", action="store_true", default=False, help="Instantiate caches") parser.add_argument("--last-cache-level", type=int, default=2, help="Last level of caches (e.g. 3 for L3)") parser.add_argument("--big-cpu-clock", type=str, default="2GHz", help="Big CPU clock frequency") parser.add_argument("--little-cpu-clock", type=str, default="1GHz", help="Little CPU clock frequency") m5.ticks.fixGlobalFrequency() options = parser.parse_args() if options.atomic: cpu_config = { 'cpu' : AtomicSimpleCPU } big_cpu_config, little_cpu_config = cpu_config, cpu_config else: big_cpu_config = { 'cpu' : CpuConfig.get("arm_detailed"), 'l1i' : devices.L1I, 'l1d' : devices.L1D, 'wcache' : devices.WalkCache, 'l2' : devices.L2 } little_cpu_config = { 'cpu' : MinorCPU, 'l1i' : devices.L1I, 'l1d' : devices.L1D, 'wcache' : devices.WalkCache, 'l2' : devices.L2 } big_cpu_class = big_cpu_config['cpu'] little_cpu_class = little_cpu_config['cpu'] kernel_cmd = [ "earlyprintk=pl011,0x1c090000", "console=ttyAMA0", "lpj=19988480", "norandmaps", "loglevel=8", "mem=%s" % default_mem_size, "root=/dev/vda1", "rw", "init=%s" % options.kernel_init, "vmalloc=768MB", ] root = Root(full_system=True) assert big_cpu_class.memory_mode() == little_cpu_class.memory_mode() disks = default_disk if len(options.disk) == 0 else options.disk system = createSystem(options.kernel, big_cpu_class.memory_mode(), options.bootscript, disks=disks) root.system = system system.boot_osflags = " ".join(kernel_cmd) # big cluster if options.big_cpus > 0: system.bigCluster = CpuCluster() system.bigCluster.addCPUs(big_cpu_config, options.big_cpus, options.big_cpu_clock) # LITTLE cluster if options.little_cpus > 0: system.littleCluster = CpuCluster() system.littleCluster.addCPUs(little_cpu_config, options.little_cpus, options.little_cpu_clock) # add caches if options.caches: cluster_mem_bus = addCaches(system, options.last_cache_level) else: if big_cpu_class.require_caches(): m5.util.panic("CPU model %s requires caches" % str(big_cpu_class)) if little_cpu_class.require_caches(): m5.util.panic("CPU model %s requires caches" % str(little_cpu_class)) cluster_mem_bus = system.membus # connect each cluster to the memory hierarchy for cluster in system._clusters: cluster.connectMemSide(cluster_mem_bus) # Linux device tree system.dtb_filename = SysPaths.binary(options.dtb) # Get and load from the chkpt or simpoint checkpoint if options.restore_from is not None: m5.instantiate(options.restore_from) else: m5.instantiate() # start simulation (and drop checkpoints when requested) while True: event = m5.simulate() exit_msg = event.getCause() if exit_msg == "checkpoint": print "Dropping checkpoint at tick %d" % m5.curTick() cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick()) m5.checkpoint(os.path.join(cpt_dir)) print "Checkpoint done." else: print exit_msg, " @ ", m5.curTick() break sys.exit(event.getCode())
def main(): parser = argparse.ArgumentParser( description="Generic ARM big.LITTLE configuration") parser.add_argument("--restore-from", type=str, default=None, help="Restore from checkpoint") parser.add_argument("--dtb", type=str, default=default_dtb, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk", action="append", type=str, default=[], help="Disks to instantiate") parser.add_argument("--bootscript", type=str, default=default_rcs, help="Linux bootscript") parser.add_argument("--atomic", action="store_true", default=False, help="Use atomic CPUs") parser.add_argument("--kernel-init", type=str, default="/sbin/init", help="Override init") parser.add_argument("--big-cpus", type=int, default=1, help="Number of big CPUs to instantiate") parser.add_argument("--little-cpus", type=int, default=1, help="Number of little CPUs to instantiate") parser.add_argument("--caches", action="store_true", default=False, help="Instantiate caches") parser.add_argument("--last-cache-level", type=int, default=2, help="Last level of caches (e.g. 3 for L3)") parser.add_argument("--big-cpu-clock", type=str, default="2GHz", help="Big CPU clock frequency") parser.add_argument("--little-cpu-clock", type=str, default="1GHz", help="Little CPU clock frequency") m5.ticks.fixGlobalFrequency() options = parser.parse_args() kernel_cmd = [ "earlyprintk=pl011,0x1c090000", "console=ttyAMA0", "lpj=19988480", "norandmaps", "loglevel=8", "mem=%s" % default_mem_size, "root=/dev/vda1", "rw", "init=%s" % options.kernel_init, "vmalloc=768MB", ] root = Root(full_system=True) disks = default_disk if len(options.disk) == 0 else options.disk system = createSystem(options.kernel, options.bootscript, disks=disks) root.system = system system.boot_osflags = " ".join(kernel_cmd) AtomicCluster = devices.AtomicCluster if options.big_cpus + options.little_cpus == 0: m5.util.panic("Empty CPU clusters") # big cluster if options.big_cpus > 0: if options.atomic: system.bigCluster = AtomicCluster(system, options.big_cpus, options.big_cpu_clock) else: system.bigCluster = BigCluster(system, options.big_cpus, options.big_cpu_clock) mem_mode = system.bigCluster.memoryMode() # little cluster if options.little_cpus > 0: if options.atomic: system.littleCluster = AtomicCluster(system, options.little_cpus, options.little_cpu_clock) else: system.littleCluster = LittleCluster(system, options.little_cpus, options.little_cpu_clock) mem_mode = system.littleCluster.memoryMode() if options.big_cpus > 0 and options.little_cpus > 0: if system.bigCluster.memoryMode() != system.littleCluster.memoryMode(): m5.util.panic("Memory mode missmatch among CPU clusters") system.mem_mode = mem_mode # create caches system.addCaches(options.caches, options.last_cache_level) if not options.caches: if options.big_cpus > 0 and system.bigCluster.requireCaches(): m5.util.panic("Big CPU model requires caches") if options.little_cpus > 0 and system.littleCluster.requireCaches(): m5.util.panic("Little CPU model requires caches") # Linux device tree system.dtb_filename = SysPaths.binary(options.dtb) # Get and load from the chkpt or simpoint checkpoint if options.restore_from is not None: m5.instantiate(options.restore_from) else: m5.instantiate() # start simulation (and drop checkpoints when requested) while True: event = m5.simulate() exit_msg = event.getCause() if exit_msg == "checkpoint": print "Dropping checkpoint at tick %d" % m5.curTick() cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick()) m5.checkpoint(os.path.join(cpt_dir)) print "Checkpoint done." else: print exit_msg, " @ ", m5.curTick() break sys.exit(event.getCode())
m5.ticks.setGlobalFrequency('1THz') if args.abs_max_tick: maxtick = args.abs_max_tick else: maxtick = m5.MaxTick # Benchmarks support work item annotations Simulation.setWorkCountOptions(system, args) # Checkpointing is not supported by APU model if (args.checkpoint_dir != None or args.checkpoint_restore != None): fatal("Checkpointing not supported by apu model") checkpoint_dir = None m5.instantiate(checkpoint_dir) # Map workload to this address space host_cpu.workload[0].map(0x10000000, 0x200000000, 4096) if args.fast_forward: print("Switch at instruction count: %d" % cpu_list[0].max_insts_any_thread) exit_event = m5.simulate(maxtick) if args.fast_forward: if exit_event.getCause() == "a thread reached the max instruction count": m5.switchCpus(system, switch_cpu_list) print("Switched CPUS @ tick %s" % (m5.curTick())) m5.stats.reset() exit_event = m5.simulate(maxtick - m5.curTick())
def run(options, root, testsys, cpu_class): if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") np = options.num_cpus max_checkpoints = options.max_checkpoints switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [ cpu_class(defer_registration=True, cpu_id=(np + i)) for i in xrange(np) ] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[0].clock # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.standard_switch: if not options.caches: # O3 CPU must have a cache to work. print "O3 CPU must be used with caches" sys.exit(1) switch_cpus = [ TimingSimpleCPU(defer_registration=True, cpu_id=(np + i)) for i in xrange(np) ] switch_cpus_1 = [ DerivO3CPU(defer_registration=True, cpu_id=(2 * np + i)) for i in xrange(np) ] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[0].clock switch_cpus_1[i].clock = testsys.cpu[0].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int( testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: from os.path import isdir, exists from os import listdir import re if not isdir(cptdir): fatal("checkpoint dir %s does not exist!", cptdir) if options.at_instruction or options.simpoint: inst = options.checkpoint_restore if options.simpoint: # assume workload 0 has the simpoint if testsys.cpu[0].workload[0].simpoint == 0: fatal('Unable to find simpoint') inst += int(testsys.cpu[0].workload[0].simpoint) checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst)) if not exists(checkpoint_dir): fatal("Unable to find checkpoint directory %s", checkpoint_dir) else: dirs = listdir(cptdir) expr = re.compile('cpt\.([0-9]*)') cpts = [] for dir in dirs: match = expr.match(dir) if match: cpts.append(match.group(1)) cpts.sort(lambda a, b: cmp(long(a), long(b))) cpt_num = options.checkpoint_restore if cpt_num > len(cpts): fatal('Checkpoint %d not found', cpt_num) ## Adjust max tick based on our starting tick maxtick = maxtick - int(cpts[cpt_num - 1]) checkpoint_dir = joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1]) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Using Fault Injection Method" print "1) Simulate with Detailed" exit_event = m5.simulate() exit_cause = exit_event.getCause() if exit_cause == "switchcpu": print "2) DINOSRetutn Results with Atomic simple" m5.changeToAtomic(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) print "Successfully resumed the system" exit_event = m5.simulate() exit_cause = exit_event.getCause() print "Fault Injection System stopped" print "Exiting @ tick %i because %s" % (m5.curTick(), exit_cause) return elif exit_cause == "fi_system_init": print "Fi_system_init encountered" return 1 else: m5.drain(testsys) print "Fault Injection System stopped" print "Exiting @ tick %i because %s" % (m5.curTick(), exit_cause) return # when you change to Timing (or Atomic), you halt the system # given as argument. When you are finished with the system # changes (including switchCpus), you must resume the system # manually. You DON'T need to resume after just switching # CPUs if you haven't changed anything on the system level. m5.changeToTiming(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.warmup) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.drain(testsys) m5.switchCpus(switch_cpu_list1) m5.resume(testsys) num_checkpoints = 0 exit_cause = '' # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. if options.take_checkpoints != None: if options.at_instruction or options.simpoint: checkpoint_inst = int(options.take_checkpoints) # maintain correct offset if we restored from some instruction if options.checkpoint_restore != None: checkpoint_inst += options.checkpoint_restore print "Creating checkpoint at inst:%d" % (checkpoint_inst) exit_event = m5.simulate() print "exit cause = %s" % (exit_event.getCause()) # skip checkpoint instructions should they exist while exit_event.getCause() == "checkpoint": exit_event = m5.simulate() if exit_event.getCause() == \ "a thread reached the max instruction count": m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ (options.bench, checkpoint_inst))) print "Checkpoint written." num_checkpoints += 1 if exit_event.getCause() == "user interrupt received": exit_cause = exit_event.getCause() else: when, period = options.take_checkpoints.split(",", 1) when = int(when) period = int(period) exit_event = m5.simulate(when) while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(when - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 sim_ticks = when exit_cause = "maximum %d checkpoints dropped" % max_checkpoints while num_checkpoints < max_checkpoints and \ exit_event.getCause() == "simulate() limit reached": if (sim_ticks + period) > maxtick: exit_event = m5.simulate(maxtick - sim_ticks) exit_cause = exit_event.getCause() break else: exit_event = m5.simulate(period) sim_ticks += period while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(sim_ticks - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if exit_event.getCause() != "simulate() limit reached": exit_cause = exit_event.getCause() else: # no checkpoints being taken via this script if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" exit_event = m5.simulate(maxtick) while exit_event.getCause() == "checkpoint": m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if num_checkpoints == max_checkpoints: exit_cause = "maximum %d checkpoints dropped" % max_checkpoints break exit_event = m5.simulate(maxtick - m5.curTick()) exit_cause = exit_event.getCause() print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) if exit_cause == '': exit_cause = exit_event.getCause() print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d"))
def run(options, root, testsys, cpu_class, numpids): if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [ cpu_class(defer_registration=True, cpu_id=(i)) for i in xrange(np) ] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: if options.cpu_type == "arm_detailed": if not options.caches: print "O3 CPU must be used with caches" sys.exit(1) repeat_switch_cpus = [O3_ARM_v7a_3(defer_registration=True, \ cpu_id=(i)) for i in xrange(np)] elif options.cpu_type == "detailed": if not options.caches: print "O3 CPU must be used with caches" sys.exit(1) repeat_switch_cpus = [DerivO3CPU(defer_registration=True, \ cpu_id=(i)) for i in xrange(np)] elif options.cpu_type == "inorder": print "inorder CPU switching not supported" sys.exit(1) elif options.cpu_type == "timing": repeat_switch_cpus = [TimingSimpleCPU(defer_registration=True, \ cpu_id=(i)) for i in xrange(np)] else: repeat_switch_cpus = [AtomicSimpleCPU(defer_registration=True, \ cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clock = testsys.cpu[i].clock if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: switch_cpus = [ TimingSimpleCPU(defer_registration=True, cpu_id=(i)) for i in xrange(np) ] switch_cpus_1 = [ DerivO3CPU(defer_registration=True, cpu_id=(i)) for i in xrange(np) ] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock switch_cpus_1[i].clock = testsys.cpu[i].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int( testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: maxtick, checkpoint_dir = findCptDir(options, maxtick, cptdir, testsys) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate(maxtick, numpids) elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate(maxtick, numpids) else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) # when you change to Timing (or Atomic), you halt the system # given as argument. When you are finished with the system # changes (including switchCpus), you must resume the system # manually. You DON'T need to resume after just switching # CPUs if you haven't changed anything on the system level. m5.changeToTiming(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate(maxtick, numpids) else: exit_event = m5.simulate(options.standard_switch, numpids) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.drain(testsys) m5.switchCpus(switch_cpu_list1) m5.resume(testsys) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None: # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_cause = scriptCheckpoints(options, cptdir) else: if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_cause = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_cause = benchCheckpoints(options, maxtick, cptdir, numpids) print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d"))
elif options.benchmark == 'LU_noncontig': system.cpu[i].workload = LU_noncontig() elif options.benchmark == 'Radix': system.cpu[i].workload = Radix() elif options.benchmark == 'Barnes': system.cpu[i].workload = Barnes() elif options.benchmark == 'FMM': system.cpu[i].workload = FMM() elif options.benchmark == 'OceanContig': system.cpu[i].workload = Ocean_contig() elif options.benchmark == 'OceanNoncontig': system.cpu[i].workload = Ocean_noncontig() elif options.benchmark == 'Raytrace': system.cpu[i].workload = Raytrace() elif options.benchmark == 'WaterNSquared': system.cpu[i].workload = Water_nsquared() elif options.benchmark == 'WaterSpatial': system.cpu[i].workload = Water_spatial() else: system.cpu[i].workload = process root.system.mem_mode = 'timing' m5.instantiate(root) try: exit_event = m5.simulate(m5.MaxTick) print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause() except: print 'Failed @ tick', m5.curTick()
def run_test(root, switcher=None, freq=1000, verbose=False): """Test runner for CPU switcheroo tests. The switcheroo test runner is used to switch CPUs in a system that has been prepared for CPU switching. Such systems should have multiple CPUs when they are instantiated, but only one should be switched in. Such configurations can be created using the base_config.BaseFSSwitcheroo class. A CPU switcher object is used to control switching. The default switcher sequentially switches between all CPUs in a system, starting with the CPU that is currently switched in. Unlike most other test runners, this one automatically configures the memory mode of the system based on the first CPU the switcher reports. Keyword Arguments: switcher -- CPU switcher implementation. See Sequential for an example implementation. period -- Switching frequency in Hz. verbose -- Enable output at each switch (suppressed by default). """ if switcher == None: switcher = Sequential(root.system.cpu) current_cpu = switcher.first() system = root.system system.mem_mode = type(current_cpu).memory_mode() # Suppress "Entering event queue" messages since we get tons of them. # Worse yet, they include the timestamp, which makes them highly # variable and unsuitable for comparing as test outputs. if not verbose: _m5.core.Logger.setLevel(_m5.core.Logger.WARN) # instantiate configuration m5.instantiate() # Determine the switching period, this has to be done after # instantiating the system since the time base must be fixed. period = m5.ticks.fromSeconds(1.0 / freq) while True: exit_event = m5.simulate(period) exit_cause = exit_event.getCause() if exit_cause == "simulate() limit reached": next_cpu = switcher.next() if verbose: print "Switching CPUs..." print "Next CPU: %s" % type(next_cpu) m5.drain() if current_cpu != next_cpu: m5.switchCpus(system, [(current_cpu, next_cpu)], verbose=verbose) else: print "Source CPU and destination CPU are the same, skipping..." current_cpu = next_cpu elif exit_cause == "target called exit()" or \ exit_cause == "m5_exit instruction encountered": sys.exit(0) else: print "Test failed: Unknown exit cause: %s" % exit_cause sys.exit(1)
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("commands_to_run", metavar="command(s)", nargs='*', help="Command(s) to run") parser.add_argument("--cpu", type=str, choices=list(cpu_types.keys()), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=ObjectList.mem_list.get_names(), help="type of memory to use") parser.add_argument("--mem-channels", type=int, default=2, help="number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help="number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") args = parser.parse_args() # Create a single root node for gem5's object hierarchy. There can # only exist one root node in the simulator at any given # time. Tell gem5 that we want to use syscall emulation mode # instead of full system mode. root = Root(full_system=False) # Populate the root node with a system. A system corresponds to a # single node with shared memory. root.system = create(args) # Instantiate the C++ object hierarchy. After this point, # SimObjects can't be instantiated anymore. m5.instantiate() # Start the simulator. This gives control to the C++ world and # starts the simulator. The returned event tells the simulation # script why the simulator exited. event = m5.simulate() # Print the reason for the simulation exit. Some exit codes are # requests for service (e.g., checkpoints) from the simulation # script. We'll just ignore them here and exit. print(event.getCause(), " @ ", m5.curTick()) sys.exit(event.getCode())
m5.ticks.setGlobalFrequency('1THz') if options.abs_max_tick: maxtick = options.abs_max_tick else: maxtick = m5.MaxTick # Benchmarks support work item annotations Simulation.setWorkCountOptions(system, options) # Checkpointing is not supported by APU model if (options.checkpoint_dir != None or options.checkpoint_restore != None): fatal("Checkpointing not supported by apu model") checkpoint_dir = None m5.instantiate(checkpoint_dir) # Map workload to this address space host_cpu.workload[0].map(0x10000000, 0x200000000, 4096) if options.fast_forward: print("Switch at instruction count: %d" % cpu_list[0].max_insts_any_thread) exit_event = m5.simulate(maxtick) if options.fast_forward: if exit_event.getCause() == "a thread reached the max instruction count": m5.switchCpus(system, switch_cpu_list) print("Switched CPUS @ tick %s" % (m5.curTick())) m5.stats.reset() exit_event = m5.simulate(maxtick - m5.curTick())
make_level(spec[1:], prototypes[1:], cache, "cpu_side") else: # we just built the MemTest objects parent.cpu = objs for t in objs: t.test = getattr(attach_obj, attach_port) t.functional = system.funcmem.port make_level(treespec, prototypes, system.physmem, "port") # ----------------------- # run simulation # ----------------------- root = Root( system = system ) if options.atomic: root.system.mem_mode = 'atomic' else: root.system.mem_mode = 'timing' # Not much point in this being higher than the L1 latency m5.ticks.setGlobalFrequency('1ns') # instantiate configuration m5.instantiate(root) # simulate until program terminates exit_event = m5.simulate(options.maxtick) print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
def main(): parser = argparse.ArgumentParser( description="Generic ARM big.LITTLE configuration") parser.add_argument("--restore-from", type=str, default=None, help="Restore from checkpoint") parser.add_argument("--dtb", type=str, default=default_dtb, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk", action="append", type=str, default=[], help="Disks to instantiate") parser.add_argument("--bootscript", type=str, default=default_rcs, help="Linux bootscript") parser.add_argument("--atomic", action="store_true", default=False, help="Use atomic CPUs") parser.add_argument("--kernel-init", type=str, default="/sbin/init", help="Override init") parser.add_argument("--big-cpus", type=int, default=1, help="Number of big CPUs to instantiate") parser.add_argument("--little-cpus", type=int, default=1, help="Number of little CPUs to instantiate") parser.add_argument("--caches", action="store_true", default=False, help="Instantiate caches") parser.add_argument("--last-cache-level", type=int, default=2, help="Last level of caches (e.g. 3 for L3)") parser.add_argument("--big-cpu-clock", type=str, default="2GHz", help="Big CPU clock frequency") parser.add_argument("--little-cpu-clock", type=str, default="1GHz", help="Little CPU clock frequency") m5.ticks.fixGlobalFrequency() options = parser.parse_args() kernel_cmd = [ "earlyprintk=pl011,0x1c090000", "console=ttyAMA0", "lpj=19988480", "norandmaps", "loglevel=8", "mem=%s" % default_mem_size, "root=/dev/vda1", "rw", "init=%s" % options.kernel_init, "vmalloc=768MB", ] root = Root(full_system=True) disks = [default_disk] if len(options.disk) == 0 else options.disk system = createSystem(options.caches, options.kernel, options.bootscript, disks=disks) root.system = system system.boot_osflags = " ".join(kernel_cmd) AtomicCluster = devices.AtomicCluster if options.big_cpus + options.little_cpus == 0: m5.util.panic("Empty CPU clusters") # big cluster if options.big_cpus > 0: if options.atomic: system.bigCluster = AtomicCluster(system, options.big_cpus, options.big_cpu_clock) else: system.bigCluster = BigCluster(system, options.big_cpus, options.big_cpu_clock) mem_mode = system.bigCluster.memoryMode() # little cluster if options.little_cpus > 0: if options.atomic: system.littleCluster = AtomicCluster(system, options.little_cpus, options.little_cpu_clock) else: system.littleCluster = LittleCluster(system, options.little_cpus, options.little_cpu_clock) mem_mode = system.littleCluster.memoryMode() if options.big_cpus > 0 and options.little_cpus > 0: if system.bigCluster.memoryMode() != system.littleCluster.memoryMode(): m5.util.panic("Memory mode missmatch among CPU clusters") system.mem_mode = mem_mode # create caches system.addCaches(options.caches, options.last_cache_level) if not options.caches: if options.big_cpus > 0 and system.bigCluster.requireCaches(): m5.util.panic("Big CPU model requires caches") if options.little_cpus > 0 and system.littleCluster.requireCaches(): m5.util.panic("Little CPU model requires caches") # Linux device tree system.dtb_filename = SysPaths.binary(options.dtb) # Get and load from the chkpt or simpoint checkpoint if options.restore_from is not None: m5.instantiate(options.restore_from) else: m5.instantiate() # start simulation (and drop checkpoints when requested) while True: event = m5.simulate() exit_msg = event.getCause() if exit_msg == "checkpoint": print "Dropping checkpoint at tick %d" % m5.curTick() cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick()) m5.checkpoint(os.path.join(cpt_dir)) print "Checkpoint done." else: print exit_msg, " @ ", m5.curTick() break sys.exit(event.getCode())
def run(options, root, testsys, cpu_class): if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [cpu_class(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus[i].progress_interval = testsys.cpu[i].progress_interval # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: switch_class = getCPUClass(options.cpu_type)[0] if switch_class.require_caches() and \ not options.caches: print "%s: Must be used with caches" % str(switch_class) sys.exit(1) if not switch_class.support_take_over(): print "%s: CPU switching not supported" % str(switch_class) sys.exit(1) repeat_switch_cpus = [switch_class(switched_out=True, \ cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus_1[i].clk_domain = testsys.cpu[i].clk_domain # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset if options.take_simpoint_checkpoints != None: simpoints, interval_length = parseSimpointAnalysisFile(options, testsys) checkpoint_dir = None if options.checkpoint_restore: cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys) m5.instantiate(checkpoint_dir) # Initialization is complete. If we're not in control of simulation # (that is, if we're a slave simulator acting as a component in another # 'master' simulator) then we're done here. The other simulator will # call simulate() directly. --initialize-only is used to indicate this. if options.initialize_only: return # Handle the max tick settings now that tick frequency was resolved # during system instantiation # NOTE: the maxtick variable here is in absolute ticks, so it must # include any simulated ticks before a checkpoint explicit_maxticks = 0 maxtick_from_abs = m5.MaxTick maxtick_from_rel = m5.MaxTick maxtick_from_maxtime = m5.MaxTick if options.abs_max_tick: maxtick_from_abs = options.abs_max_tick explicit_maxticks += 1 if options.rel_max_tick: maxtick_from_rel = options.rel_max_tick if options.checkpoint_restore: # NOTE: this may need to be updated if checkpoints ever store # the ticks per simulated second maxtick_from_rel += cpt_starttick if options.at_instruction or options.simpoint: warn("Relative max tick specified with --at-instruction or" \ " --simpoint\n These options don't specify the " \ "checkpoint start tick, so assuming\n you mean " \ "absolute max tick") explicit_maxticks += 1 if options.maxtime: maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime) explicit_maxticks += 1 if explicit_maxticks > 1: warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\ " Using least") maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime]) if options.checkpoint_restore != None and maxtick < cpt_starttick: fatal("Bad maxtick (%d) specified: " \ "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) m5.switchCpus(testsys, switch_cpu_list) if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.standard_switch) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.switchCpus(testsys, switch_cpu_list1) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if (options.take_checkpoints or options.take_simpoint_checkpoints) \ and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None : # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_event = scriptCheckpoints(options, maxtick, cptdir) # Take SimPoint checkpoints elif options.take_simpoint_checkpoints != None: takeSimpointCheckpoints(simpoints, interval_length, cptdir) # Restore from SimPoint checkpoints elif options.restore_simpoint_checkpoint != None: restoreSimpointCheckpoint() else: if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_event = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_event = benchCheckpoints(options, maxtick, cptdir) print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d")) if not m5.options.interactive: sys.exit(exit_event.getCode())
def simulate(opts, binary): if opts.policy == 'random': policy_obj = RandomRP() elif opts.policy == 'lru': policy_obj = LRURP() elif opts.policy == 'treelru': policy_obj = TreePLRURP() elif opts.policy == 'lip': policy_obj = LIPRP() elif opts.policy == 'mru': policy_obj = MRURP() elif opts.policy == 'lfu': policy_obj = LFURP() elif opts.policy == 'fifo': policy_obj = FIFORP() elif opts.policy == 'secondchance': policy_obj = SecondChanceRP() elif opts.policy == 'nru': policy_obj = NRURP() elif opts.policy == 'rrip': policy_obj = RRIPRP() elif opts.policy == 'brrip': policy_obj = BRRIPRP() else: raise Exception("Unknown policy " + opts.policy + ". Known policies: " + (", ".join([it for it in globals() if it[-2:] == "RP"]))) """ if opts.predictor == 'local': predictor_obj = LocalBP() elif opts.predictor == 'tournament': predictor_obj = TournamentBP() elif opts.predictor == 'bimode': predictor_obj = BiModeBP() else: raise Exception("Unknown predictor " + opts.predictor + ". Known predictors: local, tournament, bimode") """ predictor_obj = TournamentBP() predictor_obj.localPredictorSize = opts.local_buffer predictor_obj.globalPredictorSize = opts.global_buffer predictor_obj.BTBEntries = opts.btb_entries predictor_obj.RASSize = opts.ras_size # create the system we are going to simulate system = System() # Set the clock fequency of the system (and all of its children) system.clk_domain = SrcClockDomain() system.clk_domain.clock = opts.speed or '1GHz' system.clk_domain.voltage_domain = VoltageDomain() # Set up the system system.mem_mode = 'timing' # Use timing accesses system.mem_ranges = [AddrRange('512MB')] # Create an address range # Create a simple CPU system.cpu = TimingSimpleCPU() # system.cpu.wait_for_remote_gdb = True system.cpu.branchPred = predictor_obj # Create an L1 instruction and data cache class CacheConfig(): def __init__(self, l1_size, l2_size): self.l1i_size = self.l1d_size = str(l1_size) + "B" self.l2_size = str(l2_size) + "B" cache_config = CacheConfig(opts.l1_size, opts.l2_size) system.cpu.icache = L1ICache(cache_config) system.cpu.dcache = L1DCache(cache_config) system.cpu.dcache.replacement_policy = policy_obj system.cpu.icache.replacement_policy = policy_obj # Connect the instruction and data caches to the CPU system.cpu.icache.connectCPU(system.cpu) system.cpu.dcache.connectCPU(system.cpu) # Create a memory bus system.membus = SystemXBar() has_l2_cache = str(opts.l2_size) != "0" if has_l2_cache: # Create a memory bus, a coherent crossbar, in this case system.l2bus = L2XBar() # Hook the CPU ports up to the l2bus system.cpu.icache.connectBus(system.l2bus) system.cpu.dcache.connectBus(system.l2bus) # Create an L2 cache and connect it to the l2bus system.l2cache = L2Cache(cache_config) system.l2cache.replacement_policy = policy_obj system.l2cache.connectCPUSideBus(system.l2bus) # Connect the L2 cache to the membus system.l2cache.connectMemSideBus(system.membus) else: # Connect the CPU ports to the membus system.cpu.icache.connectBus(system.membus) system.cpu.dcache.connectBus(system.membus) # create the interrupt controller for the CPU system.cpu.createInterruptController() # For x86 only, make sure the interrupts are connected to the memory # Note: these are directly connected to the memory bus and are not cached if m5.defines.buildEnv['TARGET_ISA'] == "x86": system.cpu.interrupts[0].pio = system.membus.master system.cpu.interrupts[0].int_master = system.membus.slave system.cpu.interrupts[0].int_slave = system.membus.master # Create a DDR3 memory controller if m5.defines.buildEnv['TARGET_ISA'].lower() == "alpha": # syntax for gem5 v19, required for using ALPHA print( "Using old (gem5 v19) syntax for the memory controller, patch simulate.py if this is incorrect" ) system.mem_ctrl = DDR3_1600_8x8() system.mem_ctrl.range = system.mem_ranges[0] system.mem_ctrl.port = system.membus.master else: # syntax for the latest version of gem5 (v21) print( "Using new (gem5 v21) syntax for the memory controller, patch simulate.py if this is incorrect" ) system.mem_ctrl = MemCtrl() system.mem_ctrl.dram = DDR3_1600_8x8() system.mem_ctrl.dram.range = system.mem_ranges[0] system.mem_ctrl.port = system.membus.master # Connect the system up to the membus system.system_port = system.membus.slave # Create a process for a simple "Hello World" application process = Process() # Set the command # cmd is a list which begins with the executable (like argv) process.cmd = [binary] # Set the cpu to use the process as its workload and create thread contexts system.cpu.workload = process system.cpu.createThreads() # set up the root SimObject and start the simulation root = Root(full_system=False, system=system) # instantiate all of the objects we've created above m5.instantiate() print("Beginning simulation!") exit_event = m5.simulate() print('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()))
def main(): parser = argparse.ArgumentParser(epilog=__doc__) parser.add_argument("--dtb", type=str, default=None, help="DTB file to load") parser.add_argument("--kernel", type=str, default=default_kernel, help="Linux kernel") parser.add_argument("--disk-image", type=str, default=default_disk, help="Disk to instantiate") parser.add_argument( "--root-device", type=str, default=default_root_device, help="OS device name for root partition (default: {})".format( default_root_device)) parser.add_argument("--script", type=str, default="", help="Linux bootscript") parser.add_argument("--cpu", type=str, choices=list(cpu_types.keys()), default="atomic", help="CPU model to use") parser.add_argument("--cpu-freq", type=str, default="4GHz") parser.add_argument("--num-cores", type=int, default=1, help="Number of CPU cores") parser.add_argument("--mem-type", default="DDR3_1600_8x8", choices=ObjectList.mem_list.get_names(), help="type of memory to use") parser.add_argument("--mem-channels", type=int, default=1, help="number of memory channels") parser.add_argument("--mem-ranks", type=int, default=None, help="number of memory ranks per channel") parser.add_argument("--mem-size", action="store", type=str, default="2GB", help="Specify the physical memory size") parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--restore", type=str, default=None) # Add options #Options.addCommonOptions(parser) parser.add_argument( "--stats-root", action="append", default=[], help="If given, dump only stats of objects under the given SimObject. " "SimObjects are identified with Python notation as in: " "system.cpu[0].dtb. All elements of an array can be selected at " "once with: system.cpu[:].dtb. If given multiple times, dump stats " "that are present under any of the roots. If not given, dump all " "stats. ") args = parser.parse_args() root = Root(full_system=True) root.system = create(args) dump_stats = [] for stat_root_str in args.stats_root: dump_stats.extend(root.get_simobj(stat_root_str)) m5.stats.global_dump_roots = dump_stats if args.restore is not None: m5.instantiate(args.restore) else: m5.instantiate() run(args)
return peers parser = argparse.ArgumentParser() parser.add_argument('config_file', metavar='config-file.ini', help='.ini configuration file to load and run') parser.add_argument('--checkpoint-dir', type=str, default=None, help='A checkpoint to directory to restore when starting ' 'the simulation') args = parser.parse_args(sys.argv[1:]) if args.config_file.endswith('.ini'): config = ConfigIniFile() config.load(args.config_file) else: config = ConfigJsonFile() config.load(args.config_file) ticks.fixGlobalFrequency() mgr = ConfigManager(config) mgr.find_all_objects() m5.instantiate(args.checkpoint_dir) exit_event = m5.simulate() print('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()))
import argparse import m5 import sys from m5.objects import SystemC_Kernel, Root, SystemC_Printer, Gem5_Feeder # pylint:disable=unused-variable parser = argparse.ArgumentParser() parser.add_argument('--word', action="append", default=[]) parser.add_argument('--delay', default='1ns') parser.add_argument('--prefix', default='') args = parser.parse_args() printer = SystemC_Printer() printer.prefix = args.prefix feeder = Gem5_Feeder() feeder.printer = printer feeder.delay = args.delay feeder.strings = args.word kernel = SystemC_Kernel(feeder=feeder) root = Root(full_system=True, systemc_kernel=kernel) m5.instantiate(None) cause = m5.simulate(m5.MaxTick).getCause() print(cause)
fatal("Checkpoint directory '%s' already exists.", options.checkpoint_dir) else: os.mkdir(options.checkpoint_dir) root = Root(full_system = False, system = system) ckpt_dir = None if options.simpoint_mode == "checkpoint": simpoints = sorted([max(int(line.split()[0]) * options.simpoint_interval, 1) for line in open(options.simpoint_points)]) if options.checkpoint_num >= len(simpoints): fatal("Invalid checkpoint number %d. Max possible %d", options.checkpoint_num, len(simple_end_points)) point_inst = simpoints[options.checkpoint_num]; cpu.simpoint_start_insts = [ options.simpoint_interval ] ckpt_dir = os.path.join(options.checkpoint_dir, "simpoint.ckpt.inst.%d" % point_inst) m5.instantiate(ckpt_dir) if options.simpoint_mode == "none" or options.simpoint_mode == "checkpoint" or options.simpoint_mode == "generate": exit_event = m5.simulate() exit_cause = exit_event.getCause() elif options.simpoint_mode == "fastfwd": exit_event = m5.simulate() exit_cause = exit_event.getCause() while exit_cause == "simpoint starting point found": m5.switchCpus(system, switch_cpu_list) tmp_cpu_list = [] for old_cpu, new_cpu in switch_cpu_list: tmp_cpu_list.append((new_cpu, old_cpu)) switch_cpu_list = tmp_cpu_list m5.stats.reset()
def run(options, root, testsys, cpu_class): if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [cpu_class(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: switch_class = getCPUClass("detailed")[0] print "Going to simulate with %s" % str(switch_class) if switch_class.require_caches() and \ not options.caches: print "%s: Must be used with caches" % str(switch_class) sys.exit(1) if not switch_class.support_take_over(): print "%s: CPU switching not supported" % str(switch_class) sys.exit(1) repeat_switch_cpus = [switch_class(switched_out=True, \ cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus_1[i].clk_domain = testsys.cpu[i].clk_domain # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore: cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys) m5.instantiate(checkpoint_dir) # Handle the max tick settings now that tick frequency was resolved # during system instantiation # NOTE: the maxtick variable here is in absolute ticks, so it must # include any simulated ticks before a checkpoint explicit_maxticks = 0 maxtick_from_abs = m5.MaxTick maxtick_from_rel = m5.MaxTick maxtick_from_maxtime = m5.MaxTick if options.abs_max_tick: maxtick_from_abs = options.abs_max_tick explicit_maxticks += 1 if options.rel_max_tick: maxtick_from_rel = options.rel_max_tick if options.checkpoint_restore: # NOTE: this may need to be updated if checkpoints ever store # the ticks per simulated second maxtick_from_rel += cpt_starttick if options.at_instruction or options.simpoint: warn("Relative max tick specified with --at-instruction or" \ " --simpoint\n These options don't specify the " \ "checkpoint start tick, so assuming\n you mean " \ "absolute max tick") explicit_maxticks += 1 if options.maxtime: maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime) explicit_maxticks += 1 if explicit_maxticks > 1: warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\ " Using least") maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime]) if options.checkpoint_restore != None and maxtick < cpt_starttick: fatal("Bad maxtick (%d) specified: " \ "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick) if options.standard_switch or cpu_class: exit_event = m5.simulate(100) exit_cause=exit_event.getCause() counter = 0 while True: print "Switching One more time" counter = counter + 1 if (counter % 2) == 0: m5.switchCpus(testsys,switch_cpu_list1) else: m5.switchCpus(testsys,switch_cpu_list) exit_event = m5.simulate(); exit_cause = exit_event.getCause() print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) if exit_cause != "switchcpu": break print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) sys.exit(exit_event.getCode()) if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif options.switch_on_fault: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) exit_event = m5.simulate() exit_cause = exit_event.getCause() if exit_cause == "switchcpu": print "GEMFI:switched cpu" m5.switchCpus(testsys, switch_cpu_list) else: print "exiting cause of %s"%exit_event.getCause() if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate() print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.switchCpus(testsys, switch_cpu_list1) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None : # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_event = scriptCheckpoints(options, maxtick, cptdir) else: if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_event = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_event = benchCheckpoints(options, maxtick, cptdir) print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d")) if not m5.options.interactive: sys.exit(exit_event.getCode())
# Authors: Gabe Black from __future__ import print_function import argparse import m5 import os import re import sys from m5.objects import SystemC_Kernel, Root # pylint:disable=unused-variable kernel = SystemC_Kernel() root = Root(full_system=True, systemc_kernel=kernel) m5.systemc.sc_main('gem5_systemc_test'); m5.instantiate(None) cause = m5.simulate(m5.MaxTick).getCause() result = m5.systemc.sc_main_result() if result.code != 0: # Arguably this should make gem5 fail, but some tests purposefully # generate errors, and as long as their output matches that's still # considered correct. A "real" systemc config should expect sc_main # (if present) not to fail. sys.exit(int(result.code))
def run(options, root, testsys, cpu_class): if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [ cpu_class(switched_out=True, cpu_id=(i)) for i in xrange(np) ] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus[i].progress_interval = \ testsys.cpu[i].progress_interval switch_cpus[i].isa = testsys.cpu[i].isa # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() if options.bp_type: bpClass = BPConfig.get(options.bp_type) switch_cpus[i].branchPred = bpClass() # If elastic tracing is enabled attach the elastic trace probe # to the switch CPUs if options.elastic_trace_en: CpuConfig.config_etrace(cpu_class, switch_cpus, options) testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: switch_class = getCPUClass(options.cpu_type)[0] if switch_class.require_caches() and \ not options.caches: print("%s: Must be used with caches" % str(switch_class)) sys.exit(1) if not switch_class.support_take_over(): print("%s: CPU switching not supported" % str(switch_class)) sys.exit(1) repeat_switch_cpus = [switch_class(switched_out=True, \ cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain repeat_switch_cpus[i].isa = testsys.cpu[i].isa if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: #switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i)) switch_cpus = [ DerivO3CPU(switched_out=True, cpu_id=(i)) for i in xrange(np) ] switch_cpus_1 = [ DerivO3CPU(switched_out=True, cpu_id=(i)) for i in xrange(np) ] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus_1[i].clk_domain = testsys.cpu[i].clk_domain switch_cpus[i].isa = testsys.cpu[i].isa switch_cpus_1[i].isa = testsys.cpu[i].isa # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int( testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset if options.take_simpoint_checkpoints != None: simpoints, interval_length = parseSimpointAnalysisFile( options, testsys) checkpoint_dir = None if options.checkpoint_restore: cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys) root.apply_config(options.param) m5.instantiate(checkpoint_dir) # Initialization is complete. If we're not in control of simulation # (that is, if we're a slave simulator acting as a component in another # 'master' simulator) then we're done here. The other simulator will # call simulate() directly. --initialize-only is used to indicate this. if options.initialize_only: return # Handle the max tick settings now that tick frequency was resolved # during system instantiation # NOTE: the maxtick variable here is in absolute ticks, so it must # include any simulated ticks before a checkpoint explicit_maxticks = 0 maxtick_from_abs = m5.MaxTick maxtick_from_rel = m5.MaxTick maxtick_from_maxtime = m5.MaxTick if options.abs_max_tick: maxtick_from_abs = options.abs_max_tick explicit_maxticks += 1 if options.rel_max_tick: maxtick_from_rel = options.rel_max_tick if options.checkpoint_restore: # NOTE: this may need to be updated if checkpoints ever store # the ticks per simulated second maxtick_from_rel += cpt_starttick if options.at_instruction or options.simpoint: warn("Relative max tick specified with --at-instruction or" \ " --simpoint\n These options don't specify the " \ "checkpoint start tick, so assuming\n you mean " \ "absolute max tick") explicit_maxticks += 1 if options.maxtime: maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime) explicit_maxticks += 1 if explicit_maxticks > 1: warn("Specified multiple of --abs-max-tick, --rel-max-tick, --maxtime."\ " Using least") maxtick = min([maxtick_from_abs, maxtick_from_rel, maxtick_from_maxtime]) if options.checkpoint_restore != None and maxtick < cpt_starttick: fatal("Bad maxtick (%d) specified: " \ "Checkpoint starts starts from tick: %d", maxtick, cpt_starttick) if options.standard_switch or cpu_class: if options.standard_switch: print("Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread)) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print("Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread)) exit_event = m5.simulate() else: print("Switch at curTick count:%s" % str(10000)) exit_event = m5.simulate(10000) print("Switched CPUS @ tick %s" % (m5.curTick())) m5.switchCpus(testsys, switch_cpu_list) if options.standard_switch: print("Switch at instruction count:%d" % (testsys.switch_cpus[0].max_insts_any_thread)) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.standard_switch) print("Switching CPUS @ tick %s" % (m5.curTick())) print("Simulation ends instruction count:%d" % (testsys.switch_cpus_1[0].max_insts_any_thread)) m5.switchCpus(testsys, switch_cpu_list1) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if (options.take_checkpoints or options.take_simpoint_checkpoints) \ and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None: # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_event = scriptCheckpoints(options, maxtick, cptdir) # Take SimPoint checkpoints elif options.take_simpoint_checkpoints != None: takeSimpointCheckpoints(simpoints, interval_length, cptdir) # Restore from SimPoint checkpoints elif options.restore_simpoint_checkpoint != None: restoreSimpointCheckpoint() else: if options.fast_forward: m5.stats.reset() print("**** REAL SIMULATION ****") # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_event = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_event = benchCheckpoints(options, maxtick, cptdir) print('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d")) if exit_event.getCode() != 0: print("Simulated exit code not 0! Exit code is", exit_event.getCode())
def run_system_with_cpu( process, options, output_dir, warmup_cpu_class=None, warmup_instructions=0, real_cpu_create_function=lambda cpu_id: DerivO3CPU(cpu_id=cpu_id), ): # Override the -d outdir --outdir option to gem5 m5.options.outdir = output_dir m5.core.setOutputDir(m5.options.outdir) m5.stats.reset() max_tick = options.abs_max_tick if options.rel_max_tick: max_tick = options.rel_max_tick elif options.maxtime: max_tick = int(options.maxtime * 1000 * 1000 * 1000 * 1000) eprint("Simulating until tick=%s" % (max_tick)) real_cpus = [real_cpu_create_function(0)] mem_mode = real_cpus[0].memory_mode() if warmup_cpu_class: warmup_cpus = [warmup_cpu_class(cpu_id=0)] warmup_cpus[0].max_insts_any_thread = warmup_instructions else: warmup_cpus = real_cpus system = System(cpu=warmup_cpus, mem_mode=mem_mode, mem_ranges=[AddrRange(options.mem_size)], cache_line_size=options.cacheline_size) system.multi_thread = False system.voltage_domain = VoltageDomain(voltage=options.sys_voltage) system.clk_domain = SrcClockDomain(clock=options.sys_clock, voltage_domain=system.voltage_domain) system.cpu_voltage_domain = VoltageDomain() system.cpu_clk_domain = SrcClockDomain( clock=options.cpu_clock, voltage_domain=system.cpu_voltage_domain) system.cache_line_size = options.cacheline_size if warmup_cpu_class: for cpu in real_cpus: cpu.clk_domain = system.cpu_clk_domain cpu.workload = process cpu.system = system cpu.switched_out = True cpu.createThreads() system.switch_cpus = real_cpus for cpu in system.cpu: cpu.clk_domain = system.cpu_clk_domain cpu.workload = process if options.prog_interval: cpu.progress_interval = options.prog_interval cpu.createThreads() MemClass = Simulation.setMemClass(options) system.membus = SystemXBar() system.system_port = system.membus.slave system.cpu[0].connectAllPorts(system.membus) MemConfig.config_mem(options, system) root = Root(full_system=False, system=system) m5.options.outdir = output_dir m5.instantiate(None) # None == no checkpoint if warmup_cpu_class: eprint("Running warmup with warmup CPU class (%d instrs.)" % (warmup_instructions)) eprint("Starting simulation") exit_event = m5.simulate(max_tick) if warmup_cpu_class: max_tick -= m5.curTick() m5.stats.reset() debug_print("Finished warmup; running real simulation") m5.switchCpus(system, real_cpus) exit_event = m5.simulate(max_tick) eprint("Done simulation @ tick = %s: %s" % (m5.curTick(), exit_event.getCause())) m5.stats.dump()
def run(options, root, testsys, cpu_class): if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [cpu_class(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: switch_class = getCPUClass(options.cpu_type)[0] if switch_class.require_caches() and \ not options.caches: print "%s: Must be used with caches" % str(switch_class) sys.exit(1) if not switch_class.support_take_over(): print "%s: CPU switching not supported" % str(switch_class) sys.exit(1) repeat_switch_cpus = [switch_class(switched_out=True, \ cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clock = testsys.cpu[i].clock if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: switch_cpus = [TimingSimpleCPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] switch_cpus_1 = [DerivO3CPU(switched_out=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock switch_cpus_1[i].clock = testsys.cpu[i].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal('simpoint not found') testsys.cpu[i].max_insts_any_thread = \ testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and \ (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal('no simpoint for testsys.cpu[%d].workload[0]', i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: maxtick, checkpoint_dir = findCptDir(options, maxtick, cptdir, testsys) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % \ str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate() else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) m5.switchCpus(testsys, switch_cpu_list) if options.standard_switch: print "Switch at instruction count:%d" % \ (testsys.switch_cpus[0].max_insts_any_thread) #warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate() else: exit_event = m5.simulate(options.standard_switch) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % \ (testsys.switch_cpus_1[0].max_insts_any_thread) m5.switchCpus(testsys, switch_cpu_list1) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None : # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_event = scriptCheckpoints(options, maxtick, cptdir) else: if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_event = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_event = benchCheckpoints(options, maxtick, cptdir) print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d")) if not m5.options.interactive: sys.exit(exit_event.getCode())
# For cpu2 # Create a process process = Process(pid = 102) # Set the command process.cmd = ['configs/code_module_1/write_attack'] # Set the cpu to use the process as its workload and create thread contexts system.cpu[2].workload = process system.cpu[2].createThreads() # For cpu3 # Create a process process = Process(pid = 103) # Set the command process.cmd = ['configs/code_module_1/write_attack'] # Set the cpu to use the process as its workload and create thread contexts system.cpu[3].workload = process system.cpu[3].createThreads() # set up the root SimObject and start the simulation root = Root(full_system = False, system = system) # instantiate all of the objects we've created above m5.instantiate() print("Beginning simulation!") exit_event = m5.simulate() print('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()))
tester.port = xbar.slave else: # Single tester testers[0].port = next_cache.cpu_side # Top level call to create the cache hierarchy, bottom up make_cache_level(cachespec, cache_proto, len(cachespec), None) # Connect the lowest level crossbar to the memory last_subsys = getattr(system, "l%dsubsys0" % len(cachespec)) last_subsys.xbar.master = system.physmem.port root = Root(full_system=False, system=system) if options.atomic: root.system.mem_mode = "atomic" else: root.system.mem_mode = "timing" # The system port is never used in the tester so merely connect it # to avoid problems root.system.system_port = last_subsys.xbar.slave # Instantiate configuration m5.instantiate() # Simulate until program terminates exit_event = m5.simulate(options.maxtick) print "Exiting @ tick", m5.curTick(), "because", exit_event.getCause()
def run(options, root, testsys, cpu_class, numpids): if options.maxtick: maxtick = options.maxtick elif options.maxtime: simtime = m5.ticks.seconds(simtime) print "simulating for: ", simtime maxtick = simtime else: maxtick = m5.MaxTick if options.checkpoint_dir: cptdir = options.checkpoint_dir elif m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.fast_forward and options.checkpoint_restore != None: fatal("Can't specify both --fast-forward and --checkpoint-restore") if options.standard_switch and not options.caches: fatal("Must specify --caches when using --standard-switch") if options.standard_switch and options.repeat_switch: fatal("Can't specify both --standard-switch and --repeat-switch") if options.repeat_switch and options.take_checkpoints: fatal("Can't specify both --repeat-switch and --take-checkpoints") np = options.num_cpus switch_cpus = None if options.prog_interval: for i in xrange(np): testsys.cpu[i].progress_interval = options.prog_interval if options.maxinsts: for i in xrange(np): testsys.cpu[i].max_insts_any_thread = options.maxinsts if cpu_class: switch_cpus = [cpu_class(defer_registration=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): if options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) switch_cpus[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock # simulation period if options.maxinsts: switch_cpus[i].max_insts_any_thread = options.maxinsts # Add checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() testsys.switch_cpus = switch_cpus switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] if options.repeat_switch: if options.cpu_type == "arm_detailed": if not options.caches: print "O3 CPU must be used with caches" sys.exit(1) repeat_switch_cpus = [O3_ARM_v7a_3(defer_registration=True, cpu_id=(i)) for i in xrange(np)] elif options.cpu_type == "detailed": if not options.caches: print "O3 CPU must be used with caches" sys.exit(1) repeat_switch_cpus = [DerivO3CPU(defer_registration=True, cpu_id=(i)) for i in xrange(np)] elif options.cpu_type == "inorder": print "inorder CPU switching not supported" sys.exit(1) elif options.cpu_type == "timing": repeat_switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(i)) for i in xrange(np)] else: repeat_switch_cpus = [AtomicSimpleCPU(defer_registration=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): repeat_switch_cpus[i].system = testsys repeat_switch_cpus[i].workload = testsys.cpu[i].workload repeat_switch_cpus[i].clock = testsys.cpu[i].clock if options.maxinsts: repeat_switch_cpus[i].max_insts_any_thread = options.maxinsts if options.checker: repeat_switch_cpus[i].addCheckerCpu() testsys.repeat_switch_cpus = repeat_switch_cpus if cpu_class: repeat_switch_cpu_list = [(switch_cpus[i], repeat_switch_cpus[i]) for i in xrange(np)] else: repeat_switch_cpu_list = [(testsys.cpu[i], repeat_switch_cpus[i]) for i in xrange(np)] if options.standard_switch: switch_cpus = [TimingSimpleCPU(defer_registration=True, cpu_id=(i)) for i in xrange(np)] switch_cpus_1 = [DerivO3CPU(defer_registration=True, cpu_id=(i)) for i in xrange(np)] for i in xrange(np): switch_cpus[i].system = testsys switch_cpus_1[i].system = testsys switch_cpus[i].workload = testsys.cpu[i].workload switch_cpus_1[i].workload = testsys.cpu[i].workload switch_cpus[i].clock = testsys.cpu[i].clock switch_cpus_1[i].clock = testsys.cpu[i].clock # if restoring, make atomic cpu simulate only a few instructions if options.checkpoint_restore != None: testsys.cpu[i].max_insts_any_thread = 1 # Fast forward to specified location if we are not restoring elif options.fast_forward: testsys.cpu[i].max_insts_any_thread = int(options.fast_forward) # Fast forward to a simpoint (warning: time consuming) elif options.simpoint: if testsys.cpu[i].workload[0].simpoint == 0: fatal("simpoint not found") testsys.cpu[i].max_insts_any_thread = testsys.cpu[i].workload[0].simpoint # No distance specified, just switch else: testsys.cpu[i].max_insts_any_thread = 1 # warmup period if options.warmup_insts: switch_cpus[i].max_insts_any_thread = options.warmup_insts # simulation period if options.maxinsts: switch_cpus_1[i].max_insts_any_thread = options.maxinsts # attach the checker cpu if selected if options.checker: switch_cpus[i].addCheckerCpu() switch_cpus_1[i].addCheckerCpu() testsys.switch_cpus = switch_cpus testsys.switch_cpus_1 = switch_cpus_1 switch_cpu_list = [(testsys.cpu[i], switch_cpus[i]) for i in xrange(np)] switch_cpu_list1 = [(switch_cpus[i], switch_cpus_1[i]) for i in xrange(np)] # set the checkpoint in the cpu before m5.instantiate is called if options.take_checkpoints != None and (options.simpoint or options.at_instruction): offset = int(options.take_checkpoints) # Set an instruction break point if options.simpoint: for i in xrange(np): if testsys.cpu[i].workload[0].simpoint == 0: fatal("no simpoint for testsys.cpu[%d].workload[0]", i) checkpoint_inst = int(testsys.cpu[i].workload[0].simpoint) + offset testsys.cpu[i].max_insts_any_thread = checkpoint_inst # used for output below options.take_checkpoints = checkpoint_inst else: options.take_checkpoints = offset # Set all test cpus with the right number of instructions # for the upcoming simulation for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset checkpoint_dir = None if options.checkpoint_restore != None: maxtick, checkpoint_dir = findCptDir(options, maxtick, cptdir, testsys) m5.instantiate(checkpoint_dir) if options.standard_switch or cpu_class: if options.standard_switch: print "Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate(maxtick, numpids) elif cpu_class and options.fast_forward: print "Switch at instruction count:%s" % str(testsys.cpu[0].max_insts_any_thread) exit_event = m5.simulate(maxtick, numpids) else: print "Switch at curTick count:%s" % str(10000) exit_event = m5.simulate(10000) print "Switched CPUS @ tick %s" % (m5.curTick()) # when you change to Timing (or Atomic), you halt the system # given as argument. When you are finished with the system # changes (including switchCpus), you must resume the system # manually. You DON'T need to resume after just switching # CPUs if you haven't changed anything on the system level. m5.changeToTiming(testsys) m5.switchCpus(switch_cpu_list) m5.resume(testsys) if options.standard_switch: print "Switch at instruction count:%d" % (testsys.switch_cpus[0].max_insts_any_thread) # warmup instruction count may have already been set if options.warmup_insts: exit_event = m5.simulate(maxtick, numpids) else: exit_event = m5.simulate(options.standard_switch, numpids) print "Switching CPUS @ tick %s" % (m5.curTick()) print "Simulation ends instruction count:%d" % (testsys.switch_cpus_1[0].max_insts_any_thread) m5.drain(testsys) m5.switchCpus(switch_cpu_list1) m5.resume(testsys) # If we're taking and restoring checkpoints, use checkpoint_dir # option only for finding the checkpoints to restore from. This # lets us test checkpointing by restoring from one set of # checkpoints, generating a second set, and then comparing them. if options.take_checkpoints and options.checkpoint_restore: if m5.options.outdir: cptdir = m5.options.outdir else: cptdir = getcwd() if options.take_checkpoints != None: # Checkpoints being taken via the command line at <when> and at # subsequent periods of <period>. Checkpoint instructions # received from the benchmark running are ignored and skipped in # favor of command line checkpoint instructions. exit_cause = scriptCheckpoints(options, cptdir) else: if options.fast_forward: m5.stats.reset() print "**** REAL SIMULATION ****" # If checkpoints are being taken, then the checkpoint instruction # will occur in the benchmark code it self. if options.repeat_switch and maxtick > options.repeat_switch: exit_cause = repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, options.repeat_switch) else: exit_cause = benchCheckpoints(options, maxtick, cptdir, numpids) print "Exiting @ tick %i because %s" % (m5.curTick(), exit_cause) if options.checkpoint_at_end: m5.checkpoint(joinpath(cptdir, "cpt.%d"))