Commit 529b6fbc authored by Alexey Bayduraev's avatar Alexey Bayduraev Committed by Arnaldo Carvalho de Melo

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: 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/5c7bdebfaadd7fcb729bd999b181feccaa292e8e.1634113027.git.alexey.v.bayduraev@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent dedcc0ea
...@@ -2176,6 +2176,13 @@ struct reader { ...@@ -2176,6 +2176,13 @@ struct reader {
u64 data_offset; u64 data_offset;
reader_cb_t process; reader_cb_t process;
bool in_place_update; 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 static int
...@@ -2183,28 +2190,27 @@ reader__process_events(struct reader *rd, struct perf_session *session, ...@@ -2183,28 +2190,27 @@ reader__process_events(struct reader *rd, struct perf_session *session,
struct ui_progress *prog) struct ui_progress *prog)
{ {
u64 data_size = rd->data_size; u64 data_size = rd->data_size;
u64 head, page_offset, file_offset, file_pos, size; u64 page_offset, size;
int err = 0, mmap_prot, mmap_flags, map_idx = 0; int err = 0, mmap_prot, mmap_flags;
size_t mmap_size; char *buf, **mmaps = rd->mmaps;
char *buf, *mmaps[NUM_MMAPS];
union perf_event *event; union perf_event *event;
s64 skip; s64 skip;
page_offset = page_size * (rd->data_offset / page_size); page_offset = page_size * (rd->data_offset / page_size);
file_offset = page_offset; rd->file_offset = page_offset;
head = rd->data_offset - page_offset; rd->head = rd->data_offset - page_offset;
ui_progress__init_size(prog, data_size, "Processing events..."); ui_progress__init_size(prog, data_size, "Processing events...");
data_size += rd->data_offset; data_size += rd->data_offset;
mmap_size = MMAP_SIZE; rd->mmap_size = MMAP_SIZE;
if (mmap_size > data_size) { if (rd->mmap_size > data_size) {
mmap_size = data_size; rd->mmap_size = data_size;
session->one_mmap = true; session->one_mmap = true;
} }
memset(mmaps, 0, sizeof(mmaps)); memset(mmaps, 0, sizeof(rd->mmaps));
mmap_prot = PROT_READ; mmap_prot = PROT_READ;
mmap_flags = MAP_SHARED; mmap_flags = MAP_SHARED;
...@@ -2216,35 +2222,36 @@ reader__process_events(struct reader *rd, struct perf_session *session, ...@@ -2216,35 +2222,36 @@ reader__process_events(struct reader *rd, struct perf_session *session,
mmap_flags = MAP_PRIVATE; mmap_flags = MAP_PRIVATE;
} }
remap: remap:
buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, rd->fd, buf = mmap(NULL, rd->mmap_size, mmap_prot, mmap_flags, rd->fd,
file_offset); rd->file_offset);
if (buf == MAP_FAILED) { if (buf == MAP_FAILED) {
pr_err("failed to mmap file\n"); pr_err("failed to mmap file\n");
err = -errno; err = -errno;
goto out; goto out;
} }
mmaps[map_idx] = buf; mmaps[rd->mmap_idx] = rd->mmap_cur = buf;
map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); rd->mmap_idx = (rd->mmap_idx + 1) & (ARRAY_SIZE(rd->mmaps) - 1);
file_pos = file_offset + head; rd->file_pos = rd->file_offset + rd->head;
if (session->one_mmap) { if (session->one_mmap) {
session->one_mmap_addr = buf; session->one_mmap_addr = buf;
session->one_mmap_offset = file_offset; session->one_mmap_offset = rd->file_offset;
} }
more: 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)) if (IS_ERR(event))
return PTR_ERR(event); return PTR_ERR(event);
if (!event) { if (!event) {
if (mmaps[map_idx]) { if (mmaps[rd->mmap_idx]) {
munmap(mmaps[map_idx], mmap_size); munmap(mmaps[rd->mmap_idx], rd->mmap_size);
mmaps[map_idx] = NULL; mmaps[rd->mmap_idx] = NULL;
} }
page_offset = page_size * (head / page_size); page_offset = page_size * (rd->head / page_size);
file_offset += page_offset; rd->file_offset += page_offset;
head -= page_offset; rd->head -= page_offset;
goto remap; goto remap;
} }
...@@ -2253,9 +2260,9 @@ reader__process_events(struct reader *rd, struct perf_session *session, ...@@ -2253,9 +2260,9 @@ reader__process_events(struct reader *rd, struct perf_session *session,
skip = -EINVAL; skip = -EINVAL;
if (size < sizeof(struct perf_event_header) || 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", 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)); event->header.type, strerror(-skip));
err = skip; err = skip;
goto out; goto out;
...@@ -2264,8 +2271,8 @@ reader__process_events(struct reader *rd, struct perf_session *session, ...@@ -2264,8 +2271,8 @@ reader__process_events(struct reader *rd, struct perf_session *session,
if (skip) if (skip)
size += skip; size += skip;
head += size; rd->head += size;
file_pos += size; rd->file_pos += size;
err = __perf_session__process_decomp_events(session); err = __perf_session__process_decomp_events(session);
if (err) if (err)
...@@ -2276,7 +2283,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, ...@@ -2276,7 +2283,7 @@ reader__process_events(struct reader *rd, struct perf_session *session,
if (session_done()) if (session_done())
goto out; goto out;
if (file_pos < data_size) if (rd->file_pos < data_size)
goto more; goto more;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment