Commit 6e4e6376 authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan

Minor refactoring and documentation in profiling RTS code

parent 05cd2319
......@@ -36,7 +36,7 @@ typedef struct CostCentre_ {
StgWord64 mem_alloc; // align 8 (Note [struct alignment])
StgWord time_ticks;
StgInt is_caf; // non-zero for a CAF cost centre
StgBool is_caf; // true <=> CAF cost centre
struct CostCentre_ *link;
} CostCentre;
......@@ -96,9 +96,8 @@ void startProfTimer ( void );
#define EMPTY_TABLE NULL
/* Constants used to set is_caf flag on CostCentres */
#define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */
#define CC_NOT_CAF 0
#define CC_IS_CAF true
#define CC_NOT_CAF false
/* -----------------------------------------------------------------------------
* Data Structures
* ---------------------------------------------------------------------------*/
......@@ -109,10 +108,15 @@ void startProfTimer ( void );
// result).
typedef struct IndexTable_ {
// Just a linked list of (cc, ccs) pairs, where the `ccs` is the result of
// pushing `cc` to the owner of the index table (another CostCentreStack).
CostCentre *cc;
CostCentreStack *ccs;
struct IndexTable_ *next;
uint32_t back_edge;
// back_edge is true when `cc` is already in the stack, so pushing it
// truncates or drops (see RECURSION_DROPS and RECURSION_TRUNCATES in
// Profiling.c).
bool back_edge;
} IndexTable;
......
......@@ -118,7 +118,7 @@ static CostCentreStack * pruneCCSTree ( CostCentreStack *ccs );
static CostCentreStack * actualPush ( CostCentreStack *, CostCentre * );
static CostCentreStack * isInIndexTable ( IndexTable *, CostCentre * );
static IndexTable * addToIndexTable ( IndexTable *, CostCentreStack *,
CostCentre *, unsigned int );
CostCentre *, bool );
static void ccsSetSelected ( CostCentreStack *ccs );
static void aggregateCCCosts( CostCentreStack *ccs );
......@@ -476,48 +476,23 @@ ccsSetSelected (CostCentreStack *ccs)
Cost-centre stack manipulation
-------------------------------------------------------------------------- */
#if defined(DEBUG)
CostCentreStack * _pushCostCentre ( CostCentreStack *ccs, CostCentre *cc );
CostCentreStack *
pushCostCentre ( CostCentreStack *ccs, CostCentre *cc )
#define pushCostCentre _pushCostCentre
{
IF_DEBUG(prof,
traceBegin("pushing %s on ", cc->label);
debugCCS(ccs);
traceEnd(););
return pushCostCentre(ccs,cc);
}
#endif
/* Append ccs1 to ccs2 (ignoring any CAF cost centre at the root of ccs1 */
#if defined(DEBUG)
CostCentreStack *_appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 );
CostCentreStack *
appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 )
#define appendCCS _appendCCS
{
IF_DEBUG(prof,
if (ccs1 != ccs2) {
debugBelch("Appending ");
debugCCS(ccs1);
debugBelch(" to ");
debugCCS(ccs2);
debugBelch("\n");});
return appendCCS(ccs1,ccs2);
}
#endif
IF_DEBUG(prof,
if (ccs1 != ccs2) {
debugBelch("Appending ");
debugCCS(ccs1);
debugBelch(" to ");
debugCCS(ccs2);
debugBelch("\n");});
CostCentreStack *
appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 )
{
if (ccs1 == ccs2) {
return ccs1;
}
if (ccs2 == CCS_MAIN || ccs2->cc->is_caf == CC_IS_CAF) {
if (ccs2 == CCS_MAIN || ccs2->cc->is_caf) {
// stop at a CAF element
return ccs1;
}
......@@ -532,8 +507,12 @@ appendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 )
CostCentreStack *
pushCostCentre (CostCentreStack *ccs, CostCentre *cc)
{
CostCentreStack *temp_ccs, *ret;
IndexTable *ixtable;
IF_DEBUG(prof,
traceBegin("pushing %s on ", cc->label);
debugCCS(ccs);
traceEnd(););
CostCentreStack *ret;
if (ccs == EMPTY_STACK) {
ACQUIRE_LOCK(&ccs_mutex);
......@@ -545,8 +524,8 @@ pushCostCentre (CostCentreStack *ccs, CostCentre *cc)
return ccs;
} else {
// check if we've already memoized this stack
ixtable = ccs->indexTable;
temp_ccs = isInIndexTable(ixtable,cc);
IndexTable *ixtable = ccs->indexTable;
CostCentreStack *temp_ccs = isInIndexTable(ixtable,cc);
if (temp_ccs != EMPTY_STACK) {
return temp_ccs;
......@@ -585,7 +564,7 @@ pushCostCentre (CostCentreStack *ccs, CostCentre *cc)
new_ccs = ccs;
#endif
ccs->indexTable = addToIndexTable (ccs->indexTable,
new_ccs, cc, 1);
new_ccs, cc, true);
ret = new_ccs;
} else {
ret = actualPush (ccs,cc);
......@@ -649,7 +628,7 @@ actualPush_ (CostCentreStack *ccs, CostCentre *cc, CostCentreStack *new_ccs)
/* update the memoization table for the parent stack */
ccs->indexTable = addToIndexTable(ccs->indexTable, new_ccs, cc,
0/*not a back edge*/);
false/*not a back edge*/);
/* return a pointer to the new stack */
return new_ccs;
......@@ -674,7 +653,7 @@ isInIndexTable(IndexTable *it, CostCentre *cc)
static IndexTable *
addToIndexTable (IndexTable *it, CostCentreStack *new_ccs,
CostCentre *cc, unsigned int back_edge)
CostCentre *cc, bool back_edge)
{
IndexTable *new_it;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment