perf: Make perf_event_init_context function static
Subsystems (2)
Jiri Olsa
reviewerPATCH 1/3 perf: Make perf_event_init_context function static
From: Jiri Olsa <[email protected]>
Leftover from '8dc85d5 perf: Multiple task contexts'.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -7775,7 +7775,7 @@ inherit_task_group(struct perf_event *event, struct task_struct *parent,/* * Initialize the perf_event context in task_struct */ -int perf_event_init_context (struct task_struct *child,int ctxn) +static int perf_event_init_context (struct task_struct *child,int ctxn) {struct perf_event_context *child_ctx, *parent_ctx;struct perf_event_context *cloned_ctx;
Signature · 1 line
1.8.3.1
Jiri Olsa
reviewerPATCH 2/3 perf: Do not allow optimized switch for non-cloned events
From: Jiri Olsa <[email protected]>
The context check in perf_event_context_sched_out allows non-cloned context to be part of the optimized schedule out switch.
This could move non-cloned context into another workload child. Once this child exits, the context is closed and leaves all original (parent) events in closed state.
Any other new cloned event will have closed state and not measure anything. And probably causing other odd bugs.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -2319,7 +2319,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, next_parent =rcu_dereference (next_ctx->parent_ctx);/* If neither context have a parent context; they cannot be clones. */ -if (!parent && !next_parent) +if (!parent || !next_parent) goto unlock;if (next_parent == ctx || next_ctx == parent || next_parent == parent) {
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerRe: [PATCH 2/3] perf: Do not allow optimized switch for non-cloned events
Quoted 31 lines · Jiri Olsa
From: Jiri Olsa <[email protected]>
The context check in
perf_event_context_sched_outallows non-cloned context to be part of the optimized schedule out switch.This could move non-cloned context into another workload child. Once this child exits, the context is closed and leaves all original (parent) events in closed state.
Any other new cloned event will have closed state and not measure anything. And probably causing other odd bugs.
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/events/core.c +0
-0
kernel/events/core.c static void perf_event_context_sched_out(struct task_struct *task, int ctxn, · line 2325
Quoted 8 lines
kernel/events/core.c +1
-1@@ -2319,7 +2319,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, next_parent =rcu_dereference (next_ctx->parent_ctx);/* If neither context have a parent context; they cannot be clones. */ -if (!parent && !next_parent) +if (!parent || !next_parent) goto unlock;if (next_parent == ctx || next_ctx == parent || next_parent == parent) {
Ohh, nice, good catch!
Thanks
Re: [PATCH 2/3] perf: Do not allow optimized switch for non-cloned events
Quoted 34 lines · Peter Zijlstra
Quoted 33 lines · Jiri Olsa
From: Jiri Olsa <[email protected]>
The context check in
perf_event_context_sched_outallows non-cloned context to be part of the optimized schedule out switch.This could move non-cloned context into another workload child. Once this child exits, the context is closed and leaves all original (parent) events in closed state.
Any other new cloned event will have closed state and not measure anything. And probably causing other odd bugs.
Cc Arnaldo Carvalho de Melo <[email protected]>Cc Corey Ashford <[email protected]>Cc David Ahern <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/events/core.c +0
-0@@ -2319,7 +2319,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, next_parent =rcu_dereference (next_ctx->parent_ctx);
Quoted 8 lines
kernel/events/core.c static void perf_event_context_sched_out(struct task_struct *task, int ctxn, · line 2325
Quoted 6 lines
kernel/events/core.c +1
-1/* If neither context have a parent context; they cannot be clones. */ -if (!parent && !next_parent) +if (!parent || !next_parent) goto unlock;if (next_parent == ctx || next_ctx == parent || next_parent == parent) {Ohh, nice, good catch!
should I queue it with your ack?
jirka
Peter Zijlstra
maintainerRe: [PATCH 2/3] perf: Do not allow optimized switch for non-cloned events
Quoted 2 lines · Jiri Olsa
should I queue it with your ack?
I picked up the lot.
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf: Do not allow optimized switch for non-cloned events
In reply to Jiri Olsaperf: Do not allow optimized switch for non-cloned events
Commit-ID: 1f9a7268c67f0290837aada443d28fd953ddca90 Gitweb: http://git.kernel.org/tip/1f9a7268c67f0290837aada443d28fd953ddca90 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 24 Jun 2014 10:20:25 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 2 Jul 2014 08:35:56 +0200
perf: Do not allow optimized switch for non-cloned events
The context check in perf_event_context_sched_out allows non-cloned context to be part of the optimized schedule out switch.
This could move non-cloned context into another workload child. Once this child exits, the context is closed and leaves all original (parent) events in closed state.
Any other new cloned event will have closed state and not measure anything. And probably causing other odd bugs.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -2320,7 +2320,7 @@ static void perf_event_context_sched_out(struct task_struct *task, int ctxn, next_parent =rcu_dereference (next_ctx->parent_ctx);/* If neither context have a parent context; they cannot be clones. */ -if (!parent && !next_parent) +if (!parent || !next_parent) goto unlock;if (next_parent == ctx || next_ctx == parent || next_parent == parent) {
Jiri Olsa
reviewerPATCH 3/3 perf tests: Add test to hit wrong event sched out
In reply to Jiri OlsaWe create single breakpoint event with inherit = true and create many workload children.
With some luck (which is directly proportional to number of children) we hit event optimized sched out moving original (parent) event into one of the child, closing it and causing wrong measured numbers.
--- tools/perf/Makefile.perf | 1 + tools/perf/tests/builtin-test.c | 4 ++ tools/perf/tests/optimized-sched-out.c | 90 ++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 96 insertions(+) create mode 100644 tools/perf/tests/optimized-sched-out.c
tools/perf/Makefile.perf +1 -0
@@ -419,6 +419,7 @@ endif endif LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o +LIB_OBJS += $(OUTPUT)tests/optimized-sched-out.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
@@ -154,6 +154,10 @@ static struct test { .func = test__hists_cumulate, }, { + .desc = "Test optimized event schedule out", + .func = test__optimized_sched_out, + }, + { .func = NULL, }, };
tools/perf/tests/optimized-sched-out.c new file +90 -0
90 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -48,6 +48,7 @@ int test__mmap_thread_lookup(void);int test__thread_mg_share (void );int test__hists_output (void );int test__hists_cumulate (void ); +int test__optimized_sched_out (void );#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.8.3.1
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf: Make perf_event_init_context() function static
In reply to Jiri Olsaperf: Make perf_event_init_context() function static
Commit-ID: 985c8dcbe15ddd8a1b98dc6b9c6403cb5d7012ab Gitweb: http://git.kernel.org/tip/985c8dcbe15ddd8a1b98dc6b9c6403cb5d7012ab Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 24 Jun 2014 10:20:24 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 5 Jul 2014 11:21:52 +0200
perf: Make perf_event_init_context() function static
Leftover from '8dc85d5 perf: Multiple task contexts'.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -7776,7 +7776,7 @@ inherit_task_group(struct perf_event *event, struct task_struct *parent,/* * Initialize the perf_event context in task_struct */ -int perf_event_init_context (struct task_struct *child,int ctxn) +static int perf_event_init_context (struct task_struct *child,int ctxn) {struct perf_event_context *child_ctx, *parent_ctx;struct perf_event_context *cloned_ctx;