Questions about "time and space profiling for non-strict langs" paper and cost centre impl. of GHC
Ömer Sinan Ağacan
omeragacan at gmail.com
Sun May 18 09:57:57 UTC 2014
Thanks Peter. Simon Marlow's talk was really interesting. After
reading the slides I read related GHC code and realized that
"cost-centre stack" and the stack trace printed using GHC.Stack is
same thing. `libraries/base/GHC/Stack.hsc` has this definition:
currentCallStack :: IO [String]
currentCallStack = ccsToStrings =<< getCurrentCCS ()
So actually string representation of cost-centre stack is returned
when current call stack is requested.
(off-topic: I'm wondering why an empty tuple is passed to `getCurrentCSS`?)
Now my first question is: Assuming stack traces are implemented as
explained by Simon Marlow in his talk and slides, can we say that
costs are always assigned to top cost-centre in the stack? So in case
of an allocation or when "tick counter" triggered, can I say that
always the top-most cost-centre in `rCCCs` register will be modified?
(then `inherited` costs would be calculated)
I'm asking this because I can't read the code generated for
cost-centre annotations(code generated for StgSCC code) because for
that I need to follow code generation through compilation to Cmm, but
I don't know anything about Cmm yet.
As far as I can understand, current implementation is different from
what's explained in Sansom and Jones, for example
* I can't see "SUB" cost-centre in list of "built-in cost-centres" in
`rts/Profiling.c`.
* We now have "stacks" which are assigned to RHS of bindings.
I tried reading output of -ddump-stg but generated STG is confusing.
For example, this function:
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
is annotated with `CCS_DONT_CARE`. Why is that? Also, I can see
`_push_` and `_tick_`(what's this?) instructions placed in generated
STG but no `_call_` instructions. There is also something like `CCCS`
in generated STG but I have no ideas about this.
So in short I'm trying to understand how cost-centre related
annotations are generated and how are they used. Any paper/source
code/blog post suggestions would be very appreciated. As far as I can
see current implementation is different than ones explained in
slides/papers.
Thanks,
---
Ömer Sinan Ağacan
http://osa1.net
More information about the ghc-devs
mailing list