summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-02-14 01:46:54 -0800
committerGabe Black <gabeblack@google.com>2019-02-19 23:34:05 +0000
commit598991fda1ee852ef7fa38917e3e2198811fe4f9 (patch)
tree19ed5c54c3d2a0e6e914665043fb5b0823a134b9 /src/sim
parent150104648f713fcf45a1ea423468948d1dc509fc (diff)
downloadgem5-598991fda1ee852ef7fa38917e3e2198811fe4f9.tar.xz
sim: Add a mechanism to exit the simulation loop immediately.
There are some cases, specifically when running systemc, that it's necessary to exit the simulation loop immediately rather than finishing running events scheduled for the current Tick. When running under sc_main, sc_stop and sc_pause return control to sc_main which can happen immediately. When running without sc_main, control needs to return to the python config script which needs to happen through a global exit event. Since sc_pause and sc_stop are supposed to stop simulation without necessarily letting all the events at the current time run, we need a way to schedule an exit event with a very high priority (rather than a very low priority). This change adds a new exitSimLoopNow function which does that, and adds a new constructor to the GlobalSimLoopExitEvent which uses that priority. Also, a couple of cruft functions from the sim events are removed. Change-Id: Icfbec17fb10f98084a75740acd839dbf4096fbb3 Reviewed-on: https://gem5-review.googlesource.com/c/16444 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/sim_events.cc14
-rw-r--r--src/sim/sim_events.hh5
-rw-r--r--src/sim/sim_exit.hh4
3 files changed, 19 insertions, 4 deletions
diff --git a/src/sim/sim_events.cc b/src/sim/sim_events.cc
index 23da8fd8d..f9237e4ba 100644
--- a/src/sim/sim_events.cc
+++ b/src/sim/sim_events.cc
@@ -62,6 +62,13 @@ GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
{
}
+GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(const std::string &_cause,
+ int c, Tick r)
+ : GlobalEvent(curTick(), Minimum_Pri, IsExitEvent),
+ cause(_cause), code(c), repeat(r)
+{
+}
+
const char *
GlobalSimLoopExitEvent::description() const
{
@@ -90,6 +97,13 @@ exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
}
+void
+exitSimLoopNow(const std::string &message, int exit_code, Tick repeat,
+ bool serialize)
+{
+ new GlobalSimLoopExitEvent(message, exit_code, repeat);
+}
+
LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
Tick r)
: Event(Sim_Exit_Pri, IsExitEvent),
diff --git a/src/sim/sim_events.hh b/src/sim/sim_events.hh
index 6343071dc..8a4555212 100644
--- a/src/sim/sim_events.hh
+++ b/src/sim/sim_events.hh
@@ -60,10 +60,9 @@ class GlobalSimLoopExitEvent : public GlobalEvent
Tick repeat;
public:
- // non-scheduling version for createForUnserialize()
- GlobalSimLoopExitEvent();
GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c,
Tick repeat = 0);
+ GlobalSimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0);
const std::string getCause() const { return cause; }
int getCode() const { return code; }
@@ -94,8 +93,6 @@ class LocalSimLoopExitEvent : public Event
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
- static Serializable *createForUnserialize(CheckpointIn &cp,
- const std::string &section);
};
//
diff --git a/src/sim/sim_exit.hh b/src/sim/sim_exit.hh
index 55db55ff2..0a4634679 100644
--- a/src/sim/sim_exit.hh
+++ b/src/sim/sim_exit.hh
@@ -52,5 +52,9 @@ void registerExitCallback(Callback *);
void exitSimLoop(const std::string &message, int exit_code = 0,
Tick when = curTick(), Tick repeat = 0,
bool serialize = false);
+/// Schedule an event as above, but make it high priority so it runs before
+/// any normal events which are schedule at the current time.
+void exitSimLoopNow(const std::string &message, int exit_code = 0,
+ Tick repeat = 0, bool serialize = false);
#endif // __SIM_EXIT_HH__