root/rts/Sparks.h

Revision 5d091088ce94be4c389fa669911d0e842bd08952, 2.9 KB (checked in by Duncan Coutts <duncan@…>, 11 months ago)

Move allocation of spark pools into initCapability

Rather than a separate phase of initSparkPools. It means all the spark
stuff for a capability is initialisaed at the same time, which is then
becomes a good place to stick an initial spark trace event.

  • Property mode set to 100644
Line 
1/* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 2000-2009
4 *
5 * Sparking support for GRAN, PAR and THREADED_RTS versions of the RTS.
6 *
7 * ---------------------------------------------------------------------------*/
8
9#ifndef SPARKS_H
10#define SPARKS_H
11
12#include "WSDeque.h"
13
14#include "BeginPrivate.h"
15
16/* typedef for SparkPool in RtsTypes.h */
17
18/* Stats on spark creation/conversion */
19typedef struct {
20    StgWord created;
21    StgWord dud;
22    StgWord overflowed;
23    StgWord converted;
24    StgWord gcd;
25    StgWord fizzled;
26} SparkCounters;
27
28#if defined(THREADED_RTS)
29
30typedef WSDeque SparkPool;
31
32// Initialisation
33SparkPool *allocSparkPool (void);
34
35// Take a spark from the "write" end of the pool.  Can be called
36// by the pool owner only.
37INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool);
38
39// Returns True if the spark pool is empty (can give a false positive
40// if the pool is almost empty).
41INLINE_HEADER rtsBool looksEmpty(SparkPool* deque);
42
43INLINE_HEADER StgClosure * tryStealSpark (SparkPool *pool);
44INLINE_HEADER rtsBool      fizzledSpark  (StgClosure *);
45
46void         freeSparkPool     (SparkPool *pool);
47void         createSparkThread (Capability *cap);
48void         traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
49void         pruneSparkQueue   (Capability *cap);
50
51INLINE_HEADER void discardSparks  (SparkPool *pool);
52INLINE_HEADER long sparkPoolSize  (SparkPool *pool);
53
54/* -----------------------------------------------------------------------------
55 * PRIVATE below here
56 * -------------------------------------------------------------------------- */
57
58INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool)
59{
60    return popWSDeque(pool);
61}
62
63INLINE_HEADER rtsBool looksEmpty(SparkPool* deque)
64{
65    return looksEmptyWSDeque(deque);
66}
67
68INLINE_HEADER long sparkPoolSize (SparkPool *pool) 
69{ 
70    return dequeElements(pool);
71}
72
73INLINE_HEADER void discardSparks (SparkPool *pool)
74{
75    discardElements(pool);
76}
77
78/* ----------------------------------------------------------------------------
79 *
80 * tryStealSpark: try to steal a spark from a Capability.
81 *
82 * Returns either:
83 *  (a) a useful spark;
84 *  (b) a fizzled spark (use fizzledSpark to check);
85 *  (c) or NULL if the pool was empty, and can occasionally return NULL
86 *      if there was a race with another thread stealing from the same
87 *      pool.  In this case, try again later.
88 *
89 -------------------------------------------------------------------------- */
90
91INLINE_HEADER StgClosure * tryStealSpark (SparkPool *pool)
92{
93    return stealWSDeque_(pool);
94    // use the no-loopy version, stealWSDeque_(), since if we get a
95    // spurious NULL here the caller may want to try stealing from
96    // other pools before trying again.
97}
98
99INLINE_HEADER rtsBool fizzledSpark (StgClosure *spark)
100{
101    return (GET_CLOSURE_TAG(spark) != 0 || !closure_SHOULD_SPARK(spark));
102}
103
104#endif // THREADED_RTS
105
106#include "EndPrivate.h"
107
108#endif /* SPARKS_H */
Note: See TracBrowser for help on using the browser.