summaryrefslogtreecommitdiff
path: root/rts/Capability.h
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2008-10-22 09:27:44 +0000
committerSimon Marlow <marlowsd@gmail.com>2008-10-22 09:27:44 +0000
commit99df892cc9620fcc92747b79bba75dad8a1d295c (patch)
tree536df57e1d9975f88ce781627bb2dacaee5b2c0c /rts/Capability.h
parentcf9650f2a1690c04051c716124bb0350adc74ae7 (diff)
downloadhaskell-99df892cc9620fcc92747b79bba75dad8a1d295c.tar.gz
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.
Diffstat (limited to 'rts/Capability.h')
-rw-r--r--rts/Capability.h43
1 files changed, 37 insertions, 6 deletions
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 */