]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.4.57/perf-fix-event-group-context-move.patch
Linux 3.4.57
[thirdparty/kernel/stable-queue.git] / releases / 3.4.57 / perf-fix-event-group-context-move.patch
1 From 0231bb5336758426b44ccd798ccd3c5419c95d58 Mon Sep 17 00:00:00 2001
2 From: Jiri Olsa <jolsa@redhat.com>
3 Date: Fri, 1 Feb 2013 11:23:45 +0100
4 Subject: perf: Fix event group context move
5
6 From: Jiri Olsa <jolsa@redhat.com>
7
8 commit 0231bb5336758426b44ccd798ccd3c5419c95d58 upstream.
9
10 When we have group with mixed events (hw/sw) we want to end up
11 with group leader being in hw context. So if group leader is
12 initialy sw event, we move all the events under hw context.
13
14 The move is done for each event by removing it from its context
15 and adding it back into proper one. As a part of the removal the
16 event is automatically disabled, which is not what we want at
17 this stage of creating groups.
18
19 The fix is to initialize event state after removal from sw
20 context.
21
22 This fix resulted from the following discussion:
23
24 http://thread.gmane.org/gmane.linux.kernel.perf.user/1144
25
26 Reported-by: Andreas Hollmann <hollmann@in.tum.de>
27 Signed-off-by: Jiri Olsa <jolsa@redhat.com>
28 Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
29 Cc: Namhyung Kim <namhyung@kernel.org>
30 Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
31 Cc: Frederic Weisbecker <fweisbec@gmail.com>
32 Cc: Paul Mackerras <paulus@samba.org>
33 Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
34 Cc: Stephane Eranian <eranian@google.com>
35 Cc: Vince Weaver <vince@deater.net>
36 Link: http://lkml.kernel.org/r/1359714225-4231-1-git-send-email-jolsa@redhat.com
37 Signed-off-by: Ingo Molnar <mingo@kernel.org>
38 Cc: Li Zefan <lizefan@huawei.com>
39 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
40
41 ---
42 kernel/events/core.c | 20 ++++++++++++++++++--
43 1 file changed, 18 insertions(+), 2 deletions(-)
44
45 --- a/kernel/events/core.c
46 +++ b/kernel/events/core.c
47 @@ -911,6 +911,15 @@ list_add_event(struct perf_event *event,
48 }
49
50 /*
51 + * Initialize event state based on the perf_event_attr::disabled.
52 + */
53 +static inline void perf_event__state_init(struct perf_event *event)
54 +{
55 + event->state = event->attr.disabled ? PERF_EVENT_STATE_OFF :
56 + PERF_EVENT_STATE_INACTIVE;
57 +}
58 +
59 +/*
60 * Called at perf_event creation and when events are attached/detached from a
61 * group.
62 */
63 @@ -6058,8 +6067,7 @@ perf_event_alloc(struct perf_event_attr
64 event->overflow_handler = overflow_handler;
65 event->overflow_handler_context = context;
66
67 - if (attr->disabled)
68 - event->state = PERF_EVENT_STATE_OFF;
69 + perf_event__state_init(event);
70
71 pmu = NULL;
72
73 @@ -6481,9 +6489,17 @@ SYSCALL_DEFINE5(perf_event_open,
74
75 mutex_lock(&gctx->mutex);
76 perf_remove_from_context(group_leader);
77 +
78 + /*
79 + * Removing from the context ends up with disabled
80 + * event. What we want here is event in the initial
81 + * startup state, ready to be add into new context.
82 + */
83 + perf_event__state_init(group_leader);
84 list_for_each_entry(sibling, &group_leader->sibling_list,
85 group_entry) {
86 perf_remove_from_context(sibling);
87 + perf_event__state_init(sibling);
88 put_ctx(gctx);
89 }
90 mutex_unlock(&gctx->mutex);