From 6eaa4d3571e340598a2ddd03c8479d0bc993bde2 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 13:40:02 -0500 Subject: fix indent (so emacs and vi aren't screwed up.) --HG-- extra : convert_revision : 589f37476fec14aa5e3c6e018631e291113d4e69 --- sim/pyconfig/m5config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sim') diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index 4e3a4103c..c9bfdab54 100644 --- a/sim/pyconfig/m5config.py +++ b/sim/pyconfig/m5config.py @@ -28,9 +28,9 @@ from __future__ import generators import os, re, sys, types noDot = False try: - import pydot + import pydot except: - noDot = True + noDot = True env = {} env.update(os.environ) -- cgit v1.2.3 From 89ba024b9843719bf06a9c3efaaf1b137dee2a12 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 13:41:53 -0500 Subject: Fix the panic message so that it looks more like M5's panic. Make it so the same path is not added to the system path twice. --HG-- extra : convert_revision : fe18db38cc4e335ad3525a364e9f8faf62b60e52 --- sim/pyconfig/m5config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sim') diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index c9bfdab54..bbd437b30 100644 --- a/sim/pyconfig/m5config.py +++ b/sim/pyconfig/m5config.py @@ -36,11 +36,12 @@ env = {} env.update(os.environ) def panic(*args, **kwargs): - sys.exit(*args, **kwargs) + print >>sys.stderr, 'panic:', string + sys.exit(1) def AddToPath(path): path = os.path.realpath(path) - if os.path.isdir(path): + if os.path.isdir(path) and path not in sys.path: sys.path.append(path) def Import(path): -- cgit v1.2.3 From b46baf107fb88c7b0e80664a9f9951aeaa6ba249 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 17:33:28 -0500 Subject: enable the Trace, Statistics, and Serialize param contexts. objects/Root.mpy: Fake the param context stuff for now. sim/param.cc: Make empty vector enums work sim/serialize.cc: serialize_dir is always valid --HG-- extra : convert_revision : c46373f0f4c70e6a2f01a81c0fa6bacab72d4c4f --- sim/param.cc | 5 +++++ sim/serialize.cc | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'sim') diff --git a/sim/param.cc b/sim/param.cc index d16578a2d..ff023ce85 100644 --- a/sim/param.cc +++ b/sim/param.cc @@ -441,6 +441,11 @@ EnumVectorParam::parse(const string &s) { vector tokens; + if (s.empty()) { + wasSet = true; + return; + } + tokenize(tokens, s, ' '); value.resize(tokens.size()); diff --git a/sim/serialize.cc b/sim/serialize.cc index 3a073f68d..d5f217e55 100644 --- a/sim/serialize.cc +++ b/sim/serialize.cc @@ -333,11 +333,7 @@ SerializeParamContext::~SerializeParamContext() void SerializeParamContext::checkParams() { - if (serialize_dir.isValid()) { - checkpointDirBase = serialize_dir; - } else { - checkpointDirBase = outputDirectory + "cpt.%012d"; - } + checkpointDirBase = outputDirectory + (string)serialize_dir; // guarantee that directory ends with a '/' if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') -- cgit v1.2.3 From 8efd7d90633520b93c4bfba93d248b9c9bd8fe5a Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 23:55:21 -0500 Subject: More fixes to the pbs stuff to make it more robust. sim/pyconfig/SConscript: Embed the jobfile.py script into the binary so that we don't need to copy it into the Base directory every time. test/genini.py: Add the util/pbs directory to the path so we can get to jobfile.py Add a -I argument to set to add to the path. util/pbs/pbs.py: Create a MyPOpen class. This is a lot like the popen2.Popen3 class in the python library except that my version allows redirection of standard in and standard out to a file instead of a pipe. Use this popen class to execute qsub or ssh qsub. This was important for the ssh version of qsub because we need to pipe the script into standard in of ssh so that the script can get to the qsub command. (Otherwise we have a problem discovering the path.) util/pbs/send.py: Tweak the script so it figures out paths in NFS correctly. Use the new system for running qsub. --HG-- extra : convert_revision : 1289915ba99cec6fd464b71215c32d2197ff2824 --- sim/pyconfig/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sim') diff --git a/sim/pyconfig/SConscript b/sim/pyconfig/SConscript index 5708ac9a8..9154d3b99 100644 --- a/sim/pyconfig/SConscript +++ b/sim/pyconfig/SConscript @@ -170,7 +170,7 @@ EmbedMap %(name)s("%(fname)s", /* namespace */ } ''' -embedded_py_files = ['m5config.py'] +embedded_py_files = ['m5config.py', '../../util/pbs/jobfile.py'] objpath = os.path.join(env['SRCDIR'], 'objects') for root, dirs, files in os.walk(objpath, topdown=True): for i,dir in enumerate(dirs): -- cgit v1.2.3 From 60b263466e35139ee2c773cac6c96622be990fda Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 11 Feb 2005 01:40:49 -0500 Subject: Make sure we have all values when trying to generate the ini file sim/pyconfig/m5config.py: When getting all values, make sure we get the ones that are parameter defaults as well. --HG-- extra : convert_revision : 2b1c4b2f27dfab17ef9df18d7e5936e4a00bb12e --- sim/pyconfig/m5config.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sim') diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index bbd437b30..9a48e2fa4 100644 --- a/sim/pyconfig/m5config.py +++ b/sim/pyconfig/m5config.py @@ -350,6 +350,13 @@ class MetaConfigNode(type): for p,v in c._values.iteritems(): if not values.has_key(p): values[p] = v + for p,v in c._params.iteritems(): + if not values.has_key(p) and hasattr(v, 'default'): + v.valid(v.default) + v = v.default + cls._setvalue(p, v) + values[p] = v + return values def _getvalue(cls, name, default = AttributeError): -- cgit v1.2.3 From 06a4686af9b0d8e9e25e0591873d2f269bfb6d1b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 11 Feb 2005 09:47:41 -0500 Subject: Rework the command line paramters for python output and how output files and the output directory are are handled. Make the output directory configuration via a command line parameter, or an environment variable. SConscript: Add new output file stuff base/misc.cc: dev/simconsole.cc: use new output file code cpu/base_cpu.cc: use new output file code to generate output streams dev/etherdump.cc: use the output file code to find the output directory use a real stream instead of a pointer dev/etherdump.hh: use a real stream instead of a pointer objects/Root.mpy: output_dir and config_output_file are not longer configured here. sim/main.cc: - Completely rework the command line argument passing to deal with changes in python and output files. - Update help output to reflect changes. - Remove all direct support for .ini files. They are strictly for intermediate representation. - Remove the --foo:bar=blah syntax for .ini files and add --foo.bar=blah syntax for python. This will generate: foo.bar = 'blah' in the python script. - Add '-d' to set the output directory. - Use new output file code to access the output stream. sim/serialize.cc: use the new code to find the output directory sim/universe.cc: Get rid of makeOutputStream. Use the new output file code. Remove output_dir and config_output_file as parameters. --HG-- extra : convert_revision : df2f0e13d401c3a60cae1239aa1ec3511721544d --- sim/main.cc | 263 +++++++++++++++++++++++++------------------------------ sim/serialize.cc | 3 +- sim/universe.cc | 98 ++++----------------- 3 files changed, 137 insertions(+), 227 deletions(-) (limited to 'sim') diff --git a/sim/main.cc b/sim/main.cc index 163c835ee..1748294af 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -42,6 +42,7 @@ #include "base/embedfile.hh" #include "base/inifile.hh" #include "base/misc.hh" +#include "base/output.hh" #include "base/pollevent.hh" #include "base/statistics.hh" #include "base/str.hh" @@ -109,25 +110,32 @@ abortHandler(int sigtype) const char *myProgName = ""; /// Show brief help message. -static void +void showBriefHelp(ostream &out) { - out << "Usage: " << myProgName - << " [-hnu] [-Dname[=def]] [-Uname] [-I[dir]] " - << " [ ...]\n" - << "[] [ ...]\n" - << " -h: print long help (including parameter listing)\n" - << " -u: don't quit on unreferenced parameters\n" - << " -D,-U,-I: passed to cpp for preprocessing .ini files\n" - << " : config file name (.ini or .py) or\n" - << " single param (--
:=)" - << endl; + char *prog = basename(myProgName); + + ccprintf(out, "Usage:\n"); + ccprintf(out, +"%s [-d ] [-E [=]] [-I ] [-P ]\n" +" [--=] \n" +"\n" +" -d set the output directory to \n" +" -E set the environment variable to (or 'True')\n" +" -I add the directory to python's path\n" +" -P execute directly in the configuration\n" +" --var=val set the python variable to ''\n" +" config file name (.py or .mpy)\n", + prog); + + ccprintf(out, "%s -X\n -X extract embedded files\n", prog); + ccprintf(out, "%s -h\n -h print long help\n", prog); } /// Show verbose help message. Includes parameter listing from /// showBriefHelp(), plus an exhaustive list of ini-file parameters /// and SimObjects (with their parameters). -static void +void showLongHelp(ostream &out) { showBriefHelp(out); @@ -152,7 +160,7 @@ showLongHelp(ostream &out) } /// Print welcome message. -static void +void sayHello(ostream &out) { extern const char *compileDate; // from date.cc @@ -176,7 +184,7 @@ sayHello(ostream &out) /// Echo the command line for posterity in such a way that it can be /// used to rerun the same simulation (given the same .ini files). /// -static void +void echoCommandLine(int argc, char **argv, ostream &out) { out << "command line: " << argv[0]; @@ -208,16 +216,20 @@ echoCommandLine(int argc, char **argv, ostream &out) out << endl << endl; } +char * +getOptionString(int &index, int argc, char **argv) +{ + char *option = argv[index] + 2; + if (*option != '\0') + return option; -/// -/// The simulator configuration database. This is the union of all -/// specified .ini files. This shouldn't need to be visible outside -/// this file, as it is passed as a parameter to all the param-parsing -/// routines. -/// -static IniFile simConfigDB; + // We didn't find an argument, it must be in the next variable. + if (++index >= argc) + panic("option string for option '%s' not found", argv[index - 1]); + + return argv[index]; +} -/// M5 entry point. int main(int argc, char **argv) { @@ -233,18 +245,9 @@ main(int argc, char **argv) sayHello(cerr); - // Initialize statistics database - Stats::InitSimStats(); - - vector cppArgs; - - // Should we quit if there are unreferenced parameters? By - // default, yes... it's a good way of catching typos in - // section/parameter names (which otherwise go by silently). Use - // -u to override. - bool quitOnUnreferenced = true; - - bool python_initialized = false; + bool configfile_found = false; + PythonConfig pyconfig; + string outdir; // Parse command-line options. // Since most of the complex options are handled through the @@ -253,12 +256,53 @@ main(int argc, char **argv) for (int i = 1; i < argc; ++i) { char *arg_str = argv[i]; - // if arg starts with '-', parse as option, - // else treat it as a configuration file name and load it - if (arg_str[0] == '-') { + // if arg starts with '--', parse as a special python option + // of the format --=, if the arg + // starts with '-', it should be a simulator option with a + // format similar to getopt. In any other case, treat the + // option as a configuration file name and load it. + if (arg_str[0] == '-' && arg_str[1] == '-') { + string str = &arg_str[2]; + string var, val; + + if (!split_first(str, var, val, '=')) + panic("Could not parse configuration argument '%s'\n" + "Expecting --=\n", arg_str); + + pyconfig.setVariable(var, val); + } else if (arg_str[0] == '-') { + char *option; + string var, val; // switch on second char switch (arg_str[1]) { + case 'd': + outdir = getOptionString(i, argc, argv); + break; + + case 'h': + showLongHelp(cerr); + exit(1); + + case 'E': + option = getOptionString(i, argc, argv); + if (!split_first(option, var, val, '=')) + val = "True"; + + if (setenv(var.c_str(), val.c_str(), true) == -1) + panic("setenv: %s\n", strerror(errno)); + break; + + case 'I': + option = getOptionString(i, argc, argv); + pyconfig.addPath(option); + break; + + case 'P': + option = getOptionString(i, argc, argv); + pyconfig.writeLine(option); + break; + case 'X': { list lst; EmbedMap::all(lst); @@ -274,124 +318,58 @@ main(int argc, char **argv) return 0; } - case 'h': - // -h: show help - showLongHelp(cerr); - exit(1); - - case 'u': - // -u: don't quit on unreferenced parameters - quitOnUnreferenced = false; - break; - - case 'D': - case 'U': - // cpp options: record & pass to cpp. Note that these - // cannot have spaces, i.e., '-Dname=val' is OK, but - // '-D name=val' is not. I don't consider this a - // problem, since even though gnu cpp accepts the - // latter, other cpp implementations do not (Tru64, - // for one). - cppArgs.push_back(arg_str); - break; - - case 'I': { - // We push -I as an argument to cpp - cppArgs.push_back(arg_str); - - string arg = arg_str + 2; - eat_white(arg); - - // Send this as the python path - addPythonPath(arg); - } break; - - case 'P': - if (!python_initialized) { - initPythonConfig(); - python_initialized = true; - } - writePythonString(arg_str + 2); - writePythonString("\n"); - - case 'E': - if (putenv(arg_str + 2) == -1) - panic("putenv: %s\n", strerror(errno)); - break; - - case '-': - // command-line configuration parameter: - // '--
:=' - if (!simConfigDB.add(arg_str + 2)) { - // parse error - ccprintf(cerr, - "Could not parse configuration argument '%s'\n" - "Expecting --
:=\n", - arg_str); - exit(0); - } - break; - default: showBriefHelp(cerr); - ccprintf(cerr, "Fatal: invalid argument '%s'\n", arg_str); - exit(0); - } - } - else { - // no '-', treat as config file name - - // make STL string out of file name - string filename(arg_str); - - int ext_loc = filename.rfind("."); - - string ext = - (ext_loc != string::npos) ? filename.substr(ext_loc) : ""; - - if (ext == ".ini") { - if (!simConfigDB.loadCPP(filename, cppArgs)) { - cprintf("Error processing file %s\n", filename); - exit(1); - } - } else if (ext == ".py" || ext == ".mpy") { - if (!python_initialized) { - initPythonConfig(); - python_initialized = true; - } - loadPythonConfig(filename); - } - else { - cprintf("Config file name '%s' must end in '.py' or '.ini'.\n", - filename); - exit(1); + panic("invalid argument '%s'\n", arg_str); } + } else { + string file(arg_str); + string base, ext; + + if (!split_last(file, base, ext, '.') || + ext != "py" && ext != "mpy") + panic("Config file '%s' must end in '.py' or '.mpy'\n", file); + + pyconfig.load(file); + configfile_found = true; } } - if (python_initialized && !finishPythonConfig(simConfigDB)) { - cprintf("Error processing python code\n"); - exit(1); + if (outdir.empty()) { + char *env = getenv("OUTPUT_DIR"); + outdir = env ? env : "."; } - // The configuration database is now complete; start processing it. + simout.setDirectory(outdir); - // Parse and check all non-config-hierarchy parameters. - ParamContext::parseAllContexts(simConfigDB); - ParamContext::checkAllContexts(); + char *env = getenv("CONFIG_OUTPUT"); + if (!env) + env = "config.out"; + configStream = simout.find(env); - // Print header info into stats file. Can't do this sooner since - // the stat file name is set via a .ini param... thus it just got - // opened above during ParamContext::checkAllContexts(). + if (!configfile_found) + panic("no configuration file specified!"); + + // The configuration database is now complete; start processing it. + IniFile inifile; + if (!pyconfig.output(inifile)) + panic("Error processing python code"); + + // Initialize statistics database + Stats::InitSimStats(); // Now process the configuration hierarchy and create the SimObjects. - ConfigHierarchy configHierarchy(simConfigDB); + ConfigHierarchy configHierarchy(inifile); configHierarchy.build(); configHierarchy.createSimObjects(); + // Parse and check all non-config-hierarchy parameters. + ParamContext::parseAllContexts(inifile); + ParamContext::checkAllContexts(); + // Print hello message to stats file if it's actually a file. If // it's not (i.e. it's cout or cerr) then we already did it above. - if (outputStream != &cout && outputStream != &cerr) + if (simout.isFile(*outputStream)) sayHello(*outputStream); // Echo command line and all parameter settings to stats file as well. @@ -406,13 +384,8 @@ main(int argc, char **argv) // Done processing the configuration database. // Check for unreferenced entries. - if (simConfigDB.printUnreferenced() && quitOnUnreferenced) { - cerr << "Fatal: unreferenced .ini sections/entries." << endl - << "If this is not an error, add 'unref_section_ok=y' or " - << "'unref_entries_ok=y' to the appropriate sections " - << "to suppress this message." << endl; - exit(1); - } + if (inifile.printUnreferenced()) + panic("unreferenced sections/entries in the intermediate ini file"); SimObject::regAllStats(); diff --git a/sim/serialize.cc b/sim/serialize.cc index d5f217e55..846d191e0 100644 --- a/sim/serialize.cc +++ b/sim/serialize.cc @@ -38,6 +38,7 @@ #include "base/inifile.hh" #include "base/misc.hh" +#include "base/output.hh" #include "base/str.hh" #include "base/trace.hh" #include "sim/config_node.hh" @@ -333,7 +334,7 @@ SerializeParamContext::~SerializeParamContext() void SerializeParamContext::checkParams() { - checkpointDirBase = outputDirectory + (string)serialize_dir; + checkpointDirBase = simout.resolve(serialize_dir); // guarantee that directory ends with a '/' if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') diff --git a/sim/universe.cc b/sim/universe.cc index 115f6f790..9137baaf0 100644 --- a/sim/universe.cc +++ b/sim/universe.cc @@ -26,10 +26,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include - #include #include #include @@ -37,6 +33,7 @@ #include #include "base/misc.hh" +#include "base/output.hh" #include "sim/builder.hh" #include "sim/host.hh" #include "sim/sim_object.hh" @@ -51,7 +48,7 @@ double __ticksPerUS; double __ticksPerNS; double __ticksPerPS; -string outputDirectory; +bool fullSystem; ostream *outputStream; ostream *configStream; @@ -61,81 +58,40 @@ class Root : public SimObject public: Root(const std::string &name) : SimObject(name) {} }; -Root *root = NULL; - -std::ostream * -makeOutputStream(std::string &name) -{ - if (name == "cerr" || name == "stderr") - return &std::cerr; - - if (name == "cout" || name == "stdout") - return &std::cout; - - string path = (name[0] != '/') ? outputDirectory + name : name; - - // have to dynamically allocate a stream since we're going to - // return it... though the caller can't easily free it since it - // may be cerr or cout. need GC! - ofstream *s = new ofstream(path.c_str(), ios::trunc); - - if (!s->is_open()) - fatal("Cannot open file %s", path); - - return s; -} - - -void -closeOutputStream(std::ostream *os) -{ - // can't close cerr or cout - if (os == &std::cerr || os == &std::cout) - return; - - // can only close ofstreams, not generic ostreams, so try to - // downcast and close only if the downcast succeeds - std::ofstream *ofs = dynamic_cast(os); - if (ofs) - ofs->close(); -} - BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root) Param full_system; Param frequency; - Param output_dir; Param output_file; - Param config_output_file; END_DECLARE_SIM_OBJECT_PARAMS(Root) BEGIN_INIT_SIM_OBJECT_PARAMS(Root) - INIT_PARAM_DFLT(full_system, "full system simulation", true), - INIT_PARAM_DFLT(frequency, "tick frequency", 200000000), - INIT_PARAM_DFLT(output_dir, "directory to output data to", "."), - INIT_PARAM_DFLT(output_file, "file to dump simulator output to", "cout"), - INIT_PARAM_DFLT(config_output_file, "file to dump simulator config to", - "m5config.out") + INIT_PARAM(full_system, "full system simulation"), + INIT_PARAM(frequency, "tick frequency"), + INIT_PARAM(output_file, "file to dump simulator output to") END_INIT_SIM_OBJECT_PARAMS(Root) CREATE_SIM_OBJECT(Root) { + static bool created = false; + if (created) + panic("only one root object allowed!"); + + created = true; + fullSystem = full_system; + #ifdef FULL_SYSTEM - if (!bool(full_system)) + if (!fullSystem) panic("FULL_SYSTEM compiled and configuration not full_system"); #else - if (bool(full_system)) + if (fullSystem) panic("FULL_SYSTEM not compiled but configuration is full_system"); #endif - if (root) - panic("only one root object allowed!"); - root = new Root(getInstanceName()); - ticksPerSecond = frequency; double freq = double(ticksPerSecond); __ticksPerMS = freq / 1.0e3; @@ -143,29 +99,9 @@ CREATE_SIM_OBJECT(Root) __ticksPerNS = freq / 1.0e9; __ticksPerPS = freq / 1.0e12; - outputDirectory = output_dir; - if (!outputDirectory.empty()) { - outputDirectory = output_dir; - - // guarantee that directory ends with a '/' - if (outputDirectory[outputDirectory.size() - 1] != '/') - outputDirectory += "/"; - - if (mkdir(outputDirectory.c_str(), 0777) < 0) { - if (errno != EEXIST) { - panic("%s\ncould not make output directory: %s\n", - strerror(errno), outputDirectory); - } - } - } - - outputStream = makeOutputStream(output_file); - configStream = outputStream; - string cof = config_output_file; - if (!cof.empty()) - configStream = makeOutputStream(cof); - - return root; + outputStream = simout.find(output_file); + + return new Root(getInstanceName()); } REGISTER_SIM_OBJECT("Root", Root) -- cgit v1.2.3