X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=rts%2FThreads.c;h=f824d021d47acf6683f56c7cd0bd5ffbbd692640;hp=28820c8d440e8e1d59cb2daec2d180e6e674889c;hb=7408b39235bccdcde48df2a73337ff976fbc09b7;hpb=a2a67cd520b9841114d69a87a423dabcb3b4368e diff --git a/rts/Threads.c b/rts/Threads.c index 28820c8..f824d02 100644 --- a/rts/Threads.c +++ b/rts/Threads.c @@ -63,7 +63,7 @@ createThread(Capability *cap, nat size) } size = round_to_mblocks(size); - tso = (StgTSO *)allocateLocal(cap, size); + tso = (StgTSO *)allocate(cap, size); stack_size = size - TSO_STRUCT_SIZEW; TICK_ALLOC_TSO(stack_size, 0); @@ -74,8 +74,9 @@ createThread(Capability *cap, nat size) tso->what_next = ThreadRunGHC; tso->why_blocked = NotBlocked; - tso->blocked_exceptions = END_TSO_QUEUE; - tso->flags = TSO_DIRTY; + tso->blocked_exceptions = END_BLOCKED_EXCEPTIONS_QUEUE; + tso->flags = 0; + tso->dirty = 1; tso->saved_errno = 0; tso->bound = NULL; @@ -101,15 +102,13 @@ createThread(Capability *cap, nat size) */ ACQUIRE_LOCK(&sched_mutex); tso->id = next_thread_id++; // while we have the mutex - tso->global_link = g0s0->threads; - g0s0->threads = tso; + tso->global_link = g0->threads; + g0->threads = tso; RELEASE_LOCK(&sched_mutex); - postEvent (cap, EVENT_CREATE_THREAD, tso->id, 0); + // ToDo: report the stack size in the event? + traceEventCreateThread(cap, tso); - debugTrace(DEBUG_sched, - "created thread %ld, stack size = %lx words", - (long)tso->id, (long)tso->stack_size); return tso; } @@ -219,8 +218,9 @@ unblockOne_ (Capability *cap, StgTSO *tso, // NO, might be a WHITEHOLE: ASSERT(get_itbl(tso)->type == TSO); ASSERT(tso->why_blocked != NotBlocked); + ASSERT(tso->why_blocked != BlockedOnMsgWakeup || + tso->block_info.closure->header.info == &stg_IND_info); - tso->why_blocked = NotBlocked; next = tso->_link; tso->_link = END_TSO_QUEUE; @@ -231,11 +231,13 @@ unblockOne_ (Capability *cap, StgTSO *tso, // We are waking up this thread on the current Capability, which // might involve migrating it from the Capability it was last on. if (tso->bound) { - ASSERT(tso->bound->cap == tso->cap); - tso->bound->cap = cap; + ASSERT(tso->bound->task->cap == tso->cap); + tso->bound->task->cap = cap; } tso->cap = cap; + write_barrier(); + tso->why_blocked = NotBlocked; appendToRunQueue(cap,tso); // context-switch soonish so we can migrate the new thread if @@ -247,6 +249,7 @@ unblockOne_ (Capability *cap, StgTSO *tso, wakeupThreadOnCapability(cap, tso->cap, tso); } #else + tso->why_blocked = NotBlocked; appendToRunQueue(cap,tso); // context-switch soonish so we can migrate the new thread if @@ -255,10 +258,7 @@ unblockOne_ (Capability *cap, StgTSO *tso, cap->context_switch = 1; #endif - postEvent (cap, EVENT_THREAD_WAKEUP, tso->id, tso->cap->no); - - debugTrace(DEBUG_sched, "waking up thread %ld on cap %d", - (long)tso->id, tso->cap->no); + traceEventThreadWakeup (cap, tso, tso->cap->no); return next; } @@ -331,13 +331,15 @@ printThreadBlockage(StgTSO *tso) case BlockedOnMVar: debugBelch("is blocked on an MVar @ %p", tso->block_info.closure); break; - case BlockedOnException: - debugBelch("is blocked on delivering an exception to thread %lu", - (unsigned long)tso->block_info.tso->id); - break; case BlockedOnBlackHole: debugBelch("is blocked on a black hole"); break; + case BlockedOnMsgWakeup: + debugBelch("is blocked on a wakeup message"); + break; + case BlockedOnMsgThrowTo: + debugBelch("is blocked on a throwto message"); + break; case NotBlocked: debugBelch("is not blocked"); break; @@ -356,6 +358,7 @@ printThreadBlockage(StgTSO *tso) } } + void printThreadStatus(StgTSO *t) { @@ -377,7 +380,7 @@ printThreadStatus(StgTSO *t) default: printThreadBlockage(t); } - if (t->flags & TSO_DIRTY) { + if (t->dirty) { debugBelch(" (TSO_DIRTY)"); } else if (t->flags & TSO_LINK_DIRTY) { debugBelch(" (TSO_LINK_DIRTY)"); @@ -390,24 +393,10 @@ void printAllThreads(void) { StgTSO *t, *next; - nat i, s; + nat i, g; Capability *cap; -# if defined(GRAN) - char time_string[TIME_STR_LEN], node_str[NODE_STR_LEN]; - ullong_format_string(TIME_ON_PROC(CurrentProc), - time_string, rtsFalse/*no commas!*/); - - debugBelch("all threads at [%s]:\n", time_string); -# elif defined(PARALLEL_HASKELL) - char time_string[TIME_STR_LEN], node_str[NODE_STR_LEN]; - ullong_format_string(CURRENT_TIME, - time_string, rtsFalse/*no commas!*/); - - debugBelch("all threads at [%s]:\n", time_string); -# else debugBelch("all threads:\n"); -# endif for (i = 0; i < n_capabilities; i++) { cap = &capabilities[i]; @@ -418,8 +407,8 @@ printAllThreads(void) } debugBelch("other threads:\n"); - for (s = 0; s < total_steps; s++) { - for (t = all_steps[s].threads; t != END_TSO_QUEUE; t = next) { + for (g = 0; g < RtsFlags.GcFlags.generations; g++) { + for (t = generations[g].threads; t != END_TSO_QUEUE; t = next) { if (t->why_blocked != NotBlocked) { printThreadStatus(t); }