/libraries/ghc-7.10/base/include/CCS.h

http://github.com/valderman/haste-compiler · C Header · 254 lines · 118 code · 61 blank · 75 comment · 6 complexity · 21041c36210146bcbd30e9889c4fef7d MD5 · raw file

  1. /* -----------------------------------------------------------------------------
  2. *
  3. * (c) The GHC Team, 2009-2012
  4. *
  5. * Macros for profiling operations in STG code
  6. *
  7. * Do not #include this file directly: #include "Rts.h" instead.
  8. *
  9. * To understand the structure of the RTS headers, see the wiki:
  10. * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
  11. *
  12. * ---------------------------------------------------------------------------*/
  13. #ifndef RTS_PROF_CCS_H
  14. #define RTS_PROF_CCS_H
  15. /* -----------------------------------------------------------------------------
  16. * Data Structures
  17. * ---------------------------------------------------------------------------*/
  18. /*
  19. * Note [struct alignment]
  20. * NB. be careful to avoid unwanted padding between fields, by
  21. * putting the 8-byte fields on an 8-byte boundary. Padding can
  22. * vary between C compilers, and we don't take into account any
  23. * possible padding when generating CCS and CC decls in the code
  24. * generator (compiler/codeGen/StgCmmProf.hs).
  25. */
  26. typedef struct CostCentre_ {
  27. StgInt ccID; // Unique Id, allocated by the RTS
  28. char * label;
  29. char * module;
  30. char * srcloc;
  31. // used for accumulating costs at the end of the run...
  32. StgWord64 mem_alloc; // align 8 (Note [struct alignment])
  33. StgWord time_ticks;
  34. StgInt is_caf; // non-zero for a CAF cost centre
  35. struct CostCentre_ *link;
  36. } CostCentre;
  37. typedef struct CostCentreStack_ {
  38. StgInt ccsID; // unique ID, allocated by the RTS
  39. CostCentre *cc; // Cost centre at the top of the stack
  40. struct CostCentreStack_ *prevStack; // parent
  41. struct IndexTable_ *indexTable; // children
  42. struct CostCentreStack_ *root; // root of stack
  43. StgWord depth; // number of items in the stack
  44. StgWord64 scc_count; // Count of times this CCS is entered
  45. // align 8 (Note [struct alignment])
  46. StgWord selected; // is this CCS shown in the heap
  47. // profile? (zero if excluded via -hc
  48. // -hm etc.)
  49. StgWord time_ticks; // number of time ticks accumulated by
  50. // this CCS
  51. StgWord64 mem_alloc; // mem allocated by this CCS
  52. // align 8 (Note [struct alignment])
  53. StgWord64 inherited_alloc; // sum of mem_alloc over all children
  54. // (calculated at the end)
  55. // align 8 (Note [struct alignment])
  56. StgWord inherited_ticks; // sum of time_ticks over all children
  57. // (calculated at the end)
  58. } CostCentreStack;
  59. /* -----------------------------------------------------------------------------
  60. * Start and stop the profiling timer. These can be called from
  61. * Haskell to restrict the profile to portion(s) of the execution.
  62. * See the module GHC.Profiling.
  63. * ---------------------------------------------------------------------------*/
  64. void stopProfTimer ( void );
  65. void startProfTimer ( void );
  66. /* -----------------------------------------------------------------------------
  67. * The rest is PROFILING only...
  68. * ---------------------------------------------------------------------------*/
  69. #if defined(PROFILING)
  70. /* -----------------------------------------------------------------------------
  71. * Constants
  72. * ---------------------------------------------------------------------------*/
  73. #define EMPTY_STACK NULL
  74. #define EMPTY_TABLE NULL
  75. /* Constants used to set is_caf flag on CostCentres */
  76. #define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */
  77. #define CC_NOT_CAF 0
  78. /* -----------------------------------------------------------------------------
  79. * Data Structures
  80. * ---------------------------------------------------------------------------*/
  81. // IndexTable is the list of children of a CCS. (Alternatively it is a
  82. // cache of the results of pushing onto a CCS, so that the second and
  83. // subsequent times we push a certain CC on a CCS we get the same
  84. // result).
  85. typedef struct IndexTable_ {
  86. CostCentre *cc;
  87. CostCentreStack *ccs;
  88. struct IndexTable_ *next;
  89. nat back_edge;
  90. } IndexTable;
  91. /* -----------------------------------------------------------------------------
  92. Pre-defined cost centres and cost centre stacks
  93. -------------------------------------------------------------------------- */
  94. #if IN_STG_CODE
  95. extern StgWord CC_MAIN[];
  96. extern StgWord CCS_MAIN[]; // Top CCS
  97. extern StgWord CC_SYSTEM[];
  98. extern StgWord CCS_SYSTEM[]; // RTS costs
  99. extern StgWord CC_GC[];
  100. extern StgWord CCS_GC[]; // Garbage collector costs
  101. extern StgWord CC_OVERHEAD[];
  102. extern StgWord CCS_OVERHEAD[]; // Profiling overhead
  103. extern StgWord CC_DONT_CARE[];
  104. extern StgWord CCS_DONT_CARE[]; // CCS attached to static constructors
  105. #else
  106. extern CostCentre CC_MAIN[];
  107. extern CostCentreStack CCS_MAIN[]; // Top CCS
  108. extern CostCentre CC_SYSTEM[];
  109. extern CostCentreStack CCS_SYSTEM[]; // RTS costs
  110. extern CostCentre CC_GC[];
  111. extern CostCentreStack CCS_GC[]; // Garbage collector costs
  112. extern CostCentre CC_OVERHEAD[];
  113. extern CostCentreStack CCS_OVERHEAD[]; // Profiling overhead
  114. extern CostCentre CC_DONT_CARE[];
  115. extern CostCentreStack CCS_DONT_CARE[]; // shouldn't ever get set
  116. extern CostCentre CC_PINNED[];
  117. extern CostCentreStack CCS_PINNED[]; // pinned memory
  118. extern CostCentre CC_IDLE[];
  119. extern CostCentreStack CCS_IDLE[]; // capability is idle
  120. #endif /* IN_STG_CODE */
  121. extern unsigned int RTS_VAR(CC_ID); // global ids
  122. extern unsigned int RTS_VAR(CCS_ID);
  123. extern unsigned int RTS_VAR(era);
  124. /* -----------------------------------------------------------------------------
  125. * Functions
  126. * ---------------------------------------------------------------------------*/
  127. CostCentreStack * pushCostCentre (CostCentreStack *, CostCentre *);
  128. void enterFunCCS (StgRegTable *reg, CostCentreStack *);
  129. /* -----------------------------------------------------------------------------
  130. Registering CCs and CCSs
  131. Registering a CC or CCS consists of
  132. - assigning it a unique ID
  133. - linking it onto the list of registered CCs/CCSs
  134. Cost centres are registered at startup by a C constructor function
  135. generated by the compiler in the _stub.c file for each module. The
  136. macros below are invoked by that C code to register CCs and CCSs.
  137. -------------------------------------------------------------------------- */
  138. extern CostCentre * RTS_VAR(CC_LIST); // registered CC list
  139. extern CostCentreStack * RTS_VAR(CCS_LIST); // registered CCS list
  140. #define REGISTER_CC(cc) \
  141. do { \
  142. if ((cc)->link == (CostCentre *)0) { \
  143. (cc)->link = CC_LIST; \
  144. CC_LIST = (cc); \
  145. (cc)->ccID = CC_ID++; \
  146. }} while(0)
  147. #define REGISTER_CCS(ccs) \
  148. do { \
  149. if ((ccs)->prevStack == (CostCentreStack *)0) { \
  150. (ccs)->prevStack = CCS_LIST; \
  151. CCS_LIST = (ccs); \
  152. (ccs)->ccsID = CCS_ID++; \
  153. }} while(0)
  154. /* -----------------------------------------------------------------------------
  155. * Declaring Cost Centres & Cost Centre Stacks.
  156. * -------------------------------------------------------------------------- */
  157. # define CC_DECLARE(cc_ident,name,mod,loc,caf,is_local) \
  158. is_local CostCentre cc_ident[1] \
  159. = {{ .ccID = 0, \
  160. .label = name, \
  161. .module = mod, \
  162. .srcloc = loc, \
  163. .time_ticks = 0, \
  164. .mem_alloc = 0, \
  165. .link = 0, \
  166. .is_caf = caf \
  167. }};
  168. # define CCS_DECLARE(ccs_ident,cc_ident,is_local) \
  169. is_local CostCentreStack ccs_ident[1] \
  170. = {{ .ccsID = 0, \
  171. .cc = cc_ident, \
  172. .prevStack = NULL, \
  173. .indexTable = NULL, \
  174. .root = NULL, \
  175. .depth = 0, \
  176. .selected = 0, \
  177. .scc_count = 0, \
  178. .time_ticks = 0, \
  179. .mem_alloc = 0, \
  180. .inherited_ticks = 0, \
  181. .inherited_alloc = 0 \
  182. }};
  183. /* -----------------------------------------------------------------------------
  184. * Time / Allocation Macros
  185. * ---------------------------------------------------------------------------*/
  186. /* eliminate profiling overhead from allocation costs */
  187. #define CCS_ALLOC(ccs, size) (ccs)->mem_alloc += ((size)-sizeofW(StgProfHeader))
  188. #else /* !PROFILING */
  189. #define CCS_ALLOC(ccs, amount) doNothing()
  190. #endif /* PROFILING */
  191. #endif /* RTS_PROF_CCS_H */