opensubscriber
   Find in this group all groups
 
Unknown more information…

f : freebsd-hackers@freebsd.org 11 March 2012 • 11:45PM -0400

pmc(3): when are the counters updated?
by Vitaly Magerya

REPLY TO AUTHOR
 
REPLY TO GROUP




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 <sys/types.h>
    #include <pmc.h>
    #include <stdio.h>
    #include <unistd.h>

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

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.