diff -r 989ad55c4aca -r d7b2b7524fe4 configs/common/Simulation.py --- a/configs/common/Simulation.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/common/Simulation.py Sun Jun 27 23:30:33 2010 -0700 @@ -190,7 +190,7 @@ for i in xrange(np): testsys.cpu[i].max_insts_any_thread = offset - m5.instantiate(root) + m5.instantiate() if options.checkpoint_restore != None: from os.path import isdir, exists @@ -207,7 +207,7 @@ fatal("Unable to find checkpoint directory %s", checkpoint_dir) print "Restoring checkpoint ..." - m5.restoreCheckpoint(root, checkpoint_dir) + m5.restoreCheckpoint(checkpoint_dir) print "Done." elif options.simpoint: # assume workload 0 has the simpoint @@ -224,7 +224,7 @@ options.bench, options.checkpoint_restore) print "Restoring checkpoint ..." - m5.restoreCheckpoint(root,checkpoint_dir) + m5.restoreCheckpoint(checkpoint_dir) print "Done." else: dirs = listdir(cptdir) @@ -246,8 +246,8 @@ maxtick = maxtick - int(cpts[cpt_num - 1]) ## Restore the checkpoint - m5.restoreCheckpoint(root, - joinpath(cptdir, "cpt.%s" % cpts[cpt_num - 1])) + m5.restoreCheckpoint(joinpath(cptdir, + "cpt.%s" % cpts[cpt_num - 1])) if options.standard_switch or cpu_class: if options.standard_switch: @@ -314,7 +314,7 @@ if exit_event.getCause() == \ "a thread reached the max instruction count": - m5.checkpoint(root, joinpath(cptdir, "cpt.%s.%d" % \ + m5.checkpoint(joinpath(cptdir, "cpt.%s.%d" % \ (options.bench, checkpoint_inst))) print "Checkpoint written." num_checkpoints += 1 @@ -331,7 +331,7 @@ exit_event = m5.simulate(when - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": - m5.checkpoint(root, joinpath(cptdir, "cpt.%d")) + m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 sim_ticks = when @@ -348,7 +348,7 @@ while exit_event.getCause() == "checkpoint": exit_event = m5.simulate(sim_ticks - m5.curTick()) if exit_event.getCause() == "simulate() limit reached": - m5.checkpoint(root, joinpath(cptdir, "cpt.%d")) + m5.checkpoint(joinpath(cptdir, "cpt.%d")) num_checkpoints += 1 if exit_event.getCause() != "simulate() limit reached": diff -r 989ad55c4aca -r d7b2b7524fe4 configs/example/memtest-ruby.py --- a/configs/example/memtest-ruby.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/example/memtest-ruby.py Sun Jun 27 23:30:33 2010 -0700 @@ -129,7 +129,7 @@ m5.ticks.setGlobalFrequency('1ns') # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates exit_event = m5.simulate(options.maxtick) diff -r 989ad55c4aca -r d7b2b7524fe4 configs/example/memtest.py --- a/configs/example/memtest.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/example/memtest.py Sun Jun 27 23:30:33 2010 -0700 @@ -181,7 +181,7 @@ m5.ticks.setGlobalFrequency('1ns') # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates exit_event = m5.simulate(options.maxtick) diff -r 989ad55c4aca -r d7b2b7524fe4 configs/example/rubytest.py --- a/configs/example/rubytest.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/example/rubytest.py Sun Jun 27 23:30:33 2010 -0700 @@ -118,7 +118,7 @@ m5.ticks.setGlobalFrequency('1ns') # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates exit_event = m5.simulate(options.maxtick) diff -r 989ad55c4aca -r d7b2b7524fe4 configs/splash2/cluster.py --- a/configs/splash2/cluster.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/splash2/cluster.py Sun Jun 27 23:30:33 2010 -0700 @@ -292,7 +292,7 @@ root.system.mem_mode = 'timing' # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates if options.maxtick: diff -r 989ad55c4aca -r d7b2b7524fe4 configs/splash2/run.py --- a/configs/splash2/run.py Sun Jun 27 23:30:26 2010 -0700 +++ b/configs/splash2/run.py Sun Jun 27 23:30:33 2010 -0700 @@ -276,7 +276,7 @@ root.system.mem_mode = 'timing' # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates if options.maxtick: diff -r 989ad55c4aca -r d7b2b7524fe4 src/python/m5/simulate.py --- a/src/python/m5/simulate.py Sun Jun 27 23:30:26 2010 -0700 +++ b/src/python/m5/simulate.py Sun Jun 27 23:30:33 2010 -0700 @@ -39,13 +39,30 @@ import SimObject import ticks import objects +from util import warn, fatal # define a MaxTick parameter MaxTick = 2**63 - 1 +# function to check for an explicitly passed root arg (for backwards +# compatibility), warn of deprecation, and verify it is *the* root +def check_root_arg(root): + warn("No need to pass root to instantiate()") + assert root == objects.Root.getInstance() + # The final hook to generate .ini files. Called from the user script # once the config is built. -def instantiate(root): +def instantiate(*posargs): + if len(posargs) == 1: + check_root_arg(posargs[0]) + elif len(posargs) > 1: + fatal("Bad call to instantiate: too many args") + + root = objects.Root.getInstance() + + if not root: + fatal("Need to instantiate Root() before calling instantiate()") + # we need to fix the global frequency ticks.fixGlobalFrequency() @@ -136,7 +153,18 @@ def resume(root): root.resume() -def checkpoint(root, dir): +def checkpoint(*posargs): + if len(posargs) == 1: + # new args: (dir) + dir = posargs[0] + elif len(posargs) == 2: + # old args: (root, dir) + check_root_arg(posargs[0]) + dir = posargs[1] + elif len(posargs) > 2: + fatal("Bad call to checkpoint: too many args") + + root = objects.Root.getInstance() if not isinstance(root, objects.Root): raise TypeError, "Checkpoint must be called on a root object." doDrain(root) @@ -144,7 +172,18 @@ internal.core.serializeAll(dir) resume(root) -def restoreCheckpoint(root, dir): +def restoreCheckpoint(*posargs): + if len(posargs) == 1: + # new args: (dir) + dir = posargs[0] + elif len(posargs) == 2: + # old args: (root, dir) + check_root_arg(posargs[0]) + dir = posargs[1] + elif len(posargs) > 2: + fatal("Bad call to restoreCheckpoint: too many args") + + root = objects.Root.getInstance() print "Restoring from checkpoint" internal.core.unserializeAll(dir) need_resume.append(root) diff -r 989ad55c4aca -r d7b2b7524fe4 src/python/m5/util/__init__.py --- a/src/python/m5/util/__init__.py Sun Jun 27 23:30:26 2010 -0700 +++ b/src/python/m5/util/__init__.py Sun Jun 27 23:30:33 2010 -0700 @@ -66,6 +66,11 @@ print >>sys.stderr, errorURL('fatal',fmt) sys.exit(1) +# warn() is just a warning +def warn(fmt, *args): + print >>sys.stderr, 'warn:', fmt % args + print >>sys.stderr, errorURL('warn',fmt) + class Singleton(type): def __call__(cls, *args, **kwargs): if hasattr(cls, '_instance'): diff -r 989ad55c4aca -r d7b2b7524fe4 src/sim/Root.py --- a/src/sim/Root.py Sun Jun 27 23:30:26 2010 -0700 +++ b/src/sim/Root.py Sun Jun 27 23:30:33 2010 -0700 @@ -28,7 +28,43 @@ from m5.SimObject import SimObject from m5.params import * +from m5.util import fatal class Root(SimObject): + + _the_instance = None + + def __new__(cls, **kwargs): + if Root._the_instance: + return Root._the_instance + + # first call: allocate the unique instance + # + # Don't set _the_instance yet, as we still need it to be None + # to signal __init__ (which will be called next) that this is + # the first call. + # + # If SimObject ever implements __new__, we may want to pass + # kwargs here, but for now this goes straight to + # object.__new__ which prints an ugly warning if you pass it + # args. Seems like a bad design but that's the way it is. + return SimObject.__new__(cls) + + def __init__(self, **kwargs): + if Root._the_instance: + # could make this a warning and return _the_instance, but + # that seems unlikely to work correctly, so might as well + # just call it a fatal error + fatal("Attempt to allocate multiple instances of Root.") + return + + Root._the_instance = self + + SimObject.__init__(self, **kwargs) + + @classmethod + def getInstance(cls): + return Root._the_instance + type = 'Root' dummy = Param.Int(0, "We don't support objects without params") diff -r 989ad55c4aca -r d7b2b7524fe4 tests/run.py --- a/tests/run.py Sun Jun 27 23:30:26 2010 -0700 +++ b/tests/run.py Sun Jun 27 23:30:33 2010 -0700 @@ -78,7 +78,7 @@ execfile(joinpath(tests_root, category, name, 'test.py')) # instantiate configuration -m5.instantiate(root) +m5.instantiate() # simulate until program terminates exit_event = m5.simulate(maxtick)