netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@plumgrid.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Wang Nan <wangnan0@huawei.com>, He Kuang <hekuang@huawei.com>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 1/3] perf: pad raw data samples automatically
Date: Tue, 20 Oct 2015 20:02:33 -0700	[thread overview]
Message-ID: <1445396556-4854-2-git-send-email-ast@kernel.org> (raw)
In-Reply-To: <1445396556-4854-1-git-send-email-ast@kernel.org>

Instead of WARN_ON in perf_event_output() on unpaded raw samples,
pad them automatically.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/events/core.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index b11756f9b6dc..64754bfecd70 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5286,9 +5286,15 @@ void perf_output_sample(struct perf_output_handle *handle,
 
 	if (sample_type & PERF_SAMPLE_RAW) {
 		if (data->raw) {
-			perf_output_put(handle, data->raw->size);
-			__output_copy(handle, data->raw->data,
-					   data->raw->size);
+			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);
 		} else {
 			struct {
 				u32	size;
@@ -5420,8 +5426,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 		else
 			size += sizeof(u32);
 
-		WARN_ON_ONCE(size & (sizeof(u64)-1));
-		header->size += size;
+		header->size += round_up(size, sizeof(u64));
 	}
 
 	if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
-- 
1.7.9.5

  reply	other threads:[~2015-10-21  3:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-21  3:02 [PATCH net-next 0/3] bpf_perf_event_output helper Alexei Starovoitov
2015-10-21  3:02 ` Alexei Starovoitov [this message]
2015-10-21  3:02 ` [PATCH net-next 2/3] bpf: introduce bpf_perf_event_output() helper Alexei Starovoitov
2015-10-21 10:01   ` He Kuang
2015-10-21 11:05     ` Wangnan (F)
2015-10-21 20:04       ` Alexei Starovoitov
2015-10-21 12:06   ` Peter Zijlstra
2015-10-21 17:26     ` Alexei Starovoitov
2015-10-21 19:33       ` Peter Zijlstra
2015-10-22 13:59   ` Peter Zijlstra
2015-10-22 15:38     ` Alexei Starovoitov
2015-10-23 14:39   ` Peter Zijlstra
2015-10-23 15:02     ` Alexei Starovoitov
2015-10-23 16:42       ` Peter Zijlstra
2015-10-23 17:25         ` Alexei Starovoitov
2015-10-26  1:46           ` Wangnan (F)
2015-10-26 10:27             ` Alexei Starovoitov
2015-10-21  3:02 ` [PATCH net-next 3/3] samples: bpf: add bpf_perf_event_output example Alexei Starovoitov
2015-10-22 13:42 ` [PATCH net-next 0/3] bpf_perf_event_output helper David Miller

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=1445396556-4854-2-git-send-email-ast@kernel.org \
    --to=ast@plumgrid.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hekuang@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=wangnan0@huawei.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;
as well as URLs for NNTP newsgroup(s).