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>
This commit is contained in:
Родитель
06763e7b30
Коммит
de096489d0
|
@ -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;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче