[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YVsHZCv6mGdO7jGv@krava>
Date: Mon, 4 Oct 2021 15:53:40 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
linux-kernel <linux-kernel@...r.kernel.org>,
Andi Kleen <ak@...ux.intel.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Alexander Antonov <alexander.antonov@...ux.intel.com>,
Alexei Budankov <abudankov@...wei.com>,
Riccardo Mancini <rickyman7@...il.com>
Subject: Re: [PATCH 3/6] perf session: Introduce decompressor into reader
object
On Wed, Sep 29, 2021 at 11:41:51AM +0300, Alexey Bayduraev wrote:
> Introduce decompressor into reader object so that decompression
> could be executed separately for each data file. Adding active_reader
> into perf_session object to select current decompressor.
>
> Acked-by: Namhyung Kim <namhyung@...il.com>
> Reviewed-by: Riccardo Mancini <rickyman7@...il.com>
> Tested-by: Riccardo Mancini <rickyman7@...il.com>
> Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>
> ---
> tools/perf/util/session.c | 48 +++++++++++++++++++++++++++++----------
> tools/perf/util/session.h | 2 ++
> 2 files changed, 38 insertions(+), 12 deletions(-)
>
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 262efc18caac..3bea0830b3b8 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -71,6 +71,9 @@ struct reader {
> u64 data_offset;
> reader_cb_t process;
> bool in_place_update;
> + struct zstd_data zstd_data;
> + struct decomp *decomp;
> + struct decomp *decomp_last;
so reader and session share the same fields, I think it'd be better
if we put them to the new struct.. perhaps have something like:
struct compress {
struct zstd_data zstd_data;
struct decomp *decomp;
struct decomp *decomp_last;
}
struct session {
...
struct compress *compress; /* initialized to &compress_lcl */
struct compress compress_lcl;
}
struct reader {
...
struct compress compress;
}
reader__process_events will set session->compress to &reader->compress
perf_session__process_compressed_event would always work with
compress pointer.. this would ease up following code as well
also I don't like the idea sharing the whole reader with session,
it'll be abused.. let's give up gradually ;-)
thanks,
jirka
> struct reader_state state;
> };
>
> @@ -82,7 +85,10 @@ static int perf_session__process_compressed_event(struct perf_session *session,
> size_t decomp_size, src_size;
> u64 decomp_last_rem = 0;
> size_t mmap_len, decomp_len = session->header.env.comp_mmap_len;
> - struct decomp *decomp, *decomp_last = session->decomp_last;
> + struct decomp *decomp, *decomp_last = session->active_reader ?
> + session->active_reader->decomp_last : session->decomp_last;
> + struct zstd_data *zstd_data = session->active_reader ?
> + &session->active_reader->zstd_data : &session->zstd_data;
>
> if (decomp_last) {
> decomp_last_rem = decomp_last->size - decomp_last->head;
> @@ -109,7 +115,7 @@ static int perf_session__process_compressed_event(struct perf_session *session,
> src = (void *)event + sizeof(struct perf_record_compressed);
> src_size = event->pack.header.size - sizeof(struct perf_record_compressed);
>
> - decomp_size = zstd_decompress_stream(&(session->zstd_data), src, src_size,
> + decomp_size = zstd_decompress_stream(zstd_data, src, src_size,
> &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem);
> if (!decomp_size) {
> munmap(decomp, mmap_len);
> @@ -119,12 +125,22 @@ static int perf_session__process_compressed_event(struct perf_session *session,
>
> decomp->size += decomp_size;
>
> - if (session->decomp == NULL) {
> - session->decomp = decomp;
> - session->decomp_last = decomp;
> + if (session->active_reader) {
> + if (session->active_reader->decomp == NULL) {
> + session->active_reader->decomp = decomp;
> + session->active_reader->decomp_last = decomp;
> + } else {
> + session->active_reader->decomp_last->next = decomp;
> + session->active_reader->decomp_last = decomp;
> + }
> } else {
> - session->decomp_last->next = decomp;
> - session->decomp_last = decomp;
> + if (session->decomp == NULL) {
> + session->decomp = decomp;
> + session->decomp_last = decomp;
> + } else {
> + session->decomp_last->next = decomp;
> + session->decomp_last = decomp;
> + }
> }
>
> pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size);
> @@ -314,11 +330,11 @@ static void perf_session__delete_threads(struct perf_session *session)
> machine__delete_threads(&session->machines.host);
> }
>
> -static void perf_session__release_decomp_events(struct perf_session *session)
> +static void perf_decomp__release_events(struct decomp *next)
> {
> - struct decomp *next, *decomp;
> + struct decomp *decomp;
> size_t mmap_len;
> - next = session->decomp;
> +
> do {
> decomp = next;
> if (decomp == NULL)
> @@ -337,7 +353,7 @@ void perf_session__delete(struct perf_session *session)
> auxtrace_index__free(&session->auxtrace_index);
> perf_session__destroy_kernel_maps(session);
> perf_session__delete_threads(session);
> - perf_session__release_decomp_events(session);
> + perf_decomp__release_events(session->decomp);
> perf_env__exit(&session->header.env);
> machines__exit(&session->machines);
> if (session->data) {
> @@ -2155,7 +2171,8 @@ static int __perf_session__process_decomp_events(struct perf_session *session)
> {
> s64 skip;
> u64 size, file_pos = 0;
> - struct decomp *decomp = session->decomp_last;
> + struct decomp *decomp = session->active_reader ?
> + session->active_reader->decomp_last : session->decomp_last;
>
> if (!decomp)
> return 0;
> @@ -2212,6 +2229,9 @@ reader__process_events(struct reader *rd, struct perf_session *session,
>
> memset(mmaps, 0, sizeof(st->mmaps));
>
> + if (zstd_init(&rd->zstd_data, 0))
> + return -1;
> +
> mmap_prot = PROT_READ;
> mmap_flags = MAP_SHARED;
>
> @@ -2255,6 +2275,7 @@ reader__process_events(struct reader *rd, struct perf_session *session,
> goto remap;
> }
>
> + session->active_reader = rd;
> size = event->header.size;
>
> skip = -EINVAL;
> @@ -2287,6 +2308,9 @@ reader__process_events(struct reader *rd, struct perf_session *session,
> goto more;
>
> out:
> + session->active_reader = NULL;
> + perf_decomp__release_events(rd->decomp);
> + zstd_fini(&rd->zstd_data);
> return err;
> }
>
> diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
> index 5d8bd14a0a39..45f9f652a12a 100644
> --- a/tools/perf/util/session.h
> +++ b/tools/perf/util/session.h
> @@ -19,6 +19,7 @@ struct thread;
>
> struct auxtrace;
> struct itrace_synth_opts;
> +struct reader;
>
> struct perf_session {
> struct perf_header header;
> @@ -41,6 +42,7 @@ struct perf_session {
> struct zstd_data zstd_data;
> struct decomp *decomp;
> struct decomp *decomp_last;
> + struct reader *active_reader;
> };
>
> struct decomp {
> --
> 2.19.0
>
Powered by blists - more mailing lists