1 /* ---------------------------------------------------------------------------
3 * (c) The GHC Team, 2000-2008
5 * Sparking support for PARALLEL_HASKELL and THREADED_RTS versions of the RTS.
7 -------------------------------------------------------------------------*/
9 #include "PosixSource.h"
20 #include "SMP.h" // for cas
24 #if defined(THREADED_RTS) || defined(PARALLEL_HASKELL)
27 initSparkPools( void )
30 /* walk over the capabilities, allocating a spark pool for each one */
32 for (i = 0; i < n_capabilities; i++) {
33 capabilities[i].sparks = newWSDeque(RtsFlags.ParFlags.maxLocalSparks);
36 /* allocate a single spark pool */
37 MainCapability->sparks = newWSDeque(RtsFlags.ParFlags.maxLocalSparks);
42 freeSparkPool (SparkPool *pool)
47 /* -----------------------------------------------------------------------------
49 * Turn a spark into a real thread
51 * -------------------------------------------------------------------------- */
54 createSparkThread (Capability *cap)
58 tso = createIOThread (cap, RtsFlags.GcFlags.initialStkSize,
59 &base_GHCziConc_runSparks_closure);
60 appendToRunQueue(cap,tso);
63 /* --------------------------------------------------------------------------
64 * newSpark: create a new spark, as a result of calling "par"
65 * Called directly from STG.
66 * -------------------------------------------------------------------------- */
69 newSpark (StgRegTable *reg, StgClosure *p)
71 Capability *cap = regTableToCapability(reg);
72 SparkPool *pool = cap->sparks;
74 /* I am not sure whether this is the right thing to do.
75 * Maybe it is better to exploit the tag information
76 * instead of throwing it away?
80 if (closure_SHOULD_SPARK(p)) {
84 cap->sparks_created++;
89 /* -----------------------------------------------------------------------------
91 * tryStealSpark: try to steal a spark from a Capability.
93 * Returns a valid spark, or NULL if the pool was empty, and can
94 * occasionally return NULL if there was a race with another thread
95 * stealing from the same pool. In this case, try again later.
97 -------------------------------------------------------------------------- */
100 tryStealSpark (Capability *cap)
102 SparkPool *pool = cap->sparks;
106 stolen = stealWSDeque_(pool);
107 // use the no-loopy version, stealWSDeque_(), since if we get a
108 // spurious NULL here the caller may want to try stealing from
109 // other pools before trying again.
110 } while (stolen != NULL && !closure_SHOULD_SPARK(stolen));
115 /* --------------------------------------------------------------------------
116 * Remove all sparks from the spark queues which should not spark any
117 * more. Called after GC. We assume exclusive access to the structure
118 * and replace all sparks in the queue, see explanation below. At exit,
119 * the spark pool only contains sparkable closures.
120 * -------------------------------------------------------------------------- */
123 pruneSparkQueue (evac_fn evac, void *user, Capability *cap)
126 StgClosurePtr spark, tmp, *elements;
127 nat n, pruned_sparks; // stats only
128 StgWord botInd,oldBotInd,currInd; // indices in array (always < size)
129 const StgInfoTable *info;
131 PAR_TICKY_MARK_SPARK_QUEUE_START();
138 // it is possible that top > bottom, indicating an empty pool. We
139 // fix that here; this is only necessary because the loop below
141 if (pool->top > pool->bottom)
142 pool->top = pool->bottom;
144 // Take this opportunity to reset top/bottom modulo the size of
145 // the array, to avoid overflow. This is only possible because no
146 // stealing is happening during GC.
147 pool->bottom -= pool->top & ~pool->moduloSize;
148 pool->top &= pool->moduloSize;
149 pool->topBound = pool->top;
151 debugTrace(DEBUG_sched,
152 "markSparkQueue: current spark queue len=%ld; (hd=%ld; tl=%ld)",
153 sparkPoolSize(pool), pool->bottom, pool->top);
155 ASSERT_WSDEQUE_INVARIANTS(pool);
157 elements = (StgClosurePtr *)pool->elements;
159 /* We have exclusive access to the structure here, so we can reset
160 bottom and top counters, and prune invalid sparks. Contents are
161 copied in-place if they are valuable, otherwise discarded. The
162 routine uses "real" indices t and b, starts by computing them
163 as the modulus size of top and bottom,
167 At the beginning, the pool structure can look like this:
168 ( bottom % size >= top % size , no wrap-around)
170 ___________***********_________________
172 or like this ( bottom % size < top % size, wrap-around )
174 ***********__________******************
175 As we need to remove useless sparks anyway, we make one pass
176 between t and b, moving valuable content to b and subsequent
177 cells (wrapping around when the size is reached).
180 ***********OOO_______XX_X__X?**********
183 After this movement, botInd becomes the new bottom, and old
184 bottom becomes the new top index, both as indices in the array
188 currInd = (pool->top) & (pool->moduloSize); // mod
190 // copies of evacuated closures go to space from botInd on
191 // we keep oldBotInd to know when to stop
192 oldBotInd = botInd = (pool->bottom) & (pool->moduloSize); // mod
194 // on entry to loop, we are within the bounds
195 ASSERT( currInd < pool->size && botInd < pool->size );
197 while (currInd != oldBotInd ) {
198 /* must use != here, wrap-around at size
199 subtle: loop not entered if queue empty
202 /* check element at currInd. if valuable, evacuate and move to
203 botInd, otherwise move on */
204 spark = elements[currInd];
206 // We have to be careful here: in the parallel GC, another
207 // thread might evacuate this closure while we're looking at it,
208 // so grab the info pointer just once.
209 info = spark->header.info;
210 if (IS_FORWARDING_PTR(info)) {
211 tmp = (StgClosure*)UN_FORWARDING_PTR(info);
212 /* if valuable work: shift inside the pool */
213 if (closure_SHOULD_SPARK(tmp)) {
214 elements[botInd] = tmp; // keep entry (new address)
218 pruned_sparks++; // discard spark
219 cap->sparks_pruned++;
222 if (!(closure_flags[INFO_PTR_TO_STRUCT(info)->type] & _NS)) {
223 elements[botInd] = spark; // keep entry (new address)
224 evac (user, &elements[botInd]);
228 pruned_sparks++; // discard spark
229 cap->sparks_pruned++;
234 // in the loop, we may reach the bounds, and instantly wrap around
235 ASSERT( currInd <= pool->size && botInd <= pool->size );
236 if ( currInd == pool->size ) { currInd = 0; }
237 if ( botInd == pool->size ) { botInd = 0; }
239 } // while-loop over spark pool elements
241 ASSERT(currInd == oldBotInd);
243 pool->top = oldBotInd; // where we started writing
244 pool->topBound = pool->top;
246 pool->bottom = (oldBotInd <= botInd) ? botInd : (botInd + pool->size);
247 // first free place we did not use (corrected by wraparound)
249 PAR_TICKY_MARK_SPARK_QUEUE_END(n);
251 debugTrace(DEBUG_sched, "pruned %d sparks", pruned_sparks);
253 debugTrace(DEBUG_sched,
254 "new spark queue len=%ld; (hd=%ld; tl=%ld)",
255 sparkPoolSize(pool), pool->bottom, pool->top);
257 ASSERT_WSDEQUE_INVARIANTS(pool);
260 /* GC for the spark pool, called inside Capability.c for all
261 capabilities in turn. Blindly "evac"s complete spark pool. */
263 traverseSparkQueue (evac_fn evac, void *user, Capability *cap)
267 StgWord top,bottom, modMask;
271 ASSERT_WSDEQUE_INVARIANTS(pool);
274 bottom = pool->bottom;
275 sparkp = (StgClosurePtr*)pool->elements;
276 modMask = pool->moduloSize;
278 while (top < bottom) {
279 /* call evac for all closures in range (wrap-around via modulo)
280 * In GHC-6.10, evac takes an additional 1st argument to hold a
281 * GC-specific register, see rts/sm/GC.c::mark_root()
283 evac( user , sparkp + (top & modMask) );
287 debugTrace(DEBUG_sched,
288 "traversed spark queue, len=%ld; (hd=%ld; tl=%ld)",
289 sparkPoolSize(pool), pool->bottom, pool->top);
292 /* ----------------------------------------------------------------------------
293 * balanceSparkPoolsCaps: takes an array of capabilities (usually: all
294 * capabilities) and its size. Accesses all spark pools and equally
295 * distributes the sparks among them.
297 * Could be called after GC, before Cap. release, from scheduler.
298 * -------------------------------------------------------------------------- */
299 void balanceSparkPoolsCaps(nat n_caps, Capability caps[]);
301 void balanceSparkPoolsCaps(nat n_caps STG_UNUSED,
302 Capability caps[] STG_UNUSED) {
303 barf("not implemented");
309 newSpark (StgRegTable *reg STG_UNUSED, StgClosure *p STG_UNUSED)
316 #endif /* PARALLEL_HASKELL || THREADED_RTS */
319 /* -----------------------------------------------------------------------------
321 * GRAN & PARALLEL_HASKELL stuff beyond here.
325 * -------------------------------------------------------------------------- */
327 #if defined(PARALLEL_HASKELL) || defined(GRAN)
329 static void slide_spark_pool( StgSparkPool *pool );
332 add_to_spark_queue( StgClosure *closure, StgSparkPool *pool )
334 if (pool->tl == pool->lim)
335 slide_spark_pool(pool);
337 if (closure_SHOULD_SPARK(closure) &&
338 pool->tl < pool->lim) {
339 *(pool->tl++) = closure;
341 #if defined(PARALLEL_HASKELL)
342 // collect parallel global statistics (currently done together with GC stats)
343 if (RtsFlags.ParFlags.ParStats.Global &&
344 RtsFlags.GcFlags.giveStats > NO_GC_STATS) {
345 // debugBelch("Creating spark for %x @ %11.2f\n", closure, usertime());
346 globalParStats.tot_sparks_created++;
351 #if defined(PARALLEL_HASKELL)
352 // collect parallel global statistics (currently done together with GC stats)
353 if (RtsFlags.ParFlags.ParStats.Global &&
354 RtsFlags.GcFlags.giveStats > NO_GC_STATS) {
355 //debugBelch("Ignoring spark for %x @ %11.2f\n", closure, usertime());
356 globalParStats.tot_sparks_ignored++;
364 slide_spark_pool( StgSparkPool *pool )
366 StgClosure **sparkp, **to_sparkp;
369 to_sparkp = pool->base;
370 while (sparkp < pool->tl) {
371 ASSERT(to_sparkp<=sparkp);
372 ASSERT(*sparkp!=NULL);
373 ASSERT(LOOKS_LIKE_GHC_INFO((*sparkp)->header.info));
375 if (closure_SHOULD_SPARK(*sparkp)) {
376 *to_sparkp++ = *sparkp++;
381 pool->hd = pool->base;
382 pool->tl = to_sparkp;
389 #if !defined(THREADED_RTS)
394 pool = &(cap->rSparks);
395 ASSERT(pool->hd <= pool->tl && pool->tl <= pool->lim);
397 ASSERT(spark != (StgClosure *)NULL);
405 Search the spark queue of the proc in event for a spark that's worth
406 turning into a thread
407 (was gimme_spark in the old RTS)
410 findLocalSpark (rtsEvent *event, rtsBool *found_res, rtsSparkQ *spark_res)
412 PEs proc = event->proc, /* proc to search for work */
413 creator = event->creator; /* proc that requested work */
416 rtsSparkQ spark_of_non_local_node = NULL,
417 spark_of_non_local_node_prev = NULL,
418 low_priority_spark = NULL,
419 low_priority_spark_prev = NULL,
420 spark = NULL, prev = NULL;
422 /* Choose a spark from the local spark queue */
423 prev = (rtsSpark*)NULL;
424 spark = pending_sparks_hds[proc];
427 // ToDo: check this code & implement local sparking !! -- HWL
428 while (!found && spark != (rtsSpark*)NULL)
430 ASSERT((prev!=(rtsSpark*)NULL || spark==pending_sparks_hds[proc]) &&
431 (prev==(rtsSpark*)NULL || prev->next==spark) &&
432 (spark->prev==prev));
434 if (!closure_SHOULD_SPARK(node))
436 IF_GRAN_DEBUG(checkSparkQ,
437 debugBelch("^^ pruning spark %p (node %p) in gimme_spark",
440 if (RtsFlags.GranFlags.GranSimStats.Sparks)
441 DumpRawGranEvent(proc, (PEs)0, SP_PRUNED,(StgTSO*)NULL,
442 spark->node, spark->name, spark_queue_len(proc));
444 ASSERT(spark != (rtsSpark*)NULL);
445 ASSERT(SparksAvail>0);
448 ASSERT(prev==(rtsSpark*)NULL || prev->next==spark);
449 spark = delete_from_sparkq (spark, proc, rtsTrue);
450 if (spark != (rtsSpark*)NULL)
454 /* -- node should eventually be sparked */
455 else if (RtsFlags.GranFlags.PreferSparksOfLocalNodes &&
456 !IS_LOCAL_TO(PROCS(node),CurrentProc))
458 barf("Local sparking not yet implemented");
460 /* Remember first low priority spark */
461 if (spark_of_non_local_node==(rtsSpark*)NULL) {
462 spark_of_non_local_node_prev = prev;
463 spark_of_non_local_node = spark;
466 if (spark->next == (rtsSpark*)NULL) {
467 /* ASSERT(spark==SparkQueueTl); just for testing */
468 prev = spark_of_non_local_node_prev;
469 spark = spark_of_non_local_node;
474 # if defined(GRAN) && defined(GRAN_CHECK)
475 /* Should never happen; just for testing
476 if (spark==pending_sparks_tl) {
477 debugBelch("ReSchedule: Last spark != SparkQueueTl\n");
478 stg_exit(EXIT_FAILURE);
483 ASSERT(SparksAvail>0);
487 else if ( RtsFlags.GranFlags.DoPrioritySparking ||
488 (spark->gran_info >= RtsFlags.GranFlags.SparkPriority2) )
490 if (RtsFlags.GranFlags.DoPrioritySparking)
491 barf("Priority sparking not yet implemented");
496 else /* only used if SparkPriority2 is defined */
498 /* ToDo: fix the code below and re-integrate it */
499 /* Remember first low priority spark */
500 if (low_priority_spark==(rtsSpark*)NULL) {
501 low_priority_spark_prev = prev;
502 low_priority_spark = spark;
505 if (spark->next == (rtsSpark*)NULL) {
506 /* ASSERT(spark==spark_queue_tl); just for testing */
507 prev = low_priority_spark_prev;
508 spark = low_priority_spark;
509 found = rtsTrue; /* take low pri spark => rc is 2 */
513 /* Should never happen; just for testing
514 if (spark==pending_sparks_tl) {
515 debugBelch("ReSchedule: Last spark != SparkQueueTl\n");
516 stg_exit(EXIT_FAILURE);
523 debugBelch("++ Ignoring spark of priority %u (SparkPriority=%u); node=%p; name=%u\n",
524 spark->gran_info, RtsFlags.GranFlags.SparkPriority,
525 spark->node, spark->name);)
528 } /* while (spark!=NULL && !found) */
535 Turn the spark into a thread.
536 In GranSim this basically means scheduling a StartThread event for the
537 node pointed to by the spark at some point in the future.
538 (was munch_spark in the old RTS)
541 activateSpark (rtsEvent *event, rtsSparkQ spark)
543 PEs proc = event->proc, /* proc to search for work */
544 creator = event->creator; /* proc that requested work */
547 rtsTime spark_arrival_time;
550 We've found a node on PE proc requested by PE creator.
551 If proc==creator we can turn the spark into a thread immediately;
552 otherwise we schedule a MoveSpark event on the requesting PE
558 /* only possible if we simulate GUM style fishing */
559 ASSERT(RtsFlags.GranFlags.Fishing);
561 /* Message packing costs for sending a Fish; qeq jabbI'ID */
562 CurrentTime[proc] += RtsFlags.GranFlags.Costs.mpacktime;
564 if (RtsFlags.GranFlags.GranSimStats.Sparks)
565 DumpRawGranEvent(proc, (PEs)0, SP_EXPORTED,
566 (StgTSO*)NULL, spark->node,
567 spark->name, spark_queue_len(proc));
569 /* time of the spark arrival on the remote PE */
570 spark_arrival_time = CurrentTime[proc] + RtsFlags.GranFlags.Costs.latency;
572 new_event(creator, proc, spark_arrival_time,
574 (StgTSO*)NULL, spark->node, spark);
576 CurrentTime[proc] += RtsFlags.GranFlags.Costs.mtidytime;
578 } else { /* proc==creator i.e. turn the spark into a thread */
580 if ( RtsFlags.GranFlags.GranSimStats.Global &&
581 spark->gran_info < RtsFlags.GranFlags.SparkPriority2 ) {
583 globalGranStats.tot_low_pri_sparks++;
585 debugBelch("++ No high priority spark available; low priority (%u) spark chosen: node=%p; name=%u\n",
587 spark->node, spark->name));
590 CurrentTime[proc] += RtsFlags.GranFlags.Costs.threadcreatetime;
595 /* ToDo: fix the GC interface and move to StartThread handling-- HWL */
596 if (GARBAGE COLLECTION IS NECESSARY) {
597 /* Some kind of backoff needed here in case there's too little heap */
598 # if defined(GRAN_CHECK) && defined(GRAN)
599 if (RtsFlags.GcFlags.giveStats)
600 fprintf(RtsFlags.GcFlags.statsFile,"***** vIS Qu' chen veQ boSwI'; spark=%p, node=%p; name=%u\n",
601 /* (found==2 ? "no hi pri spark" : "hi pri spark"), */
602 spark, node, spark->name);
604 new_event(CurrentProc, CurrentProc, CurrentTime[CurrentProc]+1,
606 (StgTSO*)NULL, (StgClosure*)NULL, (rtsSpark*)NULL);
607 barf("//// activateSpark: out of heap ; ToDo: call GarbageCollect()");
608 GarbageCollect(GetRoots, rtsFalse);
609 // HWL old: ReallyPerformThreadGC(TSO_HS+TSO_CTS_SIZE,rtsFalse);
610 // HWL old: SAVE_Hp -= TSO_HS+TSO_CTS_SIZE;
612 return; /* was: continue; */ /* to the next event, eventually */
616 if (RtsFlags.GranFlags.GranSimStats.Sparks)
617 DumpRawGranEvent(CurrentProc,(PEs)0,SP_USED,(StgTSO*)NULL,
618 spark->node, spark->name,
619 spark_queue_len(CurrentProc));
621 new_event(proc, proc, CurrentTime[proc],
623 END_TSO_QUEUE, node, spark); // (rtsSpark*)NULL);
625 procStatus[proc] = Starting;
629 /* -------------------------------------------------------------------------
630 This is the main point where handling granularity information comes into
632 ------------------------------------------------------------------------- */
634 #define MAX_RAND_PRI 100
637 Granularity info transformers.
638 Applied to the GRAN_INFO field of a spark.
640 STATIC_INLINE nat ID(nat x) { return(x); };
641 STATIC_INLINE nat INV(nat x) { return(-x); };
642 STATIC_INLINE nat IGNORE(nat x) { return (0); };
643 STATIC_INLINE nat RAND(nat x) { return ((random() % MAX_RAND_PRI) + 1); }
645 /* NB: size_info and par_info are currently unused (what a shame!) -- HWL */
647 newSpark(node,name,gran_info,size_info,par_info,local)
649 nat name, gran_info, size_info, par_info, local;
654 pri = RtsFlags.GranFlags.RandomPriorities ? RAND(gran_info) :
655 RtsFlags.GranFlags.InversePriorities ? INV(gran_info) :
656 RtsFlags.GranFlags.IgnorePriorities ? IGNORE(gran_info) :
659 if ( RtsFlags.GranFlags.SparkPriority!=0 &&
660 pri<RtsFlags.GranFlags.SparkPriority ) {
662 debugBelch(",, NewSpark: Ignoring spark of priority %u (SparkPriority=%u); node=%#x; name=%u\n",
663 pri, RtsFlags.GranFlags.SparkPriority, node, name));
664 return ((rtsSpark*)NULL);
667 newspark = (rtsSpark*) stgMallocBytes(sizeof(rtsSpark), "NewSpark");
668 newspark->prev = newspark->next = (rtsSpark*)NULL;
669 newspark->node = node;
670 newspark->name = (name==1) ? CurrentTSO->gran.sparkname : name;
671 newspark->gran_info = pri;
672 newspark->global = !local; /* Check that with parAt, parAtAbs !!*/
674 if (RtsFlags.GranFlags.GranSimStats.Global) {
675 globalGranStats.tot_sparks_created++;
676 globalGranStats.sparks_created_on_PE[CurrentProc]++;
697 disposeSparkQ(spark->next);
700 if (SparksAvail < 0) {
701 debugBelch("disposeSparkQ: SparksAvail<0 after disposing sparkq @ %p\n", &spark);
710 With PrioritySparking add_to_spark_queue performs an insert sort to keep
711 the spark queue sorted. Otherwise the spark is just added to the end of
716 add_to_spark_queue(spark)
719 rtsSpark *prev = NULL, *next = NULL;
721 rtsBool found = rtsFalse;
723 if ( spark == (rtsSpark *)NULL ) {
727 if (RtsFlags.GranFlags.DoPrioritySparking && (spark->gran_info != 0) ) {
728 /* Priority sparking is enabled i.e. spark queues must be sorted */
730 for (prev = NULL, next = pending_sparks_hd, count=0;
732 !(found = (spark->gran_info >= next->gran_info));
733 prev = next, next = next->next, count++)
736 } else { /* 'utQo' */
737 /* Priority sparking is disabled */
739 found = rtsFalse; /* to add it at the end */
744 /* next points to the first spark with a gran_info smaller than that
745 of spark; therefore, add spark before next into the spark queue */
747 if ( next == NULL ) {
748 pending_sparks_tl = spark;
753 if ( prev == NULL ) {
754 pending_sparks_hd = spark;
758 } else { /* (RtsFlags.GranFlags.DoPrioritySparking && !found) || !DoPrioritySparking */
759 /* add the spark at the end of the spark queue */
761 spark->prev = pending_sparks_tl;
762 if (pending_sparks_hd == NULL)
763 pending_sparks_hd = spark;
765 pending_sparks_tl->next = spark;
766 pending_sparks_tl = spark;
770 /* add costs for search in priority sparking */
771 if (RtsFlags.GranFlags.DoPrioritySparking) {
772 CurrentTime[CurrentProc] += count * RtsFlags.GranFlags.Costs.pri_spark_overhead;
775 IF_GRAN_DEBUG(checkSparkQ,
776 debugBelch("++ Spark stats after adding spark %p (node %p) to queue on PE %d",
777 spark, spark->node, CurrentProc);
778 print_sparkq_stats());
780 # if defined(GRAN_CHECK)
781 if (RtsFlags.GranFlags.Debug.checkSparkQ) {
782 for (prev = NULL, next = pending_sparks_hd;
784 prev = next, next = next->next)
786 if ( (prev!=NULL) && (prev!=pending_sparks_tl) )
787 debugBelch("SparkQ inconsistency after adding spark %p: (PE %u) pending_sparks_tl (%p) not end of queue (%p)\n",
789 pending_sparks_tl, prev);
793 # if defined(GRAN_CHECK)
794 /* Check if the sparkq is still sorted. Just for testing, really! */
795 if ( RtsFlags.GranFlags.Debug.checkSparkQ &&
796 RtsFlags.GranFlags.Debug.pri ) {
797 rtsBool sorted = rtsTrue;
798 rtsSpark *prev, *next;
800 if (pending_sparks_hd == NULL ||
801 pending_sparks_hd->next == NULL ) {
802 /* just 1 elem => ok */
804 for (prev = pending_sparks_hd,
805 next = pending_sparks_hd->next;
807 prev = next, next = next->next) {
809 (prev->gran_info >= next->gran_info);
813 debugBelch("ghuH: SPARKQ on PE %d is not sorted:\n",
815 print_sparkq(CurrentProc);
822 spark_queue_len(proc)
825 rtsSpark *prev, *spark; /* prev only for testing !! */
828 for (len = 0, prev = NULL, spark = pending_sparks_hds[proc];
830 len++, prev = spark, spark = spark->next)
833 # if defined(GRAN_CHECK)
834 if ( RtsFlags.GranFlags.Debug.checkSparkQ )
835 if ( (prev!=NULL) && (prev!=pending_sparks_tls[proc]) )
836 debugBelch("ERROR in spark_queue_len: (PE %u) pending_sparks_tl (%p) not end of queue (%p)\n",
837 proc, pending_sparks_tls[proc], prev);
844 Take spark out of the spark queue on PE p and nuke the spark. Adjusts
845 hd and tl pointers of the spark queue. Returns a pointer to the next
849 delete_from_sparkq (spark, p, dispose_too) /* unlink and dispose spark */
857 barf("delete_from_sparkq: trying to delete NULL spark\n");
859 # if defined(GRAN_CHECK)
860 if ( RtsFlags.GranFlags.Debug.checkSparkQ ) {
861 debugBelch("## |%p:%p| (%p)<-spark=%p->(%p) <-(%p)\n",
862 pending_sparks_hd, pending_sparks_tl,
863 spark->prev, spark, spark->next,
864 (spark->next==NULL ? 0 : spark->next->prev));
868 if (spark->prev==NULL) {
869 /* spark is first spark of queue => adjust hd pointer */
870 ASSERT(pending_sparks_hds[p]==spark);
871 pending_sparks_hds[p] = spark->next;
873 spark->prev->next = spark->next;
875 if (spark->next==NULL) {
876 ASSERT(pending_sparks_tls[p]==spark);
877 /* spark is first spark of queue => adjust tl pointer */
878 pending_sparks_tls[p] = spark->prev;
880 spark->next->prev = spark->prev;
882 new_spark = spark->next;
884 # if defined(GRAN_CHECK)
885 if ( RtsFlags.GranFlags.Debug.checkSparkQ ) {
886 debugBelch("## |%p:%p| (%p)<-spark=%p->(%p) <-(%p); spark=%p will be deleted NOW \n",
887 pending_sparks_hd, pending_sparks_tl,
888 spark->prev, spark, spark->next,
889 (spark->next==NULL ? 0 : spark->next->prev), spark);
899 /* Mark all nodes pointed to by sparks in the spark queues (for GC) */
903 StgClosure *MarkRoot(StgClosure *root); // prototype
907 for (p=0; p<RtsFlags.GranFlags.proc; p++)
908 for (sp=pending_sparks_hds[p]; sp!=NULL; sp=sp->next) {
909 ASSERT(sp->node!=NULL);
910 ASSERT(LOOKS_LIKE_GHC_INFO(sp->node->header.info));
911 // ToDo?: statistics gathering here (also for GUM!)
912 sp->node = (StgClosure *)MarkRoot(sp->node);
916 debugBelch("markSparkQueue: spark statistics at start of GC:");
917 print_sparkq_stats());
927 debugBelch("Spark: NIL\n");
931 ((spark->node==NULL) ? "______" : "%#6lx"),
932 stgCast(StgPtr,spark->node));
934 debugBelch("Spark: Node %8s, Name %#6x, Global %5s, Creator %5x, Prev %6p, Next %6p\n",
936 ((spark->global)==rtsTrue?"True":"False"), spark->creator,
937 spark->prev, spark->next);
946 rtsSpark *x = pending_sparks_hds[proc];
948 debugBelch("Spark Queue of PE %d with root at %p:\n", proc, x);
949 for (; x!=(rtsSpark*)NULL; x=x->next) {
955 Print a statistics of all spark queues.
958 print_sparkq_stats(void)
962 debugBelch("SparkQs: [");
963 for (p=0; p<RtsFlags.GranFlags.proc; p++)
964 debugBelch(", PE %d: %d", p, spark_queue_len(p));