Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1220926pxb; Thu, 7 Oct 2021 03:27:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPxMY1yQIQKxkY+uxj2XGi8TfeCdHfv29fYTRExdGDVUMZFUvBAd58oPbETHm+E4r1eohw X-Received: by 2002:a17:90a:4483:: with SMTP id t3mr4552341pjg.44.1633602450353; Thu, 07 Oct 2021 03:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633602450; cv=none; d=google.com; s=arc-20160816; b=1I3Fi64NC+gzVJvNh/qJMmCcn3WA7j+jyGA81A/drd6FlvDIkohnl9AmFaFduoMTyl wY29VeqYGAnUHn2fAmAsOdV5SUhK1j8Tf0KQZEUGT5anmZCOj6mgpzNoJBxq0OukWrjQ bH7NjghHBE9T8dMvdgfWM96NYOlYX8CW6tykPoew/mZc0e+L5npw64RB5EerbkfD4MMR 0ApCBFZvsqEoVVky51Dk8VO8DxbGMtZqkBwZEIsA0sXLraJhWSR5sb3/am9N55laEyEP L9HOKue1qtd6i0eJK2P0SS+1eoXeUJzx/4sW6WBfs/J9Zch95mCCH9+2Zxr55fRCaOr7 1Qyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1daIpfEBNuxljh+HVfN5Cg23jhDG/6eN/Te1uVGkptI=; b=ry/OPZUeenheQtSsL3J7vhVHKpXEtUVt/bbJnm274UPbkf315nxREP2j2h2jhugogF T40KsS8P7T1z+e+vhWFXkg6TDnKwBct2+ALMiqhtVnhoVsN1Kc6NGzc3XBPAuWyxKmbX nqFrA7XTJnoPsvEojoX150SPps9Ew7elGwFrXMXU9aa5lQxhGHQOKn13U1cYPzdSo6ZI T3jUCsY/xqOR6737bIH3RKroO21nr+27EaDyQf6OE4NspgcYyhIAywakaXAqRZPSCOyc WsoOyQJPNPbBxOczG8aVzjdytBrDb7n2/qbHeac4k42K+MDfl/nDy7LRL2RWx1kBk80Y XwKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s5si28303108pgk.86.2021.10.07.03.27.14; Thu, 07 Oct 2021 03:27:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240886AbhJGK1z (ORCPT + 99 others); Thu, 7 Oct 2021 06:27:55 -0400 Received: from mga01.intel.com ([192.55.52.88]:3730 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbhJGK1y (ORCPT ); Thu, 7 Oct 2021 06:27:54 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10129"; a="249532643" X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="249532643" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 03:25:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="657335457" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga005.jf.intel.com with ESMTP; 07 Oct 2021 03:25:51 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: [PATCH v3 2/8] perf session: Introduce decompressor in reader object Date: Thu, 7 Oct 2021 13:25:37 +0300 Message-Id: <664203f1a6aee3ca9dd5ea3d5a92dd707ebda9a8.1633596227.git.alexey.v.bayduraev@linux.intel.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introducing decompressor data structure with pointers to decomp objects and to zstd object. We cannot just move session->zstd_data to decomp_data as session->zstd_data is used not only for decompression. Adding decompressor data object to reader object and introducing active_decomp into perf_session object to select current decompressor. Thus decompression could be executed separately for each data file. Acked-by: Namhyung Kim Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini Signed-off-by: Alexey Bayduraev --- tools/perf/util/session.c | 39 +++++++++++++++++++++++++-------------- tools/perf/util/session.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index bf73e8c1f15c..c3930c49da7a 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -44,7 +44,7 @@ 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_decomp->decomp_last; if (decomp_last) { decomp_last_rem = decomp_last->size - decomp_last->head; @@ -71,7 +71,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(session->active_decomp->zstd_decomp, src, src_size, &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem); if (!decomp_size) { munmap(decomp, mmap_len); @@ -81,13 +81,12 @@ 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; - } else { - session->decomp_last->next = decomp; - session->decomp_last = decomp; - } + if (session->active_decomp->decomp == NULL) + session->active_decomp->decomp = decomp; + else + session->active_decomp->decomp_last->next = decomp; + + session->active_decomp->decomp_last = decomp; pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size); @@ -197,6 +196,8 @@ struct perf_session *__perf_session__new(struct perf_data *data, session->repipe = repipe; session->tool = tool; + session->decomp_data.zstd_decomp = &session->zstd_data; + session->active_decomp = &session->decomp_data; INIT_LIST_HEAD(&session->auxtrace_index); machines__init(&session->machines); ordered_events__init(&session->ordered_events, @@ -276,11 +277,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) @@ -299,7 +300,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_data.decomp); perf_env__exit(&session->header.env); machines__exit(&session->machines); if (session->data) { @@ -2117,7 +2118,7 @@ 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_decomp->decomp_last; if (!decomp) return 0; @@ -2178,6 +2179,8 @@ struct reader { u64 file_pos; u64 file_offset; u64 head; + struct zstd_data zstd_data; + struct decomp_data decomp_data; }; static int @@ -2207,6 +2210,10 @@ reader__process_events(struct reader *rd, struct perf_session *session, memset(mmaps, 0, sizeof(rd->mmaps)); + if (zstd_init(&rd->zstd_data, 0)) + return -1; + rd->decomp_data.zstd_decomp = &rd->zstd_data; + mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2250,6 +2257,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, goto remap; } + session->active_decomp = &rd->decomp_data; size = event->header.size; skip = -EINVAL; @@ -2282,6 +2290,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, goto more; out: + session->active_decomp = &session->decomp_data; return err; } @@ -2334,6 +2343,8 @@ static int __perf_session__process_events(struct perf_session *session) */ ordered_events__reinit(&session->ordered_events); auxtrace__free_events(session); + perf_decomp__release_events(rd.decomp_data.decomp); + zstd_fini(&rd.zstd_data); session->one_mmap = false; return err; } diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 5d8bd14a0a39..46c854292ad6 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -20,6 +20,12 @@ struct thread; struct auxtrace; struct itrace_synth_opts; +struct decomp_data { + struct decomp *decomp; + struct decomp *decomp_last; + struct zstd_data *zstd_decomp; +}; + struct perf_session { struct perf_header header; struct machines machines; @@ -39,8 +45,8 @@ struct perf_session { u64 bytes_transferred; u64 bytes_compressed; struct zstd_data zstd_data; - struct decomp *decomp; - struct decomp *decomp_last; + struct decomp_data decomp_data; + struct decomp_data *active_decomp; }; struct decomp { -- 2.19.0