perf session: Move all state items to reader object

We need all the state info about reader in separate object to load data
from multiple files, so we can keep multiple readers at the same time.
Moving all items that need to be kept from reader__process_events to
the reader object. Introducing mmap_cur to keep current mapping.

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/5c7bdebfaadd7fcb729bd999b181feccaa292e8e.1634113027.git.alexey.v.bayduraev@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Alexey Bayduraev 2021-10-13 12:06:35 +03:00 committed by Arnaldo Carvalho de Melo
parent dedcc0ea6d
commit 529b6fbca0

View File

@ -2176,6 +2176,13 @@ struct reader {
u64 data_offset;
reader_cb_t process;
bool in_place_update;
char *mmaps[NUM_MMAPS];
size_t mmap_size;
int mmap_idx;
char *mmap_cur;
u64 file_pos;
u64 file_offset;
u64 head;
};
static int
@ -2183,28 +2190,27 @@ reader__process_events(struct reader *rd, struct perf_session *session,
struct ui_progress *prog)
{
u64 data_size = rd->data_size;
u64 head, page_offset, file_offset, file_pos, size;
int err = 0, mmap_prot, mmap_flags, map_idx = 0;
size_t mmap_size;
char *buf, *mmaps[NUM_MMAPS];
u64 page_offset, size;
int err = 0, mmap_prot, mmap_flags;
char *buf, **mmaps = rd->mmaps;
union perf_event *event;
s64 skip;
page_offset = page_size * (rd->data_offset / page_size);
file_offset = page_offset;
head = rd->data_offset - page_offset;
rd->file_offset = page_offset;
rd->head = rd->data_offset - page_offset;
ui_progress__init_size(prog, data_size, "Processing events...");
data_size += rd->data_offset;
mmap_size = MMAP_SIZE;
if (mmap_size > data_size) {
mmap_size = data_size;
rd->mmap_size = MMAP_SIZE;
if (rd->mmap_size > data_size) {
rd->mmap_size = data_size;
session->one_mmap = true;
}
memset(mmaps, 0, sizeof(mmaps));
memset(mmaps, 0, sizeof(rd->mmaps));
mmap_prot = PROT_READ;
mmap_flags = MAP_SHARED;
@ -2216,35 +2222,36 @@ reader__process_events(struct reader *rd, struct perf_session *session,
mmap_flags = MAP_PRIVATE;
}
remap:
buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, rd->fd,
file_offset);
buf = mmap(NULL, rd->mmap_size, mmap_prot, mmap_flags, rd->fd,
rd->file_offset);
if (buf == MAP_FAILED) {
pr_err("failed to mmap file\n");
err = -errno;
goto out;
}
mmaps[map_idx] = buf;
map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1);
file_pos = file_offset + head;
mmaps[rd->mmap_idx] = rd->mmap_cur = buf;
rd->mmap_idx = (rd->mmap_idx + 1) & (ARRAY_SIZE(rd->mmaps) - 1);
rd->file_pos = rd->file_offset + rd->head;
if (session->one_mmap) {
session->one_mmap_addr = buf;
session->one_mmap_offset = file_offset;
session->one_mmap_offset = rd->file_offset;
}
more:
event = fetch_mmaped_event(head, mmap_size, buf, session->header.needs_swap);
event = fetch_mmaped_event(rd->head, rd->mmap_size, rd->mmap_cur,
session->header.needs_swap);
if (IS_ERR(event))
return PTR_ERR(event);
if (!event) {
if (mmaps[map_idx]) {
munmap(mmaps[map_idx], mmap_size);
mmaps[map_idx] = NULL;
if (mmaps[rd->mmap_idx]) {
munmap(mmaps[rd->mmap_idx], rd->mmap_size);
mmaps[rd->mmap_idx] = NULL;
}
page_offset = page_size * (head / page_size);
file_offset += page_offset;
head -= page_offset;
page_offset = page_size * (rd->head / page_size);
rd->file_offset += page_offset;
rd->head -= page_offset;
goto remap;
}
@ -2253,9 +2260,9 @@ more:
skip = -EINVAL;
if (size < sizeof(struct perf_event_header) ||
(skip = rd->process(session, event, file_pos)) < 0) {
(skip = rd->process(session, event, rd->file_pos)) < 0) {
pr_err("%#" PRIx64 " [%#x]: failed to process type: %d [%s]\n",
file_offset + head, event->header.size,
rd->file_offset + rd->head, event->header.size,
event->header.type, strerror(-skip));
err = skip;
goto out;
@ -2264,8 +2271,8 @@ more:
if (skip)
size += skip;
head += size;
file_pos += size;
rd->head += size;
rd->file_pos += size;
err = __perf_session__process_decomp_events(session);
if (err)
@ -2276,7 +2283,7 @@ more:
if (session_done())
goto out;
if (file_pos < data_size)
if (rd->file_pos < data_size)
goto more;
out: