2009-12-28 11:16:37

by Tim Blechmann

[permalink] [raw]
Subject: perf: counter and event question

hi all,

trying to use the perf subsystem, i am a bit confused by the terms
`performance counter' and `performance event'.

i am trying to compare `counting' counters with `sampling' counters. as
a test case, i am counting PERF_COUNT_HW_INSTRUCTIONS of the same code
piece with both approaches. the sampling counters are sampled with a
period of 1. the code is really trivial [1].

the `counting' counters report numbers of about 9000 instructions, but
the mmap buffer only seems to contain about 100 to 200 event samples.
from my (limited) understanding, these number should at least be
similar, so i am a bit confused to see such a big difference. am i
missing something, like it is impossible to sample instructions with a
period of 1? or could there be an issue with my code?

thanks, tim

[1] http://tim.klingt.org/git?p=perf-cpp.git

--
[email protected]
http://tim.klingt.org

I don't write music for sissy ears.
Charles Ives


Attachments:
signature.asc (197.00 B)
OpenPGP digital signature

2009-12-28 11:26:51

by Peter Zijlstra

[permalink] [raw]
Subject: Re: perf: counter and event question

On Mon, 2009-12-28 at 12:16 +0100, Tim Blechmann wrote:
> like it is impossible to sample instructions with a period of 1?

Pretty much, imagine the cpu getting a trap every cycle.

In order to avoid the machine grinding to a halt, we've implemented a
throttle which defaults to 100k samples/s, anything over that will be
discarted.

2009-12-28 12:43:36

by Tim Blechmann

[permalink] [raw]
Subject: Re: perf: counter and event question

On 12/28/2009 12:26 PM, Peter Zijlstra wrote:
> On Mon, 2009-12-28 at 12:16 +0100, Tim Blechmann wrote:
>> like it is impossible to sample instructions with a period of 1?
>
> Pretty much, imagine the cpu getting a trap every cycle.

is this a hardware restriction? a slowdown is acceptable for me, as long
as i am able to collect a huge number of samples accurately ...

> In order to avoid the machine grinding to a halt, we've implemented a
> throttle which defaults to 100k samples/s, anything over that will be
> discarted.

i just found the proc interface for perf_event_max_sample_rate ... it
would be nice to have a short section on the event throttling in
tools/perf/design.txt ...

thanks, tim

--
[email protected]
http://tim.klingt.org

art is short - life is long
Jack Kerouac


Attachments:
signature.asc (197.00 B)
OpenPGP digital signature

2009-12-28 13:04:12

by Peter Zijlstra

[permalink] [raw]
Subject: Re: perf: counter and event question

On Mon, 2009-12-28 at 13:39 +0100, Tim Blechmann wrote:
> On 12/28/2009 12:26 PM, Peter Zijlstra wrote:
> > On Mon, 2009-12-28 at 12:16 +0100, Tim Blechmann wrote:
> >> like it is impossible to sample instructions with a period of 1?
> >
> > Pretty much, imagine the cpu getting a trap every cycle.
>
> is this a hardware restriction? a slowdown is acceptable for me, as long
> as i am able to collect a huge number of samples accurately ...

Large number of samples and sample interval are only related through the
runtime of your application.

Use a sensible period (~10k ins) and run a 'little' longer.


2009-12-28 13:10:37

by Tim Blechmann

[permalink] [raw]
Subject: Re: perf: counter and event question

>>>> like it is impossible to sample instructions with a period of 1?
>>>
>>> Pretty much, imagine the cpu getting a trap every cycle.
>>
>> is this a hardware restriction? a slowdown is acceptable for me, as long
>> as i am able to collect a huge number of samples accurately ...
>
> Large number of samples and sample interval are only related through the
> runtime of your application.
>
> Use a sensible period (~10k ins) and run a 'little' longer.

well, for my application, i am not interested in statistical data, but
in the order of the events ...
(i am not doing profiling, but trying to gather a sequence of
machine-structured data for an artistic project)

tim

--
[email protected]
http://tim.klingt.org

It is better to make a piece of music than to perform one, better to
perform one than to listen to one, better to listen to one than to
misuse it as a means of distraction, entertainment, or acquisition of
'culture'.
John Cage


Attachments:
signature.asc (197.00 B)
OpenPGP digital signature

2009-12-28 14:02:38

by Peter Zijlstra

[permalink] [raw]
Subject: Re: perf: counter and event question

On Mon, 2009-12-28 at 14:09 +0100, Tim Blechmann wrote:
> >>>> like it is impossible to sample instructions with a period of 1?
> >>>
> >>> Pretty much, imagine the cpu getting a trap every cycle.
> >>
> >> is this a hardware restriction? a slowdown is acceptable for me, as long
> >> as i am able to collect a huge number of samples accurately ...
> >
> > Large number of samples and sample interval are only related through the
> > runtime of your application.
> >
> > Use a sensible period (~10k ins) and run a 'little' longer.
>
> well, for my application, i am not interested in statistical data, but
> in the order of the events ...
> (i am not doing profiling, but trying to gather a sequence of
> machine-structured data for an artistic project)

Well, then use the branch tracer, that will give you the relation
between blocks of code and is actually doable.

But I guess you could hack out the throttle and run the cycle counter
with period=1 for userspace only.