From 99df892cc9620fcc92747b79bba75dad8a1d295c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 22 Oct 2008 09:27:44 +0000 Subject: Refactoring and reorganisation of the scheduler Change the way we look for work in the scheduler. Previously, checking to see whether there was anything to do was a non-side-effecting operation, but this has changed now that we do work-stealing. This lead to a refactoring of the inner loop of the scheduler. Also, lots of cleanup in the new work-stealing code, but no functional changes. One new statistic is added to the +RTS -s output: SPARKS: 1430 (2 converted, 1427 pruned) lets you know something about the use of `par` in the program. --- rts/Capability.h | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'rts/Capability.h') diff --git a/rts/Capability.h b/rts/Capability.h index 59458951eb..779a1945a5 100644 --- a/rts/Capability.h +++ b/rts/Capability.h @@ -23,9 +23,9 @@ #ifndef CAPABILITY_H #define CAPABILITY_H -#include "RtsTypes.h" #include "RtsFlags.h" #include "Task.h" +#include "Sparks.h" struct Capability_ { // State required by the STG virtual machine when running Haskell @@ -91,6 +91,13 @@ struct Capability_ { // woken up by another Capability. StgTSO *wakeup_queue_hd; StgTSO *wakeup_queue_tl; + + SparkPool *sparks; + + // Stats on spark creation/conversion + nat sparks_created; + nat sparks_converted; + nat sparks_pruned; #endif // Per-capability STM-related data @@ -100,8 +107,6 @@ struct Capability_ { StgTRecHeader *free_trec_headers; nat transaction_tokens; - SparkPool *sparks; - }; // typedef Capability, defined in RtsAPI.h @@ -147,12 +152,16 @@ void initCapabilities (void); // ASSUMES: cap->running_task is the current Task. // #if defined(THREADED_RTS) -void releaseCapability (Capability* cap); -void releaseCapability_ (Capability* cap); // assumes cap->lock is held +void releaseCapability (Capability* cap); +void releaseAndWakeupCapability (Capability* cap); +void releaseCapability_ (Capability* cap, rtsBool always_wakeup); +// assumes cap->lock is held #else // releaseCapability() is empty in non-threaded RTS INLINE_HEADER void releaseCapability (Capability* cap STG_UNUSED) {}; -INLINE_HEADER void releaseCapability_ (Capability* cap STG_UNUSED) {}; +INLINE_HEADER void releaseAndWakeupCapability (Capability* cap STG_UNUSED) {}; +INLINE_HEADER void releaseCapability_ (Capability* cap STG_UNUSED, + rtsBool always_wakeup STG_UNUSED) {}; #endif #if !IN_STG_CODE @@ -231,6 +240,14 @@ void shutdownCapability (Capability *cap, Task *task, rtsBool wait_foreign); // rtsBool tryGrabCapability (Capability *cap, Task *task); +// Try to steal a spark from other Capabilities +// +rtsBool stealWork (Capability *cap); + +INLINE_HEADER rtsBool emptySparkPoolCap (Capability *cap); +INLINE_HEADER nat sparkPoolSizeCap (Capability *cap); +INLINE_HEADER void discardSparksCap (Capability *cap); + #else // !THREADED_RTS // Grab a capability. (Only in the non-threaded RTS; in the threaded @@ -273,4 +290,18 @@ recordMutableCap (StgClosure *p, Capability *cap, nat gen) *bd->free++ = (StgWord)p; } +#if defined(THREADED_RTS) +INLINE_HEADER rtsBool +emptySparkPoolCap (Capability *cap) +{ return looksEmpty(cap->sparks); } + +INLINE_HEADER nat +sparkPoolSizeCap (Capability *cap) +{ return sparkPoolSize(cap->sparks); } + +INLINE_HEADER void +discardSparksCap (Capability *cap) +{ return discardSparks(cap->sparks); } +#endif + #endif /* CAPABILITY_H */ -- cgit v1.2.1