Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Mar 2012 14:04:08 +0100
From:      Harald Servat <redcrash@gmail.com>
To:        Vitaly Magerya <vmagerya@gmail.com>
Cc:        freebsd-hackers@freebsd.org, Fabien Thomas <fabien.thomas@netasq.com>
Subject:   Re: pmc(3): when are the counters updated?
Message-ID:  <CAEOTYRcdvpn8thf36NYWE6qVUJ=n-xzbGyb3PwAqppp=DpQ__w@mail.gmail.com>
In-Reply-To: <4F5DEE7E.5030008@gmail.com>
References:  <CAL409Kxng3Yzw=grvP=fvbdLrqcOG_bG_ajaO8thZEPJtk2YaQ@mail.gmail.com> <C8C86488-254E-45B3-9636-9272DC67CD0C@netasq.com> <4F5DEE7E.5030008@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
2012/3/12 Vitaly Magerya <vmagerya@gmail.com>

> Fabien Thomas wrote:
> >> So, what's going on here? Is this the intended behavior, or can it
> >> be changed? And how do I get accurate readings?
> >
> > If i remember well:
> > The current code will get real HW PMC if the PMC is running and attached
> to owner.
> > The first case is not true in your code so you get the saved value which
> is updated at
> > process switch out time.
> >
> > I think you can do:
> > pmc_read
> > pmc_stop.
>
> Changing the code to this:
>
>    [...]
>    pmc_read(pmcid, &value);
>    pmc_stop(pmcid);
>    printf("reading #1: %lu\n", (unsigned long)value);
>    pmc_read(pmcid, &value);
>    printf("reading #2: %lu\n", (unsigned long)value);
>    sleep(1);
>    pmc_read(pmcid, &value);
>    printf("reading #3: %lu\n", (unsigned long)value);
>    [...]
>
> Gives me this output:
>
>    reading #1: 15039441
>    reading #2: 0
>    reading #3: 15084037
>
> So, it seems that you are correct; pmc_read reports current values if
> the PMC is not stopped, after which it's updated on context switches.
>
>
Hello,

  I've used the PMC library in the past, and I think that you can't stop
the counters if you want to read them. By having them started, you can read
their value anywhere in the code, not only in context switches.

  I suggest you changing the code to something like

  pmc_read(..);
  do_some_calculation(..);
  pmc_read(..); /* difference between reads is devoted to
do_some_calculation */

  and when you're about to finalize the application, issue pmc_stop.

  Please, also note, sleep(1) yields the process, so counting it (even if
it's 1 second or more) will probably result in very low counter values.

Regards


-- 
 Fry: You can see how I lived before I met you.
 Bender: You lived before you met me?!
 Fry: Yeah, lots of people did.
 Bender: Really?!



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAEOTYRcdvpn8thf36NYWE6qVUJ=n-xzbGyb3PwAqppp=DpQ__w>