changeset f9c0692f73ec in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=f9c0692f73ec
description:
sim: Reuse the same limit_event in simulate()
This patch accomplishes two things:
1. Makes simulate()'s GlobalSimLoopExitEvent a singleton reused
across calls. This is slightly more efficient than recreating
it every time.
2. Gives callers to simulate() (especially other simulators) a
foolproof way of knowing that the simulation period ended
successfully by hitting the limit event. They can call
getLimitEvent() and compare it to the return
value of simulate().
This change was motivated by an ongoing effort to integrate gem5
and SST, with SST as the master sim and gem5 as the slave sim.
diffstat:
src/sim/sim_events.hh | 5 +++++
src/sim/simulate.cc | 18 +++++++++---------
src/sim/simulate.hh | 1 +
3 files changed, 15 insertions(+), 9 deletions(-)
diffs (65 lines):
diff -r dcd7cf19f7c5 -r f9c0692f73ec src/sim/sim_events.hh
--- a/src/sim/sim_events.hh Mon Mar 23 06:57:34 2015 -0400
+++ b/src/sim/sim_events.hh Mon Mar 23 06:57:36 2015 -0400
@@ -71,6 +71,11 @@
void process(); // process event
virtual const char *description() const;
+
+ virtual ~GlobalSimLoopExitEvent() {
+ // simulate()'s singleton GlobalSimLoopExitEvent is always scheduled
+ deschedule();
+ }
};
class LocalSimLoopExitEvent : public Event
diff -r dcd7cf19f7c5 -r f9c0692f73ec src/sim/simulate.cc
--- a/src/sim/simulate.cc Mon Mar 23 06:57:34 2015 -0400
+++ b/src/sim/simulate.cc Mon Mar 23 06:57:36 2015 -0400
@@ -71,6 +71,14 @@
}
}
+GlobalEvent*
+getLimitEvent(void) {
+ static GlobalSimLoopExitEvent
+ simulate_limit_event(mainEventQueue[0]->getCurTick(),
+ "simulate() limit reached", 0);
+ return &simulate_limit_event;
+}
+
/** Simulate for num_cycles additional cycles. If num_cycles is -1
* (the default), do not limit simulation; some other event must
* terminate the loop. Exported to Python via SWIG.
@@ -105,8 +113,7 @@
else // counter would roll over or be set to MaxTick anyhow
num_cycles = MaxTick;
- GlobalEvent *limit_event = new GlobalSimLoopExitEvent(num_cycles,
- "simulate() limit reached", 0, 0);
+ getLimitEvent()->reschedule(num_cycles);
GlobalSyncEvent *quantum_event = NULL;
if (numMainEventQueues > 1) {
@@ -137,13 +144,6 @@
dynamic_cast<GlobalSimLoopExitEvent *>(global_event);
assert(global_exit_event != NULL);
- // if we didn't hit limit_event, delete it.
- if (global_exit_event != limit_event) {
- assert(limit_event->scheduled());
- limit_event->deschedule();
- delete limit_event;
- }
-
//! Delete the simulation quantum event.
if (quantum_event != NULL) {
quantum_event->deschedule();
diff -r dcd7cf19f7c5 -r f9c0692f73ec src/sim/simulate.hh
--- a/src/sim/simulate.hh Mon Mar 23 06:57:34 2015 -0400
+++ b/src/sim/simulate.hh Mon Mar 23 06:57:36 2015 -0400
@@ -33,3 +33,4 @@
#include "sim/sim_events.hh"
GlobalSimLoopExitEvent *simulate(Tick num_cycles = MaxTick);
+GlobalEvent* getLimitEvent();
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev