systemc: Clear out the scheduler more agressively and with common code.
authorGabe Black <gabeblack@google.com>
Wed, 22 Aug 2018 21:54:08 +0000 (14:54 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 25 Sep 2018 23:55:43 +0000 (23:55 +0000)
It's be useful/necessary to flush pending activity even when not
tearing down the scheduler, specifically when stopping.

Change-Id: I6b3716a8ca1f8ca151222e08f30bd3c9a43364b9
Reviewed-on: https://gem5-review.googlesource.com/12248
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/core/scheduler.cc
src/systemc/core/scheduler.hh

index f930bb5157f2ff5f433eed41768903279ad4e682..58c79562fade97f9d49a92bff12fa53b0ba6418b 100644 (file)
@@ -54,18 +54,25 @@ Scheduler::~Scheduler()
 {
     // Clear out everything that belongs to us to make sure nobody tries to
     // clear themselves out after the scheduler goes away.
+    clear();
+}
 
+void
+Scheduler::clear()
+{
     // Delta notifications.
     for (auto &e: deltas)
         e->deschedule();
+    deltas.clear();
 
     // Timed notifications.
-    for (auto &ts: timeSlots) {
-        for (auto &e: ts.second->events)
+    for (auto &tsp: timeSlots) {
+        TimeSlot *&ts = tsp.second;
+        for (auto &e: ts->events)
             e->deschedule();
-        delete ts.second;
-        ts.second = nullptr;
+        eq->deschedule(ts);
     }
+    timeSlots.clear();
 
     // gem5 events.
     if (readyEvent.scheduled())
@@ -273,8 +280,7 @@ Scheduler::stop()
     _stopped = true;
     kernel->stop();
 
-    if (readyEvent.scheduled())
-        eq->deschedule(&readyEvent);
+    clear();
 
     runOnce = false;
     scMain->run();
@@ -338,17 +344,9 @@ Scheduler::scheduleStop(bool finish_delta)
         return;
 
     if (!finish_delta) {
-        // If we're not supposed to finish the delta cycle, flush the list
-        // of ready processes, scheduled updates, and delta notifications.
-        Process *p;
-        while ((p = readyList.getNext()))
-            p->popListNode();
-        Channel *c;
-        while ((c = updateList.getNext()))
-            c->popListNode();
-        for (auto &e: deltas)
-            e->deschedule();
-        deltas.clear();
+        // If we're not supposed to finish the delta cycle, flush all
+        // pending activity.
+        clear();
     }
     eq->schedule(&stopEvent, eq->getCurTick());
 }
index 24b7fd2ff4ad1f74501c179cd19228ed7f571436..697aa11ad389bba81d9285086f00b724d72d7430 100644 (file)
@@ -161,6 +161,8 @@ class Scheduler
     Scheduler();
     ~Scheduler();
 
+    void clear();
+
     const std::string name() const { return "systemc_scheduler"; }
 
     uint64_t numCycles() { return _numCycles; }