From e7033f718f3e7913d2b38562b83e6d68e47eafbc Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Thu, 8 Jan 2004 14:13:31 -0500 Subject: [PATCH 1/6] should now build... fixed relative path problem --HG-- extra : convert_revision : 78c9445993a84b68be1b0a477555246f1ea6ce0c From 98613950a36463ca194ac4878809308e3b2daac7 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Thu, 8 Jan 2004 16:35:47 -0500 Subject: [PATCH 2/6] Fixed another small libelf problem, everything should work now, on any machine. base/loader/elf_object.hh: put #defines for libelf that normally arn't defined so that -Wundef doesn't cause problems. --HG-- extra : convert_revision : fa2de6aa94c7ddbaa59990db4473402b0df7d93a --- base/loader/elf_object.hh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/base/loader/elf_object.hh b/base/loader/elf_object.hh index afd4cd62b5..9f0385d86a 100644 --- a/base/loader/elf_object.hh +++ b/base/loader/elf_object.hh @@ -29,8 +29,13 @@ #ifndef __ELF_OBJECT_HH__ #define __ELF_OBJECT_HH__ -#include +/* Because of the -Wundef flag we have to do this */ +#define __LIBELF_INTERNAL__ 0 +#define __LIBELF64_LINUX 1 +#define __LIBELF_NEED_LINK_H 0 + #include +#include #include "base/loader/object_file.hh" class ElfObject : public ObjectFile From 54b6d8c5a8a4abd47536bf50c6f04c5535036752 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Thu, 8 Jan 2004 22:42:21 -0500 Subject: [PATCH 3/6] the build directory is now correctly created --HG-- extra : convert_revision : 4a7b91821e2de64e400417f8ac503af7e596571d From 7e07aa9300f75bb4bbdacf97dce45213e7fa69c0 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sun, 11 Jan 2004 15:09:27 -0800 Subject: [PATCH 4/6] Fix cprintf bug, plus minor cleanup & better error messages. base/cprintf.cc: Fix bug where a call with a format string with no specifiers but one or more arguments would crash. Old code tried to print extra args using last available format, but in this case there was no format, hence the problem. Now we just print "" for each extra arg. Also reorganized code a bit to make scope of fmt variable match the scope in which you can be confident it's meaningful. base/cprintf.hh: Print specific error message instead of calling format_invalid(). base/cprintf_formats.hh: Clear Format object in constructor. Use specific error messages instead of format_invalid() function. --HG-- extra : convert_revision : 87d5e902174e3eb2583131d056742af166540db0 --- base/cprintf.cc | 39 ++++++++++++++++++++------------------- base/cprintf.hh | 2 +- base/cprintf_formats.hh | 19 ++++++------------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/base/cprintf.cc b/base/cprintf.cc index af3b26a577..5796a712bb 100644 --- a/base/cprintf.cc +++ b/base/cprintf.cc @@ -45,8 +45,6 @@ ArgList::dump(const string &format) stream->fill(' '); stream->flags((ios::fmtflags)0); - Format fmt; - while (*p) { switch (*p) { case '%': { @@ -56,12 +54,7 @@ ArgList::dump(const string &format) continue; } - if (objects.empty()) - format_invalid(*stream); - - Base *data = objects.front(); - - fmt.clear(); + Format fmt; bool done = false; bool end_number = false; bool have_precision = false; @@ -205,18 +198,26 @@ ArgList::dump(const string &format) } } - ios::fmtflags saved_flags = stream->flags(); - char old_fill = stream->fill(); - int old_precision = stream->precision(); + if (!objects.empty()) + { + Base *data = objects.front(); + objects.pop_front(); - data->process(*stream, fmt); + ios::fmtflags saved_flags = stream->flags(); + char old_fill = stream->fill(); + int old_precision = stream->precision(); - stream->flags(saved_flags); - stream->fill(old_fill); - stream->precision(old_precision); + data->process(*stream, fmt); + + stream->flags(saved_flags); + stream->fill(old_fill); + stream->precision(old_precision); + + delete data; + } else { + *stream << ""; + } - delete data; - objects.pop_front(); ++p; } break; @@ -241,10 +242,10 @@ ArgList::dump(const string &format) } while (!objects.empty()) { + *stream << ""; Base *data = objects.front(); - data->process(*stream, fmt); - delete data; objects.pop_front(); + delete data; } } diff --git a/base/cprintf.hh b/base/cprintf.hh index 8360d227c5..ac34cd2521 100644 --- a/base/cprintf.hh +++ b/base/cprintf.hh @@ -75,7 +75,7 @@ class ArgList break; default: - format_invalid(out); + out << ""; break; } } diff --git a/base/cprintf_formats.hh b/base/cprintf_formats.hh index 1e5de4fdf8..b921c05062 100644 --- a/base/cprintf_formats.hh +++ b/base/cprintf_formats.hh @@ -43,8 +43,10 @@ struct Format int precision; int width; - Format() { } - void clear() { + Format() { clear(); } + + void clear() + { alternate_form = false; flush_left = false; print_sign = false; @@ -58,15 +60,6 @@ struct Format } }; -inline void -format_invalid(std::ostream &out) -{ - using namespace std; - - out << "format invalid!!!" << endl; -} - - template inline void _format_char(std::ostream &out, const T& data, Format &fmt) @@ -233,7 +226,7 @@ _format_string(std::ostream &out, const T& data, Format &fmt) template inline void format_char(std::ostream &out, const T& data, Format &fmt) -{ format_invalid(out); } +{ out << ""; } inline void format_char(std::ostream &out, char data, Format &fmt) @@ -329,7 +322,7 @@ format_integer(std::ostream &out, unsigned long long data, Format &fmt) template inline void format_float(std::ostream &out, const T& data, Format &fmt) -{ format_invalid(out); } +{ out << ""; } inline void format_float(std::ostream &out, float data, Format &fmt) From 510eef0fa02ffcb123aa450943ce7e08a57d5b06 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sun, 11 Jan 2004 15:24:18 -0800 Subject: [PATCH 5/6] Modify handling of serialize:dir parameter to make it more useful. Move global checkpoint-related functions and vars into Checkpoint class (as statics). arch/alpha/pseudo_inst.cc: dev/disk_image.cc: Move global checkpoint-related functions and vars into Checkpoint class (as statics). sim/serialize.cc: Move global checkpoint-related functions and vars into Checkpoint class (as statics). Checkpoint constructor now takes checkpoint directory name instead of file name. Make serialize:dir parameter actually set checkpoint directory name instead of directory in which checkpoint directory is created. If the value contains a '%', the curTick value is sprintf'd into the format to create the directory name. The default is backwards compatible with the old fixed name ("m5.%012d"). sim/serialize.hh: Move global checkpoint-related functions and vars into Checkpoint class (as statics). Checkpoint constructor now takes checkpoint directory name instead of file name. --HG-- extra : convert_revision : d0aa87b62911f405a4f5811271b9e6351fdd9fe4 --- arch/alpha/pseudo_inst.cc | 2 +- dev/disk_image.cc | 2 +- sim/serialize.cc | 39 ++++++++++++++++++++++++--------------- sim/serialize.hh | 26 +++++++++++++++++--------- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/arch/alpha/pseudo_inst.cc b/arch/alpha/pseudo_inst.cc index c5d82bd215..7f8c6b17cc 100644 --- a/arch/alpha/pseudo_inst.cc +++ b/arch/alpha/pseudo_inst.cc @@ -127,7 +127,7 @@ namespace AlphaPseudo Tick when = curTick + NS2Ticks(delay); Tick repeat = NS2Ticks(period); - SetupCheckpoint(when, repeat); + Checkpoint::setup(when, repeat); } class Context : public ParamContext diff --git a/dev/disk_image.cc b/dev/disk_image.cc index 02c8b50b64..142fb60a5c 100644 --- a/dev/disk_image.cc +++ b/dev/disk_image.cc @@ -405,7 +405,7 @@ CowDiskImage::write(const uint8_t *data, off_t offset) void CowDiskImage::serialize(ostream &os) { - string cowFilename = CheckpointDir() + name() + ".cow"; + string cowFilename = Checkpoint::dir() + name() + ".cow"; SERIALIZE_SCALAR(cowFilename); save(cowFilename); } diff --git a/sim/serialize.cc b/sim/serialize.cc index 95aacc361c..33956c6e7e 100644 --- a/sim/serialize.cc +++ b/sim/serialize.cc @@ -222,11 +222,11 @@ Globals::unserialize(Checkpoint *cp) void Serializable::serializeAll() { - string dir = CheckpointDir(); + string dir = Checkpoint::dir(); if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST) - warn("could mkdir %s\n", dir); + fatal("couldn't mkdir %s\n", dir); - string cpt_file = dir + "m5.cpt"; + string cpt_file = dir + Checkpoint::baseFilename; ofstream outstream(cpt_file.c_str()); time_t t = time(NULL); outstream << "// checkpoint generated: " << ctime(&t); @@ -273,19 +273,21 @@ SerializeEvent::process() schedule(curTick + repeat); } -string __CheckpointDirBase; +const char *Checkpoint::baseFilename = "m5.cpt"; + +static string checkpointDirBase; string -CheckpointDir() +Checkpoint::dir() { - if (__CheckpointDirBase.empty()) - return __CheckpointDirBase; - - return csprintf("%s/m5.%012d/", __CheckpointDirBase, curTick); + // use csprintf to insert curTick into directory name if it + // appears to have a format placeholder in it. + return (checkpointDirBase.find("%") != string::npos) ? + csprintf(checkpointDirBase, curTick) : checkpointDirBase; } void -SetupCheckpoint(Tick when, Tick period) +Checkpoint::setup(Tick when, Tick period) { new SerializeEvent(when, period); } @@ -304,8 +306,9 @@ class SerializeParamContext : public ParamContext SerializeParamContext serialParams("serialize"); Param serialize_dir(&serialParams, - "dir", - "dir to stick checkpoint in", "."); + "dir", + "dir to stick checkpoint in " + "(sprintf format with cycle #)", "m5.%012d"); Param serialize_cycle(&serialParams, "cycle", @@ -330,9 +333,14 @@ SerializeParamContext::~SerializeParamContext() void SerializeParamContext::checkParams() { - __CheckpointDirBase = serialize_dir; + checkpointDirBase = serialize_dir; + // guarantee that directory ends with a '/' + if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') { + checkpointDirBase += "/"; + } + if (serialize_cycle > 0) - SetupCheckpoint(serialize_cycle, serialize_period); + Checkpoint::setup(serialize_cycle, serialize_period); } void @@ -415,10 +423,11 @@ Serializable::create(Checkpoint *cp, const std::string §ion) } -Checkpoint::Checkpoint(const std::string &filename, const std::string &path, +Checkpoint::Checkpoint(const std::string &cpt_dir, const std::string &path, const ConfigNode *_configNode) : db(new IniFile), basePath(path), configNode(_configNode) { + string filename = cpt_dir + "/" + Checkpoint::baseFilename; if (!db->load(filename)) { fatal("Can't load checkpoint file '%s'\n", filename); } diff --git a/sim/serialize.hh b/sim/serialize.hh index 60e06f94be..32802409d5 100644 --- a/sim/serialize.hh +++ b/sim/serialize.hh @@ -207,7 +207,7 @@ class Checkpoint std::map objMap; public: - Checkpoint(const std::string &filename, const std::string &path, + Checkpoint(const std::string &cpt_dir, const std::string &path, const ConfigNode *_configNode); bool find(const std::string §ion, const std::string &entry, @@ -217,14 +217,22 @@ class Checkpoint Serializable *&value); bool sectionExists(const std::string §ion); + + // The following static functions have to do with checkpoint + // creation rather than restoration. This class makes a handy + // namespace for them though. + + // Export current checkpoint directory name so other objects can + // derive filenames from it (e.g., memory). The return value is + // guaranteed to end in '/' so filenames can be directly appended. + // This function is only valid while a checkpoint is being created. + static std::string dir(); + + // Filename for base checkpoint file within directory. + static const char *baseFilename; + + // Set up a checkpoint creation event or series of events. + static void setup(Tick when, Tick period = 0); }; - -// -// Export checkpoint filename param so other objects can derive -// filenames from it (e.g., memory). -// -std::string CheckpointDir(); -void SetupCheckpoint(Tick when, Tick period = 0); - #endif // __SERIALIZE_HH__ From f8ed615bc65139076289e8af4bc6c7908aae4aa8 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Sun, 11 Jan 2004 15:26:48 -0800 Subject: [PATCH 6/6] Minor cleanup to bk ignore and makefile libelf rule. --HG-- extra : convert_revision : 77dd858344a74dea15bb36bcb0de04f3af9260f3