Implement more m5 pseduo opcodes:

resetstats
dumpstats
dumpresetstats
m5checkpoint

Lots of cleanup of serialization and stats dumping/resetting to
work with these new instructions

arch/alpha/isa_desc:
    Implement more m5 pseduo opcodes:
    resetstats
    dumpstats
    dumpresetstats
    m5checkpoint

    All of these functions take two optional parameters, the first is a delay,
    and the second is a period.  The delay tells the simulator to wait the
    specified number of nanoseconds before triggering the event, the period
    tells the simulator to repeat the event with a specified frequency
base/statistics.cc:
base/statistics.hh:
    regReset RegResetCallback
dev/disk_image.cc:
    serializeFilename -> CheckpointFile()
sim/debug.cc:
    Move this debugging statement to sim_stats.cc
sim/eventq.cc:
    Don't AutoDelete an event if it is scheduled since the process()
    function could potentially schedule the event again.
sim/main.cc:
    DumpStatsEvent is now Statistics::SetupEvent(Dump, curTick)
sim/serialize.cc:
    Change the serialize event so that it's possible to cause the
    event to repeat.  Also make the priority such that the event
    happens just before the simulator would exit if both events
    were scheduled for the same cycle.

    get rid of the serializeFilename variable and provide a CheckpointFile()
    function.  This function takes a basename that is set in the
    configuration, and appends the current cycle to the name so that
    multiple checkpoints can be dumped from the same simulation.

    Also, don't exit the simulation when a checkpoint file is dumped.
sim/serialize.hh:
    serializeFilename -> CheckpointFile()
    SetupCheckpoint function to tell the simulator to prepare
    to checkpoint at a certain time with a certain period
sim/sim_events.cc:
    DumpStatsEvent stuff gets move to sim_stats.(cc|hh)
    The context stuff gets moved into the already existing
    stats context in stat_context.cc
sim/sim_events.hh:
    DumpStatsEvent stuff gets move to sim_stats.(cc|hh)
sim/universe.cc:
    Provide some simple functions for converting times into
    ticks.  These use floating point math to get as close as
    possible to the real values.  Multipliers are set up ahead
    of time

--HG--
extra : convert_revision : d06ef26a9237529a1e5060cb1ac2dcc04d4ec252
This commit is contained in:
Nathan Binkert 2003-11-02 18:02:58 -05:00
parent 3e87070209
commit 667cbb6690
12 changed files with 112 additions and 123 deletions

View file

@ -28,7 +28,9 @@ let {{
#include "cpu/simple_cpu/simple_cpu.hh" #include "cpu/simple_cpu/simple_cpu.hh"
#include "cpu/static_inst.hh" #include "cpu/static_inst.hh"
#include "sim/annotation.hh" #include "sim/annotation.hh"
#include "sim/serialize.hh"
#include "sim/sim_events.hh" #include "sim/sim_events.hh"
#include "sim/sim_stats.hh"
#ifdef FULL_SYSTEM #ifdef FULL_SYSTEM
#include "targetarch/ev5.hh" #include "targetarch/ev5.hh"
@ -2431,20 +2433,58 @@ decode OPCODE default Unknown::unknown() {
}}, No_OpClass); }}, No_OpClass);
0x21: m5exit({{ 0x21: m5exit({{
if (!xc->misspeculating()) { if (!xc->misspeculating()) {
Tick when = curTick;
Tick delay = xc->regs.intRegFile[16]; Tick delay = xc->regs.intRegFile[16];
if (delay != 0) { Tick when = curTick + NS2Ticks(delay);
delay *= ticksPerUS;
delay /= 1000;
when += delay;
}
SimExit(when, "m5_exit instruction encountered"); SimExit(when, "m5_exit instruction encountered");
} }
}}, No_OpClass); }}, No_OpClass);
0x30: initparam({{ Ra = xc->cpu->system->init_param; }}); 0x30: initparam({{ Ra = xc->cpu->system->init_param; }});
0x40: resetstats({{ 0x40: resetstats({{
if (!xc->misspeculating()) if (!xc->misspeculating()) {
Statistics::reset(); using namespace Statistics;
Tick delay = xc->regs.intRegFile[16];
Tick period = xc->regs.intRegFile[17];
Tick when = curTick + NS2Ticks(delay);
Tick repeat = NS2Ticks(period);
SetupEvent(Reset, when, repeat);
}
}});
0x41: dumpstats({{
if (!xc->misspeculating()) {
using namespace Statistics;
Tick delay = xc->regs.intRegFile[16];
Tick period = xc->regs.intRegFile[17];
Tick when = curTick + NS2Ticks(delay);
Tick repeat = NS2Ticks(period);
SetupEvent(Dump, when, repeat);
}
}});
0x42: dumpresetstats({{
if (!xc->misspeculating()) {
using namespace Statistics;
Tick delay = xc->regs.intRegFile[16];
Tick period = xc->regs.intRegFile[17];
Tick when = curTick + NS2Ticks(delay);
Tick repeat = NS2Ticks(period);
SetupEvent(Dump|Reset, when, repeat);
}
}});
0x43: m5checkpoint({{
if (!xc->misspeculating()) {
Tick delay = xc->regs.intRegFile[16];
Tick period = xc->regs.intRegFile[17];
Tick when = curTick + NS2Ticks(delay);
Tick repeat = NS2Ticks(period);
SetupCheckpoint(when, repeat);
}
}}); }});
} }
} }

View file

@ -919,7 +919,7 @@ dump(ostream &stream)
CallbackQueue resetQueue; CallbackQueue resetQueue;
void void
regReset(Callback *cb) RegResetCallback(Callback *cb)
{ {
resetQueue.add(cb); resetQueue.add(cb);
} }

View file

@ -2763,7 +2763,7 @@ class Formula : public Detail::VectorStat
void check(); void check();
void dump(std::ostream &stream); void dump(std::ostream &stream);
void reset(); void reset();
void regReset(Callback *cb); void RegResetCallback(Callback *cb);
inline Detail::Temp inline Detail::Temp
operator+(Detail::Temp l, Detail::Temp r) operator+(Detail::Temp l, Detail::Temp r)

View file

@ -405,7 +405,7 @@ CowDiskImage::write(const uint8_t *data, off_t offset)
void void
CowDiskImage::serialize(ostream &os) CowDiskImage::serialize(ostream &os)
{ {
string cowFilename = serializeFilename + "." + name() + ".cow"; string cowFilename = CheckpointFile() + "." + name() + ".cow";
SERIALIZE_SCALAR(cowFilename); SERIALIZE_SCALAR(cowFilename);
save(cowFilename); save(cowFilename);
} }

View file

@ -125,11 +125,6 @@ extern "C" void sched_break_cycle(Tick when)
new DebugBreakEvent(&mainEventQueue, when); new DebugBreakEvent(&mainEventQueue, when);
} }
extern "C" void dump_stats()
{
new DumpStatsEvent();
}
extern "C" void eventq_dump() extern "C" void eventq_dump()
{ {
mainEventQueue.dump(); mainEventQueue.dump();

View file

@ -112,7 +112,7 @@ EventQueue::serviceOne()
else else
event->clearFlags(Event::Squashed); event->clearFlags(Event::Squashed);
if (event->getFlags(Event::AutoDelete)) if (event->getFlags(Event::AutoDelete) && !event->scheduled())
delete event; delete event;
} }

View file

@ -400,7 +400,9 @@ main(int argc, char **argv)
async_event = false; async_event = false;
if (async_dump) { if (async_dump) {
async_dump = false; async_dump = false;
new DumpStatsEvent();
using namespace Statistics;
SetupEvent(Dump, curTick);
} }
if (async_exit) { if (async_exit) {

View file

@ -245,14 +245,14 @@ Serializer::add_objects()
} }
void void
Serializer::serialize(const string &f) Serializer::serialize()
{ {
if (Serializeable::serializer != NULL) if (Serializeable::serializer != NULL)
panic("in process of serializing!"); panic("in process of serializing!");
Serializeable::serializer = this; Serializeable::serializer = this;
file = f; file = CheckpointFile();
string cpt_file = file + ".cpt"; string cpt_file = file + ".cpt";
output = new ofstream(cpt_file.c_str()); output = new ofstream(cpt_file.c_str());
time_t t = time(NULL); time_t t = time(NULL);
@ -286,38 +286,49 @@ class SerializeEvent : public Event
{ {
protected: protected:
string file; string file;
Tick repeat;
public: public:
SerializeEvent(EventQueue *q, Tick when, const string &file); SerializeEvent(Tick _when, Tick _repeat);
~SerializeEvent();
virtual void process(); 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) SerializeEvent::SerializeEvent(Tick _when, Tick _repeat)
: Event(q), file(f) : Event(&mainEventQueue, 990), repeat(_repeat)
{ {
setFlags(AutoDelete); setFlags(AutoDelete);
schedule(when); schedule(_when);
}
SerializeEvent::~SerializeEvent()
{
} }
void void
SerializeEvent::process() SerializeEvent::process()
{ {
Serializer serial; Serializer serial;
serial.serialize(file); serial.serialize();
new SimExitEvent("Serialization caused exit"); if (repeat)
schedule(curTick + repeat);
}
string __CheckpointFileBase;
string
CheckpointFile()
{
if (__CheckpointFileBase.empty())
return __CheckpointFileBase;
return csprintf("%s.%d", __CheckpointFileBase, curTick);
} }
void void
SerializeEvent::serialize(ostream &os) SetupCheckpoint(Tick when, Tick period)
{ {
panic("Cannot serialize the SerializeEvent"); new SerializeEvent(when, period);
} }
class SerializeParamContext : public ParamContext class SerializeParamContext : public ParamContext
@ -333,18 +344,21 @@ class SerializeParamContext : public ParamContext
SerializeParamContext serialParams("serialize"); SerializeParamContext serialParams("serialize");
Param<string> serialize_file(&serialParams,
"file",
"file to write to", "m5");
Param<Counter> serialize_cycle(&serialParams, Param<Counter> serialize_cycle(&serialParams,
"cycle", "cycle",
"cycle to serialize", "cycle to serialize",
0); 0);
Param<string> serialize_file(&serialParams, Param<Counter> serialize_period(&serialParams,
"file", "period",
"file to write to", ""); "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 &section) SerializeParamContext::SerializeParamContext(const string &section)
: ParamContext(section), event(NULL) : ParamContext(section), event(NULL)
@ -357,22 +371,23 @@ SerializeParamContext::~SerializeParamContext()
void void
SerializeParamContext::checkParams() SerializeParamContext::checkParams()
{ {
serializeFilename = serialize_file; __CheckpointFileBase = serialize_file;
if (!serializeFilename.empty() && serialize_cycle > 0) if (serialize_cycle > 0)
event = new SerializeEvent(&mainEventQueue, serialize_cycle, SetupCheckpoint(serialize_cycle, serialize_period);
serializeFilename);
} }
void void
debug_serialize(const char *file) debug_serialize()
{ {
Serializer serial; Serializer serial;
serial.serialize(file); serial.serialize();
new SimExitEvent("Serialization caused exit");
} }
void
debug_serialize(Tick when)
{
new SerializeEvent(when, 0);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// //

View file

@ -148,7 +148,7 @@ class Serializer
void add_objects(); void add_objects();
public: public:
void serialize(const std::string &file); void serialize();
const std::string &filename() const { return file; } const std::string &filename() const { return file; }
}; };
@ -251,6 +251,7 @@ class Checkpoint
// Export checkpoint filename param so other objects can derive // Export checkpoint filename param so other objects can derive
// filenames from it (e.g., memory). // filenames from it (e.g., memory).
// //
extern std::string serializeFilename; std::string CheckpointFile();
void SetupCheckpoint(Tick when, Tick period = 0);
#endif // __SERIALIZE_HH__ #endif // __SERIALIZE_HH__

View file

@ -103,20 +103,6 @@ CountedExitEvent::description()
return "counted exit"; return "counted exit";
} }
void
DumpStatsEvent::process()
{
dumpStats();
}
const char *
DumpStatsEvent::description()
{
return "stats dump";
}
#ifdef CHECK_SWAP_CYCLES #ifdef CHECK_SWAP_CYCLES
new CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES); new CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES);
#endif #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 // Simulation termination parameters

View file

@ -91,30 +91,6 @@ class CountedExitEvent : public Event
// //
// Event to cause a statistics dump // 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 class CheckSwapEvent : public Event
{ {
private: private:

View file

@ -38,9 +38,9 @@ using namespace std;
Tick curTick = 0; Tick curTick = 0;
Tick ticksPerSecond; Tick ticksPerSecond;
Tick ticksPerMS; double __ticksPerMS;
Tick ticksPerUS; double __ticksPerUS;
Tick ticksPerNS; double __ticksPerNS;
class UniverseParamContext : public ParamContext class UniverseParamContext : public ParamContext
{ {
@ -58,7 +58,8 @@ void
UniverseParamContext::checkParams() UniverseParamContext::checkParams()
{ {
ticksPerSecond = universe_freq; ticksPerSecond = universe_freq;
ticksPerMS = universe_freq / 1000; double freq = double(ticksPerSecond);
ticksPerUS = universe_freq / (1000 * 1000); __ticksPerMS = freq / 1.0e3;
ticksPerNS = universe_freq / (1000 * 1000 * 1000); __ticksPerUS = freq / 1.0e6;
__ticksPerNS = freq / 1.0e9;
} }