From d15cb49d6fe600090fac7c56805ee4b13f4aaa47 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 6 Nov 2008 16:08:10 +0000 Subject: [PATCH] re-instate counting of sparks converted lost in patch "Run sparks in batches" --- rts/Capability.c | 19 ++++++++++++++++--- rts/Capability.h | 4 ++-- rts/PrimOps.cmm | 10 ++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/rts/Capability.c b/rts/Capability.c index ddb47b4..9b5d81d 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -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 diff --git a/rts/Capability.h b/rts/Capability.h index 07b8838..db9e1e3 100644 --- a/rts/Capability.h +++ b/rts/Capability.h @@ -245,9 +245,9 @@ void shutdownCapability (Capability *cap, Task *task, rtsBool wait_foreign); // rtsBool tryGrabCapability (Capability *cap, Task *task); -// Try to steal a spark from other Capabilities +// Try to find a spark to run // -StgClosure *stealWork (Capability *cap); +StgClosure *findSpark (Capability *cap); // True if any capabilities have sparks // diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm index 55ada8c..f63f20a 100644 --- a/rts/PrimOps.cmm +++ b/rts/PrimOps.cmm @@ -2295,17 +2295,11 @@ getSparkzh_fast #ifndef THREADED_RTS RET_NP(0,ghczmprim_GHCziBool_False_closure); #else - (spark) = foreign "C" tryStealSpark(MyCapability()); + (spark) = foreign "C" findSpark(MyCapability()); if (spark != 0) { RET_NP(1,spark); } else { - (spark) = foreign "C" stealWork (MyCapability()); - if (spark != 0) { - RET_NP(1,spark); - } else { - RET_NP(0,ghczmprim_GHCziBool_False_closure); - - } + RET_NP(0,ghczmprim_GHCziBool_False_closure); } #endif } -- 1.7.10.4