Subject: Re: PMC strawman
To: Allen Briggs <>
From: Matt Thomas <>
List: port-powerpc
Date: 02/14/2003 19:42:44
At 06:46 PM 2/14/2003, Allen Briggs wrote:
>On Fri, Feb 14, 2003 at 10:51:52AM -0800, Matt Thomas wrote:
> > Note that to use perfctrs with individual pthreads we need
> > to add a PMC glob to struct mcontext.  Does anyone have a
> > problem with that?
>You mean a glob to treat the PMC registers as part of the context?
>If it's only conditionally restored, that seems reasonable to me.
>It's what?  Another 44 bytes of mcontext overhead?  It might be
>nice to perhaps have a way to avoid that for production system
>code, though.  Maybe a compile-time knob?

There would be a bit to note whether that blob has info.  I'd
make the blob explicitly opaque to userspace.

> > But what about the kernel?  I assume that doing performance
> > of user processes and the kernel concurrently will be desired.
> > If so, then on user traps and execptions, the user PM context
> > will need to be saved in the trapframe and then the kernel's
> > loaded from cpu_info (so it's per-cpu).
>This is something that I kind of ignored with the XScale
>implementation.  It would certainly be useful to have,
>though I would certainly want to avoid the overhead unless
>PERFCTRS is enabled.

Of course it would conditional.  I'd also prefer to have
separate contents for interrupt / non-interrupt code.

> > Though the current PMC framework doesn't allow for it, it
> > might be useful for multiple processes/threads to be able to
> > share one PMC context.
>What do you think this should look like?

Right now the pmc counters are per proc, not lwp, which needs to be
fixed.  I was thinking about creating a pmc context that a process
could establish and share among it's children (or all of its threads).
Make it refcnt'ed and on last reference, free it.
Then l_md.md_pmc would be a pointer to it.  To access it will be
fairly cheap, the adding of PMCs is not:

         mfmsr   r
         mtcr    r
         b       4,28,1f

         lwz     r,CI_CURLWP(r)
         lwz     r,LWP_MD+MD_PMC(r)

         mfspr   s,SPR_PMC1
         lwz     hi,PMC_PMC1(r)
         lwz     lo,PMC_PMC1+4(r)
         add     lo,s,lo
         stw     lo,PMC_PMC1+4(r)
         addze   hi,hi
         stw     hi,PMC_PMC1(r)

Note that it can't be in the PCB since PCB's are not shared.

Matt Thomas               Internet:
3am Software Foundry      WWW URL:
Cupertino, CA             Disclaimer: I avow all knowledge of this message