[ 3.5.y.z extended stable ] Patch "perf: Fix event group context move" has been added to staging queue

Luis Henriques luis.henriques at canonical.com
Tue Aug 6 09:36:47 UTC 2013


This is a note to let you know that I have just added a patch titled

    perf: Fix event group context move

to the linux-3.5.y-queue branch of the 3.5.y.z extended stable tree 
which can be found at:

 http://kernel.ubuntu.com/git?p=ubuntu/linux.git;a=shortlog;h=refs/heads/linux-3.5.y-queue

If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.5.y.z tree, see
https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable

Thanks.
-Luis

------

>From 8198b62edce33b0841d5d81942ca8dc7f180c3ac Mon Sep 17 00:00:00 2001
From: Jiri Olsa <jolsa at redhat.com>
Date: Fri, 1 Feb 2013 11:23:45 +0100
Subject: [PATCH] perf: Fix event group context move

commit 0231bb5336758426b44ccd798ccd3c5419c95d58 upstream.

When we have group with mixed events (hw/sw) we want to end up
with group leader being in hw context. So if group leader is
initialy sw event, we move all the events under hw context.

The move is done for each event by removing it from its context
and adding it back into proper one. As a part of the removal the
event is automatically disabled, which is not what we want at
this stage of creating groups.

The fix is to initialize event state after removal from sw
context.

This fix resulted from the following discussion:

  http://thread.gmane.org/gmane.linux.kernel.perf.user/1144

Reported-by: Andreas Hollmann <hollmann at in.tum.de>
Signed-off-by: Jiri Olsa <jolsa at redhat.com>
Cc: Arnaldo Carvalho de Melo <acme at redhat.com>
Cc: Namhyung Kim <namhyung at kernel.org>
Cc: Corey Ashford <cjashfor at linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec at gmail.com>
Cc: Paul Mackerras <paulus at samba.org>
Cc: Peter Zijlstra <a.p.zijlstra at chello.nl>
Cc: Stephane Eranian <eranian at google.com>
Cc: Vince Weaver <vince at deater.net>
Link: http://lkml.kernel.org/r/1359714225-4231-1-git-send-email-jolsa@redhat.com
Signed-off-by: Ingo Molnar <mingo at kernel.org>
Cc: Li Zefan <lizefan at huawei.com>
Signed-off-by: Luis Henriques <luis.henriques at canonical.com>
---
 kernel/events/core.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 00aa7e3..dd815c3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -915,6 +915,15 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
 }

 /*
+ * Initialize event state based on the perf_event_attr::disabled.
+ */
+static inline void perf_event__state_init(struct perf_event *event)
+{
+	event->state = event->attr.disabled ? PERF_EVENT_STATE_OFF :
+					      PERF_EVENT_STATE_INACTIVE;
+}
+
+/*
  * Called at perf_event creation and when events are attached/detached from a
  * group.
  */
@@ -6061,8 +6070,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 	event->overflow_handler	= overflow_handler;
 	event->overflow_handler_context = context;

-	if (attr->disabled)
-		event->state = PERF_EVENT_STATE_OFF;
+	perf_event__state_init(event);

 	pmu = NULL;

@@ -6484,9 +6492,17 @@ SYSCALL_DEFINE5(perf_event_open,

 		mutex_lock(&gctx->mutex);
 		perf_remove_from_context(group_leader);
+
+		/*
+		 * Removing from the context ends up with disabled
+		 * event. What we want here is event in the initial
+		 * startup state, ready to be add into new context.
+		 */
+		perf_event__state_init(group_leader);
 		list_for_each_entry(sibling, &group_leader->sibling_list,
 				    group_entry) {
 			perf_remove_from_context(sibling);
+			perf_event__state_init(sibling);
 			put_ctx(gctx);
 		}
 		mutex_unlock(&gctx->mutex);
--
1.8.3.2





More information about the kernel-team mailing list