From b46baf107fb88c7b0e80664a9f9951aeaa6ba249 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 17:33:28 -0500 Subject: [PATCH 01/14] 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 --- objects/Root.mpy | 7 +++++++ sim/param.cc | 5 +++++ sim/serialize.cc | 6 +----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/objects/Root.mpy b/objects/Root.mpy index b21396e360..dd485ac73b 100644 --- a/objects/Root.mpy +++ b/objects/Root.mpy @@ -1,4 +1,8 @@ from HierParams import HierParams +from Serialize import Serialize +from Statistics import Statistics +from Trace import Trace + simobj Root(SimObject): type = 'Root' frequency = Param.Tick(200000000, "tick frequency") @@ -9,3 +13,6 @@ simobj Root(SimObject): full_system = Param.Bool("Full system simulation?") hier = HierParams(do_data = False, do_events = True) checkpoint = Param.String('', "Checkpoint file") + stats = Statistics() + trace = Trace() + serialize = Serialize() diff --git a/sim/param.cc b/sim/param.cc index d16578a2d3..ff023ce85f 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 3a073f68d2..d5f217e551 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] != '/') From 7fed053bebc49d0f3dc10995360f78be191ca39b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 18:12:39 -0500 Subject: [PATCH 02/14] More fixes for running from anywhere. util/pbs/send.py: always access the job directory via full path --HG-- extra : convert_revision : 1792aadb39428e7c91953ac58f6da212b7f92835 --- util/pbs/send.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/pbs/send.py b/util/pbs/send.py index 1f174b1f85..3741b86966 100755 --- a/util/pbs/send.py +++ b/util/pbs/send.py @@ -131,21 +131,22 @@ if listonly: if not onlyecho: jl = [] for jobname in joblist: + jobdir = joinpath(rootdir, jobname) if os.path.exists(jobname): if not force: - if os.path.isfile(joinpath(jobname, '.success')): + if os.path.isfile(joinpath(jobdir, '.success')): continue - if os.path.isfile(joinpath(jobname, '.start')) and \ - not os.path.isfile(joinpath(jobname, '.stop')): + if os.path.isfile(joinpath(jobdir, '.start')) and \ + not os.path.isfile(joinpath(jobdir, '.stop')): continue if not clean: sys.exit('job directory not clean!') - job.cleandir(jobname) + job.cleandir(jobdir) else: - os.mkdir(jobname) + os.mkdir(jobdir) jl.append(jobname) joblist = jl From 4a3e33fb6d2e13a0febd9696905da05e02f93834 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 22:21:58 -0500 Subject: [PATCH 03/14] Fix bug in trace param context so we can compile --HG-- extra : convert_revision : 667c76132adb143e1f2c0726c80ad3e567a530aa From 8efd7d90633520b93c4bfba93d248b9c9bd8fe5a Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 23:55:21 -0500 Subject: [PATCH 04/14] 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 +- test/genini.py | 17 ++--- util/pbs/pbs.py | 136 ++++++++++++++++++++++++++++------------ util/pbs/send.py | 33 +++++++--- 4 files changed, 132 insertions(+), 56 deletions(-) diff --git a/sim/pyconfig/SConscript b/sim/pyconfig/SConscript index 5708ac9a86..9154d3b994 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): diff --git a/test/genini.py b/test/genini.py index 0dac0d4092..73e7012f62 100644 --- a/test/genini.py +++ b/test/genini.py @@ -31,23 +31,26 @@ from os.path import join as joinpath, realpath mypath = sys.path[0] sys.path.append(joinpath(mypath, '..')) sys.path.append(joinpath(mypath, '../configs/kernel')) +sys.path.append(joinpath(mypath, '../util/pbs')) sys.path.append(joinpath(mypath, '../sim/pyconfig')) from importer import mpy_exec, mpy_execfile, AddToPath from m5config import * try: - opts, args = getopt.getopt(sys.argv[1:], '-E:') - for o,a in opts: - if o == '-E': - offset = a.find('=') + opts, args = getopt.getopt(sys.argv[1:], '-E:I:') + for opt,arg in opts: + if opt == '-E': + offset = arg.find('=') if offset == -1: - name = a + name = arg value = True else: - name = a[:offset] - value = a[offset+1:] + name = arg[:offset] + value = arg[offset+1:] env[name] = value + if opt == '-I': + AddToPath(arg) except getopt.GetoptError: sys.exit('Improper Usage') diff --git a/util/pbs/pbs.py b/util/pbs/pbs.py index a71dbbf8e8..cd55da7229 100755 --- a/util/pbs/pbs.py +++ b/util/pbs/pbs.py @@ -26,18 +26,76 @@ # # Authors: Nathan Binkert -import os, re, sys +import os, popen2, re, sys -def ssh(host, script, tty = False, user = ''): - args = [ 'ssh', '-x' ] - if user: - args.append('-l' + user) - if tty: - args.append('-t') - args.append(host) - args.append(script) +class MyPOpen(object): + def __init__(self, cmd, input = None, output = None, bufsize = -1): + self.sts = -1 - return os.spawnvp(os.P_WAIT, args[0], args) + if input is None: + p2c_read, p2c_write = os.pipe() + self.tochild = os.fdopen(p2c_write, 'w', bufsize) + else: + p2c_write = None + if isinstance(input, file): + p2c_read = input.fileno() + elif isinstance(input, str): + input = file(input, 'r') + p2c_read = input.fileno() + elif isinstance(input, int): + p2c_read = input + else: + raise AttributeError + + if output is None: + c2p_read, c2p_write = os.pipe() + self.fromchild = os.fdopen(c2p_read, 'r', bufsize) + else: + c2p_read = None + if isinstance(output, file): + c2p_write = output.fileno() + elif isinstance(output, str): + output = file(output, 'w') + c2p_write = output.fileno() + elif isinstance(output, int): + c2p_write = output + else: + raise AttributeError + + self.pid = os.fork() + if self.pid == 0: + os.dup2(p2c_read, 0) + os.dup2(c2p_write, 1) + os.dup2(c2p_write, 2) + if isinstance(cmd, basestring): + cmd = ['/bin/sh', '-c', cmd] + if False: + for i in range(3, MAXFD): + try: + os.close(i) + except OSError: + pass + try: + os.execvp(cmd[0], cmd) + finally: + os._exit(1) + + os.close(p2c_read) + os.close(c2p_write) + + def poll(self): + if self.sts < 0: + pid, sts = os.waitpid(self.pid, os.WNOHANG) + if pid == self.pid: + self.sts = sts + return self.sts + + def wait(self): + if self.sts < 0: + pid, sts = os.waitpid(self.pid, 0) + if pid == self.pid: + self.sts = sts + return self.sts class qsub: def __init__(self): @@ -56,37 +114,35 @@ class qsub: self.pbshost = '' self.qsub = 'qsub' self.env = {} - self.onlyecho = False - self.verbose = False - def do(self, script, ): - args = [self.qsub] + def build(self, script, args = []): + self.cmd = [ self.qsub ] if self.env: arg = '-v' arg += ','.join([ '%s=%s' % i for i in self.env.iteritems() ]) - args.append(arg) + self.cmd.append(arg) if self.hold: - args.append('-h') + self.cmd.append('-h') if len(self.stdout): - args.append('-olocalhost:' + self.stdout) + self.cmd.append('-olocalhost:' + self.stdout) if self.keep_stdout and self.keep_stderr: - args.append('-koe') + self.cmd.append('-koe') elif self.keep_stdout: - args.append('-ko') + self.cmd.append('-ko') elif self.keep_stderr: - args.append('-ke') + self.cmd.append('-ke') else: - args.append('-kn') + self.cmd.append('-kn') if self.join: - args.append('-joe') + self.cmd.append('-joe') if len(self.node_type): - args.append('-lnodes=' + self.node_type) + self.cmd.append('-lnodes=' + self.node_type) if self.mail_abort or self.mail_begin or self.mail_end: flags = '' @@ -97,30 +153,32 @@ class qsub: if self.mail_end: flags.append('e') if len(flags): - args.append('-m ' + flags) + self.cmd.append('-m ' + flags) if len(self.name): - args.append("-N%s" % self.name) + self.cmd.append("-N%s" % self.name) if self.priority != 0: - args.append('-p' + self.priority) + self.cmd.append('-p' + self.priority) if len(self.queue): - args.append('-q' + self.queue) + self.cmd.append('-q' + self.queue) - args.append(script) + self.cmd.extend(args) + self.script = script + self.command = ' '.join(self.cmd + [ self.script ]) - if self.verbose or self.onlyecho: - print >>sys.stderr, 'PBS Command: ', ' '.join(args) + def do(self): + pbs = MyPOpen(self.cmd + [ self.script ]) + self.result = pbs.fromchild.read() + ec = pbs.wait() - if self.onlyecho: - return 0 - - print >>sys.stderr, 'PBS Jobid: ', - - ec = os.spawnvp(os.P_WAIT, args[0], args) - - if ec != 0 and len(self.pbshost): - ec = ssh(self.pbshost, ' '.join(args)) + if ec != 0 and self.pbshost: + cmd = ' '.join(self.cmd + [ '-' ]) + cmd = [ 'ssh', '-x', self.pbshost, cmd ] + self.command = ' '.join(cmd) + ssh = MyPOpen(cmd, input = self.script) + self.result = ssh.fromchild.read() + ec = ssh.wait() return ec diff --git a/util/pbs/send.py b/util/pbs/send.py index 3741b86966..4daf15b454 100755 --- a/util/pbs/send.py +++ b/util/pbs/send.py @@ -28,12 +28,20 @@ # Authors: Ali Saidi # Nathan Binkert -import os, os.path, re, sys +import os, os.path, re, socket, sys from os import environ as env, listdir from os.path import basename, isdir, isfile, islink, join as joinpath from filecmp import cmp as filecmp from shutil import copyfile +def nfspath(dir): + if dir.startswith('/.automount/'): + dir = '/n/%s' % dir[12:] + elif not dir.startswith('/n/'): + dir = '/n/%s%s' % (socket.gethostname().split('.')[0], dir) + return dir + +progpath = nfspath(sys.path[0]) progname = basename(sys.argv[0]) usage = """\ Usage: @@ -65,7 +73,7 @@ force = False listonly = False queue = '' verbose = False -rootdir = re.sub(r'^/\.automount/', r'/n/', os.getcwd()) +rootdir = nfspath(os.getcwd()) for opt,arg in opts: if opt == '-c': clean = True @@ -92,7 +100,8 @@ for arg in args: exprs.append(re.compile(arg)) if not listonly and not onlyecho and isdir(linkdir): - print 'Checking for outdated files in Link directory' + if verbose: + print 'Checking for outdated files in Link directory' entries = listdir(linkdir) for entry in entries: link = joinpath(linkdir, entry) @@ -156,8 +165,8 @@ for jobname in joblist: if not onlyecho and not os.path.isdir(jobdir): sys.exit('%s is not a directory. Cannot build job' % jobdir) - print >>sys.stderr, 'Job name: %s' % jobname - print >>sys.stderr, 'Job directory: %s' % jobdir + print 'Job name: %s' % jobname + print 'Job directory: %s' % jobdir qsub = pbs.qsub() qsub.pbshost = 'simpool.eecs.umich.edu' @@ -165,11 +174,17 @@ for jobname in joblist: qsub.name = jobname qsub.join = True qsub.node_type = 'FAST' - qsub.onlyecho = onlyecho qsub.env['ROOTDIR'] = rootdir - qsub.verbose = verbose if len(queue): qsub.queue = queue + qsub.build(joinpath(progpath, 'job.py')) - qsub.do(joinpath(basedir, 'job.py')) - print >>sys.stderr, '' + if verbose: + print 'PBS Command: %s' % qsub.command + + if not onlyecho: + ec = qsub.do() + if ec == 0: + print 'PBS Jobid: %s' % qsub.result + else: + print 'PBS Failed' From 200246d1cadd3cf671860e14aad9632671d63537 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 10 Feb 2005 00:02:51 -0500 Subject: [PATCH 05/14] Some cosmetic changes to MyPOpen util/pbs/pbs.py: More tweaks that I forgot --HG-- extra : convert_revision : 7298f91b80bc7d8d946be93fc622e5f9f6e155f9 --- util/pbs/pbs.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/util/pbs/pbs.py b/util/pbs/pbs.py index cd55da7229..ecacbeba2e 100755 --- a/util/pbs/pbs.py +++ b/util/pbs/pbs.py @@ -30,7 +30,7 @@ import os, popen2, re, sys class MyPOpen(object): def __init__(self, cmd, input = None, output = None, bufsize = -1): - self.sts = -1 + self.status = -1 if input is None: p2c_read, p2c_write = os.pipe() @@ -64,17 +64,9 @@ class MyPOpen(object): self.pid = os.fork() if self.pid == 0: - os.dup2(p2c_read, 0) - os.dup2(c2p_write, 1) - os.dup2(c2p_write, 2) - if isinstance(cmd, basestring): - cmd = ['/bin/sh', '-c', cmd] - if False: - for i in range(3, MAXFD): - try: - os.close(i) - except OSError: - pass + os.dup2(p2c_read, sys.stdin.fileno()) + os.dup2(c2p_write, sys.stdout.fileno()) + os.dup2(c2p_write, sys.stderr.fileno()) try: os.execvp(cmd[0], cmd) finally: @@ -84,18 +76,18 @@ class MyPOpen(object): os.close(c2p_write) def poll(self): - if self.sts < 0: - pid, sts = os.waitpid(self.pid, os.WNOHANG) + if self.status < 0: + pid, status = os.waitpid(self.pid, os.WNOHANG) if pid == self.pid: - self.sts = sts - return self.sts + self.status = status + return self.status def wait(self): - if self.sts < 0: - pid, sts = os.waitpid(self.pid, 0) + if self.status < 0: + pid, status = os.waitpid(self.pid, 0) if pid == self.pid: - self.sts = sts - return self.sts + self.status = status + return self.status class qsub: def __init__(self): From 60b263466e35139ee2c773cac6c96622be990fda Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 11 Feb 2005 01:40:49 -0500 Subject: [PATCH 06/14] 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(+) diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index bbd437b308..9a48e2fa4b 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): From 06a4686af9b0d8e9e25e0591873d2f269bfb6d1b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 11 Feb 2005 09:47:41 -0500 Subject: [PATCH 07/14] 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 --- SConscript | 1 + base/misc.cc | 5 +- base/output.cc | 129 +++++++++++++++++++++++ base/output.hh | 61 +++++++++++ cpu/base_cpu.cc | 9 +- dev/etherdump.cc | 19 ++-- dev/etherdump.hh | 4 +- dev/simconsole.cc | 21 ++-- objects/Root.mpy | 3 - sim/main.cc | 259 +++++++++++++++++++++------------------------- sim/serialize.cc | 3 +- sim/universe.cc | 96 +++-------------- 12 files changed, 352 insertions(+), 258 deletions(-) create mode 100644 base/output.cc create mode 100644 base/output.hh diff --git a/SConscript b/SConscript index 187edadff7..19f84f9131 100644 --- a/SConscript +++ b/SConscript @@ -63,6 +63,7 @@ base_sources = Split(''' base/intmath.cc base/match.cc base/misc.cc + base/output.cc base/pollevent.cc base/python.cc base/range.cc diff --git a/base/misc.cc b/base/misc.cc index 0c459352fe..4b7c3632a5 100644 --- a/base/misc.cc +++ b/base/misc.cc @@ -30,10 +30,11 @@ #include #include "base/cprintf.hh" -#include "sim/host.hh" #include "base/hostinfo.hh" #include "base/misc.hh" +#include "base/output.hh" #include "base/trace.hh" +#include "sim/host.hh" #include "sim/universe.hh" using namespace std; @@ -116,7 +117,7 @@ __warn(const string &format, cp::ArgList &args, const char *func, #endif args.dump(cerr, fmt); - if (outputStream != &cerr && outputStream != &cout) + if (simout.isFile(*outputStream)) args.dump(*outputStream, fmt); delete &args; diff --git a/base/output.cc b/base/output.cc new file mode 100644 index 0000000000..2b1733f21c --- /dev/null +++ b/base/output.cc @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include + +#include "base/misc.hh" +#include "base/output.hh" + +using namespace std; + +OutputDirectory simout; + +/** + * + */ +OutputDirectory::OutputDirectory() +{} + +OutputDirectory::~OutputDirectory() +{} + +void +OutputDirectory::setDirectory(const string &d) +{ + if (!dir.empty()) + panic("Output directory already set!\n"); + + dir = d; + + if (dir != ".") { + if (mkdir(dir.c_str(), 0777) < 0 && errno != EEXIST) + panic("couldn't make output dir %s: %s\n", + dir, strerror(errno)); + } + + // guarantee that directory ends with a '/' + if (dir[dir.size() - 1] != '/') + dir += "/"; +} + +const string & +OutputDirectory::directory() +{ + if (dir.empty()) + panic("Output directory not set!"); + + return dir; +} + +string +OutputDirectory::resolve(const string &name) +{ + return (name[0] != '/') ? dir + name : name; +} + +ostream * +OutputDirectory::create(const string &name) +{ + if (name == "cerr" || name == "stderr") + return &cerr; + + if (name == "cout" || name == "stdout") + return &cout; + + ofstream *file = new ofstream(resolve(name).c_str(), ios::trunc); + if (!file->is_open()) + panic("Cannot open file %s", name); + + return file; +} + +ostream * +OutputDirectory::find(const string &name) +{ + if (name == "cerr" || name == "stderr") + return &cerr; + + if (name == "cout" || name == "stdout") + return &cout; + + string filename = resolve(name); + map_t::iterator i = files.find(filename); + if (i != files.end()) + return (*i).second; + + ofstream *file = new ofstream(filename.c_str(), ios::trunc); + if (!file->is_open()) + panic("Cannot open file %s", filename); + + files[filename] = file; + return file; +} + +bool +OutputDirectory::isFile(const std::ostream *os) +{ + return os && os != &cerr && os != &cout; +} diff --git a/base/output.hh b/base/output.hh new file mode 100644 index 0000000000..3bbe73e3b0 --- /dev/null +++ b/base/output.hh @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __BASE_OUTPUT_HH__ +#define __BASE_OUTPUT_HH__ + +#include +#include +#include + +class OutputDirectory +{ + private: + typedef std::map map_t; + + map_t files; + std::string dir; + + public: + OutputDirectory(); + ~OutputDirectory(); + + void setDirectory(const std::string &dir); + const std::string &directory(); + + std::string resolve(const std::string &name); + std::ostream *create(const std::string &name); + std::ostream *find(const std::string &name); + + static bool isFile(const std::ostream *os); + static inline bool isFile(const std::ostream &os) { return isFile(&os); } +}; + +extern OutputDirectory simout; + +#endif // __BASE_OUTPUT_HH__ diff --git a/cpu/base_cpu.cc b/cpu/base_cpu.cc index c4bb97ff87..425ac8877a 100644 --- a/cpu/base_cpu.cc +++ b/cpu/base_cpu.cc @@ -26,13 +26,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include #include "base/cprintf.hh" #include "base/loader/symtab.hh" #include "base/misc.hh" +#include "base/output.hh" #include "cpu/base_cpu.hh" #include "cpu/exec_context.hh" #include "sim/param.hh" @@ -132,8 +133,7 @@ BaseCPU::BaseCPU(const string &_name, int _number_of_threads, bool _def_reg, functionTracingEnabled = false; if (_function_trace) { - std::string filename = csprintf("ftrace.%s", name()); - functionTraceStream = makeOutputStream(filename); + functionTraceStream = simout.find(csprintf("ftrace.%s", name())); currentFunctionStart = currentFunctionEnd = 0; functionEntryTick = _function_trace_start; @@ -157,11 +157,8 @@ BaseCPU::enableFunctionTrace() BaseCPU::~BaseCPU() { - if (functionTracingEnabled) - closeOutputStream(functionTraceStream); } - void BaseCPU::init() { diff --git a/dev/etherdump.cc b/dev/etherdump.cc index 485d5599cb..3de417bdc2 100644 --- a/dev/etherdump.cc +++ b/dev/etherdump.cc @@ -36,14 +36,15 @@ #include #include "base/misc.hh" +#include "base/output.hh" #include "dev/etherdump.hh" #include "sim/builder.hh" #include "sim/universe.hh" using std::string; -EtherDump::EtherDump(const string &name, std::ostream *_stream, int max) - : SimObject(name), stream(_stream), maxlen(max) +EtherDump::EtherDump(const string &name, const string &file, int max) + : SimObject(name), stream(file.c_str()), maxlen(max) { } @@ -86,7 +87,7 @@ EtherDump::init() hdr.sigfigs = 0; hdr.linktype = DLT_EN10MB; - stream->write(reinterpret_cast(&hdr), sizeof(hdr)); + stream.write(reinterpret_cast(&hdr), sizeof(hdr)); /* * output an empty packet with the current time so that we know @@ -98,9 +99,9 @@ EtherDump::init() pkthdr.microseconds = 0; pkthdr.caplen = 0; pkthdr.len = 0; - stream->write(reinterpret_cast(&pkthdr), sizeof(pkthdr)); + stream.write(reinterpret_cast(&pkthdr), sizeof(pkthdr)); - stream->flush(); + stream.flush(); } void @@ -111,9 +112,9 @@ EtherDump::dumpPacket(PacketPtr &packet) pkthdr.microseconds = (curTick / us_freq) % ULL(1000000); pkthdr.caplen = std::min(packet->length, maxlen); pkthdr.len = packet->length; - stream->write(reinterpret_cast(&pkthdr), sizeof(pkthdr)); - stream->write(reinterpret_cast(packet->data), pkthdr.caplen); - stream->flush(); + stream.write(reinterpret_cast(&pkthdr), sizeof(pkthdr)); + stream.write(reinterpret_cast(packet->data), pkthdr.caplen); + stream.flush(); } BEGIN_DECLARE_SIM_OBJECT_PARAMS(EtherDump) @@ -132,7 +133,7 @@ END_INIT_SIM_OBJECT_PARAMS(EtherDump) CREATE_SIM_OBJECT(EtherDump) { - return new EtherDump(getInstanceName(), makeOutputStream(file), maxlen); + return new EtherDump(getInstanceName(), simout.resolve(file), maxlen); } REGISTER_SIM_OBJECT("EtherDump", EtherDump) diff --git a/dev/etherdump.hh b/dev/etherdump.hh index b127d05e2f..ba15796c83 100644 --- a/dev/etherdump.hh +++ b/dev/etherdump.hh @@ -43,7 +43,7 @@ class EtherDump : public SimObject { private: - std::ostream *stream; + std::ofstream stream; const int maxlen; void dumpPacket(PacketPtr &packet); void init(); @@ -53,7 +53,7 @@ class EtherDump : public SimObject Tick us_freq; public: - EtherDump(const std::string &name, std::ostream *_stream, int max); + EtherDump(const std::string &name, const std::string &file, int max); inline void dump(PacketPtr &pkt) { dumpPacket(pkt); } }; diff --git a/dev/simconsole.cc b/dev/simconsole.cc index 48e5d0201f..94fd9ec1fc 100644 --- a/dev/simconsole.cc +++ b/dev/simconsole.cc @@ -43,6 +43,7 @@ #include #include "base/misc.hh" +#include "base/output.hh" #include "base/socket.hh" #include "base/trace.hh" #include "dev/platform.hh" @@ -71,7 +72,7 @@ SimConsole::Event::process(int revent) cons->detach(); } -SimConsole::SimConsole(const string &name, std::ostream *os, int num) +SimConsole::SimConsole(const string &name, ostream *os, int num) : SimObject(name), event(NULL), number(num), in_fd(-1), out_fd(-1), listener(NULL), txbuf(16384), rxbuf(16384), outfile(os) #if TRACING_ON == 1 @@ -85,8 +86,6 @@ SimConsole::SimConsole(const string &name, std::ostream *os, int num) SimConsole::~SimConsole() { close(); - if (outfile) - closeOutputStream(outfile); } void @@ -313,18 +312,16 @@ END_INIT_SIM_OBJECT_PARAMS(SimConsole) CREATE_SIM_OBJECT(SimConsole) { - string filename; + string filename = output; + ostream *stream = NULL; - if (filename.empty()) { - filename = getInstanceName(); - } else if (append_name) { - filename = (string)output + "." + getInstanceName(); - } else { - filename = output; + if (!filename.empty()) { + if (append_name) + filename += "." + getInstanceName(); + stream = simout.find(filename); } - SimConsole *console = new SimConsole(getInstanceName(), - makeOutputStream(filename), number); + SimConsole *console = new SimConsole(getInstanceName(), stream, number); ((ConsoleListener *)listener)->add(console); return console; diff --git a/objects/Root.mpy b/objects/Root.mpy index dd485ac73b..0e531054b0 100644 --- a/objects/Root.mpy +++ b/objects/Root.mpy @@ -6,10 +6,7 @@ from Trace import Trace simobj Root(SimObject): type = 'Root' frequency = Param.Tick(200000000, "tick frequency") - output_dir = Param.String('.', "directory to output data to") output_file = Param.String('cout', "file to dump simulator output to") - config_output_file = Param.String('m5config.out', - "file to dump simulator config to") full_system = Param.Bool("Full system simulation?") hier = HierParams(do_data = False, do_events = True) checkpoint = Param.String('', "Checkpoint file") diff --git a/sim/main.cc b/sim/main.cc index 163c835ee8..1748294af9 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); + panic("invalid argument '%s'\n", arg_str); } - } - else { - // no '-', treat as config file name + } else { + string file(arg_str); + string base, ext; - // make STL string out of file name - string filename(arg_str); + if (!split_last(file, base, ext, '.') || + ext != "py" && ext != "mpy") + panic("Config file '%s' must end in '.py' or '.mpy'\n", file); - 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); - } + 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 : "."; } + simout.setDirectory(outdir); + + char *env = getenv("CONFIG_OUTPUT"); + if (!env) + env = "config.out"; + configStream = simout.find(env); + + 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"); - // Parse and check all non-config-hierarchy parameters. - ParamContext::parseAllContexts(simConfigDB); - ParamContext::checkAllContexts(); - - // 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(). + // 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 d5f217e551..846d191e0a 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 115f6f790e..9137baaf09 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; + outputStream = simout.find(output_file); - // 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; + return new Root(getInstanceName()); } REGISTER_SIM_OBJECT("Root", Root) From 57482491c5eeb3e52f2f29f5f56040445004cb43 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Sun, 13 Feb 2005 23:03:04 -0500 Subject: [PATCH 08/14] build mysql version if libraries exist add dprintf on alignment faults fix RR benchmark rcS script name Add Dual test without rcS script Update Monet to be closer to the real thing Fix p4/monet configs Add a way to read the DRIR register with at 32bit access for validation SConscript: build/SConstruct: always use mysql if the libraries are installed arch/alpha/alpha_memory.cc: Add a DPRINTF to print alignment faults when they happen dev/tsunami_cchip.cc: Add a way to read the DRIR for validation. --HG-- extra : convert_revision : 8c112c958f36b785390c46e70a889a79c6bea015 --- SConscript | 13 ++++++------- arch/alpha/alpha_memory.cc | 2 ++ build/SConstruct | 11 ----------- dev/tsunami_cchip.cc | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/SConscript b/SConscript index 187edadff7..e49a507b88 100644 --- a/SConscript +++ b/SConscript @@ -28,6 +28,7 @@ import os import sys +from os.path import isdir # This file defines how to build a particular configuration of M5 # based on variable settings in the 'env' build environment. @@ -335,18 +336,16 @@ else: extra_libraries = [] env.Append(LIBS=['z']) -if env['USE_MYSQL']: +if isdir('/usr/lib64/mysql') or isdir('/usr/lib/mysql') or \ + isdir('/usr/local/lib/mysql'): + env.Append(LIBPATH=['/usr/lib64/mysql', '/usr/local/lib/mysql/', + '/usr/lib/mysql']) + env.Append(CPPPATH=['/usr/local/include/mysql', '/usr/include/mysql']) sources += mysql_sources env.Append(CPPDEFINES = 'USE_MYSQL') env.Append(CPPDEFINES = 'STATS_BINNING') - env.Append(CPPPATH=['/usr/local/include/mysql', '/usr/include/mysql']) - if os.path.isdir('/usr/lib64'): - env.Append(LIBPATH=['/usr/lib64/mysql']) - else: - env.Append(LIBPATH=['/usr/lib/mysql/']) env.Append(LIBS=['mysqlclient']) - ################################################### # # Special build rules. diff --git a/arch/alpha/alpha_memory.cc b/arch/alpha/alpha_memory.cc index 81a1902a08..639abbeb8e 100644 --- a/arch/alpha/alpha_memory.cc +++ b/arch/alpha/alpha_memory.cc @@ -501,6 +501,8 @@ AlphaDTB::translate(MemReqPtr &req, bool write) const */ if (req->vaddr & (req->size - 1)) { fault(req, write ? MM_STAT_WR_MASK : 0); + DPRINTF(TLB, "Alignment Fault on %#x, size = %d", req->vaddr, + req->size); return Alignment_Fault; } diff --git a/build/SConstruct b/build/SConstruct index 3d7db1db2a..5c4ae94a1f 100644 --- a/build/SConstruct +++ b/build/SConstruct @@ -101,23 +101,12 @@ configs_map = { 'KERNEL' : KernelConfig } -# Enable detailed full-system binning. -def MeasureOpt(env): - env.Replace(USE_MYSQL = True) - env.Append(CPPDEFINES = 'FS_MEASURE') - -# Enable MySql database output for stats. -def MySqlOpt(env): - env.Replace(USE_MYSQL = True) - # Disable FastAlloc object allocation. def NoFastAllocOpt(env): env.Append(CPPDEFINES = 'NO_FAST_ALLOC') # Configuration options map. options_map = { - 'MEASURE' : MeasureOpt, - 'MYSQL' : MySqlOpt, 'NO_FAST_ALLOC' : NoFastAllocOpt } diff --git a/dev/tsunami_cchip.cc b/dev/tsunami_cchip.cc index 6bf4d8b578..2fb293fbf7 100644 --- a/dev/tsunami_cchip.cc +++ b/dev/tsunami_cchip.cc @@ -176,7 +176,7 @@ TsunamiCChip::read(MemReqPtr &req, uint8_t *data) if (regnum == TSDEV_CC_DRIR) { warn("accessing DRIR with 32 bit read, " "hopefully your just reading this for timing"); - *(uint64_t*)data = drir; + *(uint32_t*)data = drir; } else panic("invalid access size(?) for tsunami register!\n"); return No_Fault; From b1ab7b53c337cd725fcddc03f1d91b11fe842c29 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 14 Feb 2005 18:54:38 -0500 Subject: [PATCH 09/14] output dir changes to python files util/pbs/job.py: pass output dir to m5 directly --HG-- extra : convert_revision : 00d1568bb2da3b3e646fc75b4884314bf4cb2d71 --- util/pbs/job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/pbs/job.py b/util/pbs/job.py index 5eed0cd758..7c8d4bc163 100755 --- a/util/pbs/job.py +++ b/util/pbs/job.py @@ -134,7 +134,7 @@ if __name__ == '__main__': os.symlink(joinpath(jobdir, 'output'), 'status.out') - args = [ joinpath(basedir, 'm5'), joinpath(basedir, 'run.mpy') ] + args = [ joinpath(basedir, 'm5'), '-d', '%s' % jobdir, joinpath(basedir, 'run.mpy') ] if not len(args): sys.exit("no arguments") From 5e9bc06457923893d5acf049ab5d1dd621a865cc Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 14 Feb 2005 20:22:27 -0500 Subject: [PATCH 10/14] Make it so we append jobs to the joblist in the for loop not outside of the loop so we get all of the jobs, not just the last one. util/pbs/send.py: fix indent --HG-- extra : convert_revision : eee9546b4945ff949fdfdf339fc95a23603b47d3 --- util/pbs/send.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/pbs/send.py b/util/pbs/send.py index 4daf15b454..b796cadbd4 100755 --- a/util/pbs/send.py +++ b/util/pbs/send.py @@ -156,7 +156,7 @@ if not onlyecho: job.cleandir(jobdir) else: os.mkdir(jobdir) - jl.append(jobname) + jl.append(jobname) joblist = jl for jobname in joblist: From f4e2f0ea339d0b2524dde28c6bf903c06e97c948 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 14 Feb 2005 20:47:05 -0500 Subject: [PATCH 11/14] undoing change per nates request --HG-- extra : convert_revision : c5c2fd88dfd8d893da51c2b80907260ec14a7593 --- SConscript | 13 +++++++------ build/SConstruct | 11 +++++++++++ util/pbs/job.py | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/SConscript b/SConscript index 8f78991348..19f84f9131 100644 --- a/SConscript +++ b/SConscript @@ -28,7 +28,6 @@ import os import sys -from os.path import isdir # This file defines how to build a particular configuration of M5 # based on variable settings in the 'env' build environment. @@ -337,16 +336,18 @@ else: extra_libraries = [] env.Append(LIBS=['z']) -if isdir('/usr/lib64/mysql') or isdir('/usr/lib/mysql') or \ - isdir('/usr/local/lib/mysql'): - env.Append(LIBPATH=['/usr/lib64/mysql', '/usr/local/lib/mysql/', - '/usr/lib/mysql']) - env.Append(CPPPATH=['/usr/local/include/mysql', '/usr/include/mysql']) +if env['USE_MYSQL']: sources += mysql_sources env.Append(CPPDEFINES = 'USE_MYSQL') env.Append(CPPDEFINES = 'STATS_BINNING') + env.Append(CPPPATH=['/usr/local/include/mysql', '/usr/include/mysql']) + if os.path.isdir('/usr/lib64'): + env.Append(LIBPATH=['/usr/lib64/mysql']) + else: + env.Append(LIBPATH=['/usr/lib/mysql/']) env.Append(LIBS=['mysqlclient']) + ################################################### # # Special build rules. diff --git a/build/SConstruct b/build/SConstruct index 5c4ae94a1f..3d7db1db2a 100644 --- a/build/SConstruct +++ b/build/SConstruct @@ -101,12 +101,23 @@ configs_map = { 'KERNEL' : KernelConfig } +# Enable detailed full-system binning. +def MeasureOpt(env): + env.Replace(USE_MYSQL = True) + env.Append(CPPDEFINES = 'FS_MEASURE') + +# Enable MySql database output for stats. +def MySqlOpt(env): + env.Replace(USE_MYSQL = True) + # Disable FastAlloc object allocation. def NoFastAllocOpt(env): env.Append(CPPDEFINES = 'NO_FAST_ALLOC') # Configuration options map. options_map = { + 'MEASURE' : MeasureOpt, + 'MYSQL' : MySqlOpt, 'NO_FAST_ALLOC' : NoFastAllocOpt } diff --git a/util/pbs/job.py b/util/pbs/job.py index 7c8d4bc163..5eed0cd758 100755 --- a/util/pbs/job.py +++ b/util/pbs/job.py @@ -134,7 +134,7 @@ if __name__ == '__main__': os.symlink(joinpath(jobdir, 'output'), 'status.out') - args = [ joinpath(basedir, 'm5'), '-d', '%s' % jobdir, joinpath(basedir, 'run.mpy') ] + args = [ joinpath(basedir, 'm5'), joinpath(basedir, 'run.mpy') ] if not len(args): sys.exit("no arguments") From a24016c731a69c47e694458f7f564ef1630d34c1 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 17 Feb 2005 02:48:56 -0500 Subject: [PATCH 12/14] Several tweaks to make binning work in any simulation configuration so that we can always have binning on. base/statistics.cc: If we're binning, and there is no bin active at the time we check all stats stuff, create a bin. base/statistics.hh: FS_MEASURE doesn't exist anymore base/stats/text.cc: don't print out bin names if there is only one bin sim/process.cc: don't zero stats. It happens automatically. Don't activate the context at the time it is registered, instead activate the first context in a startup callback. sim/process.hh: Add startup callback to initialize the first exec context --HG-- extra : convert_revision : bcb23cdb184b0abf7cecd79902f8a59b50f71fe4 --- base/statistics.cc | 7 +++++++ base/statistics.hh | 2 +- base/stats/text.cc | 2 +- sim/process.cc | 23 ++++++++++++++--------- sim/process.hh | 2 ++ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/base/statistics.cc b/base/statistics.cc index 6e3dae1efe..6f5caf1fe2 100644 --- a/base/statistics.cc +++ b/base/statistics.cc @@ -286,6 +286,13 @@ check() Database::stats().sort(StatData::less); +#if defined(STATS_BINNING) + if (MainBin::curBin() == NULL) { + static MainBin mainBin("main bin"); + mainBin.activate(); + } +#endif + if (i == end) return; diff --git a/base/statistics.hh b/base/statistics.hh index 9ec26eb4d4..667a0ed486 100644 --- a/base/statistics.hh +++ b/base/statistics.hh @@ -2184,7 +2184,7 @@ class SumNode : public Node * binned. If the typedef is NoBin, nothing is binned. If it is * MainBin, then all stats are binned under that Bin. */ -#if defined(FS_MEASURE) || defined(STATS_BINNING) +#if defined(STATS_BINNING) typedef MainBin DefaultBin; #else typedef NoBin DefaultBin; diff --git a/base/stats/text.cc b/base/stats/text.cc index f7e82a30fb..8cc5ff65e8 100644 --- a/base/stats/text.cc +++ b/base/stats/text.cc @@ -126,7 +126,7 @@ Text::output() using namespace Database; ccprintf(*stream, "\n---------- Begin Simulation Statistics ----------\n"); - if (bins().empty()) { + if (bins().empty() || bins().size() == 1) { stat_list_t::const_iterator i, end = stats().end(); for (i = stats().begin(); i != end; ++i) (*i)->visit(*this); diff --git a/sim/process.cc b/sim/process.cc index c725d3b1c3..4d860c51dd 100644 --- a/sim/process.cc +++ b/sim/process.cc @@ -88,8 +88,6 @@ Process::Process(const string &name, fd_map[i] = -1; } - num_syscalls = 0; - // other parameters will be initialized when the program is loaded } @@ -145,21 +143,28 @@ Process::registerExecContext(ExecContext *xc) execContexts.push_back(xc); if (myIndex == 0) { - // first exec context for this process... initialize & enable - // copy process's initial regs struct xc->regs = *init_regs; - - // mark this context as active. - // activate with zero delay so that we start ticking right - // away on cycle 0 - xc->activate(0); } // return CPU number to caller and increment available CPU count return myIndex; } +void +Process::startup() +{ + if (execContexts.empty()) + return; + + // first exec context for this process... initialize & enable + ExecContext *xc = execContexts[0]; + + // mark this context as active. + // activate with zero delay so that we start ticking right + // away on cycle 0 + xc->activate(0); +} void Process::replaceExecContext(ExecContext *xc, int xcIndex) diff --git a/sim/process.hh b/sim/process.hh index bb48298759..817ab656cd 100644 --- a/sim/process.hh +++ b/sim/process.hh @@ -108,6 +108,8 @@ class Process : public SimObject int stdout_fd, int stderr_fd); + // post initialization startup + virtual void startup(); protected: FunctionalMemory *memory; From 5de3bba7589cc5c084af8e688a46f1b32566522f Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 17 Feb 2005 02:50:34 -0500 Subject: [PATCH 13/14] Make code more portable. sim/main.cc: basename is in libgen --HG-- extra : convert_revision : 1af6ff2f492b4deee9e56edfa5ee6ea235cd4eb0 --- sim/main.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sim/main.cc b/sim/main.cc index 1748294af9..d4c31d5f2a 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -31,6 +31,7 @@ /// #include #include +#include #include #include From cfe6ed7c484b62d07bae23c528f0e2e568cf0d65 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 17 Feb 2005 03:40:17 -0500 Subject: [PATCH 14/14] Fix compile on linux sim/main.cc: For some unknown reason linux's basename doesn't take a const char * --HG-- extra : convert_revision : 30289195881e16a05429f7025abab7914a9e3eb6 --- sim/main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim/main.cc b/sim/main.cc index d4c31d5f2a..891931c2b8 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -108,7 +108,7 @@ abortHandler(int sigtype) } /// Simulator executable name -const char *myProgName = ""; +char *myProgName = ""; /// Show brief help message. void