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

Documentation and refactoring in CCS related code

- Remove REGISTER_CC and REGISTER_CCS macros, add functions registerCC
  and registerCCS to Profiling.c.

- Reduce scope of symbols: CC_LIST, CCS_LIST, CC_ID, CCS_ID

- Document CC_LIST and CCS_LIST
parent 92b684de
...@@ -166,9 +166,6 @@ extern CostCentreStack CCS_IDLE[]; // capability is idle ...@@ -166,9 +166,6 @@ extern CostCentreStack CCS_IDLE[]; // capability is idle
#endif /* IN_STG_CODE */ #endif /* IN_STG_CODE */
extern unsigned int RTS_VAR(CC_ID); // global ids
extern unsigned int RTS_VAR(CCS_ID);
extern unsigned int RTS_VAR(era); extern unsigned int RTS_VAR(era);
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -179,36 +176,7 @@ CostCentreStack * pushCostCentre (CostCentreStack *, CostCentre *); ...@@ -179,36 +176,7 @@ CostCentreStack * pushCostCentre (CostCentreStack *, CostCentre *);
void enterFunCCS (StgRegTable *reg, CostCentreStack *); void enterFunCCS (StgRegTable *reg, CostCentreStack *);
CostCentre *mkCostCentre (char *label, char *module, char *srcloc); CostCentre *mkCostCentre (char *label, char *module, char *srcloc);
/* -----------------------------------------------------------------------------
Registering CCs and CCSs
Registering a CC or CCS consists of
- assigning it a unique ID
- linking it onto the list of registered CCs/CCSs
Cost centres are registered at startup by a C constructor function
generated by the compiler in the _stub.c file for each module. The
macros below are invoked by that C code to register CCs and CCSs.
-------------------------------------------------------------------------- */
extern CostCentre * RTS_VAR(CC_LIST); // registered CC list extern CostCentre * RTS_VAR(CC_LIST); // registered CC list
extern CostCentreStack * RTS_VAR(CCS_LIST); // registered CCS list
#define REGISTER_CC(cc) \
do { \
if ((cc)->link == (CostCentre *)0) { \
(cc)->link = CC_LIST; \
CC_LIST = (cc); \
(cc)->ccID = CC_ID++; \
}} while(0)
#define REGISTER_CCS(ccs) \
do { \
if ((ccs)->prevStack == (CostCentreStack *)0) { \
(ccs)->prevStack = CCS_LIST; \
CCS_LIST = (ccs); \
(ccs)->ccsID = CCS_ID++; \
}} while(0)
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Declaring Cost Centres & Cost Centre Stacks. * Declaring Cost Centres & Cost Centre Stacks.
......
...@@ -523,12 +523,8 @@ extern StgWord RTS_VAR(stable_name_table); ...@@ -523,12 +523,8 @@ extern StgWord RTS_VAR(stable_name_table);
// Profiling.c // Profiling.c
extern unsigned int RTS_VAR(era); extern unsigned int RTS_VAR(era);
extern unsigned int RTS_VAR(entering_PAP); extern unsigned int RTS_VAR(entering_PAP);
extern StgWord RTS_VAR(CC_LIST); /* registered CC list */
extern StgWord RTS_VAR(CCS_LIST); /* registered CCS list */
extern StgWord CCS_OVERHEAD[]; extern StgWord CCS_OVERHEAD[];
extern StgWord CCS_SYSTEM[]; extern StgWord CCS_SYSTEM[];
extern unsigned int RTS_VAR(CC_ID); /* global ids */
extern unsigned int RTS_VAR(CCS_ID);
// Calls to these rts functions are generated directly // Calls to these rts functions are generated directly
// by codegen (see compiler/codeGen/StgCmmProf.hs) // by codegen (see compiler/codeGen/StgCmmProf.hs)
......
...@@ -43,8 +43,8 @@ static Arena *prof_arena; ...@@ -43,8 +43,8 @@ static Arena *prof_arena;
* closure_cats * closure_cats
*/ */
unsigned int CC_ID = 1; static unsigned int CC_ID = 1;
unsigned int CCS_ID = 1; static unsigned int CCS_ID = 1;
/* Globals for opening the profiling log file(s) /* Globals for opening the profiling log file(s)
*/ */
...@@ -54,11 +54,11 @@ FILE *prof_file; ...@@ -54,11 +54,11 @@ FILE *prof_file;
static char *hp_filename; /* heap profile (hp2ps style) log file */ static char *hp_filename; /* heap profile (hp2ps style) log file */
FILE *hp_file; FILE *hp_file;
/* Linked lists to keep track of CCs and CCSs that haven't // List of all cost centres. Used for reporting.
* been declared in the log file yet
*/
CostCentre *CC_LIST = NULL; CostCentre *CC_LIST = NULL;
CostCentreStack *CCS_LIST = NULL; // All cost centre stacks temporarily appear here, to be able to make CCS_MAIN a
// parent of all cost centres stacks (done in initProfiling2()).
static CostCentreStack *CCS_LIST = NULL;
#if defined(THREADED_RTS) #if defined(THREADED_RTS)
static Mutex ccs_mutex; static Mutex ccs_mutex;
...@@ -125,6 +125,8 @@ static IndexTable * addToIndexTable ( IndexTable *, CostCentreStack *, ...@@ -125,6 +125,8 @@ static IndexTable * addToIndexTable ( IndexTable *, CostCentreStack *,
CostCentre *, bool ); CostCentre *, bool );
static void ccsSetSelected ( CostCentreStack *ccs ); static void ccsSetSelected ( CostCentreStack *ccs );
static void aggregateCCCosts( CostCentreStack *ccs ); static void aggregateCCCosts( CostCentreStack *ccs );
static void registerCC ( CostCentre *cc );
static void registerCCS ( CostCentreStack *ccs );
static void initTimeProfiling ( void ); static void initTimeProfiling ( void );
static void initProfilingLogFile ( void ); static void initProfilingLogFile ( void );
...@@ -158,21 +160,21 @@ void initProfiling (void) ...@@ -158,21 +160,21 @@ void initProfiling (void)
/* Register all the cost centres / stacks in the program /* Register all the cost centres / stacks in the program
* CC_MAIN gets link = 0, all others have non-zero link. * CC_MAIN gets link = 0, all others have non-zero link.
*/ */
REGISTER_CC(CC_MAIN); registerCC(CC_MAIN);
REGISTER_CC(CC_SYSTEM); registerCC(CC_SYSTEM);
REGISTER_CC(CC_GC); registerCC(CC_GC);
REGISTER_CC(CC_OVERHEAD); registerCC(CC_OVERHEAD);
REGISTER_CC(CC_DONT_CARE); registerCC(CC_DONT_CARE);
REGISTER_CC(CC_PINNED); registerCC(CC_PINNED);
REGISTER_CC(CC_IDLE); registerCC(CC_IDLE);
REGISTER_CCS(CCS_SYSTEM); registerCCS(CCS_SYSTEM);
REGISTER_CCS(CCS_GC); registerCCS(CCS_GC);
REGISTER_CCS(CCS_OVERHEAD); registerCCS(CCS_OVERHEAD);
REGISTER_CCS(CCS_DONT_CARE); registerCCS(CCS_DONT_CARE);
REGISTER_CCS(CCS_PINNED); registerCCS(CCS_PINNED);
REGISTER_CCS(CCS_IDLE); registerCCS(CCS_IDLE);
REGISTER_CCS(CCS_MAIN); registerCCS(CCS_MAIN);
/* find all the registered cost centre stacks, and make them /* find all the registered cost centre stacks, and make them
* children of CCS_MAIN. * children of CCS_MAIN.
...@@ -199,10 +201,9 @@ void initProfiling (void) ...@@ -199,10 +201,9 @@ void initProfiling (void)
// //
void initProfiling2 (void) void initProfiling2 (void)
{ {
CostCentreStack *ccs, *next;
// make CCS_MAIN the parent of all the pre-defined CCSs. // make CCS_MAIN the parent of all the pre-defined CCSs.
for (ccs = CCS_LIST; ccs != NULL; ) { CostCentreStack *next;
for (CostCentreStack *ccs = CCS_LIST; ccs != NULL; ) {
next = ccs->prevStack; next = ccs->prevStack;
ccs->prevStack = NULL; ccs->prevStack = NULL;
actualPush_(CCS_MAIN,ccs->cc,ccs); actualPush_(CCS_MAIN,ccs->cc,ccs);
...@@ -312,22 +313,47 @@ endProfiling ( void ) ...@@ -312,22 +313,47 @@ endProfiling ( void )
} }
} }
/* -----------------------------------------------------------------------------
Registering CCs and CCSs
Registering a CC or CCS consists of
- assigning it a unique ID
- linking it onto the list of registered CCs/CCSs
Cost centres are registered at startup by a C constructor function
generated by the compiler (ProfInit.hs) in the _stub.c file for each module.
-------------------------------------------------------------------------- */
static void
registerCC(CostCentre *cc)
{
if (cc->link == NULL) {
cc->link = CC_LIST;
CC_LIST = cc;
cc->ccID = CC_ID++;
}
}
static void registerCCS(CostCentreStack *ccs)
{
if (ccs->prevStack == NULL) {
ccs->prevStack = CCS_LIST;
CCS_LIST = ccs;
ccs->ccsID = CCS_ID++;
}
}
/*
These are used in the C stubs produced by the code generator
to register code.
*/
void registerCcList(CostCentre **cc_list) void registerCcList(CostCentre **cc_list)
{ {
for (CostCentre **i = cc_list; *i != NULL; i++) { for (CostCentre **i = cc_list; *i != NULL; i++) {
REGISTER_CC(*i); registerCC(*i);
} }
} }
void registerCcsList(CostCentreStack **cc_list) void registerCcsList(CostCentreStack **cc_list)
{ {
for (CostCentreStack **i = cc_list; *i != NULL; i++) { for (CostCentreStack **i = cc_list; *i != NULL; i++) {
REGISTER_CCS(*i); registerCCS(*i);
} }
} }
......
...@@ -493,9 +493,6 @@ ...@@ -493,9 +493,6 @@
#define RTS_PROF_SYMBOLS \ #define RTS_PROF_SYMBOLS \
SymI_HasProto(CCS_DONT_CARE) \ SymI_HasProto(CCS_DONT_CARE) \
SymI_HasProto(CC_LIST) \ SymI_HasProto(CC_LIST) \
SymI_HasProto(CC_ID) \
SymI_HasProto(CCS_LIST) \
SymI_HasProto(CCS_ID) \
SymI_HasProto(stg_restore_cccs_info) \ SymI_HasProto(stg_restore_cccs_info) \
SymI_HasProto(enterFunCCS) \ SymI_HasProto(enterFunCCS) \
SymI_HasProto(pushCostCentre) \ SymI_HasProto(pushCostCentre) \
......
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