diff options
author | Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> | 2021-10-13 11:06:39 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2021-10-25 18:47:41 +0200 |
commit | de096489d00f7764934906d0b6688783be6b9dc0 (patch) | |
tree | 7d3e94de892270a06381014cd17258ea14ceda8b /tools/perf/util/session.c | |
parent | perf session: Move reader map code to a separate function (diff) | |
download | linux-de096489d00f7764934906d0b6688783be6b9dc0.tar.xz linux-de096489d00f7764934906d0b6688783be6b9dc0.zip |
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 <jolsa@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Reviewed-by: Riccardo Mancini <rickyman7@gmail.com>
Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Tested-by: Riccardo Mancini <rickyman7@gmail.com>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/f1c5e17cfa1ecfe912d10b411be203b55d148bc7.1634113027.git.alexey.v.bayduraev@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/session.c')
-rw-r--r-- | tools/perf/util/session.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 1abe870223f6..4cbe66366d17 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; |