Commit 699db111 authored by Yisheng Xie's avatar Yisheng Xie Committed by Arnaldo Carvalho de Melo

perf mmap: Discard head in overwrite_rb_find_range()

In overwrite mode, start will be set to head in perf_mmap__read_init().
Therefore, there is no need to set the start one more time in
overwrite_rb_find_range() and *start can be used as head instead of
passing head to overwrite_rb_find_range().
Signed-off-by: default avatarYisheng Xie <xieyisheng1@huawei.com>
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1520944274-37001-1-git-send-email-xieyisheng1@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9749adc3
...@@ -199,19 +199,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd) ...@@ -199,19 +199,18 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd)
return 0; return 0;
} }
static int overwrite_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end) static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
{ {
struct perf_event_header *pheader; struct perf_event_header *pheader;
u64 evt_head = head; u64 evt_head = *start;
int size = mask + 1; int size = mask + 1;
pr_debug2("overwrite_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head); pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
pheader = (struct perf_event_header *)(buf + (head & mask)); pheader = (struct perf_event_header *)(buf + (*start & mask));
*start = head;
while (true) { while (true) {
if (evt_head - head >= (unsigned int)size) { if (evt_head - *start >= (unsigned int)size) {
pr_debug("Finished reading overwrite ring buffer: rewind\n"); pr_debug("Finished reading overwrite ring buffer: rewind\n");
if (evt_head - head > (unsigned int)size) if (evt_head - *start > (unsigned int)size)
evt_head -= pheader->size; evt_head -= pheader->size;
*end = evt_head; *end = evt_head;
return 0; return 0;
...@@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md) ...@@ -262,7 +261,7 @@ int perf_mmap__read_init(struct perf_mmap *md)
* Backward ring buffer is full. We still have a chance to read * Backward ring buffer is full. We still have a chance to read
* most of data from it. * most of data from it.
*/ */
if (overwrite_rb_find_range(data, md->mask, head, &md->start, &md->end)) if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment