From 155d943cbbe0ee8c3443bb76c74dff99355b55aa Mon Sep 17 00:00:00 2001 From: Nicolas Frisby Date: Thu, 4 Apr 2013 22:20:27 +0100 Subject: [PATCH] added ticky counters for heap and stack checks --- compiler/codeGen/StgCmmHeap.hs | 3 ++- compiler/codeGen/StgCmmTicky.hs | 9 +++++++++ includes/Cmm.h | 2 ++ includes/stg/Ticky.h | 3 +++ rts/Linker.c | 2 ++ rts/Ticky.c | 3 +++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler/codeGen/StgCmmHeap.hs b/compiler/codeGen/StgCmmHeap.hs index 50fcfdc81299..0a817030e5ad 100644 --- a/compiler/codeGen/StgCmmHeap.hs +++ b/compiler/codeGen/StgCmmHeap.hs @@ -570,10 +570,11 @@ do_checks mb_stk_hwm checkYield mb_alloc_lit do_gc = do case mb_stk_hwm of Nothing -> return () - Just stk_hwm -> emit =<< mkCmmIfGoto (sp_oflo stk_hwm) gc_id + Just stk_hwm -> tickyStackCheck >> (emit =<< mkCmmIfGoto (sp_oflo stk_hwm) gc_id) if (isJust mb_alloc_lit) then do + tickyHeapCheck emitAssign hpReg bump_hp emit =<< mkCmmIfThen hp_oflo (alloc_n <*> mkBranch gc_id) else do diff --git a/compiler/codeGen/StgCmmTicky.hs b/compiler/codeGen/StgCmmTicky.hs index 09938a670456..64271386391e 100644 --- a/compiler/codeGen/StgCmmTicky.hs +++ b/compiler/codeGen/StgCmmTicky.hs @@ -70,9 +70,12 @@ module StgCmmTicky ( tickyDynAlloc, tickyAllocHeap, + tickyAllocPrim, tickyAllocThunk, tickyAllocPAP, + tickyHeapCheck, + tickyStackCheck, tickyUnknownCall, tickyDirectCall, @@ -481,6 +484,12 @@ tickyAllocPAP _goods _slop = ifTicky $ do bumpTickyCounterByE (fsLit "ALLOC_PAP_gds") _goods bumpTickyCounterByE (fsLit "ALLOC_PAP_slp") _slop +tickyHeapCheck :: FCode () +tickyHeapCheck = ifTicky $ bumpTickyCounter (fsLit "HEAP_CHK_ctr") + +tickyStackCheck :: FCode () +tickyStackCheck = ifTicky $ bumpTickyCounter (fsLit "STK_CHK_ctr") + -- ----------------------------------------------------------------------------- -- Ticky utils diff --git a/includes/Cmm.h b/includes/Cmm.h index 7e051c1a30e7..89baaa098768 100644 --- a/includes/Cmm.h +++ b/includes/Cmm.h @@ -373,6 +373,7 @@ CCCS_ALLOC(bytes); #define HEAP_CHECK(bytes,failure) \ + TICK_BUMP(HEAP_CHK_ctr); \ Hp = Hp + (bytes); \ if (Hp > HpLim) { HpAlloc = (bytes); failure; } \ TICK_ALLOC_HEAP_NOCTR(bytes); @@ -476,6 +477,7 @@ } #define STK_CHK(n, fun) \ + TICK_BUMP(STK_CHK_ctr); \ if (Sp - (n) < SpLim) { \ GC_PRIM(fun) \ } diff --git a/includes/stg/Ticky.h b/includes/stg/Ticky.h index 32a7f2006de9..182c99654f0c 100644 --- a/includes/stg/Ticky.h +++ b/includes/stg/Ticky.h @@ -111,6 +111,9 @@ EXTERN StgInt UPD_PAP_IN_PLACE_ctr INIT(0); EXTERN StgInt ALLOC_HEAP_ctr INIT(0); EXTERN StgInt ALLOC_HEAP_tot INIT(0); +EXTERN StgInt HEAP_CHK_ctr INIT(0); +EXTERN StgInt STK_CHK_ctr INIT(0); + EXTERN StgInt ALLOC_RTS_ctr INIT(0); EXTERN StgInt ALLOC_RTS_tot INIT(0); diff --git a/rts/Linker.c b/rts/Linker.c index 3f66313b7648..585d1e8451bf 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -958,6 +958,8 @@ typedef struct _RtsSymbolVal { SymI_HasProto(UPD_PAP_IN_PLACE_ctr) \ SymI_HasProto(ALLOC_HEAP_ctr) \ SymI_HasProto(ALLOC_HEAP_tot) \ + SymI_HasProto(HEAP_CHK_ctr) \ + SymI_HasProto(STK_CHK_ctr) \ SymI_HasProto(ALLOC_RTS_ctr) \ SymI_HasProto(ALLOC_RTS_tot) \ SymI_HasProto(ALLOC_FUN_ctr) \ diff --git a/rts/Ticky.c b/rts/Ticky.c index 243897fbe46e..0d33c43d79d5 100644 --- a/rts/Ticky.c +++ b/rts/Ticky.c @@ -330,6 +330,9 @@ PrintTickyInfo(void) PR_CTR(ALLOC_HEAP_ctr); PR_CTR(ALLOC_HEAP_tot); + PR_CTR(HEAP_CHK_ctr); + PR_CTR(STK_CHK_ctr); + PR_CTR(ALLOC_RTS_ctr); PR_CTR(ALLOC_RTS_tot);