Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/12249 )
Change subject: systemc: If sc_main returns, don't do any more systemc
stuff.
......................................................................
systemc: If sc_main returns, don't do any more systemc stuff.
When sc_main returns, clear out any pending work in the scheduler and
also block the systemc kernel from doing actions which correspond with
the start of simulation.
It's most likely that work like oustanding timeouts might survive past
the end of sc_main, especially if it never officially called sc_stop.
It's also possible for sc_main to return and never actually call
sc_start. In that case, the kernel should not call callbacks of the
various objects (which may no longer even exist), or go through the
initialization phase.
If sc_main is never called at all, then the kernel's actions aren't
gated.
Change-Id: I49bf094be3283a92d846d2f3da224950bd893a5c
Reviewed-on: https://gem5-review.googlesource.com/12249
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
---
M src/systemc/core/kernel.cc
M src/systemc/core/kernel.hh
M src/systemc/core/sc_main.cc
3 files changed, 20 insertions(+), 0 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc
index 2594bcc..545901a 100644
--- a/src/systemc/core/kernel.cc
+++ b/src/systemc/core/kernel.cc
@@ -40,6 +40,7 @@
namespace
{
+bool scMainDone = false;
bool stopAfterCallbacks = false;
bool startComplete = false;
bool endComplete = false;
@@ -51,6 +52,9 @@
bool Kernel::startOfSimulationComplete() { return startComplete; }
bool Kernel::endOfSimulationComplete() { return endComplete; }
+bool Kernel::scMainFinished() { return scMainDone; }
+void Kernel::scMainFinished(bool finished) { scMainDone = finished; }
+
sc_core::sc_status Kernel::status() { return _status; }
void Kernel::status(sc_core::sc_status s) { _status = s; }
@@ -64,6 +68,9 @@
void
Kernel::init()
{
+ if (scMainDone)
+ return;
+
status(::sc_core::SC_BEFORE_END_OF_ELABORATION);
for (auto m: sc_gem5::allModules) {
callbackModule(m);
@@ -84,6 +91,9 @@
void
Kernel::regStats()
{
+ if (scMainDone)
+ return;
+
for (auto m: sc_gem5::allModules)
for (auto p: m->ports)
p->_gem5Finalize();
@@ -106,6 +116,9 @@
void
Kernel::startup()
{
+ if (scMainDone)
+ return;
+
status(::sc_core::SC_START_OF_SIMULATION);
for (auto m: sc_gem5::allModules) {
m->sc_mod()->start_of_simulation();
diff --git a/src/systemc/core/kernel.hh b/src/systemc/core/kernel.hh
index b9a37d0..e0808fe 100644
--- a/src/systemc/core/kernel.hh
+++ b/src/systemc/core/kernel.hh
@@ -64,6 +64,9 @@
static bool startOfSimulationComplete();
static bool endOfSimulationComplete();
+ static bool scMainFinished();
+ static void scMainFinished(bool);
+
private:
static void stopWork();
diff --git a/src/systemc/core/sc_main.cc b/src/systemc/core/sc_main.cc
index 7e107af..bacde2e 100644
--- a/src/systemc/core/sc_main.cc
+++ b/src/systemc/core/sc_main.cc
@@ -62,6 +62,10 @@
{
if (::sc_main) {
::sc_main(_argc, _argv);
+ // Make sure no systemc events/notifications are scheduled
+ // after sc_main returns.
+ ::sc_gem5::Kernel::scMainFinished(true);
+ ::sc_gem5::scheduler.clear();
} else {
// If python tries to call sc_main but no sc_main was
defined...
fatal("sc_main called but not defined.\n");
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12249
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I49bf094be3283a92d846d2f3da224950bd893a5c
Gerrit-Change-Number: 12249
Gerrit-PatchSet: 9
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Matthias Jung <jun...@eit.uni-kl.de>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev