From: Alexey Bayduraev Date: Wed, 13 Oct 2021 09:06:39 +0000 (+0300) Subject: perf session: Move unmap code to reader__mmap X-Git-Tag: v6.1-rc5~2702^2~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de096489d00f7764934906d0b6688783be6b9dc0;p=platform%2Fkernel%2Flinux-starfive.git perf session: Move unmap code to reader__mmap Move the unmapping code to reader__mmap(), so that the mmap code is located together. Move the head/file_offset computation to reader__mmap(), so all the offset computation is located together and in one place only. Suggested-by: Jiri Olsa Reviewed-by: Jiri Olsa Reviewed-by: Riccardo Mancini Signed-off-by: Alexey Bayduraev Tested-by: Riccardo Mancini Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Alexei Budankov Cc: Andi Kleen Cc: Ingo Molnar Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/f1c5e17cfa1ecfe912d10b411be203b55d148bc7.1634113027.git.alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 1abe870..4cbe663 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2192,13 +2192,9 @@ static int reader__init(struct reader *rd, bool *one_mmap) { u64 data_size = rd->data_size; - u64 page_offset; char **mmaps = rd->mmaps; - page_offset = page_size * (rd->data_offset / page_size); - rd->file_offset = page_offset; - rd->head = rd->data_offset - page_offset; - + rd->head = rd->data_offset; data_size += rd->data_offset; rd->mmap_size = MMAP_SIZE; @@ -2229,6 +2225,7 @@ reader__mmap(struct reader *rd, struct perf_session *session) { int mmap_prot, mmap_flags; char *buf, **mmaps = rd->mmaps; + u64 page_offset; mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2240,6 +2237,15 @@ reader__mmap(struct reader *rd, struct perf_session *session) mmap_flags = MAP_PRIVATE; } + if (mmaps[rd->mmap_idx]) { + munmap(mmaps[rd->mmap_idx], rd->mmap_size); + mmaps[rd->mmap_idx] = NULL; + } + + page_offset = page_size * (rd->head / page_size); + rd->file_offset += page_offset; + rd->head -= page_offset; + buf = mmap(NULL, rd->mmap_size, mmap_prot, mmap_flags, rd->fd, rd->file_offset); if (buf == MAP_FAILED) { @@ -2261,9 +2267,8 @@ static int reader__process_events(struct reader *rd, struct perf_session *session, struct ui_progress *prog) { - u64 page_offset, size; + u64 size; int err = 0; - char **mmaps = rd->mmaps; union perf_event *event; s64 skip; @@ -2284,17 +2289,8 @@ more: if (IS_ERR(event)) return PTR_ERR(event); - if (!event) { - if (mmaps[rd->mmap_idx]) { - munmap(mmaps[rd->mmap_idx], rd->mmap_size); - mmaps[rd->mmap_idx] = NULL; - } - - page_offset = page_size * (rd->head / page_size); - rd->file_offset += page_offset; - rd->head -= page_offset; + if (!event) goto remap; - } size = event->header.size;