X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FThreadPaused.c;h=4882ab2374b148c603661378a8c58c9b2c989816;hb=4adc53ff5eb66b6beef9b38e18f23d00de2d56b4;hp=e76d70fbd5f52b986b3e1fcf9077ebbdea4f6c37;hpb=b33fa57b919b0b315a64662b72203de68958e0a4;p=ghc-hetmet.git diff --git a/rts/ThreadPaused.c b/rts/ThreadPaused.c index e76d70f..4882ab2 100644 --- a/rts/ThreadPaused.c +++ b/rts/ThreadPaused.c @@ -50,7 +50,7 @@ stackSqueeze(StgTSO *tso, StgPtr bottom) current_gap_size = 0; gap = (struct stack_gap *) (tso->sp - sizeofW(StgUpdateFrame)); - while (frame < bottom) { + while (frame <= bottom) { info = get_ret_itbl((StgClosure *)frame); switch (info->i.type) { @@ -74,7 +74,7 @@ stackSqueeze(StgTSO *tso, StgPtr bottom) * screw us up if we don't check. */ if (upd->updatee != updatee && !closure_IND(upd->updatee)) { - UPD_IND_NOLOCK(upd->updatee, updatee); + UPD_IND(upd->updatee, updatee); } // now mark this update frame as a stack gap. The gap @@ -178,6 +178,8 @@ threadPaused(Capability *cap, StgTSO *tso) { StgClosure *frame; StgRetInfoTable *info; + const StgInfoTable *bh_info; + const StgInfoTable *cur_bh_info USED_IF_THREADS; StgClosure *bh; StgPtr stack_end; nat words_to_squeeze = 0; @@ -193,6 +195,10 @@ threadPaused(Capability *cap, StgTSO *tso) maybePerformBlockedException (cap, tso); if (tso->what_next == ThreadKilled) { return; } + // NB. Blackholing is *not* optional, we must either do lazy + // blackholing, or eager blackholing consistently. See Note + // [upd-black-hole] in sm/Scav.c. + stack_end = &tso->stack[tso->stack_size]; frame = (StgClosure *)tso->sp; @@ -200,6 +206,11 @@ threadPaused(Capability *cap, StgTSO *tso) while (1) { // If we've already marked this frame, then stop here. if (frame->header.info == (StgInfoTable *)&stg_marked_upd_frame_info) { + if (prev_was_update_frame) { + words_to_squeeze += sizeofW(StgUpdateFrame); + weight += weight_pending; + weight_pending = 0; + } goto end; } @@ -212,15 +223,22 @@ threadPaused(Capability *cap, StgTSO *tso) SET_INFO(frame, (StgInfoTable *)&stg_marked_upd_frame_info); bh = ((StgUpdateFrame *)frame)->updatee; + bh_info = bh->header.info; - if (closure_IND(bh) || bh->header.info == &stg_BLACKHOLE_info) { +#ifdef THREADED_RTS + retry: +#endif + if (closure_flags[INFO_PTR_TO_STRUCT(bh_info)->type] & _IND + || bh_info == &stg_BLACKHOLE_info) { debugTrace(DEBUG_squeeze, "suspending duplicate work: %ld words of stack", (long)((StgPtr)frame - tso->sp)); // If this closure is already an indirection, then - // suspend the computation up to this point: - suspendComputation(cap,tso,(StgPtr)frame); + // suspend the computation up to this point. + // NB. check raiseAsync() to see what happens when + // we're in a loop (#2783). + suspendComputation(cap,tso,(StgUpdateFrame*)frame); // Now drop the update frame, and arrange to return // the value to the frame underneath: @@ -230,14 +248,12 @@ threadPaused(Capability *cap, StgTSO *tso) // And continue with threadPaused; there might be // yet more computation to suspend. - threadPaused(cap,tso); - return; + frame = (StgClosure *)tso->sp + 2; + prev_was_update_frame = rtsFalse; + continue; } if (bh->header.info != &stg_CAF_BLACKHOLE_info) { -#if (!defined(LAZY_BLACKHOLING)) && defined(DEBUG) - debugBelch("Unexpected lazy BHing required at 0x%04lx\n",(long)bh); -#endif // zero out the slop so that the sanity checker can tell // where the next closure is. DEBUG_FILL_SLOP(bh); @@ -246,7 +262,20 @@ threadPaused(Capability *cap, StgTSO *tso) // We pretend that bh is now dead. LDV_recordDead_FILL_SLOP_DYNAMIC((StgClosure *)bh); #endif + // an EAGER_BLACKHOLE gets turned into a BLACKHOLE here. +#ifdef THREADED_RTS + cur_bh_info = (const StgInfoTable *) + cas((StgVolatilePtr)&bh->header.info, + (StgWord)bh_info, + (StgWord)&stg_BLACKHOLE_info); + + if (cur_bh_info != bh_info) { + bh_info = cur_bh_info; + goto retry; + } +#else SET_INFO(bh,&stg_BLACKHOLE_info); +#endif // We pretend that bh has just been created. LDV_RECORD_CREATE(bh); @@ -285,7 +314,7 @@ end: // the number of words we have to shift down is less than the // number of stack words we squeeze away by doing so. if (RtsFlags.GcFlags.squeezeUpdFrames == rtsTrue && - weight < words_to_squeeze) { + ((weight <= 5 && words_to_squeeze > 0) || weight < words_to_squeeze)) { stackSqueeze(tso, (StgPtr)frame); } }