From: Wang Nan <wangnan0@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, Wang Nan <wangnan0@huawei.com>,
He Kuang <hekuang@huawei.com>,
Alexei Starovoitov <ast@kernel.org>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
Brendan Gregg <brendan.d.gregg@gmail.com>,
"Jiri Olsa" <jolsa@kernel.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Namhyung Kim <namhyung@kernel.org>, Zefan Li <lizefan@huawei.com>,
<pi3orama@163.com>
Subject: [RESEND PATCH 4/5] perf core: Add backward attribute to perf event
Date: Mon, 7 Mar 2016 03:50:18 +0000 [thread overview]
Message-ID: <1457322619-170254-5-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1457322619-170254-1-git-send-email-wangnan0@huawei.com>
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 by 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: Ingo Molnar <mingo@redhat.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 a9d8cab..88e2b47 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1031,6 +1031,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 a3c1903..43fc8d2 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 ed94c91..513b556 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8196,6 +8196,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 37c11c6..80b1fa7 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -233,6 +233,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
next prev parent reply other threads:[~2016-03-07 3:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-07 3:50 [RESEND PATCH 0/5] perf core: Support overwrite ring buffer Wang Nan
2016-03-07 3:50 ` [RESEND PATCH 1/5] perf core: Introduce new ioctl options to pause and resume " Wang Nan
2016-03-07 3:50 ` [RESEND PATCH 2/5] perf core: Set event's default overflow_handler Wang Nan
2016-03-07 3:50 ` [RESEND PATCH 3/5] perf core: Prepare writing into ring buffer from end Wang Nan
2016-03-07 3:50 ` Wang Nan [this message]
2016-03-07 3:50 ` [RESEND PATCH 5/5] perf core: Reduce perf event output overhead by new overflow handler Wang Nan
2016-03-08 13:44 ` [RESEND PATCH 0/5] perf core: Support overwrite ring buffer Peter Zijlstra
2016-03-08 13:49 ` Ingo Molnar
2016-03-08 13:57 ` Peter Zijlstra
2016-03-08 15:29 ` Ingo Molnar
2016-03-08 15:35 ` Dmitry Vyukov
2016-03-08 15:54 ` Ingo Molnar
2016-03-08 16:11 ` Dmitry Vyukov
2016-03-08 16:27 ` Ingo Molnar
2016-03-08 16:29 ` Dmitry Vyukov
2016-03-08 16:32 ` Peter Zijlstra
2016-03-08 16:44 ` Ingo Molnar
2016-03-08 16:48 ` Ingo Molnar
2016-03-08 16:59 ` Dmitry Vyukov
2016-03-08 17:24 ` Ingo Molnar
2016-03-08 17:27 ` Dmitry Vyukov
2016-03-08 17:37 ` Ingo Molnar
2016-03-08 17:41 ` Dmitry Vyukov
2016-03-08 17:48 ` Ingo Molnar
2016-03-08 17:56 ` Dmitry Vyukov
2016-03-08 17:56 ` Peter Zijlstra
2016-03-08 17:57 ` Ingo Molnar
2016-03-08 18:02 ` Ingo Molnar
2016-03-08 18:22 ` Ingo Molnar
2016-03-08 18:31 ` Ingo Molnar
2016-03-08 17:55 ` Peter Zijlstra
2016-03-08 16:30 ` Peter Zijlstra
2016-03-09 10:53 ` Borislav Petkov
2016-03-09 11:19 ` Dmitry Vyukov
2016-03-08 19:56 ` Jiri Olsa
2016-03-08 20:07 ` Peter Zijlstra
2016-03-08 20:44 ` Jiri Olsa
2016-03-08 21:04 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457322619-170254-5-git-send-email-wangnan0@huawei.com \
--to=wangnan0@huawei.com \
--cc=acme@redhat.com \
--cc=ast@kernel.org \
--cc=brendan.d.gregg@gmail.com \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=pi3orama@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®