Re: [PATCH v2 2/2]: perf record: enable asynchronous trace writing
From: Jiri Olsa
Date: Mon Aug 27 2018 - 04:35:02 EST
On Thu, Aug 23, 2018 at 07:47:01PM +0300, Alexey Budankov wrote:
SNIP
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index e71d46cb01cc..c8b921c88a5d 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -292,11 +292,11 @@ int perf_mmap__read_init(struct perf_mmap *map)
> }
>
> int perf_mmap__push(struct perf_mmap *md, void *to,
> - int push(void *to, void *buf, size_t size))
> + int push(void *to, void *buf, size_t size, off_t), off_t *off)
> {
> u64 head = perf_mmap__read_head(md);
> unsigned char *data = md->base + page_size;
> - unsigned long size;
> + unsigned long size, size0 = 0;
> void *buf;
> int rc = 0;
>
> @@ -308,23 +308,22 @@ int perf_mmap__push(struct perf_mmap *md, void *to,
>
> if ((md->start & md->mask) + size != (md->end & md->mask)) {
> buf = &data[md->start & md->mask];
> - size = md->mask + 1 - (md->start & md->mask);
> - md->start += size;
> -
> - if (push(to, buf, size) < 0) {
> - rc = -1;
> - goto out;
> - }
> + size0 = md->mask + 1 - (md->start & md->mask);
> + md->start += size0;
> + memcpy(md->data, buf, size0);
> }
>
> buf = &data[md->start & md->mask];
> size = md->end - md->start;
> md->start += size;
> + memcpy(md->data + size0, buf, size);
this will need more comments.. and explanation why we copy the data
over to another buffer.. it's interesting, it's still faster
jirka