From 133903b28d06842ec8fd30ae8b439c37e33da31b Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Tue, 13 Jun 2006 22:39:31 -0400 Subject: Add in a few global options. Feel free to rename them, they're just the first thing that came to mind. src/python/m5/__init__.py: Add in a few global options. --HG-- extra : convert_revision : e0dba78dd60f565a2e5cbda2cd6cf221bb3f4688 --- src/python/m5/__init__.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 60a61d66e..2d4825b0e 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -64,11 +64,34 @@ def AddToPath(path): def setTraceFlags(option, opt_str, value, parser): objects.Trace.flags = value +def setTraceStart(option, opt_str, value, parser): + objects.Trace.start = value + +def clearPCSymbol(option, opt_str, value, parser): + objects.ExecutionTrace.pc_symbol = False + +def clearPrintCycle(option, opt_str, value, parser): + objects.ExecutionTrace.print_cycle = False + +def statsTextFile(option, opt_str, value, parser): + objects.Statistics.text_file = value + # Standard optparse options. Need to be explicitly included by the # user script when it calls optparse.OptionParser(). standardOptions = [ optparse.make_option("--traceflags", type="string", action="callback", - callback=setTraceFlags) + callback=setTraceFlags), + optparse.make_option("--tracestart", type="int", action="callback", + callback=setTraceStart), + optparse.make_option("--nopcsymbol", action="callback", + callback=clearPCSymbol, + help="Turn off printing PC symbols in trace output"), + optparse.make_option("--noprintcycle", action="callback", + callback=clearPrintCycle, + help="Turn off printing cycles in trace output"), + optparse.make_option("--statsfile", type="string", action="callback", + callback=statsTextFile, metavar="FILE", + help="Sets the output file for the statistics") ] # make a SmartDict out of the build options for our local use -- cgit v1.2.3 From e981a97dec3df921f3800fd9ae5ec01ed4e9d2b1 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Tue, 13 Jun 2006 23:19:28 -0400 Subject: Move SimObject creation and Port connection loops into Python. Add Port and VectorPort objects and support for specifying port connections via assignment. The whole C++ ConfigNode hierarchy is gone now, as are C++ Connector objects. configs/test/fs.py: configs/test/test.py: Rewrite for new port connector syntax. src/SConscript: Remove unneeded files: - mem/connector.* - sim/config* src/dev/io_device.hh: src/mem/bridge.cc: src/mem/bridge.hh: src/mem/bus.cc: src/mem/bus.hh: src/mem/mem_object.hh: src/mem/physical.cc: src/mem/physical.hh: Allow getPort() to take an optional index to support vector ports (eventually). src/python/m5/__init__.py: Move SimObject construction and port connection operations into Python (with C++ calls). src/python/m5/config.py: Move SimObject construction and port connection operations into Python (with C++ calls). Add support for declaring and connecting MemObject ports in Python. src/python/m5/objects/Bus.py: src/python/m5/objects/PhysicalMemory.py: Add port declaration. src/sim/builder.cc: src/sim/builder.hh: src/sim/serialize.cc: src/sim/serialize.hh: ConfigNodes are gone; builder just gets the name of a .ini file section now. src/sim/main.cc: Move SimObject construction and port connection operations into Python (with C++ calls). Split remaining initialization operations into two parts, loadIniFile() and finalInit(). src/sim/param.cc: src/sim/param.hh: SimObject resolution done globally in Python now (not via ConfigNode hierarchy). src/sim/sim_object.cc: Remove unneeded #include. --HG-- extra : convert_revision : 2fa4001eaaec0c9a4231ef6e854f8e156d930dfe --- src/python/m5/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 60a61d66e..208d11b69 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -80,6 +80,16 @@ build_env.update(defines.m5_build_env) env = smartdict.SmartDict() env.update(os.environ) + +# Function to provide to C++ so it can look up instances based on paths +def resolveSimObject(name): + obj = config.instanceDict[name] + if not obj._ccObject: + obj.createCCObject() + if obj._ccObject == -1: + panic("resolveSimObject: recursive lookup error on %s" % name) + return obj._ccObject + # The final hook to generate .ini files. Called from the user script # once the config is built. def instantiate(root): @@ -89,7 +99,10 @@ def instantiate(root): root.print_ini() sys.stdout.close() # close config.ini sys.stdout = sys.__stdout__ # restore to original - main.initialize() # load config.ini into C++ and process it + main.loadIniFile(resolveSimObject) # load config.ini into C++ + root.createCCObject() + root.connectPorts() + main.finalInit() noDot = True # temporary until we fix dot if not noDot: dot = pydot.Dot() -- cgit v1.2.3 From 88e22ee081f1b0259b624fe320af22a58f144251 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Thu, 15 Jun 2006 11:45:51 -0400 Subject: Get Port stuff working with full-system scripts. Key was adding support for cloning port references (trickier than it sounds). Got rid of class/instance thing and go back to instance cloning... still don't allow changing SimObject parameters/children after a class (instance) has been subclassed or instantiated (or cloned), which should avoid bizarre unintended behavior. configs/test/fs.py: Add ".port" to busses to get a port reference. Get rid of commented-out code. src/python/m5/__init__.py: resolveSimObject should call getCCObject() instead of createCCObject() to avoid cycles in recursively creating objects. src/python/m5/config.py: Get rid of class/instance thing and go back to instance cloning. Deep copy has to happen only on instance cloning then (and not on subclassing). Add getCCObject() method to force creation of C++ SimObject without recursively creating its children. Add support for cloning port references (trickier than it sounds). Also clean up some very obsolete comments. src/python/m5/objects/Bridge.py: src/python/m5/objects/Device.py: Add ports. --HG-- extra : convert_revision : 4816d05ead0de520748aace06dbd1911a33f0af8 --- src/python/m5/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index a4fc9a5e3..f849a899b 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -107,11 +107,7 @@ env.update(os.environ) # Function to provide to C++ so it can look up instances based on paths def resolveSimObject(name): obj = config.instanceDict[name] - if not obj._ccObject: - obj.createCCObject() - if obj._ccObject == -1: - panic("resolveSimObject: recursive lookup error on %s" % name) - return obj._ccObject + return obj.getCCObject() # The final hook to generate .ini files. Called from the user script # once the config is built. -- cgit v1.2.3 From e889b8242301b1123ffd4c05862f84826dd77806 Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Fri, 16 Jun 2006 21:18:19 -0400 Subject: Add in some of the commonly used Trace/ExeTrace/Debug options. src/python/m5/__init__.py: Add in some of the commonly used Trace/ExeTrace/Debug options. Not terribly clean but it works. --HG-- extra : convert_revision : abb3cb4892512483a5031606baabf6540019233c --- src/python/m5/__init__.py | 93 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 10 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index f849a899b..c0728120c 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -67,15 +67,46 @@ def setTraceFlags(option, opt_str, value, parser): def setTraceStart(option, opt_str, value, parser): objects.Trace.start = value -def clearPCSymbol(option, opt_str, value, parser): - objects.ExecutionTrace.pc_symbol = False +def setTraceFile(option, opt_str, value, parser): + objects.Trace.file = value -def clearPrintCycle(option, opt_str, value, parser): - objects.ExecutionTrace.print_cycle = False +def usePCSymbol(option, opt_str, value, parser): + objects.ExecutionTrace.pc_symbol = value + +def printCycle(option, opt_str, value, parser): + objects.ExecutionTrace.print_cycle = value + +def printOp(option, opt_str, value, parser): + objects.ExecutionTrace.print_opclass = value + +def printThread(option, opt_str, value, parser): + objects.ExecutionTrace.print_thread = value + +def printEA(option, opt_str, value, parser): + objects.ExecutionTrace.print_effaddr = value + +def printData(option, opt_str, value, parser): + objects.ExecutionTrace.print_data = value + +def printFetchseq(option, opt_str, value, parser): + objects.ExecutionTrace.print_fetchseq = value + +def printCpseq(option, opt_str, value, parser): + objects.ExecutionTrace.print_cpseq = value + +def dumpOnExit(option, opt_str, value, parser): + objects.Trace.dump_on_exit = value + +def debugBreak(option, opt_str, value, parser): + objects.Debug.break_cycles = value def statsTextFile(option, opt_str, value, parser): objects.Statistics.text_file = value +# Extra list to help for options that are true or false +TrueOrFalse = ['True', 'False'] +TorF = "True | False" + # Standard optparse options. Need to be explicitly included by the # user script when it calls optparse.OptionParser(). standardOptions = [ @@ -83,12 +114,54 @@ standardOptions = [ callback=setTraceFlags), optparse.make_option("--tracestart", type="int", action="callback", callback=setTraceStart), - optparse.make_option("--nopcsymbol", action="callback", - callback=clearPCSymbol, - help="Turn off printing PC symbols in trace output"), - optparse.make_option("--noprintcycle", action="callback", - callback=clearPrintCycle, - help="Turn off printing cycles in trace output"), + optparse.make_option("--tracefile", type="string", action="callback", + callback=setTraceFile), + optparse.make_option("--pcsymbol", type="choice", choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=usePCSymbol, + help="Use PC symbols in trace output"), + optparse.make_option("--printcycle", type="choice", choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printCycle, + help="Print cycle numbers in trace output"), + optparse.make_option("--printopclass", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printOp, + help="Print cycle numbers in trace output"), + optparse.make_option("--printthread", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printThread, + help="Print thread number in trace output"), + optparse.make_option("--printeffaddr", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printEA, + help="Print effective address in trace output"), + optparse.make_option("--printdata", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printData, + help="Print result data in trace output"), + optparse.make_option("--printfetchseq", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printFetchseq, + help="Print fetch sequence numbers in trace output"), + optparse.make_option("--printcpseq", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=printCpseq, + help="Print correct path sequence numbers in trace output"), + optparse.make_option("--dumponexit", type="choice", + choices=TrueOrFalse, + default="True", metavar=TorF, + action="callback", callback=dumpOnExit, + help="Dump trace buffer on exit"), + optparse.make_option("--debugbreak", type="int", metavar="CYCLE", + action="callback", callback=debugBreak, + help="Cycle to create a breakpoint"), optparse.make_option("--statsfile", type="string", action="callback", callback=statsTextFile, metavar="FILE", help="Sets the output file for the statistics") -- cgit v1.2.3 From 4a9c0a7dfc8aa1fcd70ec2b194691adec9ce424e Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sat, 17 Jun 2006 09:58:10 -0400 Subject: Add --outdir option. Didn't call it "-d" since that's already being used for "detailed cpu". Needed to add extra function for user script to pass parsed options back to m5 module. configs/test/fs.py: configs/test/test.py: Call setStandardOptions(). src/python/m5/__init__.py: Add --outdir option. Add setStandardOptions() so user script can pass parsed options back to m5 module. src/sim/main.cc: Add SWIG-wrappable function to set output dir. --HG-- extra : convert_revision : 1323bee69ca920c699a1cd1218e15b7b0875c1e5 --- src/python/m5/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index c0728120c..19af24e6f 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -58,6 +58,20 @@ def AddToPath(path): sys.path.insert(1, path) +# The m5 module's pointer to the parsed options object +options = None + + +# User should call this function after calling parse_args() to pass +# parsed standard option values back into the m5 module for +# processing. +def setStandardOptions(_options): + # Set module global var + global options + options = _options + # tell C++ about output directory + main.setOutputDir(options.outdir) + # Callback to set trace flags. Not necessarily the best way to do # things in the long run (particularly if we change how these global # options are handled). @@ -110,6 +124,7 @@ TorF = "True | False" # Standard optparse options. Need to be explicitly included by the # user script when it calls optparse.OptionParser(). standardOptions = [ + optparse.make_option("--outdir", type="string", default="."), optparse.make_option("--traceflags", type="string", action="callback", callback=setTraceFlags), optparse.make_option("--tracestart", type="int", action="callback", @@ -187,7 +202,7 @@ def resolveSimObject(name): def instantiate(root): config.ticks_per_sec = float(root.clock.frequency) # ugly temporary hack to get output to config.ini - sys.stdout = file('config.ini', 'w') + sys.stdout = file(os.path.join(options.outdir, 'config.ini'), 'w') root.print_ini() sys.stdout.close() # close config.ini sys.stdout = sys.__stdout__ # restore to original -- cgit v1.2.3 From d96d28e56d39eec0baa1377779119495cfbf4701 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sat, 17 Jun 2006 12:08:19 -0400 Subject: Rename SWIG "main" module to "cc_main" so it's clear from the Python side that this is the interface to C++. src/SConscript: main_wrap.cc -> cc_main_wrap.cc src/python/SConscript: src/python/m5/__init__.py: src/sim/main.cc: s/main/cc_main/ src/python/m5/config.py: s/main/cc_main/ Also directly import cc_main so we don't need to put the "m5." in front all the time. --HG-- extra : convert_revision : 755552f70cf671881ff31e476c677b95ef12950d --- src/python/m5/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 19af24e6f..ac6904277 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -30,11 +30,11 @@ import sys, os, time, atexit, optparse # import the SWIG-wrapped main C++ functions -import main +import cc_main # import a few SWIG-wrapped items (those that are likely to be used # directly by user scripts) completely into this module for # convenience -from main import simulate, SimLoopExitEvent +from cc_main import simulate, SimLoopExitEvent # import the m5 compile options import defines @@ -70,7 +70,7 @@ def setStandardOptions(_options): global options options = _options # tell C++ about output directory - main.setOutputDir(options.outdir) + cc_main.setOutputDir(options.outdir) # Callback to set trace flags. Not necessarily the best way to do # things in the long run (particularly if we change how these global @@ -206,10 +206,10 @@ def instantiate(root): root.print_ini() sys.stdout.close() # close config.ini sys.stdout = sys.__stdout__ # restore to original - main.loadIniFile(resolveSimObject) # load config.ini into C++ + cc_main.loadIniFile(resolveSimObject) # load config.ini into C++ root.createCCObject() root.connectPorts() - main.finalInit() + cc_main.finalInit() noDot = True # temporary until we fix dot if not noDot: dot = pydot.Dot() @@ -223,10 +223,10 @@ def instantiate(root): # Export curTick to user script. def curTick(): - return main.cvar.curTick + return cc_main.cvar.curTick # register our C++ exit callback function with Python -atexit.register(main.doExitCleanup) +atexit.register(cc_main.doExitCleanup) # This import allows user scripts to reference 'm5.objects.Foo' after # just doing an 'import m5' (without an 'import m5.objects'). May not -- cgit v1.2.3 From 393e77fbe94ccbcc422d2575c500d1590ca87d00 Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Sat, 17 Jun 2006 22:04:48 -0400 Subject: Change options back to just being flags instead of taking in a True/False value. src/python/m5/__init__.py: Change up options. Now setting the flag enables/disables, each of which is the opposite of the default values found in the Python class. --HG-- extra : convert_revision : 23889b89e6105a437a74906587d90ab6ba885c97 --- src/python/m5/__init__.py | 88 +++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 52 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index c0728120c..d1e443b64 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -70,32 +70,32 @@ def setTraceStart(option, opt_str, value, parser): def setTraceFile(option, opt_str, value, parser): objects.Trace.file = value -def usePCSymbol(option, opt_str, value, parser): - objects.ExecutionTrace.pc_symbol = value +def noPCSymbol(option, opt_str, value, parser): + objects.ExecutionTrace.pc_symbol = False -def printCycle(option, opt_str, value, parser): - objects.ExecutionTrace.print_cycle = value +def noPrintCycle(option, opt_str, value, parser): + objects.ExecutionTrace.print_cycle = False -def printOp(option, opt_str, value, parser): - objects.ExecutionTrace.print_opclass = value +def noPrintOpclass(option, opt_str, value, parser): + objects.ExecutionTrace.print_opclass = False -def printThread(option, opt_str, value, parser): - objects.ExecutionTrace.print_thread = value +def noPrintThread(option, opt_str, value, parser): + objects.ExecutionTrace.print_thread = False -def printEA(option, opt_str, value, parser): - objects.ExecutionTrace.print_effaddr = value +def noPrintEA(option, opt_str, value, parser): + objects.ExecutionTrace.print_effaddr = False -def printData(option, opt_str, value, parser): - objects.ExecutionTrace.print_data = value +def noPrintData(option, opt_str, value, parser): + objects.ExecutionTrace.print_data = False def printFetchseq(option, opt_str, value, parser): - objects.ExecutionTrace.print_fetchseq = value + objects.ExecutionTrace.print_fetchseq = True def printCpseq(option, opt_str, value, parser): - objects.ExecutionTrace.print_cpseq = value + objects.ExecutionTrace.print_cpseq = True def dumpOnExit(option, opt_str, value, parser): - objects.Trace.dump_on_exit = value + objects.Trace.dump_on_exit = True def debugBreak(option, opt_str, value, parser): objects.Debug.break_cycles = value @@ -116,47 +116,31 @@ standardOptions = [ callback=setTraceStart), optparse.make_option("--tracefile", type="string", action="callback", callback=setTraceFile), - optparse.make_option("--pcsymbol", type="choice", choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=usePCSymbol, - help="Use PC symbols in trace output"), - optparse.make_option("--printcycle", type="choice", choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=printCycle, - help="Print cycle numbers in trace output"), - optparse.make_option("--printopclass", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=printOp, - help="Print cycle numbers in trace output"), - optparse.make_option("--printthread", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=printThread, - help="Print thread number in trace output"), - optparse.make_option("--printeffaddr", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=printEA, - help="Print effective address in trace output"), - optparse.make_option("--printdata", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, - action="callback", callback=printData, - help="Print result data in trace output"), - optparse.make_option("--printfetchseq", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, + optparse.make_option("--nopcsymbol", + action="callback", callback=noPCSymbol, + help="Disable PC symbols in trace output"), + optparse.make_option("--noprintcycle", + action="callback", callback=noPrintCycle, + help="Don't print cycle numbers in trace output"), + optparse.make_option("--noprintopclass", + action="callback", callback=noPrintOpclass, + help="Don't print op class type in trace output"), + optparse.make_option("--noprintthread", + action="callback", callback=noPrintThread, + help="Don't print thread number in trace output"), + optparse.make_option("--noprinteffaddr", + action="callback", callback=noPrintEA, + help="Don't print effective address in trace output"), + optparse.make_option("--noprintdata", + action="callback", callback=noPrintData, + help="Don't print result data in trace output"), + optparse.make_option("--printfetchseq", action="callback", callback=printFetchseq, help="Print fetch sequence numbers in trace output"), - optparse.make_option("--printcpseq", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, + optparse.make_option("--printcpseq", action="callback", callback=printCpseq, help="Print correct path sequence numbers in trace output"), - optparse.make_option("--dumponexit", type="choice", - choices=TrueOrFalse, - default="True", metavar=TorF, + optparse.make_option("--dumponexit", action="callback", callback=dumpOnExit, help="Dump trace buffer on exit"), optparse.make_option("--debugbreak", type="int", metavar="CYCLE", -- cgit v1.2.3 From f64c175f9ae81be3c002a82ea14a2844a7ee100e Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Thu, 29 Jun 2006 19:40:12 -0400 Subject: Add in support for quiescing the system, taking checkpoints, restoring from checkpoints, changing memory modes, and switching CPUs. Key new functions that can be called on the m5 object at the python interpreter: doQuiesce(root) - A helper function that quiesces the object passed in and all of its children. resume(root) - Another helper function that tells the object and all of its children that the quiesce is over. checkpoint(root) - Takes a checkpoint of the system. Checkpoint directory must be set before hand. setCheckpointDir(name) - Sets the checkpoint directory. restoreCheckpoint(root) - Restores the values from the checkpoint located in the checkpoint directory. changeToAtomic(system) - Changes the system and all of its children to atomic memory mode. changeToTiming(system) - Changes the system and all of its children to timing memory mode. switchCpus(list) - Takes in a list of tuples, where each tuple is a pair of (old CPU, new CPU). Quiesces the old CPUs, and then switches over to the new CPUs. src/SConscript: Remove serializer, replaced by python code. src/python/m5/__init__.py: Updates to support quiescing, checkpointing, changing memory modes, and switching CPUs. src/python/m5/config.py: Several functions defined on the SimObject for quiescing, changing timing modes, and switching CPUs src/sim/main.cc: Add some extra functions that are exported to python through SWIG. src/sim/serialize.cc: Change serialization around a bit. Now it is controlled through Python, so there's no need for SerializeEvents or SerializeParams. Also add in a new unserializeAll() function that loads a checkpoint and handles unserializing all objects. src/sim/serialize.hh: Add unserializeAll function and a setCheckpointName function. src/sim/sim_events.cc: Add process() function for CountedQuiesceEvent, which calls exitSimLoop() once its counter reaches 0. src/sim/sim_events.hh: Add in a CountedQuiesceEvent, which is used when the system is preparing to quiesce. Any objects that can't be quiesced immediately are given a pointer to a CountedQuiesceEvent. The event has its counter set via Python, and as objects finish quiescing they call process() on the event. Eventually the event causes the simulation to stop once all objects have quiesced. src/sim/sim_object.cc: Add a few functions for quiescing, checkpointing, and changing memory modes. src/sim/sim_object.hh: Add a state variable to all SimObjects that tracks both the timing mode of the object and the quiesce state of the object. Currently this isn't serialized, and I'm not sure it needs to be so long as the timing mode starts up the same after a checkpoint. --HG-- extra : convert_revision : a8c738d3911c68d5a7caf7de24d732dcc62cfb61 --- src/python/m5/__init__.py | 84 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index a7e653fc2..828165d15 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -34,7 +34,7 @@ import cc_main # import a few SWIG-wrapped items (those that are likely to be used # directly by user scripts) completely into this module for # convenience -from cc_main import simulate, SimLoopExitEvent +from cc_main import simulate, SimLoopExitEvent, setCheckpointDir # import the m5 compile options import defines @@ -117,10 +117,6 @@ def debugBreak(option, opt_str, value, parser): def statsTextFile(option, opt_str, value, parser): objects.Statistics.text_file = value -# Extra list to help for options that are true or false -TrueOrFalse = ['True', 'False'] -TorF = "True | False" - # Standard optparse options. Need to be explicitly included by the # user script when it calls optparse.OptionParser(). standardOptions = [ @@ -216,3 +212,81 @@ atexit.register(cc_main.doExitCleanup) # just doing an 'import m5' (without an 'import m5.objects'). May not # matter since most scripts will probably 'from m5.objects import *'. import objects + +def doQuiesce(root): + quiesce = cc_main.createCountedQuiesce() + unready_objects = root.startQuiesce(quiesce, True) + # If we've got some objects that can't quiesce immediately, then simulate + if unready_objects > 0: + quiesce.setCount(unready_objects) + simulate() + cc_main.cleanupCountedQuiesce(quiesce) + +def resume(root): + root.resume() + +def checkpoint(root): + if not isinstance(root, objects.Root): + raise TypeError, "Object is not a root object. Checkpoint must be called on a root object." + doQuiesce(root) + print "Writing checkpoint" + cc_main.serializeAll() + resume(root) + +def restoreCheckpoint(root): + print "Restoring from checkpoint" + cc_main.unserializeAll() + +def changeToAtomic(system): + if not isinstance(system, objects.Root) and not isinstance(system, System): + raise TypeError, "Object is not a root or system object. Checkpoint must be " + "called on a root object." + doQuiesce(system) + print "Changing memory mode to atomic" + system.changeTiming(cc_main.SimObject.Atomic) + resume(system) + +def changeToTiming(system): + if not isinstance(system, objects.Root) and not isinstance(system, System): + raise TypeError, "Object is not a root or system object. Checkpoint must be " + "called on a root object." + doQuiesce(system) + print "Changing memory mode to timing" + system.changeTiming(cc_main.SimObject.Timing) + resume(system) + +def switchCpus(cpuList): + if not isinstance(cpuList, list): + raise RuntimeError, "Must pass a list to this function" + for i in cpuList: + if not isinstance(i, tuple): + raise RuntimeError, "List must have tuples of (oldCPU,newCPU)" + + [old_cpus, new_cpus] = zip(*cpuList) + + for cpu in old_cpus: + if not isinstance(cpu, objects.BaseCPU): + raise TypeError, "%s is not of type BaseCPU", cpu + for cpu in new_cpus: + if not isinstance(cpu, objects.BaseCPU): + raise TypeError, "%s is not of type BaseCPU", cpu + + # Quiesce all of the individual CPUs + quiesce = cc_main.createCountedQuiesce() + unready_cpus = 0 + for old_cpu in old_cpus: + unready_cpus += old_cpu.startQuiesce(quiesce, False) + # If we've got some objects that can't quiesce immediately, then simulate + if unready_cpus > 0: + quiesce.setCount(unready_cpus) + simulate() + cc_main.cleanupCountedQuiesce(quiesce) + # Now all of the CPUs are ready to be switched out + for old_cpu in old_cpus: + old_cpu._ccObject.switchOut() + index = 0 + print "Switching CPUs" + for new_cpu in new_cpus: + new_cpu.takeOverFrom(old_cpus[index]) + new_cpu._ccObject.resume() + index += 1 -- cgit v1.2.3 From d8fd09cc159a7b5b0d314a41b09cfcdef91de55f Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Wed, 5 Jul 2006 17:59:33 -0400 Subject: Rename quiesce to drain to avoid confusion with the pseudo instruction. src/cpu/simple/timing.cc: src/cpu/simple/timing.hh: src/python/m5/__init__.py: src/python/m5/config.py: src/sim/main.cc: src/sim/sim_events.cc: src/sim/sim_events.hh: src/sim/sim_object.cc: src/sim/sim_object.hh: Rename quiesce to drain. --HG-- extra : convert_revision : fc3244a3934812e1edb8050f1f51f30382baf774 --- src/python/m5/__init__.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 828165d15..579785a46 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -213,14 +213,14 @@ atexit.register(cc_main.doExitCleanup) # matter since most scripts will probably 'from m5.objects import *'. import objects -def doQuiesce(root): - quiesce = cc_main.createCountedQuiesce() - unready_objects = root.startQuiesce(quiesce, True) - # If we've got some objects that can't quiesce immediately, then simulate +def doDrain(root): + drain_event = cc_main.createCountedDrain() + unready_objects = root.startDrain(drain_event, True) + # If we've got some objects that can't drain immediately, then simulate if unready_objects > 0: - quiesce.setCount(unready_objects) + drain_event.setCount(unready_objects) simulate() - cc_main.cleanupCountedQuiesce(quiesce) + cc_main.cleanupCountedDrain(drain_event) def resume(root): root.resume() @@ -228,7 +228,7 @@ def resume(root): def checkpoint(root): if not isinstance(root, objects.Root): raise TypeError, "Object is not a root object. Checkpoint must be called on a root object." - doQuiesce(root) + doDrain(root) print "Writing checkpoint" cc_main.serializeAll() resume(root) @@ -241,7 +241,7 @@ def changeToAtomic(system): if not isinstance(system, objects.Root) and not isinstance(system, System): raise TypeError, "Object is not a root or system object. Checkpoint must be " "called on a root object." - doQuiesce(system) + doDrain(system) print "Changing memory mode to atomic" system.changeTiming(cc_main.SimObject.Atomic) resume(system) @@ -250,7 +250,7 @@ def changeToTiming(system): if not isinstance(system, objects.Root) and not isinstance(system, System): raise TypeError, "Object is not a root or system object. Checkpoint must be " "called on a root object." - doQuiesce(system) + doDrain(system) print "Changing memory mode to timing" system.changeTiming(cc_main.SimObject.Timing) resume(system) @@ -271,16 +271,16 @@ def switchCpus(cpuList): if not isinstance(cpu, objects.BaseCPU): raise TypeError, "%s is not of type BaseCPU", cpu - # Quiesce all of the individual CPUs - quiesce = cc_main.createCountedQuiesce() + # Drain all of the individual CPUs + drain_event = cc_main.createCountedDrain() unready_cpus = 0 for old_cpu in old_cpus: - unready_cpus += old_cpu.startQuiesce(quiesce, False) - # If we've got some objects that can't quiesce immediately, then simulate + unready_cpus += old_cpu.startDrain(drain_event, False) + # If we've got some objects that can't drain immediately, then simulate if unready_cpus > 0: - quiesce.setCount(unready_cpus) + drain_event.setCount(unready_cpus) simulate() - cc_main.cleanupCountedQuiesce(quiesce) + cc_main.cleanupCountedDrain(drain_event) # Now all of the CPUs are ready to be switched out for old_cpu in old_cpus: old_cpu._ccObject.switchOut() -- cgit v1.2.3 From 8ae4f45bc4782b4ab1dc95dbca183e2cd926fc5b Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Thu, 6 Jul 2006 16:06:00 -0400 Subject: Fixes for draining. src/cpu/simple/timing.cc: Update for changed return values. src/python/m5/__init__.py: Loop in order to make sure all objects are really drained. Objects may become undrained as other objects become drained (e.g. a bus-bridge has a packet, while a bus is empty, and the first drain() will cause the bus-bridge to give the packet to the bus). The only case we know every object is actually drained is if they all return immediately that they are drained. --HG-- extra : convert_revision : 80057a1d6d30381bd0b67b23549bd202f447c5cb --- src/python/m5/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 579785a46..7d35ee8b8 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -213,14 +213,28 @@ atexit.register(cc_main.doExitCleanup) # matter since most scripts will probably 'from m5.objects import *'. import objects +# This loops until all objects have been fully drained. def doDrain(root): + all_drained = drain(root) + while (not all_drained): + all_drained = drain(root) + +# Tries to drain all objects. Draining might not be completed unless +# all objects return that they are drained on the first call. This is +# because as objects drain they may cause other objects to no longer +# be drained. +def drain(root): + all_drained = False drain_event = cc_main.createCountedDrain() unready_objects = root.startDrain(drain_event, True) # If we've got some objects that can't drain immediately, then simulate if unready_objects > 0: drain_event.setCount(unready_objects) simulate() + else: + all_drained = True cc_main.cleanupCountedDrain(drain_event) + return all_drained def resume(root): root.resume() -- cgit v1.2.3 From 6872b99c29cd4263062bb8b3ef15aa5a9f2532d4 Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Thu, 6 Jul 2006 23:16:22 -0400 Subject: Be sure to call resume after restoring from a checkpoint. --HG-- extra : convert_revision : 4d672917038779a23f4ce7eb5d4e3039c1f5d726 --- src/python/m5/__init__.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index 7d35ee8b8..dc3af7000 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -250,6 +250,7 @@ def checkpoint(root): def restoreCheckpoint(root): print "Restoring from checkpoint" cc_main.unserializeAll() + resume(root) def changeToAtomic(system): if not isinstance(system, objects.Root) and not isinstance(system, System): -- cgit v1.2.3 From 1faada9bd98a6425624a97813d4c8cdc5b78aa1f Mon Sep 17 00:00:00 2001 From: Kevin Lim Date: Fri, 7 Jul 2006 16:46:08 -0400 Subject: Take the name of the checkpoint directory in when calling checkpoint() or restoreCheckpoint(). src/sim/main.cc: src/sim/serialize.cc: src/sim/serialize.hh: Take in the directory name when checkpointing. --HG-- extra : convert_revision : 040e828622480f1051e2156f4439e24864c38d45 --- src/python/m5/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index dc3af7000..f4f5be2d1 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -34,7 +34,7 @@ import cc_main # import a few SWIG-wrapped items (those that are likely to be used # directly by user scripts) completely into this module for # convenience -from cc_main import simulate, SimLoopExitEvent, setCheckpointDir +from cc_main import simulate, SimLoopExitEvent # import the m5 compile options import defines @@ -239,17 +239,17 @@ def drain(root): def resume(root): root.resume() -def checkpoint(root): +def checkpoint(root, dir): if not isinstance(root, objects.Root): raise TypeError, "Object is not a root object. Checkpoint must be called on a root object." doDrain(root) print "Writing checkpoint" - cc_main.serializeAll() + cc_main.serializeAll(dir) resume(root) -def restoreCheckpoint(root): +def restoreCheckpoint(root, dir): print "Restoring from checkpoint" - cc_main.unserializeAll() + cc_main.unserializeAll(dir) resume(root) def changeToAtomic(system): -- cgit v1.2.3 From 55ea050d4823ca294db94d6a1f7f2fc35177e044 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 10 Jul 2006 23:00:13 -0400 Subject: Migrate most of main() and and all option parsing to python configs/test/fs.py: configs/test/test.py: update for the new way that m5 deals with options src/python/SConscript: Compile AUTHORS, LICENSE, README, and RELEASE_NOTES into the python stuff. src/python/m5/__init__.py: redo the way options work. Move them all to main.py src/sim/main.cc: Migrate more functionality for main() into python. Namely option parsing src/python/m5/attrdict.py: A dictionary object that overrides attribute access to do item access. src/python/m5/main.py: The new location for M5's option parsing, and the main() routine to set up the simulation. --HG-- extra : convert_revision : c86b87a9f508bde1994088e23fd470c7753ee4c1 --- src/python/m5/__init__.py | 110 ++-------------------------------------------- 1 file changed, 3 insertions(+), 107 deletions(-) (limited to 'src/python/m5/__init__.py') diff --git a/src/python/m5/__init__.py b/src/python/m5/__init__.py index f4f5be2d1..3d0e3defa 100644 --- a/src/python/m5/__init__.py +++ b/src/python/m5/__init__.py @@ -27,7 +27,7 @@ # Authors: Nathan Binkert # Steve Reinhardt -import sys, os, time, atexit, optparse +import atexit, os, sys # import the SWIG-wrapped main C++ functions import cc_main @@ -57,111 +57,6 @@ def AddToPath(path): # so place the new dir right after that. sys.path.insert(1, path) - -# The m5 module's pointer to the parsed options object -options = None - - -# User should call this function after calling parse_args() to pass -# parsed standard option values back into the m5 module for -# processing. -def setStandardOptions(_options): - # Set module global var - global options - options = _options - # tell C++ about output directory - cc_main.setOutputDir(options.outdir) - -# Callback to set trace flags. Not necessarily the best way to do -# things in the long run (particularly if we change how these global -# options are handled). -def setTraceFlags(option, opt_str, value, parser): - objects.Trace.flags = value - -def setTraceStart(option, opt_str, value, parser): - objects.Trace.start = value - -def setTraceFile(option, opt_str, value, parser): - objects.Trace.file = value - -def noPCSymbol(option, opt_str, value, parser): - objects.ExecutionTrace.pc_symbol = False - -def noPrintCycle(option, opt_str, value, parser): - objects.ExecutionTrace.print_cycle = False - -def noPrintOpclass(option, opt_str, value, parser): - objects.ExecutionTrace.print_opclass = False - -def noPrintThread(option, opt_str, value, parser): - objects.ExecutionTrace.print_thread = False - -def noPrintEA(option, opt_str, value, parser): - objects.ExecutionTrace.print_effaddr = False - -def noPrintData(option, opt_str, value, parser): - objects.ExecutionTrace.print_data = False - -def printFetchseq(option, opt_str, value, parser): - objects.ExecutionTrace.print_fetchseq = True - -def printCpseq(option, opt_str, value, parser): - objects.ExecutionTrace.print_cpseq = True - -def dumpOnExit(option, opt_str, value, parser): - objects.Trace.dump_on_exit = True - -def debugBreak(option, opt_str, value, parser): - objects.Debug.break_cycles = value - -def statsTextFile(option, opt_str, value, parser): - objects.Statistics.text_file = value - -# Standard optparse options. Need to be explicitly included by the -# user script when it calls optparse.OptionParser(). -standardOptions = [ - optparse.make_option("--outdir", type="string", default="."), - optparse.make_option("--traceflags", type="string", action="callback", - callback=setTraceFlags), - optparse.make_option("--tracestart", type="int", action="callback", - callback=setTraceStart), - optparse.make_option("--tracefile", type="string", action="callback", - callback=setTraceFile), - optparse.make_option("--nopcsymbol", - action="callback", callback=noPCSymbol, - help="Disable PC symbols in trace output"), - optparse.make_option("--noprintcycle", - action="callback", callback=noPrintCycle, - help="Don't print cycle numbers in trace output"), - optparse.make_option("--noprintopclass", - action="callback", callback=noPrintOpclass, - help="Don't print op class type in trace output"), - optparse.make_option("--noprintthread", - action="callback", callback=noPrintThread, - help="Don't print thread number in trace output"), - optparse.make_option("--noprinteffaddr", - action="callback", callback=noPrintEA, - help="Don't print effective address in trace output"), - optparse.make_option("--noprintdata", - action="callback", callback=noPrintData, - help="Don't print result data in trace output"), - optparse.make_option("--printfetchseq", - action="callback", callback=printFetchseq, - help="Print fetch sequence numbers in trace output"), - optparse.make_option("--printcpseq", - action="callback", callback=printCpseq, - help="Print correct path sequence numbers in trace output"), - optparse.make_option("--dumponexit", - action="callback", callback=dumpOnExit, - help="Dump trace buffer on exit"), - optparse.make_option("--debugbreak", type="int", metavar="CYCLE", - action="callback", callback=debugBreak, - help="Cycle to create a breakpoint"), - optparse.make_option("--statsfile", type="string", action="callback", - callback=statsTextFile, metavar="FILE", - help="Sets the output file for the statistics") - ] - # make a SmartDict out of the build options for our local use import smartdict build_env = smartdict.SmartDict() @@ -171,12 +66,13 @@ build_env.update(defines.m5_build_env) env = smartdict.SmartDict() env.update(os.environ) - # Function to provide to C++ so it can look up instances based on paths def resolveSimObject(name): obj = config.instanceDict[name] return obj.getCCObject() +from main import options, arguments, main + # The final hook to generate .ini files. Called from the user script # once the config is built. def instantiate(root): -- cgit v1.2.3