Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1312133

[PATCH 4/6] perf core: Add backwork attribute to perf event

From Wang Nan <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject [PATCH 4/6] perf core: Add backwork attribute to perf event
Date 2016-01-19 12:20 +0100
Message-ID <qSCun-6ZJ-25@gated-at.bofh.it> (permalink)
References <qSgNb-rq-19@gated-at.bofh.it> <qSCum-6ZJ-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


In perf_event_attr a new bit 'write_backward' is appended to indicate
this event should write ring buffer from its end to beginning.

In perf_output_begin(), prepare ring buffer according this bit.

This patch introduces small overhead into perf_output_begin():
an extra memory read and a conditional branch. Further patch can remove
this overhead using custom output handler.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 include/linux/perf_event.h      | 5 +++++
 include/uapi/linux/perf_event.h | 3 ++-
 kernel/events/core.c            | 7 +++++++
 kernel/events/ring_buffer.c     | 2 ++
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f9828a4..54c3fb2 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1032,6 +1032,11 @@ static inline bool has_aux(struct perf_event *event)
 	return event->pmu->setup_aux;
 }
 
+static inline bool is_write_backward(struct perf_event *event)
+{
+	return !!event->attr.write_backward;
+}
+
 extern int perf_output_begin(struct perf_output_handle *handle,
 			     struct perf_event *event, unsigned int size);
 extern void perf_output_end(struct perf_output_handle *handle);
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 2c7f00c..598b9b0 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -340,7 +340,8 @@ struct perf_event_attr {
 				comm_exec      :  1, /* flag comm events that are due to an exec */
 				use_clockid    :  1, /* use @clockid for time fields */
 				context_switch :  1, /* context switch data */
-				__reserved_1   : 37;
+				write_backward :  1, /* Write ring buffer from end to beginning */
+				__reserved_1   : 36;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f79c4be..8ad22a5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8107,6 +8107,13 @@ perf_event_set_output(struct perf_event *event, struct perf_event *output_event)
 		goto out;
 
 	/*
+	 * Either writing ring buffer from beginning or from end.
+	 * Mixing is not allowed.
+	 */
+	if (is_write_backward(output_event) != is_write_backward(event))
+		goto out;
+
+	/*
 	 * If both events generate aux data, they must be on the same PMU
 	 */
 	if (has_aux(event) && has_aux(output_event) &&
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index bbc3bc6..1372427 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -228,6 +228,8 @@ out:
 int perf_output_begin(struct perf_output_handle *handle,
 		      struct perf_event *event, unsigned int size)
 {
+	if (unlikely(is_write_backward(event)))
+		return __perf_output_begin(handle, event, size, true);
 	return __perf_output_begin(handle, event, size, false);
 }
 
-- 
1.8.3.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] perf core: Introduce new ioctl options to pause and resume ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-18 13:00 +0100
  Re: [PATCH] perf core: Introduce new ioctl options to pause and  resume ring buffer Peter Zijlstra <peterz@infradead.org> - 2016-01-18 13:10 +0100
    Re: [PATCH] perf core: Introduce new ioctl options to pause and resume  ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-19 04:00 +0100
    [PATCH 0/6] perf core: Read from overwrite ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 1/6] perf core: Introduce new ioctl options to pause and resume ring buffer Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 6/6] perf/core: Put size of a sample at the end of it by PERF_SAMPLE_TAILSIZE Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 2/6] perf core: Set event's default overflow_handler Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 5/6] perf core: Reduce perf event output overhead by setting overwrite handler Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 4/6] perf core: Add backwork attribute to perf event Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:20 +0100
      [PATCH 3/6] perf core: Prepare writing into ring buffer from end Wang Nan <wangnan0@huawei.com> - 2016-01-19 12:30 +0100
      Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Namhyung Kim <namhyung@kernel.org> - 2016-01-19 15:10 +0100
        Re: [PATCH 0/6] perf core: Read from overwrite ring buffer pi3orama <pi3orama@163.com> - 2016-01-19 15:20 +0100
      Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-19 18:50 +0100
        Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-20 02:40 +0100
          Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-20 03:30 +0100
            Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-21 08:00 +0100
              Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-22 03:30 +0100
                Re: [PATCH 0/6] perf core: Read from overwrite ring buffer Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-01-22 04:30 +0100
                Re: [PATCH 0/6] perf core: Read from overwrite ring buffer "Wangnan (F)" <wangnan0@huawei.com> - 2016-01-22 05:50 +0100

csiph-web