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

Change subject: systemc: Implement the SC_EXIT_ON_STARVATION exit mode.
......................................................................

systemc: Implement the SC_EXIT_ON_STARVATION exit mode.

This mode implies checking whether there's any activity left either
before starting a delta cycle, or processing delta or timed
notification or timeout.

Change-Id: I0780a1f720cf63f3d2907b8dd28685266b52d6b4
---
M src/systemc/core/scheduler.cc
M src/systemc/core/scheduler.hh
2 files changed, 42 insertions(+), 1 deletion(-)



diff --git a/src/systemc/core/scheduler.cc b/src/systemc/core/scheduler.cc
index 5174627..c2b5ec3 100644
--- a/src/systemc/core/scheduler.cc
+++ b/src/systemc/core/scheduler.cc
@@ -42,7 +42,9 @@
     eq(nullptr), readyEvent(this, false, ReadyPriority),
     pauseEvent(this, false, PausePriority),
     stopEvent(this, false, StopPriority),
-    scMain(nullptr), _started(false), _paused(false), _stopped(false),
+    scMain(nullptr),
+    starvationEvent(this, false, StarvationPriority),
+    _started(false), _paused(false), _stopped(false),
     maxTickEvent(this, false, MaxTickPriority),
     _numCycles(0), _current(nullptr), initReady(false)
 {}
@@ -143,6 +145,20 @@
     if (!readyEvent.scheduled()) {
         panic_if(!eq, "Need to schedule ready, but no event manager.\n");
         eq->schedule(&readyEvent, eq->getCurTick());
+        if (starvationEvent.scheduled())
+            eq->deschedule(&starvationEvent);
+    }
+}
+
+void
+Scheduler::scheduleStarvationEvent()
+{
+    if (!starvationEvent.scheduled()) {
+        panic_if(!eq, "Need to schedule starvation event, "
+                "but no event manager.\n");
+        eq->schedule(&starvationEvent, eq->getCurTick());
+        if (readyEvent.scheduled())
+            eq->deschedule(&readyEvent);
     }
 }

@@ -162,6 +178,9 @@
     // The update phase.
     update();

+    if (starved() && !runToTime)
+        scheduleStarvationEvent();
+
     // The delta phase will happen naturally through the event queue.
 }

@@ -202,9 +221,13 @@
     _started = true;
     _paused = false;
     _stopped = false;
+    runToTime = run_to_time;

     maxTick = max_tick;

+    if (starved() && !runToTime)
+        return;
+
     if (initReady) {
         kernel->status(::sc_core::SC_RUNNING);
         eq->schedule(&maxTickEvent, maxTick);
@@ -219,6 +242,8 @@
         eq->deschedule(&stopEvent);
     if (maxTickEvent.scheduled())
         eq->deschedule(&maxTickEvent);
+    if (starvationEvent.scheduled())
+        eq->deschedule(&starvationEvent);
 }

 void
diff --git a/src/systemc/core/scheduler.hh b/src/systemc/core/scheduler.hh
index 73d660e..0c755ed 100644
--- a/src/systemc/core/scheduler.hh
+++ b/src/systemc/core/scheduler.hh
@@ -215,6 +215,9 @@
         auto it = pendingTicks.begin();
         if (--it->second == 0)
             pendingTicks.erase(it);
+
+        if (starved() && !runToTime)
+            scheduleStarvationEvent();
     }

     // Pending activity ignores gem5 activity, much like how a systemc
@@ -277,6 +280,7 @@
     static Priority StopPriority = DefaultPriority - 1;
     static Priority PausePriority = DefaultPriority + 1;
     static Priority ReadyPriority = DefaultPriority + 2;
+    static Priority StarvationPriority = ReadyPriority;
     static Priority MaxTickPriority = DefaultPriority + 3;

     EventQueue *eq;
@@ -292,6 +296,17 @@
     EventWrapper<Scheduler, &Scheduler::stop> stopEvent;
     Fiber *scMain;

+    bool
+    starved()
+    {
+        return (readyList.empty() && updateList.empty() &&
+                (pendingTicks.empty() ||
+                 pendingTicks.begin()->first > maxTick) &&
+                initList.empty());
+    }
+    EventWrapper<Scheduler, &Scheduler::pause> starvationEvent;
+    void scheduleStarvationEvent();
+
     bool _started;
     bool _paused;
     bool _stopped;
@@ -304,6 +319,7 @@
     Process *_current;

     bool initReady;
+    bool runToTime;

     ProcessList initList;
     ProcessList toFinalize;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12038
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: I0780a1f720cf63f3d2907b8dd28685266b52d6b4
Gerrit-Change-Number: 12038
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