Skip to contentSkip to conversation

perf: Generate EXIT event only once per task context

PATCH In review Namhyung Kim 2 participants 4 messages Mar 15, 2013 – Mar 21, 2013 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf: Generate EXIT event only once per task context

From: Namhyung Kim <[email protected]>

perf_event_task_event() iterates pmu list and generate events for each eligible pmu context. But if task_event has task_ctx like in EXIT it'll generate events even though the pmu doesn't have an eligible one. Fix it by moving the code to proper places.

Before this patch:

  $ perf record -n true
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.006 MB perf.data (~248 samples) ]
  $ perf report -D | tail
  Aggregated stats:
             TOTAL events:         73
              MMAP events:         67
              COMM events:          2
              EXIT events:          4
  cycles stats:
             TOTAL events:         73
              MMAP events:         67
              COMM events:          2
              EXIT events:          4

After this patch:

  $ perf report -D | tail
  Aggregated stats:
             TOTAL events:         70
              MMAP events:         67
              COMM events:          2
              EXIT events:          1
  cycles stats:
             TOTAL events:         70
              MMAP events:         67
              COMM events:          2
              EXIT events:          1
---
 kernel/events/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/events/core.c +5 -2
index 53ac21cc4012..73ea6fcacf52 100644
@@ -4432,12 +4432,15 @@ static void perf_event_task_event(struct perf_task_event *task_event)
 			if (ctxn < 0)
 				goto next;
 			ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);
+			if (ctx)
+				perf_event_task_ctx(ctx, task_event);
 		}
-		if (ctx)
-			perf_event_task_ctx(ctx, task_event);
 next:
 		put_cpu_ptr(pmu->pmu_cpu_context);
 	}
+	if (task_event->task_ctx)
+		perf_event_task_ctx(task_event->task_ctx, task_event);
+
 	rcu_read_unlock();
 }
 
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

Hi,

I added a test case for this. Please take a look on it too. This patch is based on my previous evlist cleanup patchset:

https://lkml.org/lkml/2013/3/15/47

Thanks,
Namhyung

Quoted 1 line

From df86ff1984a2ab89331a10f5e1fc93f09e260ed9 Mon Sep 17 00:00:00 2001

From: Namhyung Kim <[email protected]>
Date: Fri, 15 Mar 2013 14:58:11 +0900
Subject: [PATCH] perf test: Add test case for checking number of EXIT events

The test__task_exit() runs a simple "/usr/bin/true" workload and then checks whether the number of EXIT event is 1 or not.

---
 tools/perf/Makefile             |   1 +
 tools/perf/tests/builtin-test.c |   4 ++
 tools/perf/tests/task-exit.c    | 123 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 129 insertions(+)
 create mode 100644 tools/perf/tests/task-exit.c
tools/perf/Makefile +1 -0
index 3dcd6273a90b..0145df853af4 100644
@@ -511,6 +511,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
 LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
+LIB_OBJS += $(OUTPUT)tests/task-exit.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
index acb98e0e39f2..dd00e5e444f8 100644
@@ -78,6 +78,10 @@ static struct test {
 		.func = test__python_use,
 	},
 	{
+		.desc = "Test number of exit event of a simple workload",
+		.func = test__task_exit,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/task-exit.c new file +123 -0

123 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index 5de0be1ff4b6..4590c10b7e65 100644
@@ -23,5 +23,6 @@ int test__dso_data(void);
 int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
+int test__task_exit(void);
 
 #endif /* TESTS_H */
Signature · 1 line
1.8.1.4
#2 lore raw

[tip:perf/core] perf test: Add test case for checking number of EXIT events

perf test: Add test case for checking number of EXIT events
Commit-ID:  d723a55096b81a13c319485f01994e0a539efcf9
Gitweb:     http://git.kernel.org/tip/d723a55096b81a13c319485f01994e0a539efcf9
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 15 Mar 2013 14:58:11 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 15 Mar 2013 13:06:12 -0300

perf test: Add test case for checking number of EXIT events

The new test__task_exit() test runs a simple "/usr/bin/true" workload and then checks whether the number of EXIT event is 1 or not.

Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ committer note: Fixup conflicts with f4c66b4 ( bp overflow tests ) ]
---
 tools/perf/Makefile             |   1 +
 tools/perf/tests/builtin-test.c |   4 ++
 tools/perf/tests/task-exit.c    | 123 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 129 insertions(+)
tools/perf/Makefile +1 -0
index 990e9a1..8e1bba3 100644
@@ -513,6 +513,7 @@ LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
 LIB_OBJS += $(OUTPUT)tests/bp_signal.o
 LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
+LIB_OBJS += $(OUTPUT)tests/task-exit.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
index 45d9ad4..9b5c70a 100644
@@ -86,6 +86,10 @@ static struct test {
 		.func = test__bp_signal_overflow,
 	},
 	{
+		.desc = "Test number of exit event of a simple workload",
+		.func = test__task_exit,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/task-exit.c new file +123 -0

123 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index 6cf1ec4..b33b328 100644
@@ -25,5 +25,6 @@ int test__hists_link(void);
 int test__python_use(void);
 int test__bp_signal(void);
 int test__bp_signal_overflow(void);
+int test__task_exit(void);
 
 #endif /* TESTS_H */
#3 lore raw
In reply to Namhyung Kim
perf: Generate EXIT event only once per task context
Commit-ID:  d610d98b5de6860feb21539726e9af7c9094151c
Gitweb:     http://git.kernel.org/tip/d610d98b5de6860feb21539726e9af7c9094151c
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 15 Mar 2013 16:27:13 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 18 Mar 2013 09:47:33 +0100

perf: Generate EXIT event only once per task context

perf_event_task_event() iterates pmu list and generate events for each eligible pmu context. But if task_event has task_ctx like in EXIT it'll generate events even though the pmu doesn't have an eligible one. Fix it by moving the code to proper places.

Before this patch:

  $ perf record -n true
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.006 MB perf.data (~248 samples) ]
  $ perf report -D | tail
  Aggregated stats:
             TOTAL events:         73
              MMAP events:         67
              COMM events:          2
              EXIT events:          4
  cycles stats:
             TOTAL events:         73
              MMAP events:         67
              COMM events:          2
              EXIT events:          4

After this patch:

  $ perf report -D | tail
  Aggregated stats:
             TOTAL events:         70
              MMAP events:         67
              COMM events:          2
              EXIT events:          1
  cycles stats:
             TOTAL events:         70
              MMAP events:         67
              COMM events:          2
              EXIT events:          1
---
 kernel/events/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/events/core.c +5 -2
index fa79c37..59412d0 100644
@@ -4434,12 +4434,15 @@ static void perf_event_task_event(struct perf_task_event *task_event)
 			if (ctxn < 0)
 				goto next;
 			ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);
+			if (ctx)
+				perf_event_task_ctx(ctx, task_event);
 		}
-		if (ctx)
-			perf_event_task_ctx(ctx, task_event);
 next:
 		put_cpu_ptr(pmu->pmu_cpu_context);
 	}
+	if (task_event->task_ctx)
+		perf_event_task_ctx(task_event->task_ctx, task_event);
+
 	rcu_read_unlock();
 }