diff options
Diffstat (limited to 'sim')
-rw-r--r-- | sim/debug.cc | 5 | ||||
-rw-r--r-- | sim/eventq.cc | 2 | ||||
-rw-r--r-- | sim/main.cc | 4 | ||||
-rw-r--r-- | sim/serialize.cc | 79 | ||||
-rw-r--r-- | sim/serialize.hh | 5 | ||||
-rw-r--r-- | sim/sim_events.cc | 41 | ||||
-rw-r--r-- | sim/sim_events.hh | 24 | ||||
-rw-r--r-- | sim/universe.cc | 13 |
8 files changed, 61 insertions, 112 deletions
diff --git a/sim/debug.cc b/sim/debug.cc index b18642942..95187baff 100644 --- a/sim/debug.cc +++ b/sim/debug.cc @@ -125,11 +125,6 @@ extern "C" void sched_break_cycle(Tick when) new DebugBreakEvent(&mainEventQueue, when); } -extern "C" void dump_stats() -{ - new DumpStatsEvent(); -} - extern "C" void eventq_dump() { mainEventQueue.dump(); diff --git a/sim/eventq.cc b/sim/eventq.cc index fda587dcb..52f7dfaff 100644 --- a/sim/eventq.cc +++ b/sim/eventq.cc @@ -112,7 +112,7 @@ EventQueue::serviceOne() else event->clearFlags(Event::Squashed); - if (event->getFlags(Event::AutoDelete)) + if (event->getFlags(Event::AutoDelete) && !event->scheduled()) delete event; } diff --git a/sim/main.cc b/sim/main.cc index ce9ef5819..addedbc85 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -400,7 +400,9 @@ main(int argc, char **argv) async_event = false; if (async_dump) { async_dump = false; - new DumpStatsEvent(); + + using namespace Statistics; + SetupEvent(Dump, curTick); } if (async_exit) { diff --git a/sim/serialize.cc b/sim/serialize.cc index 84d400e16..bd528c678 100644 --- a/sim/serialize.cc +++ b/sim/serialize.cc @@ -245,14 +245,14 @@ Serializer::add_objects() } void -Serializer::serialize(const string &f) +Serializer::serialize() { if (Serializeable::serializer != NULL) panic("in process of serializing!"); Serializeable::serializer = this; - file = f; + file = CheckpointFile(); string cpt_file = file + ".cpt"; output = new ofstream(cpt_file.c_str()); time_t t = time(NULL); @@ -286,38 +286,49 @@ class SerializeEvent : public Event { protected: string file; + Tick repeat; public: - SerializeEvent(EventQueue *q, Tick when, const string &file); - ~SerializeEvent(); - + SerializeEvent(Tick _when, Tick _repeat); virtual void process(); - virtual void serialize(std::ostream &os); + virtual void serialize(std::ostream &os) + { + panic("Cannot serialize the SerializeEvent"); + } + }; -SerializeEvent::SerializeEvent(EventQueue *q, Tick when, const string &f) - : Event(q), file(f) +SerializeEvent::SerializeEvent(Tick _when, Tick _repeat) + : Event(&mainEventQueue, 990), repeat(_repeat) { setFlags(AutoDelete); - schedule(when); -} - -SerializeEvent::~SerializeEvent() -{ + schedule(_when); } void SerializeEvent::process() { Serializer serial; - serial.serialize(file); - new SimExitEvent("Serialization caused exit"); + serial.serialize(); + if (repeat) + schedule(curTick + repeat); +} + +string __CheckpointFileBase; + +string +CheckpointFile() +{ + if (__CheckpointFileBase.empty()) + return __CheckpointFileBase; + + return csprintf("%s.%d", __CheckpointFileBase, curTick); } void -SerializeEvent::serialize(ostream &os) +SetupCheckpoint(Tick when, Tick period) { - panic("Cannot serialize the SerializeEvent"); + new SerializeEvent(when, period); } class SerializeParamContext : public ParamContext @@ -333,18 +344,21 @@ class SerializeParamContext : public ParamContext SerializeParamContext serialParams("serialize"); +Param<string> serialize_file(&serialParams, + "file", + "file to write to", "m5"); + Param<Counter> serialize_cycle(&serialParams, "cycle", "cycle to serialize", 0); -Param<string> serialize_file(&serialParams, - "file", - "file to write to", ""); +Param<Counter> serialize_period(&serialParams, + "period", + "period to repeat serializations", + 0); + -// Copy filename into regular string so we can export it without -// having to include param.hh all over the place. -string serializeFilename; SerializeParamContext::SerializeParamContext(const string §ion) : ParamContext(section), event(NULL) @@ -357,22 +371,23 @@ SerializeParamContext::~SerializeParamContext() void SerializeParamContext::checkParams() { - serializeFilename = serialize_file; - if (!serializeFilename.empty() && serialize_cycle > 0) - event = new SerializeEvent(&mainEventQueue, serialize_cycle, - serializeFilename); + __CheckpointFileBase = serialize_file; + if (serialize_cycle > 0) + SetupCheckpoint(serialize_cycle, serialize_period); } void -debug_serialize(const char *file) +debug_serialize() { Serializer serial; - serial.serialize(file); - new SimExitEvent("Serialization caused exit"); + serial.serialize(); } - - +void +debug_serialize(Tick when) +{ + new SerializeEvent(when, 0); +} //////////////////////////////////////////////////////////////////////// // diff --git a/sim/serialize.hh b/sim/serialize.hh index a8fff7b6f..78cbb702a 100644 --- a/sim/serialize.hh +++ b/sim/serialize.hh @@ -148,7 +148,7 @@ class Serializer void add_objects(); public: - void serialize(const std::string &file); + void serialize(); const std::string &filename() const { return file; } }; @@ -251,6 +251,7 @@ class Checkpoint // Export checkpoint filename param so other objects can derive // filenames from it (e.g., memory). // -extern std::string serializeFilename; +std::string CheckpointFile(); +void SetupCheckpoint(Tick when, Tick period = 0); #endif // __SERIALIZE_HH__ diff --git a/sim/sim_events.cc b/sim/sim_events.cc index 165bab2bf..265bf63dc 100644 --- a/sim/sim_events.cc +++ b/sim/sim_events.cc @@ -103,20 +103,6 @@ CountedExitEvent::description() return "counted exit"; } - -void -DumpStatsEvent::process() -{ - dumpStats(); -} - -const char * -DumpStatsEvent::description() -{ - return "stats dump"; -} - - #ifdef CHECK_SWAP_CYCLES new CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES); #endif @@ -148,33 +134,6 @@ CheckSwapEvent::description() } -class DumpStatsContext : public ParamContext -{ - public: - DumpStatsContext(const string &_iniSection) - : ParamContext(_iniSection) {} - void checkParams(); -}; - -DumpStatsContext dumpStatsParams("stats"); - -VectorParam<Tick> dump_cycle(&dumpStatsParams, "dump_cycles", - "cycles on which to dump stats"); - -void -DumpStatsContext::checkParams() -{ - if (dump_cycle.isValid()) { - vector<Tick> &cycles = dump_cycle; - - vector<Tick>::iterator i = cycles.begin(); - vector<Tick>::iterator end = cycles.end(); - - for (; i < end; ++i) - new DumpStatsEvent(*i); - } -} - /////////////////////////////////////////////////// // // Simulation termination parameters diff --git a/sim/sim_events.hh b/sim/sim_events.hh index bca978ce1..8a420e419 100644 --- a/sim/sim_events.hh +++ b/sim/sim_events.hh @@ -91,30 +91,6 @@ class CountedExitEvent : public Event // // Event to cause a statistics dump // -class DumpStatsEvent : public Event -{ - public: - DumpStatsEvent() - : Event(&mainEventQueue) - { setFlags(AutoDelete); schedule(curTick, 999); } - - DumpStatsEvent(EventQueue *q) - : Event(q) - { setFlags(AutoDelete); schedule(curTick, 999); } - - DumpStatsEvent(Tick when) - : Event(&mainEventQueue) - { setFlags(AutoDelete); schedule(when, 999); } - - DumpStatsEvent(EventQueue *q, Tick when) - : Event(q) - { setFlags(AutoDelete); schedule(when, 999); } - - void process(); - - virtual const char *description(); -}; - class CheckSwapEvent : public Event { private: diff --git a/sim/universe.cc b/sim/universe.cc index 4cfcdc563..b75b1f78a 100644 --- a/sim/universe.cc +++ b/sim/universe.cc @@ -38,9 +38,9 @@ using namespace std; Tick curTick = 0; Tick ticksPerSecond; -Tick ticksPerMS; -Tick ticksPerUS; -Tick ticksPerNS; +double __ticksPerMS; +double __ticksPerUS; +double __ticksPerNS; class UniverseParamContext : public ParamContext { @@ -58,7 +58,8 @@ void UniverseParamContext::checkParams() { ticksPerSecond = universe_freq; - ticksPerMS = universe_freq / 1000; - ticksPerUS = universe_freq / (1000 * 1000); - ticksPerNS = universe_freq / (1000 * 1000 * 1000); + double freq = double(ticksPerSecond); + __ticksPerMS = freq / 1.0e3; + __ticksPerUS = freq / 1.0e6; + __ticksPerNS = freq / 1.0e9; } |