-/* ----------------------------------------------------------------------------
- * Process an event (GRAN only)
- * ------------------------------------------------------------------------- */
-
-#if defined(GRAN)
-static StgTSO *
-scheduleProcessEvent(rtsEvent *event)
-{
- StgTSO *t;
-
- if (RtsFlags.GranFlags.Light)
- GranSimLight_enter_system(event, &ActiveTSO); // adjust ActiveTSO etc
-
- /* adjust time based on time-stamp */
- if (event->time > CurrentTime[CurrentProc] &&
- event->evttype != ContinueThread)
- CurrentTime[CurrentProc] = event->time;
-
- /* Deal with the idle PEs (may issue FindWork or MoveSpark events) */
- if (!RtsFlags.GranFlags.Light)
- handleIdlePEs();
-
- IF_DEBUG(gran, debugBelch("GRAN: switch by event-type\n"));
-
- /* main event dispatcher in GranSim */
- switch (event->evttype) {
- /* Should just be continuing execution */
- case ContinueThread:
- IF_DEBUG(gran, debugBelch("GRAN: doing ContinueThread\n"));
- /* ToDo: check assertion
- ASSERT(run_queue_hd != (StgTSO*)NULL &&
- run_queue_hd != END_TSO_QUEUE);
- */
- /* Ignore ContinueThreads for fetching threads (if synchr comm) */
- if (!RtsFlags.GranFlags.DoAsyncFetch &&
- procStatus[CurrentProc]==Fetching) {
- debugBelch("ghuH: Spurious ContinueThread while Fetching ignored; TSO %d (%p) [PE %d]\n",
- CurrentTSO->id, CurrentTSO, CurrentProc);
- goto next_thread;
- }
- /* Ignore ContinueThreads for completed threads */
- if (CurrentTSO->what_next == ThreadComplete) {
- debugBelch("ghuH: found a ContinueThread event for completed thread %d (%p) [PE %d] (ignoring ContinueThread)\n",
- CurrentTSO->id, CurrentTSO, CurrentProc);
- goto next_thread;
- }
- /* Ignore ContinueThreads for threads that are being migrated */
- if (PROCS(CurrentTSO)==Nowhere) {
- debugBelch("ghuH: trying to run the migrating TSO %d (%p) [PE %d] (ignoring ContinueThread)\n",
- CurrentTSO->id, CurrentTSO, CurrentProc);
- goto next_thread;
- }
- /* The thread should be at the beginning of the run queue */
- if (CurrentTSO!=run_queue_hds[CurrentProc]) {
- debugBelch("ghuH: TSO %d (%p) [PE %d] is not at the start of the run_queue when doing a ContinueThread\n",
- CurrentTSO->id, CurrentTSO, CurrentProc);
- break; // run the thread anyway
- }
- /*
- new_event(proc, proc, CurrentTime[proc],
- FindWork,
- (StgTSO*)NULL, (StgClosure*)NULL, (rtsSpark*)NULL);
- goto next_thread;
- */ /* Catches superfluous CONTINUEs -- should be unnecessary */
- break; // now actually run the thread; DaH Qu'vam yImuHbej
-
- case FetchNode:
- do_the_fetchnode(event);
- goto next_thread; /* handle next event in event queue */
-
- case GlobalBlock:
- do_the_globalblock(event);
- goto next_thread; /* handle next event in event queue */
-
- case FetchReply:
- do_the_fetchreply(event);
- goto next_thread; /* handle next event in event queue */
-
- case UnblockThread: /* Move from the blocked queue to the tail of */
- do_the_unblock(event);
- goto next_thread; /* handle next event in event queue */
-
- case ResumeThread: /* Move from the blocked queue to the tail of */
- /* the runnable queue ( i.e. Qu' SImqa'lu') */
- event->tso->gran.blocktime +=
- CurrentTime[CurrentProc] - event->tso->gran.blockedat;
- do_the_startthread(event);
- goto next_thread; /* handle next event in event queue */
-
- case StartThread:
- do_the_startthread(event);
- goto next_thread; /* handle next event in event queue */
-
- case MoveThread:
- do_the_movethread(event);
- goto next_thread; /* handle next event in event queue */
-
- case MoveSpark:
- do_the_movespark(event);
- goto next_thread; /* handle next event in event queue */
-
- case FindWork:
- do_the_findwork(event);
- goto next_thread; /* handle next event in event queue */
-
- default:
- barf("Illegal event type %u\n", event->evttype);
- } /* switch */
-
- /* This point was scheduler_loop in the old RTS */
-
- IF_DEBUG(gran, debugBelch("GRAN: after main switch\n"));
-
- TimeOfLastEvent = CurrentTime[CurrentProc];
- TimeOfNextEvent = get_time_of_next_event();
- IgnoreEvents=(TimeOfNextEvent==0); // HWL HACK
- // CurrentTSO = ThreadQueueHd;
-
- IF_DEBUG(gran, debugBelch("GRAN: time of next event is: %ld\n",
- TimeOfNextEvent));
-
- if (RtsFlags.GranFlags.Light)
- GranSimLight_leave_system(event, &ActiveTSO);
-
- EndOfTimeSlice = CurrentTime[CurrentProc]+RtsFlags.GranFlags.time_slice;
-
- IF_DEBUG(gran,
- debugBelch("GRAN: end of time-slice is %#lx\n", EndOfTimeSlice));
-
- /* in a GranSim setup the TSO stays on the run queue */
- t = CurrentTSO;
- /* Take a thread from the run queue. */
- POP_RUN_QUEUE(t); // take_off_run_queue(t);
-
- IF_DEBUG(gran,
- debugBelch("GRAN: About to run current thread, which is\n");
- G_TSO(t,5));
-
- context_switch = 0; // turned on via GranYield, checking events and time slice
-
- IF_DEBUG(gran,
- DumpGranEvent(GR_SCHEDULE, t));
-
- procStatus[CurrentProc] = Busy;
-}
-#endif // GRAN