Add optional eager black-holing, with new flag -feager-blackholing
[ghc-hetmet.git] / rts / Capability.c
index ddb47b4..27a2d51 100644 (file)
@@ -55,7 +55,7 @@ globalWorkToDo (void)
 
 #if defined(THREADED_RTS)
 StgClosure *
-stealWork (Capability *cap)
+findSpark (Capability *cap)
 {
   /* use the normal Sparks.h interface (internally modified to enable
      concurrent stealing) 
@@ -66,12 +66,24 @@ stealWork (Capability *cap)
   rtsBool retry;
   nat i = 0;
 
+  // first try to get a spark from our own pool.
+  // We should be using reclaimSpark(), because it works without
+  // needing any atomic instructions:
+  //   spark = reclaimSpark(cap->sparks);
+  // However, measurements show that this makes at least one benchmark
+  // slower (prsa) and doesn't affect the others.
+  spark = tryStealSpark(cap);
+  if (spark != NULL) {
+      cap->sparks_converted++;
+      return spark;
+  }
+
+  if (n_capabilities == 1) { return NULL; } // makes no sense...
+
   debugTrace(DEBUG_sched,
             "cap %d: Trying to steal work from other capabilities", 
             cap->no);
 
-  if (n_capabilities == 1) { return NULL; } // makes no sense...
-
   do {
       retry = rtsFalse;
 
@@ -96,6 +108,7 @@ stealWork (Capability *cap)
               debugTrace(DEBUG_sched,
                 "cap %d: Stole a spark from capability %d",
                          cap->no, robbed->no);
+              cap->sparks_converted++;
               return spark;
           }
           // otherwise: no success, try next one
@@ -192,6 +205,7 @@ initCapability( Capability *cap, nat i )
     cap->sparks_pruned      = 0;
 #endif
 
+    cap->f.stgEagerBlackholeInfo = (W_)&__stg_EAGER_BLACKHOLE_info;
     cap->f.stgGCEnter1     = (F_)__stg_gc_enter_1;
     cap->f.stgGCFun        = (F_)__stg_gc_fun;
 
@@ -712,8 +726,6 @@ shutdownCapability (Capability *cap, Task *task, rtsBool safe)
 {
     nat i;
 
-    ASSERT(sched_state == SCHED_SHUTTING_DOWN);
-
     task->cap = cap;
 
     // Loop indefinitely until all the workers have exited and there
@@ -723,6 +735,8 @@ shutdownCapability (Capability *cap, Task *task, rtsBool safe)
     // isn't safe, for one thing).
 
     for (i = 0; /* i < 50 */; i++) {
+        ASSERT(sched_state == SCHED_SHUTTING_DOWN);
+
        debugTrace(DEBUG_sched, 
                   "shutting down capability %d, attempt %d", cap->no, i);
        ACQUIRE_LOCK(&cap->lock);