Skip to contentSkip to conversation

perf: Fix wakeup_events logic

PATCH In review Jiri Olsa 3 participants 7 messages May 30, 2013 perf events

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover perf: Fix wakeup_events logic

hi,
this patchset enables the wakeup_events check for all type of events stored under ring buffer plus test.

Changes could be reached in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/aux_poll1

thanks,
jirka

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>

---
Jiri Olsa (2):
perf: Enable wakeup_events logic for all events perf tests: Add auxiliary events poll automated test

 kernel/events/core.c            |  14 --------
 kernel/events/ring_buffer.c     |  20 ++++++++++++
 tools/perf/Makefile             |   1 +
 tools/perf/tests/aux_poll.c     | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |   4 +++
 tools/perf/tests/tests.h        |   1 +
 6 files changed, 202 insertions(+), 14 deletions(-)
 create mode 100644 tools/perf/tests/aux_poll.c
author
#1 lore raw

PATCH 1/2 perf: Enable wakeup_events logic for all events

Currently the perf_events_attr::wakeup_events logic is checked only for regular samples.

If we have an event that produce only auxiliary events (MMAP|COMM|EXIT|FORK), the poll call does not follow the perf_events_attr wakeup_events setup and reports no data.

Fixing this by moving the perf_events_attr::wakeup_events checking logic into the function and calling it from perf_output_end. This way any output event is checked properly.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 kernel/events/core.c        | 14 --------------
 kernel/events/ring_buffer.c | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 14 deletions(-)
kernel/events/core.c +0 -14
index a0780b3..516eb25 100644
@@ -4281,20 +4281,6 @@ void perf_output_sample(struct perf_output_handle *handle,
 		}
 	}
 
-	if (!event->attr.watermark) {
-		int wakeup_events = event->attr.wakeup_events;
-
-		if (wakeup_events) {
-			struct ring_buffer *rb = handle->rb;
-			int events = local_inc_return(&rb->events);
-
-			if (events >= wakeup_events) {
-				local_sub(wakeup_events, &rb->events);
-				local_inc(&rb->wakeup);
-			}
-		}
-	}
-
 	if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
 		if (data->br_stack) {
 			size_t size;
kernel/events/ring_buffer.c +20 -0
index cd55144..1385fb1 100644
@@ -54,6 +54,25 @@ static void perf_output_wakeup(struct perf_output_handle *handle)
 	irq_work_queue(&handle->event->pending);
 }
 
+static void perf_output_check_wakeup(struct perf_output_handle *handle)
+{
+	struct perf_event *event = handle->event;
+
+	if (!event->attr.watermark) {
+		int wakeup_events = event->attr.wakeup_events;
+
+		if (wakeup_events) {
+			struct ring_buffer *rb = handle->rb;
+			int events = local_inc_return(&rb->events);
+
+			if (events >= wakeup_events) {
+				local_sub(wakeup_events, &rb->events);
+				local_inc(&rb->wakeup);
+			}
+		}
+	}
+}
+
 /*
  * We need to ensure a later event_id doesn't publish a head when a former
  * event isn't done writing. However since we need to deal with NMIs we
@@ -208,6 +227,7 @@ unsigned int perf_output_skip(struct perf_output_handle *handle,
 
 void perf_output_end(struct perf_output_handle *handle)
 {
+	perf_output_check_wakeup(handle);
 	perf_output_put_handle(handle);
 	rcu_read_unlock();
 }
Signature · 1 line
1.7.11.7
maintainer
#2 lore raw

Re: [PATCH 1/2] perf: Enable wakeup_events logic for all events

Quoted 8 lines · Jiri Olsa

Currently the perf_events_attr::wakeup_events logic is checked only for regular samples.

If we have an event that produce only auxiliary events (MMAP|COMM|EXIT|FORK), the poll call does not follow the perf_events_attr wakeup_events setup and reports no data.

Quoted 5 lines

Fixing this by moving the perf_events_attr::wakeup_events checking logic into the function and calling it from perf_output_end. This way any output event is checked properly.

So something like this came up before and ISTR doing a patch similar to what you propose but ended up not going with it because... uhm...

I have vague memories about people (possibly me) wanting wake_events to mean samples. Like get me a wakeup every 20 samples. With your patch the side-band events now also count towards 'events'.

I think the most common use of wake_events is people setting it to 1 and have perf generate a SIGfoo for every sample so they can do magic in their userspace signal handler. This is popular for interpreters.

It would be unfortunate to get SIGfoos for side-band chatter.

Makes sense?

author
#3 lore raw

Re: [PATCH 1/2] perf: Enable wakeup_events logic for all events

Quoted 22 lines · Peter Zijlstra
Quoted 8 lines · Jiri Olsa

Currently the perf_events_attr::wakeup_events logic is checked only for regular samples.

If we have an event that produce only auxiliary events (MMAP|COMM|EXIT|FORK), the poll call does not follow the perf_events_attr wakeup_events setup and reports no data.

Quoted 5 lines

Fixing this by moving the perf_events_attr::wakeup_events checking logic into the function and calling it from perf_output_end. This way any output event is checked properly.

So something like this came up before and ISTR doing a patch similar to what you propose but ended up not going with it because... uhm...

I have vague memories about people (possibly me) wanting wake_events to mean samples. Like get me a wakeup every 20 samples. With your patch the side-band events now also count towards 'events'.

Quoted 8 lines

I think the most common use of wake_events is people setting it to 1 and have perf generate a SIGfoo for every sample so they can do magic in their userspace signal handler. This is popular for interpreters.

It would be unfortunate to get SIGfoos for side-band chatter.

Makes sense?

hum, well the whole story is that for the ifunc user space tracer (profwiz) I'd need the auxiliary stuff for the tracee (MMAP, COMM...) so I could end up with 'reportable' perf.data file and use just VMA addresses for functions.

So, the only way now is to create an event which is never hit and set it up for this. At that point I noticed the poll would never return.. hence the patch ;-)

(I was also thinking of a new special SW event doing nothing, just be there to get aux stuff..)

Anyway, I could always check the map manually.. but I'd sort of expect poll to work the same for anything you write/read via RB.

how about having something like:

wakeup_events - setup for samples (stays)
wakeup_any - new flag saying to use wakeup_events for
anything going through the RB

thanks,
jirka

#4 lore raw

Re: [PATCH 1/2] perf: Enable wakeup_events logic for all events

In reply to Peter Zijlstra

Em Thu, May 30, 2013 at 01:02:39PM +0200, Peter Zijlstra escreveu:

Quoted 10 lines · Jiri Olsa
Quoted 2 lines

Currently the perf_events_attr::wakeup_events logic is checked only for regular samples.

So something like this came up before and ISTR doing a patch similar to what you propose but ended up not going with it because... uhm...

I have vague memories about people (possibly me) wanting wake_events to mean samples. Like get me a wakeup every 20 samples. With your patch the side-band events now also count towards 'events'.

I think it was me, and the test case is tools/perf/pythoh/twatch.py, that just wants those side band events, the "fix" was:

commit cfeb1d90a1b1db96383b48888cb7a5f10ca12e12

Author: Arnaldo Carvalho de Melo <[email protected]>
Date:   Mon Jan 30 14:43:21 2012 -0200

perf python: Use attr.watermark in twatch.py

We want to be woken up for every PERF_RECORD_ event,
attr.wakeup_events is only for PERF_RECORD_SAMPLE, so also use attr.watermark = 1 to fix that.

Quoted 8 lines

I think the most common use of wake_events is people setting it to 1 and have perf generate a SIGfoo for every sample so they can do magic in their userspace signal handler. This is popular for interpreters.

It would be unfortunate to get SIGfoos for side-band chatter.

Makes sense?

author
#5 lore raw

Re: [PATCH 1/2] perf: Enable wakeup_events logic for all events

Quoted 16 lines · Arnaldo Carvalho de Melo

Em Thu, May 30, 2013 at 01:02:39PM +0200, Peter Zijlstra escreveu:

Quoted 10 lines · Jiri Olsa
Quoted 2 lines

Currently the perf_events_attr::wakeup_events logic is checked only for regular samples.

So something like this came up before and ISTR doing a patch similar to what you propose but ended up not going with it because... uhm...

I have vague memories about people (possibly me) wanting wake_events to mean samples. Like get me a wakeup every 20 samples. With your patch the side-band events now also count towards 'events'.

I think it was me, and the test case is tools/perf/pythoh/twatch.py, that just wants those side band events, the "fix" was:

commit cfeb1d90a1b1db96383b48888cb7a5f10ca12e12

Quoted 8 lines
Author: Arnaldo Carvalho de Melo <[email protected]>
Date:   Mon Jan 30 14:43:21 2012 -0200

perf python: Use attr.watermark in twatch.py

We want to be woken up for every PERF_RECORD_ event,
attr.wakeup_events is only for PERF_RECORD_SAMPLE, so also use attr.watermark = 1 to fix that.

ah right, using wattermark=1.. ok ;-)

thanks,
jirka

author
#6 lore raw

PATCH 2/2 perf tests: Add auxiliary events poll automated test

In reply to Jiri Olsa

This test creates syscall entry event restricted for user space (we should get no samples) and accepting auxiliary events (MMAP, COMM, EXIT, FORK).

We test the poll works properly when only auxiliary events are received.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Makefile             |   1 +
 tools/perf/tests/aux_poll.c     | 176 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |   4 +
 tools/perf/tests/tests.h        |   1 +
 4 files changed, 182 insertions(+)
 create mode 100644 tools/perf/tests/aux_poll.c
tools/perf/Makefile +1 -0
index 74fdd2b..64e3ce8 100644
@@ -386,6 +386,7 @@ LIB_OBJS += $(OUTPUT)tests/bp_signal.o
 LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
 LIB_OBJS += $(OUTPUT)tests/task-exit.o
 LIB_OBJS += $(OUTPUT)tests/sw-clock.o
+LIB_OBJS += $(OUTPUT)tests/aux_poll.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/aux_poll.c new file +176 -0

176 lines not on this page · raw message

tools/perf/tests/builtin-test.c +4 -0
index 35b45f1466..2479be8 100644
@@ -94,6 +94,10 @@ static struct test {
 		.func = test__sw_clock_freq,
 	},
 	{
+		.desc = "Test poll syscall for auxiliary events",
+		.func = test__aux_poll,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index dd7feae..c4dff04 100644
@@ -27,5 +27,6 @@ int test__bp_signal(void);
 int test__bp_signal_overflow(void);
 int test__task_exit(void);
 int test__sw_clock_freq(void);
+int test__aux_poll(void);
 
 #endif /* TESTS_H */
Signature · 1 line
1.7.11.7