Some assertions and comments in scheduler
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Sat, 17 Nov 2018 04:59:15 +0000 (07:59 +0300)
committerÖmer Sinan Ağacan <omeragacan@gmail.com>
Sat, 17 Nov 2018 05:35:33 +0000 (08:35 +0300)
Test Plan:
I can't validate this because of existing errors with the debug runtime. I'll
see if this introduces any new failures.

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5337

rts/Capability.h
rts/Schedule.c
rts/Schedule.h

index 250ec22..05a827c 100644 (file)
@@ -264,7 +264,10 @@ typedef enum {
 //
 typedef struct {
     SyncType type;              // The kind of synchronisation
-    bool *idle;
+    bool *idle;                 // Array of size n_capabilities. idle[i] is true
+                                // if capability i will be idle during this GC
+                                // cycle. Only available when doing GC (when
+                                // type is SYNC_GC_*).
     Task *task;                 // The Task performing the sync
 } PendingSync;
 
index 0444f0c..d104cfd 100644 (file)
@@ -668,8 +668,10 @@ scheduleYield (Capability **pcap, Task *task)
     // otherwise yield (sleep), and keep yielding if necessary.
     do {
         if (doIdleGCWork(cap, false)) {
+            // there's more idle GC work to do
             didGcLast = false;
         } else {
+            // no more idle GC work to do
             didGcLast = yieldCapability(&cap,task, !didGcLast);
         }
     }
@@ -1876,7 +1878,7 @@ delete_threads_and_gc:
         releaseGCThreads(cap, idle_cap);
     }
 #endif
-    if (heap_overflow && sched_state < SCHED_INTERRUPTING) {
+    if (heap_overflow && sched_state == SCHED_RUNNING) {
         // GC set the heap_overflow flag.  We should throw an exception if we
         // can, or shut down otherwise.
 
@@ -2660,7 +2662,7 @@ exitScheduler (bool wait_foreign USED_IF_THREADS)
         ASSERT(task->incall->tso == NULL);
         releaseCapability(cap);
     }
-    sched_state = SCHED_SHUTTING_DOWN;
+    ASSERT(sched_state == SCHED_SHUTTING_DOWN);
 
     shutdownCapabilities(task, wait_foreign);
 
@@ -2749,6 +2751,7 @@ performMajorGC(void)
 void
 interruptStgRts(void)
 {
+    ASSERT(sched_state != SCHED_SHUTTING_DOWN);
     sched_state = SCHED_INTERRUPTING;
     interruptAllCapabilities();
 #if defined(THREADED_RTS)
index 49e094b..66cf839 100644 (file)
@@ -167,6 +167,7 @@ pushOnRunQueue (Capability *cap, StgTSO *tso)
 INLINE_HEADER StgTSO *
 popRunQueue (Capability *cap)
 {
+    ASSERT(cap->n_run_queue != 0);
     StgTSO *t = cap->run_queue_hd;
     ASSERT(t != END_TSO_QUEUE);
     cap->run_queue_hd = t->_link;