summaryrefslogtreecommitdiff
path: root/src/sim/simulate.cc
diff options
context:
space:
mode:
authorCurtis Dunham <Curtis.Dunham@arm.com>2015-03-23 06:57:36 -0400
committerCurtis Dunham <Curtis.Dunham@arm.com>2015-03-23 06:57:36 -0400
commit564482c78283c749dc537cb9c1b2d788bf306a82 (patch)
treed9fa838e9313aa7938cb478612bef8a22e5a080e /src/sim/simulate.cc
parent45286d9b64646bb4fe47f3ebf1815324dd6cb62b (diff)
downloadgem5-564482c78283c749dc537cb9c1b2d788bf306a82.tar.xz
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 (limited to 'src/sim/simulate.cc')
-rw-r--r--src/sim/simulate.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc
index 7d88dc11d..14dd00fc1 100644
--- a/src/sim/simulate.cc
+++ b/src/sim/simulate.cc
@@ -71,6 +71,14 @@ thread_loop(EventQueue *queue)
}
}
+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 @@ simulate(Tick num_cycles)
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 @@ simulate(Tick num_cycles)
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();