From 5ddee764beb312933256096d03df7c3ec47ac452 Mon Sep 17 00:00:00 2001 From: Kirsten Chevalier Date: Wed, 7 Feb 2007 08:14:04 +0000 Subject: Lightweight ticky-ticky profiling The following changes restore ticky-ticky profiling to functionality from its formerly bit-rotted state. Sort of. (It got bit-rotted as part of the switch to the C-- back-end.) The way that ticky-ticky is supposed to work is documented in Section 5.7 of the GHC manual (though the manual doesn't mention that it hasn't worked since sometime around 6.0, alas). Changes from this are as follows (which I'll document on the wiki): * In the past, you had to build all of the libraries with way=t in order to use ticky-ticky, because it entailed a different closure layout. No longer. You still need to do make way=t in rts/ in order to build the ticky RTS, but you should now be able to mix ticky and non-ticky modules. * Some of the counters that worked in the past aren't implemented yet. I was originally just trying to get entry counts to work, so those should be correct. The list of counters was never documented in the first place, so I hope it's not too much of a disaster that some don't appear anymore. Someday, someone (perhaps me) should document all the counters and what they do. For now, all of the counters are either accurate (or at least as accurate as they always were), zero, or missing from the ticky profiling report altogether. This hasn't been particularly well-tested, but these changes shouldn't affect anything except when compiling with -fticky-ticky (famous last words...) Implementation details: I got rid of StgTicky.h, which in the past had the macros and declarations for all of the ticky counters. Now, those macros are defined in Cmm.h. StgTicky.h was still there for inclusion in C code. Now, any remaining C code simply cannot call the ticky macros -- or rather, they do call those macros, but from the perspective of C code, they're defined as no-ops. (This shouldn't be too big a problem.) I added a new file TickyCounter.h that has all the declarations for ticky counters, as well as dummy macros for use in C code. Someday, these declarations should really be automatically generated, since they need to be kept consistent with the macros defined in Cmm.h. Other changes include getting rid of the header that was getting added to closures before, and getting rid of various code having to do with eager blackholing and permanent indirections (the changes under compiler/ and rts/Updates.*). --- rts/RtsStartup.c | 2 +- rts/StgMiscClosures.cmm | 2 +- rts/Ticky.c | 36 ++++++++++++++++++++-- rts/Updates.cmm | 5 ++-- rts/Updates.h | 80 +++++-------------------------------------------- 5 files changed, 46 insertions(+), 79 deletions(-) (limited to 'rts') diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index 7193876970..deb38e05d5 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -397,7 +397,7 @@ hs_exit(void) /* stop the ticker */ stopTimer(); - + /* reset the standard file descriptors to blocking mode */ resetNonBlockingFd(0); resetNonBlockingFd(1); diff --git a/rts/StgMiscClosures.cmm b/rts/StgMiscClosures.cmm index 0323618ba0..93de540d88 100644 --- a/rts/StgMiscClosures.cmm +++ b/rts/StgMiscClosures.cmm @@ -294,7 +294,7 @@ INFO_TABLE(stg_IND_OLDGEN_PERM,1,0,IND_OLDGEN_PERM,"IND_OLDGEN_PERM","IND_OLDGEN #if defined(TICKY_TICKY) && !defined(PROFILING) /* TICKY_TICKY && !PROFILING means PERM_IND *replaces* an IND, rather than being extra */ - TICK_ENT_PERM_IND(R1); /* tick */ + TICK_ENT_PERM_IND(); /* tick */ #endif LDV_ENTER(R1); diff --git a/rts/Ticky.c b/rts/Ticky.c index 294e12bdda..d6ac172e51 100644 --- a/rts/Ticky.c +++ b/rts/Ticky.c @@ -11,6 +11,7 @@ #define TICKY_C /* define those variables */ #include "PosixSource.h" #include "Rts.h" +#include "TickyCounters.h" #include "RtsFlags.h" #include "Ticky.h" @@ -30,6 +31,7 @@ void PrintTickyInfo(void) { unsigned long i; + unsigned long tot_allocs = /* total number of things allocated */ ALLOC_FUN_ctr + ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr + ALLOC_CON_ctr + ALLOC_TUP_ctr + + ALLOC_TSO_ctr + ALLOC_BH_ctr + ALLOC_PAP_ctr + ALLOC_PRIM_ctr @@ -67,6 +69,7 @@ PrintTickyInfo(void) unsigned long tot_thk_enters = ENT_STATIC_THK_ctr + ENT_DYN_THK_ctr; unsigned long tot_con_enters = ENT_STATIC_CON_ctr + ENT_DYN_CON_ctr; + unsigned long tot_fun_direct_enters = ENT_STATIC_FUN_DIRECT_ctr + ENT_DYN_FUN_DIRECT_ctr; unsigned long tot_ind_enters = ENT_STATIC_IND_ctr + ENT_DYN_IND_ctr; @@ -84,12 +87,13 @@ PrintTickyInfo(void) unsigned long tot_tail_calls = UNKNOWN_CALL_ctr + tot_known_calls; - unsigned long tot_enters = - tot_con_enters + tot_fun_direct_enters + + unsigned long tot_enters = + tot_con_enters + tot_fun_direct_enters + tot_ind_enters + ENT_PERM_IND_ctr + ENT_PAP_ctr + tot_thk_enters; unsigned long jump_direct_enters = tot_enters - ENT_VIA_NODE_ctr; + unsigned long tot_returns = RET_NEW_ctr + RET_OLD_ctr + RET_UNBOXED_TUP_ctr; @@ -106,6 +110,8 @@ PrintTickyInfo(void) FILE *tf = RtsFlags.TickyFlags.tickyFile; + /* krc: avoid dealing with this just now */ +#if FALSE fprintf(tf,"\n\nALLOCATIONS: %ld (%ld words total: %ld admin, %ld goods, %ld slop)\n", tot_allocs, tot_wds, tot_adm_wds, tot_gds_wds, tot_slp_wds); fprintf(tf,"\t\t\t\ttotal words:\t 2 3 4 5 6+\n"); @@ -122,6 +128,7 @@ PrintTickyInfo(void) PC(INTAVG(ALLOC_FUN_ctr, tot_allocs))); if (ALLOC_FUN_ctr != 0) fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(FUN)); + fprintf(tf,"\n%7ld (%5.1f%%) thunks", ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr, @@ -185,12 +192,16 @@ PrintTickyInfo(void) if (ALLOC_BF_ctr != 0) fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(BF)); #endif + fprintf(tf,"\n"); fprintf(tf,"\nTotal storage-manager allocations: %ld (%ld words)\n\t[%ld words lost to speculative heap-checks]\n", ALLOC_HEAP_ctr, ALLOC_HEAP_tot, ALLOC_HEAP_tot - tot_wds); +#endif /* FALSE */ + fprintf(tf,"\nSTACK USAGE:\n"); /* NB: some bits are direction sensitive */ + fprintf(tf,"\nENTERS: %ld of which %ld (%.1f%%) direct to the entry code\n\t\t [the rest indirected via Node's info ptr]\n", tot_enters, jump_direct_enters, @@ -208,6 +219,7 @@ PrintTickyInfo(void) ENT_PERM_IND_ctr, PC(INTAVG(ENT_PERM_IND_ctr,tot_enters))); + fprintf(tf,"\nFUNCTION ENTRIES: %ld\n", tot_fun_direct_enters); fprintf(tf, "\nTAIL CALLS: %ld, of which %ld (%.lf%%) were to known functions\n", @@ -232,6 +244,9 @@ PrintTickyInfo(void) VEC_RETURN_ctr, PC(INTAVG(VEC_RETURN_ctr,tot_returns))); + /* krc: comment out some of this stuff temporarily */ + + /* fprintf(tf, "\nRET_NEW: %7ld: ", RET_NEW_ctr); for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%", PC(INTAVG(RET_NEW_hst[i],RET_NEW_ctr))); } @@ -249,6 +264,7 @@ PrintTickyInfo(void) for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%", PC(INTAVG(RET_VEC_RETURN_hst[i],VEC_RETURN_ctr))); } fprintf(tf, "\n"); + */ fprintf(tf,"\nUPDATE FRAMES: %ld (%ld omitted from thunks)", UPDF_PUSHED_ctr, @@ -274,6 +290,8 @@ PrintTickyInfo(void) UPD_SQUEEZED_ctr, PC(INTAVG(UPD_SQUEEZED_ctr, tot_updates))); + /* krc: also avoid dealing with this for now */ +#if FALSE fprintf(tf, "\nUPD_CON_IN_NEW: %7ld: ", UPD_CON_IN_NEW_ctr); for (i = 0; i < 9; i++) { fprintf(tf, "%7ld", UPD_CON_IN_NEW_hst[i]); } fprintf(tf, "\n"); @@ -283,6 +301,7 @@ PrintTickyInfo(void) fprintf(tf, "UPD_PAP_IN_NEW: %7ld: ", UPD_PAP_IN_NEW_ctr); for (i = 0; i < 9; i++) { fprintf(tf, "%7ld", UPD_PAP_IN_NEW_hst[i]); } fprintf(tf, "\n"); +#endif if (tot_gengc_updates != 0) { fprintf(tf,"\nNEW GEN UPDATES: %9ld (%5.1f%%)\n", @@ -320,6 +339,8 @@ PrintTickyInfo(void) PR_CTR(ALLOC_FUN_adm); PR_CTR(ALLOC_FUN_gds); PR_CTR(ALLOC_FUN_slp); + + /* krc: comment out some of this stuff temporarily PR_HST(ALLOC_FUN_hst,0); PR_HST(ALLOC_FUN_hst,1); PR_HST(ALLOC_FUN_hst,2); @@ -420,6 +441,7 @@ PrintTickyInfo(void) PR_HST(ALLOC_BF_hst,3); PR_HST(ALLOC_BF_hst,4); #endif + */ PR_CTR(ENT_VIA_NODE_ctr); PR_CTR(ENT_STATIC_CON_ctr); @@ -481,6 +503,9 @@ PrintTickyInfo(void) PR_CTR(SLOW_CALL_PAP_CORRECT_ctr); PR_CTR(SLOW_CALL_PAP_TOO_MANY_ctr); PR_CTR(SLOW_CALL_UNEVALD_ctr); + + /* krc: put off till later... */ +#if FALSE PR_HST(SLOW_CALL_hst,0); PR_HST(SLOW_CALL_hst,1); PR_HST(SLOW_CALL_hst,2); @@ -489,12 +514,15 @@ PrintTickyInfo(void) PR_HST(SLOW_CALL_hst,5); PR_HST(SLOW_CALL_hst,6); PR_HST(SLOW_CALL_hst,7); +#endif PR_CTR(RET_NEW_ctr); PR_CTR(RET_OLD_ctr); PR_CTR(RET_UNBOXED_TUP_ctr); PR_CTR(VEC_RETURN_ctr); + /* krc: put off till later... */ +#if FALSE PR_HST(RET_NEW_hst,0); PR_HST(RET_NEW_hst,1); PR_HST(RET_NEW_hst,2); @@ -531,6 +559,7 @@ PrintTickyInfo(void) PR_HST(RET_VEC_RETURN_hst,6); PR_HST(RET_VEC_RETURN_hst,7); PR_HST(RET_VEC_RETURN_hst,8); +#endif /* FALSE */ PR_CTR(UPDF_OMITTED_ctr); PR_CTR(UPDF_PUSHED_ctr); @@ -550,6 +579,8 @@ PrintTickyInfo(void) PR_CTR(UPD_CAF_BH_UPDATABLE_ctr); PR_CTR(UPD_CAF_BH_SINGLE_ENTRY_ctr); + /* krc: put off till later...*/ +#if FALSE PR_HST(UPD_CON_IN_NEW_hst,0); PR_HST(UPD_CON_IN_NEW_hst,1); PR_HST(UPD_CON_IN_NEW_hst,2); @@ -568,6 +599,7 @@ PrintTickyInfo(void) PR_HST(UPD_PAP_IN_NEW_hst,6); PR_HST(UPD_PAP_IN_NEW_hst,7); PR_HST(UPD_PAP_IN_NEW_hst,8); +#endif /* FALSE */ PR_CTR(UPD_NEW_IND_ctr); /* see comment on ENT_PERM_IND_ctr */ diff --git a/rts/Updates.cmm b/rts/Updates.cmm index 1d2fc5fe0f..6265f90dcb 100644 --- a/rts/Updates.cmm +++ b/rts/Updates.cmm @@ -10,6 +10,7 @@ * * ---------------------------------------------------------------------------*/ + #include "Cmm.h" #include "Updates.h" #include "StgLdvProf.h" @@ -52,8 +53,8 @@ /* remove the update frame from the stack */ \ Sp = Sp + SIZEOF_StgUpdateFrame; \ \ - /* ToDo: it might be a PAP, so we should check... */ \ - TICK_UPD_CON_IN_NEW(sizeW_fromITBL(%GET_STD_INFO(updatee))); \ + /* ToDo: it might be a PAP, so we should check... */ \ + TICK_UPD_CON_IN_NEW(sizeW_fromITBL(%GET_STD_INFO(updatee))); \ \ UPD_SPEC_IND(updatee, ind_info, R1, jump (ret)); \ } diff --git a/rts/Updates.h b/rts/Updates.h index abca78817d..3461c91144 100644 --- a/rts/Updates.h +++ b/rts/Updates.h @@ -23,21 +23,14 @@ -------------------------------------------------------------------------- */ -#ifdef TICKY_TICKY -# define UPD_IND(updclosure, heapptr) \ - UPD_PERM_IND(updclosure,heapptr) -# define UPD_SPEC_IND(updclosure, ind_info, heapptr, and_then) \ - UPD_PERM_IND(updclosure,heapptr); and_then -#else # define SEMI ; # define UPD_IND(updclosure, heapptr) \ UPD_REAL_IND(updclosure,INFO_PTR(stg_IND_info),heapptr,SEMI) # define UPD_SPEC_IND(updclosure, ind_info, heapptr, and_then) \ UPD_REAL_IND(updclosure,ind_info,heapptr,and_then) -#endif /* These macros have to work in both C and C--, so here's the - * impedence matching: + * impedance matching: */ #ifdef CMINUSMINUS #define BLOCK_BEGIN @@ -57,9 +50,10 @@ #define ARG_PTR /* nothing */ #endif -/* UPD_IND actually does a PERM_IND if TICKY_TICKY is on; - if you *really* need an IND use UPD_REAL_IND - */ +/* krc: there used to be an UPD_REAL_IND and an + UPD_PERM_IND, the latter of which was used for + ticky and cost-centre profiling. + for now, we just have UPD_REAL_IND. */ #define UPD_REAL_IND(updclosure, ind_info, heapptr, and_then) \ BLOCK_BEGIN \ DECLARE_IPTR(info); \ @@ -70,34 +64,18 @@ and_then); \ BLOCK_END -#if defined(PROFILING) || defined(TICKY_TICKY) -#define UPD_PERM_IND(updclosure, heapptr) \ - BLOCK_BEGIN \ - updateWithPermIndirection(updclosure, \ - heapptr); \ - BLOCK_END -#endif - #if defined(RTS_SUPPORTS_THREADS) -# ifdef TICKY_TICKY -# define UPD_IND_NOLOCK(updclosure, heapptr) \ - BLOCK_BEGIN \ - updateWithPermIndirection(updclosure, \ - heapptr); \ - BLOCK_END -# else # define UPD_IND_NOLOCK(updclosure, heapptr) \ BLOCK_BEGIN \ updateWithIndirection(INFO_PTR(stg_IND_info), \ updclosure, \ heapptr,); \ BLOCK_END -# endif #else #define UPD_IND_NOLOCK(updclosure,heapptr) UPD_IND(updclosure,heapptr) -#endif +#endif /* RTS_SUPPORTS_THREADS */ /* ----------------------------------------------------------------------------- Awaken any threads waiting on a blocking queue (BLACKHOLE_BQ). @@ -321,49 +299,5 @@ no_slop: and_then; \ } \ } -#endif - -/* The permanent indirection version isn't performance critical. We - * therefore use an inline C function instead of the C-- macro. - */ -#ifndef CMINUSMINUS -INLINE_HEADER void -updateWithPermIndirection(StgClosure *p1, - StgClosure *p2) -{ - bdescr *bd; - - ASSERT( p1 != p2 && !closure_IND(p1) ); - - /* - * @LDV profiling - * Destroy the old closure. - * Nb: LDV_* stuff cannot mix with ticky-ticky - */ - LDV_RECORD_DEAD_FILL_SLOP_DYNAMIC(p1); - - bd = Bdescr((P_)p1); - if (bd->gen_no != 0) { - recordMutableGenLock(p1, &generations[bd->gen_no]); - ((StgInd *)p1)->indirectee = p2; - SET_INFO(p1, &stg_IND_OLDGEN_PERM_info); - /* - * @LDV profiling - * We have just created a new closure. - */ - LDV_RECORD_CREATE(p1); - TICK_UPD_OLD_PERM_IND(); - } else { - ((StgInd *)p1)->indirectee = p2; - SET_INFO(p1, &stg_IND_PERM_info); - /* - * @LDV profiling - * We have just created a new closure. - */ - LDV_RECORD_CREATE(p1); - TICK_UPD_NEW_PERM_IND(p1); - } -} -#endif - +#endif /* CMINUSMINUS */ #endif /* UPDATES_H */ -- cgit v1.2.1