Re: pmc(3): when are the counters updated?

2012-03-12 Thread Harald Servat
2012/3/12 Vitaly Magerya 

> 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?!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: pmc(3): when are the counters updated?

2012-03-12 Thread Vitaly Magerya
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.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: pmc(3): when are the counters updated?

2012-03-12 Thread Fabien Thomas

Le 11 mars 2012 à 16:45, Vitaly Magerya a écrit :

> Hi, folks. I'm trying to use pmc(3) to analyze code fragments, and
> I've run into strange behavior: the counter values returned by
> pmc_read(3) sometimes show no increment between readings, but are
> updated a second later; even if the PMC in question was stopped
> before.
> 
> Here's a test program:
> 
>#include 
>#include 
>#include 
>#include 
> 
>int main() {
>pmc_id_t pmcid;
>pmc_value_t value;
>int i;
> 
>pmc_init();
>pmc_allocate("instructions", PMC_MODE_TC, 0, PMC_CPU_ANY, &pmcid);
>pmc_start(pmcid);
>for (i = 0; i < 500; i++);
>pmc_stop(pmcid);
>pmc_read(pmcid, &value);
>printf("first reading:  %lu\n", (unsigned long)value);
>sleep(1);
>pmc_read(pmcid, &value);
>printf("second reading: %lu\n", (unsigned long)value);
>}
> 
> It's output on my system (FreeBSD 8.2 amd64, an Intel Atom processor)
> is something like this:
> 
>first reading:  0
>second reading: 15090110
> 
> I don't really like both numbers; I expect the first reading not
> to be zero (there obviously are instructions between pmc_start and
> pmc_stop), and I expect the second reading not to differ from the
> first, as the PMC was stopped before both of them, so it's value
> should not change.
> 
> 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.

> 
> (BTW, is this the right list for such questions?)
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"



pmc(3): when are the counters updated?

2012-03-11 Thread Vitaly Magerya
Hi, folks. I'm trying to use pmc(3) to analyze code fragments, and
I've run into strange behavior: the counter values returned by
pmc_read(3) sometimes show no increment between readings, but are
updated a second later; even if the PMC in question was stopped
before.

Here's a test program:

#include 
#include 
#include 
#include 

int main() {
pmc_id_t pmcid;
pmc_value_t value;
int i;

pmc_init();
pmc_allocate("instructions", PMC_MODE_TC, 0, PMC_CPU_ANY, &pmcid);
pmc_start(pmcid);
for (i = 0; i < 500; i++);
pmc_stop(pmcid);
pmc_read(pmcid, &value);
printf("first reading:  %lu\n", (unsigned long)value);
sleep(1);
pmc_read(pmcid, &value);
printf("second reading: %lu\n", (unsigned long)value);
}

It's output on my system (FreeBSD 8.2 amd64, an Intel Atom processor)
is something like this:

first reading:  0
second reading: 15090110

I don't really like both numbers; I expect the first reading not
to be zero (there obviously are instructions between pmc_start and
pmc_stop), and I expect the second reading not to differ from the
first, as the PMC was stopped before both of them, so it's value
should not change.

So, what's going on here? Is this the intended behavior, or can it
be changed? And how do I get accurate readings?

(BTW, is this the right list for such questions?)
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"