Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12607

Change subject: systemc: Catch exceptions during updates, notifications, and callbacks.
......................................................................

systemc: Catch exceptions during updates, notifications, and callbacks.

Change-Id: I6005c12ce32d24413618e3955625432985f99f69
---
M src/systemc/core/kernel.cc
M src/systemc/core/scheduler.cc
M src/systemc/core/scheduler.hh
3 files changed, 74 insertions(+), 40 deletions(-)



diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc
index 08ccf07..dc5a861 100644
--- a/src/systemc/core/kernel.cc
+++ b/src/systemc/core/kernel.cc
@@ -94,22 +94,28 @@
     if (scMainDone || stopAfterCallbacks)
         return;

-    for (auto m: sc_gem5::allModules)
-        for (auto p: m->ports)
-            p->_gem5Finalize();
+    try {
+        for (auto m: sc_gem5::allModules)
+            for (auto p: m->ports)
+                p->_gem5Finalize();

-    status(::sc_core::SC_END_OF_ELABORATION);
-    for (auto m: sc_gem5::allModules) {
-        callbackModule(m);
-        m->sc_mod()->end_of_elaboration();
-        for (auto p: m->ports)
-            p->end_of_elaboration();
-        for (auto e: m->exports)
-            e->end_of_elaboration();
+        status(::sc_core::SC_END_OF_ELABORATION);
+        for (auto m: sc_gem5::allModules) {
+            callbackModule(m);
+            m->sc_mod()->end_of_elaboration();
+            for (auto p: m->ports)
+                p->end_of_elaboration();
+            for (auto e: m->exports)
+                e->end_of_elaboration();
+        }
+        callbackModule(nullptr);
+        for (auto c: sc_gem5::allChannels)
+            c->sc_chan()->end_of_elaboration();
+    } catch (...) {
+        ::sc_gem5::scheduler.throwToScMain();
     }
-    callbackModule(nullptr);
-    for (auto c: sc_gem5::allChannels)
-        c->sc_chan()->end_of_elaboration();
+
+    ::sc_gem5::scheduler.elaborationDone(true);
 }

 void
@@ -123,16 +129,21 @@
     if (stopAfterCallbacks)
         return;

-    status(::sc_core::SC_START_OF_SIMULATION);
-    for (auto m: sc_gem5::allModules) {
-        m->sc_mod()->start_of_simulation();
-        for (auto p: m->ports)
-            p->start_of_simulation();
-        for (auto e: m->exports)
-            e->start_of_simulation();
+    try {
+        status(::sc_core::SC_START_OF_SIMULATION);
+        for (auto m: sc_gem5::allModules) {
+            m->sc_mod()->start_of_simulation();
+            for (auto p: m->ports)
+                p->start_of_simulation();
+            for (auto e: m->exports)
+                e->start_of_simulation();
+        }
+        callbackModule(nullptr);
+        for (auto c: sc_gem5::allChannels)
+            c->sc_chan()->start_of_simulation();
+    } catch (...) {
+        ::sc_gem5::scheduler.throwToScMain();
     }
-    for (auto c: sc_gem5::allChannels)
-        c->sc_chan()->start_of_simulation();

     startComplete = true;

@@ -155,15 +166,20 @@
 Kernel::stopWork()
 {
     status(::sc_core::SC_END_OF_SIMULATION);
-    for (auto m: sc_gem5::allModules) {
-        m->sc_mod()->end_of_simulation();
-        for (auto p: m->ports)
-            p->end_of_simulation();
-        for (auto e: m->exports)
-            e->end_of_simulation();
+    try {
+        for (auto m: sc_gem5::allModules) {
+            m->sc_mod()->end_of_simulation();
+            for (auto p: m->ports)
+                p->end_of_simulation();
+            for (auto e: m->exports)
+                e->end_of_simulation();
+        }
+        callbackModule(nullptr);
+        for (auto c: sc_gem5::allChannels)
+            c->sc_chan()->end_of_simulation();
+    } catch (...) {
+        ::sc_gem5::scheduler.throwToScMain();
     }
-    for (auto c: sc_gem5::allChannels)
-        c->sc_chan()->end_of_simulation();

     endComplete = true;

diff --git a/src/systemc/core/scheduler.cc b/src/systemc/core/scheduler.cc
index beec87d..8015809 100644
--- a/src/systemc/core/scheduler.cc
+++ b/src/systemc/core/scheduler.cc
@@ -328,11 +328,15 @@
 {
     status(StatusUpdate);

-    Channel *channel = updateList.getNext();
-    while (channel) {
-        channel->popListNode();
-        channel->update();
-        channel = updateList.getNext();
+    try {
+        Channel *channel = updateList.getNext();
+        while (channel) {
+            channel->popListNode();
+            channel->update();
+            channel = updateList.getNext();
+        }
+    } catch (...) {
+        throwToScMain();
     }
 }

@@ -340,8 +344,13 @@
 Scheduler::runDelta()
 {
     status(StatusDelta);
-    while (!deltas.empty())
-        deltas.front()->run();
+
+    try {
+        while (!deltas.empty())
+            deltas.front()->run();
+    } catch (...) {
+        throwToScMain();
+    }
 }

 void
@@ -431,6 +440,7 @@
     if (!r)
         r = reportifyException();
     _throwToScMain = r;
+    status(StatusOther);
     scMain->run();
 }

diff --git a/src/systemc/core/scheduler.hh b/src/systemc/core/scheduler.hh
index 7b62388..052be08 100644
--- a/src/systemc/core/scheduler.hh
+++ b/src/systemc/core/scheduler.hh
@@ -457,8 +457,16 @@
 {
     scheduler.status(StatusTiming);

-    while (!events.empty())
-        events.front()->run();
+    try {
+        while (!events.empty())
+            events.front()->run();
+    } catch (...) {
+        if (events.empty())
+            scheduler.completeTimeSlot(this);
+        else
+            scheduler.schedule(this);
+        scheduler.throwToScMain();
+    }

     scheduler.status(StatusOther);
     scheduler.completeTimeSlot(this);

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12607
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: I6005c12ce32d24413618e3955625432985f99f69
Gerrit-Change-Number: 12607
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to