Skip to contentSkip to conversation

perf: Make perf_event_init_context function static

PATCH In review Jiri Olsa 4 participants 8 messages Jun 24, 2014 – Jul 5, 2014

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/3 perf: Make perf_event_init_context function static

From: Jiri Olsa <[email protected]>

Leftover from '8dc85d5 perf: Multiple task contexts'.

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]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index cd28335..d968008 100644
@@ -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
author reviewer
#1 lore raw

PATCH 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.

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]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index d968008..4e3618e 100644
@@ -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
maintainer
#2 lore raw

Re: [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_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.

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]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +0 -0
index d968008..4e3618e 100644

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

#3 lore raw

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_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.

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]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +0 -0
index d968008..4e3618e 100644
@@ -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

maintainer
#4 lore raw

Re: [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.

#5 lore raw

[tip:perf/urgent] perf: Do not allow optimized switch for non-cloned events

In reply to Jiri Olsa
perf: 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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index a33d9a2b..b0c95f0 100644
@@ -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) {
author reviewer
#6 lore raw

PATCH 3/3 perf tests: Add test to hit wrong event sched out

In reply to Jiri Olsa

We 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.

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]>
---
 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
index 9670a16..29ff74e 100644
@@ -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
index 6f8b01b..754dc2a 100644
@@ -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
index ed64790..a62d58d 100644
@@ -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
#7 lore raw

[tip:perf/core] perf: Make perf_event_init_context() function static

In reply to Jiri Olsa
perf: 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
index a33d9a2b..67e3b9c 100644
@@ -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;