From: Frederic Weisbecker <fweisbec@gmail.com>
To: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Paul Mackerras <paulus@samba.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf tools: fix write_event()
Date: Wed, 20 Jan 2010 14:41:58 +0100 [thread overview]
Message-ID: <20100120134155.GA7281@nowhere> (raw)
In-Reply-To: <4B570657.5090105@cn.fujitsu.com>
On Wed, Jan 20, 2010 at 09:34:15PM +0800, Xiao Guangrong wrote:
> We parse the event while it's read from mmap buffer in
> write_event(), but sometimes the event will straddles the
> mmap boundary, we should handle this case
>
> And if we record events(such as perf kmem/sched) for long
> times, Ctrl + C can't interrupt it just for this reason
>
> Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
I've seen this bug recently, perf record was hanging because of
events of size 0. Must be the same bug. Thanks!
> ---
> tools/perf/builtin-record.c | 62 +++++++++++++++++++++++++++++++++---------
> 1 files changed, 48 insertions(+), 14 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 7bb9ca1..97573b7 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -111,28 +111,62 @@ static void write_output(void *buf, size_t size)
> }
> }
>
> -static void write_event(event_t *buf, size_t size)
> +static void write_event(void *buf, size_t size)
> {
> - size_t processed_size = buf->header.size;
> - event_t *ev = buf;
> + event_t *ev;
> + struct mmap_event mmap_ev;
> + static void *rec_buf;
> + static unsigned long rec_len;
>
> - do {
> - /*
> - * Add it to the list of DSOs, so that when we finish this
> - * record session we can pick the available build-ids.
> - */
> + write_output(buf, size);
> +
> + while (size > 0) {
> + if (rec_buf) {
> + int len;
> +
> + memcpy(&mmap_ev, rec_buf, rec_len);
> + len = sizeof(mmap_ev.header) - rec_len;
> + if (len > 0) {
> + memcpy(&mmap_ev + rec_len, buf, len);
> + buf += len;
> + size -= len;
> + rec_len = sizeof((mmap_ev.header));
> + }
> +
> + len = mmap_ev.header.size - rec_len;
> + if (mmap_ev.header.type == PERF_RECORD_MMAP)
> + memcpy(&mmap_ev + rec_len, buf, len);
> +
> + buf += len;
> + size -= len;
> +
> + rec_buf = NULL;
> + rec_len = 0;
> +
> + ev = (event_t *)&mmap_ev;
> + goto handle_mmap;
> + }
> +
> + ev = (event_t *)buf;
> + if (size < sizeof(struct perf_event_header) ||
> + ev->header.size > size) {
> + rec_buf = buf;
> + rec_len = size;
> + break;
> + }
> +
> + buf += ev->header.size;
> + size -= ev->header.size;
> +
> +handle_mmap:
> if (ev->header.type == PERF_RECORD_MMAP) {
> struct list_head *head = &dsos__user;
> if (ev->header.misc == 1)
> head = &dsos__kernel;
> __dsos__findnew(head, ev->mmap.filename);
> }
> + }
>
> - ev = ((void *)ev) + ev->header.size;
> - processed_size += ev->header.size;
> - } while (processed_size < size);
> -
> - write_output(buf, size);
> }
>
> static int process_synthesized_event(event_t *event,
> --
> 1.6.1.2
>
next prev parent reply other threads:[~2010-01-20 13:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-20 13:34 [PATCH] perf tools: fix write_event() Xiao Guangrong
2010-01-20 13:41 ` Peter Zijlstra
2010-01-20 13:44 ` Peter Zijlstra
2010-01-20 14:09 ` Arnaldo Carvalho de Melo
2010-01-20 14:14 ` Peter Zijlstra
2010-01-20 14:26 ` Arnaldo Carvalho de Melo
2010-01-20 14:37 ` Peter Zijlstra
2010-01-20 15:43 ` Arnaldo Carvalho de Melo
2010-01-20 14:43 ` Peter Zijlstra
2010-01-20 15:30 ` Arnaldo Carvalho de Melo
2010-01-20 13:41 ` Frederic Weisbecker [this message]
2010-01-31 8:32 ` Ingo Molnar
2010-02-01 8:56 ` 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=20100120134155.GA7281@nowhere \
--to=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=xiaoguangrong@cn.fujitsu.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