summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2019-01-10 14:39:16 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2019-01-12 01:02:30 -0500
commitcb2349a4233d6bdef2d7090853397e6278a7378c (patch)
treebb2cadf6dc87d9bda5957098b09b15a6ca0395fb /rts
parent92b684ded87d24b5770f1abd23c07570bbde43db (diff)
downloadhaskell-cb2349a4233d6bdef2d7090853397e6278a7378c.tar.gz
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
Diffstat (limited to 'rts')
-rw-r--r--rts/Profiling.c86
-rw-r--r--rts/RtsSymbols.c3
2 files changed, 56 insertions, 33 deletions
diff --git a/rts/Profiling.c b/rts/Profiling.c
index 70bf3750e3..3c7f52b6f4 100644
--- a/rts/Profiling.c
+++ b/rts/Profiling.c
@@ -43,8 +43,8 @@ static Arena *prof_arena;
* closure_cats
*/
-unsigned int CC_ID = 1;
-unsigned int CCS_ID = 1;
+static unsigned int CC_ID = 1;
+static unsigned int CCS_ID = 1;
/* Globals for opening the profiling log file(s)
*/
@@ -54,11 +54,11 @@ FILE *prof_file;
static char *hp_filename; /* heap profile (hp2ps style) log file */
FILE *hp_file;
-/* Linked lists to keep track of CCs and CCSs that haven't
- * been declared in the log file yet
- */
+// List of all cost centres. Used for reporting.
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)
static Mutex ccs_mutex;
@@ -125,6 +125,8 @@ static IndexTable * addToIndexTable ( IndexTable *, CostCentreStack *,
CostCentre *, bool );
static void ccsSetSelected ( CostCentreStack *ccs );
static void aggregateCCCosts( CostCentreStack *ccs );
+static void registerCC ( CostCentre *cc );
+static void registerCCS ( CostCentreStack *ccs );
static void initTimeProfiling ( void );
static void initProfilingLogFile ( void );
@@ -158,21 +160,21 @@ void initProfiling (void)
/* Register all the cost centres / stacks in the program
* CC_MAIN gets link = 0, all others have non-zero link.
*/
- REGISTER_CC(CC_MAIN);
- REGISTER_CC(CC_SYSTEM);
- REGISTER_CC(CC_GC);
- REGISTER_CC(CC_OVERHEAD);
- REGISTER_CC(CC_DONT_CARE);
- REGISTER_CC(CC_PINNED);
- REGISTER_CC(CC_IDLE);
-
- REGISTER_CCS(CCS_SYSTEM);
- REGISTER_CCS(CCS_GC);
- REGISTER_CCS(CCS_OVERHEAD);
- REGISTER_CCS(CCS_DONT_CARE);
- REGISTER_CCS(CCS_PINNED);
- REGISTER_CCS(CCS_IDLE);
- REGISTER_CCS(CCS_MAIN);
+ registerCC(CC_MAIN);
+ registerCC(CC_SYSTEM);
+ registerCC(CC_GC);
+ registerCC(CC_OVERHEAD);
+ registerCC(CC_DONT_CARE);
+ registerCC(CC_PINNED);
+ registerCC(CC_IDLE);
+
+ registerCCS(CCS_SYSTEM);
+ registerCCS(CCS_GC);
+ registerCCS(CCS_OVERHEAD);
+ registerCCS(CCS_DONT_CARE);
+ registerCCS(CCS_PINNED);
+ registerCCS(CCS_IDLE);
+ registerCCS(CCS_MAIN);
/* find all the registered cost centre stacks, and make them
* children of CCS_MAIN.
@@ -199,10 +201,9 @@ void initProfiling (void)
//
void initProfiling2 (void)
{
- CostCentreStack *ccs, *next;
-
// 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;
ccs->prevStack = NULL;
actualPush_(CCS_MAIN,ccs->cc,ccs);
@@ -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)
{
for (CostCentre **i = cc_list; *i != NULL; i++) {
- REGISTER_CC(*i);
+ registerCC(*i);
}
}
void registerCcsList(CostCentreStack **cc_list)
{
for (CostCentreStack **i = cc_list; *i != NULL; i++) {
- REGISTER_CCS(*i);
+ registerCCS(*i);
}
}
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
index 404756e8cd..6966d6deb9 100644
--- a/rts/RtsSymbols.c
+++ b/rts/RtsSymbols.c
@@ -493,9 +493,6 @@
#define RTS_PROF_SYMBOLS \
SymI_HasProto(CCS_DONT_CARE) \
SymI_HasProto(CC_LIST) \
- SymI_HasProto(CC_ID) \
- SymI_HasProto(CCS_LIST) \
- SymI_HasProto(CCS_ID) \
SymI_HasProto(stg_restore_cccs_info) \
SymI_HasProto(enterFunCCS) \
SymI_HasProto(pushCostCentre) \