mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH 02/11] perf: Do not get values from disabled counters in group format read
Date: Wed, 24 Oct 2012 18:03:44 +0200	[thread overview]
Message-ID: <20121024160344.GC5582@krava.brq.redhat.com> (raw)
In-Reply-To: <20121024121406.GA5582@krava.brq.redhat.com>

On Wed, Oct 24, 2012 at 02:14:06PM +0200, Jiri Olsa wrote:
> On Wed, Oct 24, 2012 at 02:01:18PM +0200, Peter Zijlstra wrote:

SNIP

> > Right, so I don't object to the patch per-se, I was just curious how you
> > ran into it, because ISTR what you just said, we enable all this stuff
> > together.
> > 
> > Also, why would disabled counters give strange values? They'd simply
> > return the same old value time after time, right?
> 
> well, x86_pmu_read calls x86_perf_event_update, which expects the event
> is active.. if it's not it'll update the count from whatever left in
> event.hw.idx counter.. could be uninitialized or used by others..
> 
> I can easily reproduce this one, so let's see.. ;)

ok, the problem code path is like this:

- running "perf record -e '{cycles,cache-misses}:S' -a sleep 1"
  which creates group of counters, that are enabled by perf via ioctl

- within the __perf_event_enable function the __perf_event_mark_enabled only
  change state for leader, so following group_sched_in will fail to schedule
  group siblings, because of the state check in event_sched_in:

	static int
	event_sched_in(struct perf_event *event,
			 struct perf_cpu_context *cpuctx,
			 struct perf_event_context *ctx)
	{
		u64 tstamp = perf_event_time(event);

		if (event->state <= PERF_EVENT_STATE_OFF)
			return 0;

- ending up with only leader enabled
- all the other events in group are enabled by perf after the leader,
  but meanwhile leader can hit sample.. and read group events.. ;)

attached patch fixies this for me and I was wondering we want
same behaviour for disable path as well (included below not tested)

I also think that we should keep that state check before calling
pmu->read() in the perf sample read

thanks,
jirka


---
diff --git a/kernel/events/core.c b/kernel/events/core.c
index dabfc5d..119a57e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1253,6 +1253,16 @@ retry:
 	raw_spin_unlock_irq(&ctx->lock);
 }
 
+static void __perf_event_mark_disabled(struct perf_event *event)
+{
+	struct perf_event *sub;
+
+	event->state = PERF_EVENT_STATE_OFF;
+
+	list_for_each_entry(sub, &event->sibling_list, group_entry)
+		sub->state = PERF_EVENT_STATE_OFF;
+}
+
 /*
  * Cross CPU call to disable a performance event
  */
@@ -1286,7 +1296,8 @@ int __perf_event_disable(void *info)
 			group_sched_out(event, cpuctx, ctx);
 		else
 			event_sched_out(event, cpuctx, ctx);
-		event->state = PERF_EVENT_STATE_OFF;
+
+		__perf_event_mark_disabled(event);
 	}
 
 	raw_spin_unlock(&ctx->lock);
@@ -1685,8 +1696,8 @@ retry:
 /*
  * Put a event into inactive state and update time fields.
  * Enabling the leader of a group effectively enables all
- * the group members that aren't explicitly disabled, so we
- * have to update their ->tstamp_enabled also.
+ * the group members, so we have to update their ->tstamp_enabled
+ * also.
  * Note: this works for group members as well as group leaders
  * since the non-leader members' sibling_lists will be empty.
  */
@@ -1697,9 +1708,10 @@ static void __perf_event_mark_enabled(struct perf_event *event)
 
 	event->state = PERF_EVENT_STATE_INACTIVE;
 	event->tstamp_enabled = tstamp - event->total_time_enabled;
+
 	list_for_each_entry(sub, &event->sibling_list, group_entry) {
-		if (sub->state >= PERF_EVENT_STATE_INACTIVE)
-			sub->tstamp_enabled = tstamp - sub->total_time_enabled;
+		sub->state = PERF_EVENT_STATE_INACTIVE;
+		sub->tstamp_enabled = tstamp - sub->total_time_enabled;
 	}
 }
 

  parent reply	other threads:[~2012-10-24 16:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-20 14:33 [PATCH 00/11] perf tool: Add PERF_SAMPLE_READ sample read support Jiri Olsa
2012-10-20 14:33 ` [PATCH 01/11] perf: Add PERF_EVENT_IOC_ID ioctl to return event ID Jiri Olsa
2012-10-20 14:33 ` [PATCH 02/11] perf: Do not get values from disabled counters in group format read Jiri Olsa
2012-10-23 16:13   ` Peter Zijlstra
2012-10-23 16:50     ` Jiri Olsa
2012-10-24 12:01       ` Peter Zijlstra
2012-10-24 12:14         ` Jiri Olsa
2012-10-24 12:32           ` Peter Zijlstra
2012-10-24 16:03           ` Jiri Olsa [this message]
2012-10-20 14:33 ` [PATCH 03/11] perf tool: Use PERF_EVENT_IOC_ID perf ioctl to read event id Jiri Olsa
2012-10-22  7:57   ` Namhyung Kim
2012-10-22  8:40     ` Jiri Olsa
2012-10-20 14:33 ` [PATCH 04/11] perf tool: Add support for parsing PERF_SAMPLE_READ sample type Jiri Olsa
2012-10-22  8:56   ` Namhyung Kim
2012-10-20 14:33 ` [PATCH 05/11] perf tool: Fix event ID retrieval for group format read case Jiri Olsa
2012-10-20 14:33 ` [PATCH 06/11] perf tool: Add perf_evlist__id2sid function to get event ID related data Jiri Olsa
2012-10-20 14:33 ` [PATCH 07/11] perf tool: Add PERF_SAMPLE_READ sample related processing Jiri Olsa
2012-10-20 14:33 ` [PATCH 08/11] perf tool: Add 'S' event/group modifier to read sample value Jiri Olsa
2012-10-20 14:33 ` [PATCH 09/11] perf test: Add parse events tests for leader sampling Jiri Olsa
2012-10-22  8:58   ` Namhyung Kim
2012-10-22  9:12     ` Jiri Olsa
2012-10-20 14:33 ` [PATCH 10/11] perf tool: Display period values for all group members Jiri Olsa
2012-10-20 14:33 ` [PATCH 11/11] perf record: Fix mmap error output condition Jiri Olsa
2012-10-30 12:11   ` [tip:perf/core] " tip-bot for Jiri Olsa
2012-10-21 16:38 ` [PATCH 00/11] perf tool: Add PERF_SAMPLE_READ sample read support Ingo Molnar
2012-10-22  8:09   ` Jiri Olsa
2012-10-22  8:51     ` Namhyung Kim
2012-10-22  9:15       ` Jiri Olsa
2012-10-22  7:32 ` Namhyung Kim
2012-10-22  7:53   ` Jiri Olsa
2012-10-22  8:53     ` Namhyung Kim
2012-10-22  9:06       ` Jiri Olsa
2012-10-26  1:29 ` Namhyung Kim
2012-10-26  9:14   ` Peter Zijlstra
2012-10-26 10:23     ` Jiri Olsa
2012-10-26 15:39       ` Namhyung Kim
2012-10-26 16:14         ` David Ahern
2012-10-26 16:25           ` Namhyung Kim
2012-10-26 16:47             ` David Ahern
2012-10-26 17:00         ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121024160344.GC5582@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome