From 50de6034343abc93a7b01daccff34121042c0e7c Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 28 Nov 2011 16:48:43 +0000 Subject: Make profiling work with multiple capabilities (+RTS -N) This means that both time and heap profiling work for parallel programs. Main internal changes: - CCCS is no longer a global variable; it is now another pseudo-register in the StgRegTable struct. Thus every Capability has its own CCCS. - There is a new built-in CCS called "IDLE", which records ticks for Capabilities in the idle state. If you profile a single-threaded program with +RTS -N2, you'll see about 50% of time in "IDLE". - There is appropriate locking in rts/Profiling.c to protect the shared cost-centre-stack data structures. This patch does enough to get it working, I have cut one big corner: the cost-centre-stack data structure is still shared amongst all Capabilities, which means that multiple Capabilities will race when updating the "allocations" and "entries" fields of a CCS. Not only does this give unpredictable results, but it runs very slowly due to cache line bouncing. It is strongly recommended that you use -fno-prof-count-entries to disable the "entries" count when profiling parallel programs. (I shall add a note to this effect to the docs). --- rts/Schedule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rts/Schedule.c') diff --git a/rts/Schedule.c b/rts/Schedule.c index 8c305008ae..04a66e31df 100644 --- a/rts/Schedule.c +++ b/rts/Schedule.c @@ -501,7 +501,7 @@ run_thread: // Costs for the scheduler are assigned to CCS_SYSTEM stopHeapProfTimer(); #if defined(PROFILING) - CCCS = CCS_SYSTEM; + cap->r.rCCCS = CCS_SYSTEM; #endif schedulePostRunThread(cap,t); @@ -2262,7 +2262,7 @@ raiseExceptionHelper (StgRegTable *reg, StgTSO *tso, StgClosure *exception) if (raise_closure == NULL) { raise_closure = (StgThunk *)allocate(cap,sizeofW(StgThunk)+1); - SET_HDR(raise_closure, &stg_raise_info, CCCS); + SET_HDR(raise_closure, &stg_raise_info, cap->r.rCCCS); raise_closure->payload[0] = exception; } updateThunk(cap, tso, ((StgUpdateFrame *)p)->updatee, -- cgit v1.2.1