-findLocalSpark (rtsEvent *event, rtsBool *found_res, rtsSparkQ *spark_res)
-{
- PEs proc = event->proc, /* proc to search for work */
- creator = event->creator; /* proc that requested work */
- StgClosure* node;
- rtsBool found;
- rtsSparkQ spark_of_non_local_node = NULL,
- spark_of_non_local_node_prev = NULL,
- low_priority_spark = NULL,
- low_priority_spark_prev = NULL,
- spark = NULL, prev = NULL;
-
- /* Choose a spark from the local spark queue */
- prev = (rtsSpark*)NULL;
- spark = pending_sparks_hds[proc];
- found = rtsFalse;
-
- // ToDo: check this code & implement local sparking !! -- HWL
- while (!found && spark != (rtsSpark*)NULL)
- {
- ASSERT((prev!=(rtsSpark*)NULL || spark==pending_sparks_hds[proc]) &&
- (prev==(rtsSpark*)NULL || prev->next==spark) &&
- (spark->prev==prev));
- node = spark->node;
- if (!closure_SHOULD_SPARK(node))
- {
- IF_GRAN_DEBUG(checkSparkQ,
- debugBelch("^^ pruning spark %p (node %p) in gimme_spark",
- spark, node));
-
- if (RtsFlags.GranFlags.GranSimStats.Sparks)
- DumpRawGranEvent(proc, (PEs)0, SP_PRUNED,(StgTSO*)NULL,
- spark->node, spark->name, spark_queue_len(proc));
-
- ASSERT(spark != (rtsSpark*)NULL);
- ASSERT(SparksAvail>0);
- --SparksAvail;
-
- ASSERT(prev==(rtsSpark*)NULL || prev->next==spark);
- spark = delete_from_sparkq (spark, proc, rtsTrue);
- if (spark != (rtsSpark*)NULL)
- prev = spark->prev;
- continue;
- }
- /* -- node should eventually be sparked */
- else if (RtsFlags.GranFlags.PreferSparksOfLocalNodes &&
- !IS_LOCAL_TO(PROCS(node),CurrentProc))
- {
- barf("Local sparking not yet implemented");
-
- /* Remember first low priority spark */
- if (spark_of_non_local_node==(rtsSpark*)NULL) {
- spark_of_non_local_node_prev = prev;
- spark_of_non_local_node = spark;
- }
-
- if (spark->next == (rtsSpark*)NULL) {
- /* ASSERT(spark==SparkQueueTl); just for testing */
- prev = spark_of_non_local_node_prev;
- spark = spark_of_non_local_node;
- found = rtsTrue;
- break;
- }
-
-# if defined(GRAN) && defined(GRAN_CHECK)
- /* Should never happen; just for testing
- if (spark==pending_sparks_tl) {
- debugBelch("ReSchedule: Last spark != SparkQueueTl\n");
- stg_exit(EXIT_FAILURE);
- } */
-# endif
- prev = spark;
- spark = spark->next;
- ASSERT(SparksAvail>0);
- --SparksAvail;
- continue;
- }
- else if ( RtsFlags.GranFlags.DoPrioritySparking ||
- (spark->gran_info >= RtsFlags.GranFlags.SparkPriority2) )
- {
- if (RtsFlags.GranFlags.DoPrioritySparking)
- barf("Priority sparking not yet implemented");
-
- found = rtsTrue;
- }
-#if 0
- else /* only used if SparkPriority2 is defined */
- {
- /* ToDo: fix the code below and re-integrate it */
- /* Remember first low priority spark */
- if (low_priority_spark==(rtsSpark*)NULL) {
- low_priority_spark_prev = prev;
- low_priority_spark = spark;
- }
-
- if (spark->next == (rtsSpark*)NULL) {
- /* ASSERT(spark==spark_queue_tl); just for testing */
- prev = low_priority_spark_prev;
- spark = low_priority_spark;
- found = rtsTrue; /* take low pri spark => rc is 2 */
- break;
- }
-
- /* Should never happen; just for testing
- if (spark==pending_sparks_tl) {
- debugBelch("ReSchedule: Last spark != SparkQueueTl\n");
- stg_exit(EXIT_FAILURE);
- break;
- } */
- prev = spark;
- spark = spark->next;
-
- IF_GRAN_DEBUG(pri,
- debugBelch("++ Ignoring spark of priority %u (SparkPriority=%u); node=%p; name=%u\n",
- spark->gran_info, RtsFlags.GranFlags.SparkPriority,
- spark->node, spark->name);)
- }
-#endif
- } /* while (spark!=NULL && !found) */
-
- *spark_res = spark;
- *found_res = found;
-}
-
-/*
- Turn the spark into a thread.
- In GranSim this basically means scheduling a StartThread event for the
- node pointed to by the spark at some point in the future.
- (was munch_spark in the old RTS)
-*/
-rtsBool
-activateSpark (rtsEvent *event, rtsSparkQ spark)
-{
- PEs proc = event->proc, /* proc to search for work */
- creator = event->creator; /* proc that requested work */
- StgTSO* tso;
- StgClosure* node;
- rtsTime spark_arrival_time;
-
- /*
- We've found a node on PE proc requested by PE creator.
- If proc==creator we can turn the spark into a thread immediately;
- otherwise we schedule a MoveSpark event on the requesting PE
- */
-
- /* DaH Qu' yIchen */
- if (proc!=creator) {
-
- /* only possible if we simulate GUM style fishing */
- ASSERT(RtsFlags.GranFlags.Fishing);
-
- /* Message packing costs for sending a Fish; qeq jabbI'ID */
- CurrentTime[proc] += RtsFlags.GranFlags.Costs.mpacktime;
-
- if (RtsFlags.GranFlags.GranSimStats.Sparks)
- DumpRawGranEvent(proc, (PEs)0, SP_EXPORTED,
- (StgTSO*)NULL, spark->node,
- spark->name, spark_queue_len(proc));
-
- /* time of the spark arrival on the remote PE */
- spark_arrival_time = CurrentTime[proc] + RtsFlags.GranFlags.Costs.latency;
-
- new_event(creator, proc, spark_arrival_time,
- MoveSpark,
- (StgTSO*)NULL, spark->node, spark);
-
- CurrentTime[proc] += RtsFlags.GranFlags.Costs.mtidytime;
-
- } else { /* proc==creator i.e. turn the spark into a thread */
-
- if ( RtsFlags.GranFlags.GranSimStats.Global &&
- spark->gran_info < RtsFlags.GranFlags.SparkPriority2 ) {
-
- globalGranStats.tot_low_pri_sparks++;
- IF_GRAN_DEBUG(pri,
- debugBelch("++ No high priority spark available; low priority (%u) spark chosen: node=%p; name=%u\n",
- spark->gran_info,
- spark->node, spark->name));
- }
-
- CurrentTime[proc] += RtsFlags.GranFlags.Costs.threadcreatetime;
-
- node = spark->node;
-
-# if 0
- /* ToDo: fix the GC interface and move to StartThread handling-- HWL */
- if (GARBAGE COLLECTION IS NECESSARY) {
- /* Some kind of backoff needed here in case there's too little heap */
-# if defined(GRAN_CHECK) && defined(GRAN)
- if (RtsFlags.GcFlags.giveStats)
- fprintf(RtsFlags.GcFlags.statsFile,"***** vIS Qu' chen veQ boSwI'; spark=%p, node=%p; name=%u\n",
- /* (found==2 ? "no hi pri spark" : "hi pri spark"), */
- spark, node, spark->name);
-# endif
- new_event(CurrentProc, CurrentProc, CurrentTime[CurrentProc]+1,
- FindWork,
- (StgTSO*)NULL, (StgClosure*)NULL, (rtsSpark*)NULL);
- barf("//// activateSpark: out of heap ; ToDo: call GarbageCollect()");
- GarbageCollect(GetRoots, rtsFalse);
- // HWL old: ReallyPerformThreadGC(TSO_HS+TSO_CTS_SIZE,rtsFalse);
- // HWL old: SAVE_Hp -= TSO_HS+TSO_CTS_SIZE;
- spark = NULL;
- return; /* was: continue; */ /* to the next event, eventually */
- }
-# endif