Re: [PATCH v2 5/5] perf: Enable applicable siblings when group leaderis enable-on-exec

From: Deng-Cheng Zhu
Date: Tue Nov 22 2011 - 22:39:20 EST


On 11/22/2011 10:23 PM, Peter Zijlstra wrote:
On Tue, 2011-11-22 at 14:20 +0000, Zhu, DengCheng wrote:
@@ -2463,11 +2461,25 @@ static int event_enable_on_exec(struct p
if (event->state>= PERF_EVENT_STATE_INACTIVE)
return 0;

- __perf_event_mark_enabled(event, ctx);
+ event->state = PERF_EVENT_STATE_INACTIVE;

return 1;
}

By simply setting the event state in here, we bypass time stamp stuff as a result.
This might lead to inaccuracies...

Ah, but it calls a __perf_event_mark_enabled() at the tail of
group_enable_on_exec() which should fix that up, right?

Oh, yes. Aside from a slight piece that the __perf_event_mark_enabled()
in group_enable_on_exec() will reassign PERF_EVENT_STATE_INACTIVE to the
group leader, your patch looks good.

In fact, my another candidate for this patch is as follows (The
comment of perf_event_enable_on_exec() says "Enable all of a task's
events that have been marked enable-on-exec", so I think the added
traversal makes sense in here):

From: Deng-Cheng Zhu <dczhu@xxxxxxxx>
Date: Wed, 23 Nov 2011 11:31:18 +0800
Subject: [PATCH] perf: Enable enable-on-exec siblings

Currently, when grouped events are created disabled and enable-on-exec,
the siblings won't be enabled on exec in fact. The problem looks like:

======================================================================
-sh-4.0# perf stat -g -e r14,cycles,instructions,r12 find / >/dev/null
^Cfind: Interrupt

Performance counter stats for 'find /':

60684699 r14
<not counted> cycles
<not counted> instructions
<not counted> r12

4.291975113 seconds time elapsed
======================================================================

This patch fixes it.

Signed-off-by: Deng-Cheng Zhu <dczhu@xxxxxxxx>
---
kernel/events/core.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0e8457d..63527d0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2476,6 +2476,12 @@ static void perf_event_enable_on_exec(struct perf_event_context *ctx)
raw_spin_lock(&ctx->lock);
task_ctx_sched_out(ctx);

+ list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
+ ret = event_enable_on_exec(event, ctx);
+ if (ret)
+ enabled = 1;
+ }
+
list_for_each_entry(event, &ctx->pinned_groups, group_entry) {
ret = event_enable_on_exec(event, ctx);
if (ret)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/