From: Peter Zijlstra <peterz@infradead.org>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: davem@davemloft.net, alexei.starovoitov@gmail.com, tgraf@suug.ch,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] perf, events: add non-linear data support for raw records
Date: Wed, 13 Jul 2016 15:42:31 +0200 [thread overview]
Message-ID: <20160713134231.GT30154@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <f6ffffc1011706426682be92f80fc6aa6a8cc196.1468362046.git.daniel@iogearbox.net>
Ok so the nonlinear thing was it doing _two_ copies, one the regular
__output_copy() on raw->data and second the optional fragment thingy
using __output_custom().
Would something like this work instead?
It does the nonlinear thing and the custom copy function thing but
allows more than 2 fragments and allows each fragment to have a custom
copy.
It doesn't look obviously more expensive; it has the one ->copy branch
extra, but then it doesn't recompute the sizes.
---
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 1fe22032f228..83e2a83e8db3 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -69,9 +69,18 @@ struct perf_callchain_entry_ctx {
bool contexts_maxed;
};
+typedef unsigned long (*perf_copy_f)(void *dst, const void *src, unsigned long len);
+
+struct perf_raw_frag {
+ struct perf_raw_frag *next;
+ perf_copy_f copy;
+ void *data;
+ u32 size;
+} __packed;
+
struct perf_raw_record {
+ struct perf_raw_frag frag;
u32 size;
- void *data;
};
/*
diff --git a/kernel/events/core.c b/kernel/events/core.c
index fe8d49a56322..f7ad7d65317d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5617,16 +5617,21 @@ void perf_output_sample(struct perf_output_handle *handle,
}
if (sample_type & PERF_SAMPLE_RAW) {
- if (data->raw) {
- u32 raw_size = data->raw->size;
- u32 real_size = round_up(raw_size + sizeof(u32),
- sizeof(u64)) - sizeof(u32);
- u64 zero = 0;
-
- perf_output_put(handle, real_size);
- __output_copy(handle, data->raw->data, raw_size);
- if (real_size - raw_size)
- __output_copy(handle, &zero, real_size - raw_size);
+ struct perf_raw_record *raw = data->raw;
+
+ if (raw) {
+ struct perf_raw_frag *frag = &raw->frag;
+
+ perf_output_put(handle, raw->size);
+ do {
+ if (frag->copy) {
+ __output_custom(handle, frag->copy,
+ frag->data, frag->size);
+ } else {
+ __output_copy(handle, frag->data, frag->size);
+ }
+ frag = frag->next;
+ } while (frag);
} else {
struct {
u32 size;
@@ -5751,14 +5756,22 @@ void perf_prepare_sample(struct perf_event_header *header,
}
if (sample_type & PERF_SAMPLE_RAW) {
- int size = sizeof(u32);
+ struct perf_raw_record *raw = data->raw;
+ int size = sizeof(u64);
- if (data->raw)
- size += data->raw->size;
- else
- size += sizeof(u32);
+ if (raw) {
+ struct perf_raw_frag *frag = &raw->frag;
- header->size += round_up(size, sizeof(u64));
+ size = sizeof(u32);
+ do {
+ size += frag->size;
+ frag = frag->next;
+ } while (frag)
+ size = round_up(size, sizeof(u64));
+ raw->size = size;
+ }
+
+ header->size += size;
}
if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
next prev parent reply other threads:[~2016-07-13 13:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 22:36 [PATCH net-next 0/3] BPF event output helper improvements Daniel Borkmann
2016-07-12 22:36 ` [PATCH net-next 1/3] perf, events: add non-linear data support for raw records Daniel Borkmann
2016-07-13 7:52 ` Peter Zijlstra
2016-07-13 9:24 ` Daniel Borkmann
2016-07-13 12:10 ` Peter Zijlstra
2016-07-13 13:16 ` Daniel Borkmann
2016-07-13 13:42 ` Peter Zijlstra [this message]
2016-07-13 14:08 ` Daniel Borkmann
2016-07-13 16:40 ` Peter Zijlstra
2016-07-13 16:53 ` Daniel Borkmann
2016-07-12 22:36 ` [PATCH net-next 2/3] bpf, perf: split bpf_perf_event_output Daniel Borkmann
2016-07-12 22:36 ` [PATCH net-next 3/3] bpf: avoid stack copy and use skb ctx for event output Daniel Borkmann
2016-07-12 23:25 ` kbuild test robot
2016-07-12 23:45 ` Daniel Borkmann
2016-07-13 0:01 ` Fengguang Wu
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=20160713134231.GT30154@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=alexei.starovoitov@gmail.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/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;
as well as URLs for NNTP newsgroup(s).