lkml.org 
[lkml]   [2018]   [Jan]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH V4 03/15] perf mmap: use perf_mmap__read_init() in perf_mmap__push()
Date
From: Kan Liang <kan.liang@intel.com>

Apply the generic perf_mmap__read_init() to perf_mmap__push().

'size' is needed for both perf_mmap__read_init() and perf_mmap__push().
Have to calculate in each function.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/util/mmap.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 414089f..7c5cbdc 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -313,38 +313,18 @@ int perf_mmap__read_init(struct perf_mmap *map, bool overwrite,
int perf_mmap__push(struct perf_mmap *md, bool overwrite,
void *to, int push(void *to, void *buf, size_t size))
{
- u64 head = perf_mmap__read_head(md);
- u64 old = md->prev;
- u64 end = head, start = old;
unsigned char *data = md->base + page_size;
+ u64 head = perf_mmap__read_head(md);
unsigned long size;
+ u64 end, start;
void *buf;
- int rc = 0;
+ int rc;

- start = overwrite ? head : old;
- end = overwrite ? old : head;
-
- if (start == end)
- return 0;
+ rc = perf_mmap__read_init(md, overwrite, &start, &end);
+ if (rc < 0)
+ return (rc == -EAGAIN) ? 0 : -1;

size = end - start;
- if (size > (unsigned long)(md->mask) + 1) {
- if (!overwrite) {
- WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
-
- md->prev = head;
- perf_mmap__consume(md, overwrite);
- return 0;
- }
-
- /*
- * Backward ring buffer is full. We still have a chance to read
- * most of data from it.
- */
- if (overwrite_rb_find_range(data, md->mask, head, &start, &end))
- return -1;
- }
-
if ((start & md->mask) + size != (end & md->mask)) {
buf = &data[start & md->mask];
size = md->mask + 1 - (start & md->mask);
--
2.5.5
\
 
 \ /
  Last update: 2018-01-15 21:27    [W:0.086 / U:33.856 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site