Commit de096489 authored by Alexey Bayduraev's avatar Alexey Bayduraev Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarJiri Olsa <jolsa@kernel.org>
Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
Reviewed-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
Signed-off-by: default avatarAlexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Tested-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
Acked-by: default avatarNamhyung 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 06763e7b
Loading
Loading
Loading
Loading
+13 −17
Original line number Diff line number Diff line
@@ -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 @@ reader__process_events(struct reader *rd, struct perf_session *session,
	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;