Questions about "time and space profiling for non-strict langs" paper and cost centre impl. of GHC

Peter Wortmann scpmw at leeds.ac.uk
Sun May 18 12:46:19 UTC 2014


Ömer Sinan Ağacan wrote: 
> (off-topic: I'm wondering why an empty tuple is passed to `getCurrentCSS`?)

See the comment on getCurrentCCS# in compiler/prelude/primops.txt.pp -
it's a token to prevent GHC optimisations from floating the primop up
(which obviously might change the call stack).

> 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?

Cost is attributed to the current cost-centre *stack*. So "a/f" !=
"b/f".

> As far as I can understand, current implementation is different from
> what's explained in Sansom and Jones, for example

The papers actually never introduce cost-centre stacks, as far as I
know. It's generally better to check Sansom's PhD thesis, the GHC source
code or the other sources I mentioned. There's been quite a bit of work
on this...

> * I can't see "SUB" cost-centre in list of "built-in cost-centres" in
> `rts/Profiling.c`.

As I understand it, the "SUB" cost centre refers to situations where the
cost-centre stack does *not* get updated on function entry. So it never
exists physically.

> is annotated with `CCS_DONT_CARE`. Why is that?

That is an annotation on lambdas, and refers to what cost-centre stack
their allocation cost should be counted on. As top-level functions and
static constructors are allocated statically, they don't count for the
heap profile, therefore "don't care".

See the definition of GenStgRhs in compiler/stgSyn/StgSyn.lhs.

> Also, I can see `_push_` and `_tick_`(what's this?) instructions
> placed in generated STG but no `_call_` instructions.

This is what actually manages cost-centre stack - "_push_" pushes the
given cost-centre on top of the cost centre stack, whereas "_tick" just
increases entry count. These two aspects have slightly different
properties as far as transformations are concerned, and therefore often
end up getting separated during optimisations.

Not sure what "_call_" is suppose to be. What's the context?

> There is also something like `CCCS` in generated STG but I have no
> ideas about this.

That's simply "current cost-centre stack". I like to think that the hint
of silliness was intentional.

> So in short I'm trying to understand how cost-centre related
> annotations are generated and how are they used.

Sure. Better place for quick queries might be #ghc on FreeNode though -
my nick is petermw.

Greetings,
  Peter Wortmann




More information about the ghc-devs mailing list