Skip to contentSkip to conversation

perf stat: Use event group to simulate PMI on PMI-less hardware counter

RFC PATCH In review Lin Ming 4 participants 10 messages Nov 10, 2010 – Nov 12, 2010 perf events

lore
Share & tools
lore

Lin Ming

author
#0 lore raw

RFC PATCH 2/2 perf stat: Use event group to simulate PMI on PMI-less hardware counter

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

---
 include/linux/perf_event.h |    4 ++-
 tools/perf/builtin-stat.c  |   58 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 55 insertions(+), 7 deletions(-)
include/linux/perf_event.h +3 -1
index 057bf22..8a4c0aa 100644
@@ -216,7 +216,9 @@ struct perf_event_attr {
 				precise_ip     :  2, /* skid constraint       */
 				mmap_data      :  1, /* non-exec mmap data    */
 
-				__reserved_1   : 46;
+				pmi_simulate   :  1, /* simulate pmi with group events */
+
+				__reserved_1   : 45;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
tools/perf/builtin-stat.c +52 -6

96 lines not on this page · raw message

Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 5 lines · Lin Ming

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

Quoted 7 lines

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

I'm terribly confused here....

- you introduce perf_event_attr:pmi_simulate, but then you never
implement it -- nor do we need it afaict.

- you use grouped counters for perf-stat, perf-stat doesn't use
sampling so I don't see a need to group events to simulate the PMI.

author
#2 lore raw
Quoted 14 lines · Peter Zijlstra
Quoted 5 lines · Lin Ming

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

Quoted 7 lines

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

Quoted 4 lines

I'm terribly confused here....

- you introduce perf_event_attr:pmi_simulate, but then you never
implement it -- nor do we need it afaict.

Someone need to simluate pmi will use it in future.

Quoted 5 lines

- you use grouped counters for perf-stat, perf-stat doesn't use
sampling so I don't see a need to group events to simulate the PMI.

Aha, sorry, actually, I mean to periodically read the PMI-less counter and reset it to zero each time to avoid overflow.

Well, seems I have done this in the wrong way.
Let me re-think about it.

maintainer
#3 lore raw
Quoted 15 lines · Lin Ming
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · Lin Ming

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

Quoted 6 lines
Quoted 4 lines

I'm terribly confused here....

- you introduce perf_event_attr:pmi_simulate, but then you never
implement it -- nor do we need it afaict.

Someone need to simluate pmi will use it in future.

Maybe, but simply adding an ABI just in case doesn't seem like a good idea. The proposed idea was to group with a software hrtimer-based event and use the hrtimer's sample to read the hardware group sibling using PERF_SAMPLE_READ.

That should be possible using today's interface.

Quoted 11 lines
Quoted 5 lines

- you use grouped counters for perf-stat, perf-stat doesn't use
sampling so I don't see a need to group events to simulate the PMI.

Aha, sorry, actually, I mean to periodically read the PMI-less counter and reset it to zero each time to avoid overflow.

Well, seems I have done this in the wrong way.
Let me re-think about it.

Right, so you're wanting to avoid overflowing the hardware counter? This is only a problem for short hardware counters without a pmi, SH and the like currently cascade 2 32bit counters to create 64bit hardware counters and avoid the overflow case that way.

Another thing they can do is simply use the system tick to fold the 32bit counters into a the 64bit counter.

Again, this doesn't need any changes to the ABI and generic code.

author
#4 lore raw
Quoted 21 lines · Peter Zijlstra
Quoted 20 lines · Lin Ming
Quoted 18 lines · Peter Zijlstra
Quoted 5 lines · Lin Ming

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

Quoted 7 lines

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

I'm terribly confused here....

- you introduce perf_event_attr:pmi_simulate, but then you never
implement it -- nor do we need it afaict.

Quoted 6 lines
Quoted 1 line

Someone need to simluate pmi will use it in future.

Maybe, but simply adding an ABI just in case doesn't seem like a good idea. The proposed idea was to group with a software hrtimer-based event and use the hrtimer's sample to read the hardware group sibling using PERF_SAMPLE_READ.

So this is usefull in perf top/record on PMI-less counter?

Quoted 9 lines

That should be possible using today's interface.

Quoted 6 lines
Quoted 5 lines

- you use grouped counters for perf-stat, perf-stat doesn't use
sampling so I don't see a need to group events to simulate the PMI.

Quoted 7 lines
Quoted 5 lines

Aha, sorry, actually, I mean to periodically read the PMI-less counter and reset it to zero each time to avoid overflow.

Well, seems I have done this in the wrong way.
Let me re-think about it.

Right, so you're wanting to avoid overflowing the hardware counter? This

Yes.

Quoted 8 lines

is only a problem for short hardware counters without a pmi, SH and the like currently cascade 2 32bit counters to create 64bit hardware counters and avoid the overflow case that way.

Another thing they can do is simply use the system tick to fold the 32bit counters into a the 64bit counter.

Again, this doesn't need any changes to the ABI and generic code.

Thanks for the explanation.

maintainer
#5 lore raw
Quoted 5 lines · Lin Ming
Quoted 3 lines

The proposed idea was to group with a software hrtimer-based event and use the hrtimer's sample to read the hardware group sibling using PERF_SAMPLE_READ.

So this is usefull in perf top/record on PMI-less counter?

Correct, Matt was implementing this.

#6 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 5 lines · Lin Ming
Quoted 3 lines

The proposed idea was to group with a software hrtimer-based event and use the hrtimer's sample to read the hardware group sibling using PERF_SAMPLE_READ.

So this is usefull in perf top/record on PMI-less counter?

Correct, Matt was implementing this.

My work in progress is here,

http://git.kernel.org/?p=linux/kernel/git/mfleming/sh-2.6.git;a=commitdiff;h=68f95e18cec7b2bc6baf3731969f94b9c51c7a08

I'll try get this submitted by the beginning of next week.

#7 lore raw
In reply to Peter Zijlstra
Quoted 39 lines · Peter Zijlstra
Quoted 15 lines · Lin Ming
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · Lin Ming

Some hardware counters(for example, Intel RAPL) can't generate interrupt when overflow. So we need to simulate the interrupt to periodically record the counter values. Otherwise, the counter may overflow and the wrong value is read.

This patch uses event group to simulate PMI as suggested by Peter Zijlstra, http://marc.info/?l=linux-kernel&m=128220854801819&w=2

create_group_counters() will create a group with 2 events, one hrtimer based event as the group leader, and the other event to count. The hrtimer is fired periodically, so the sibling event can record its counter value periodically as well.

Quoted 6 lines
Quoted 4 lines

I'm terribly confused here....

- you introduce perf_event_attr:pmi_simulate, but then you never
implement it -- nor do we need it afaict.

Someone need to simluate pmi will use it in future.

Maybe, but simply adding an ABI just in case doesn't seem like a good idea. The proposed idea was to group with a software hrtimer-based event and use the hrtimer's sample to read the hardware group sibling using PERF_SAMPLE_READ.

That should be possible using today's interface.

Quoted 9 lines
Quoted 5 lines

- you use grouped counters for perf-stat, perf-stat doesn't use
sampling so I don't see a need to group events to simulate the PMI.

Aha, sorry, actually, I mean to periodically read the PMI-less counter and reset it to zero each time to avoid overflow.

Quoted 8 lines
Quoted 2 lines

Well, seems I have done this in the wrong way.
Let me re-think about it.

Right, so you're wanting to avoid overflowing the hardware counter? This is only a problem for short hardware counters without a pmi, SH and the like currently cascade 2 32bit counters to create 64bit hardware counters and avoid the overflow case that way.

Well, the RAPL package energy perf event may need this piece of code.

"MSR_PKG_ENERGY_STATUS is a read-only MSR. It reports the actual energy
use for the package domain. This MSR is updated every ~1msec. It has a wraparound time of around 60 secs when power consumption is high, and may be longer otherwise."

As it's an energy counter, we should show it in "perf stat", right? As it doesn't have interrupt, I want to schedule a timer interrupt every 30s to update the event counter.

thanks,
rui

Quoted 7 lines

Another thing they can do is simply use the system tick to fold the 32bit counters into a the 64bit counter.

Again, this doesn't need any changes to the ABI and generic code.

maintainer
#8 lore raw
Quoted 10 lines · Zhang Rui

Well, the RAPL package energy perf event may need this piece of code.

"MSR_PKG_ENERGY_STATUS is a read-only MSR. It reports the actual energy
use for the package domain. This MSR is updated every ~1msec. It has a wraparound time of around 60 secs when power consumption is high, and may be longer otherwise."

As it's an energy counter, we should show it in "perf stat", right? As it doesn't have interrupt, I want to schedule a timer interrupt every 30s to update the event counter.

So use a timer inside the RAPL pmu driver. No need to change the interface or add generic code.

#9 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Zhang Rui

Well, the RAPL package energy perf event may need this piece of code.

"MSR_PKG_ENERGY_STATUS is a read-only MSR. It reports the actual energy
use for the package domain. This MSR is updated every ~1msec. It has a wraparound time of around 60 secs when power consumption is high, and may be longer otherwise."

Quoted 6 lines
Quoted 3 lines

As it's an energy counter, we should show it in "perf stat", right? As it doesn't have interrupt, I want to schedule a timer interrupt every 30s to update the event counter.

So use a timer inside the RAPL pmu driver. No need to change the interface or add generic code.

Okay.
I was wondering if this can be done with the current perf framework. If not, surely I'm okay with using a timer inside RAPL driver. :)

thanks,
rui