Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp657926pxj; Thu, 3 Jun 2021 16:26:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykgh/lkdK37AN4sBGBOszjjXUZ35pi+f5t+QmgAWkbpFWzvl4pJ4b6e5qiIs3Hj6Q4NLl7 X-Received: by 2002:a17:906:530e:: with SMTP id h14mr1494852ejo.165.1622762813247; Thu, 03 Jun 2021 16:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622762813; cv=none; d=google.com; s=arc-20160816; b=UbpAX+LlaiDS9B+iJseGX166BFftxDXoP8f4+j7E0oJCUjj/xn20na0BCk+BsY5W9C TxVqb1bDCsM0Gnz3GnnwkKRVpAOoxQ6gZEOawARknGgjogjPtRdjyDHBRB3tRVSl/cKb d/MHOAXwZ+gwOHWr6gO+IoJn/XU6UdU6vhvBD1bl/Zp0hBy7TZsaiCrxyGOEzgv6HBfs geRc7N/9J5tfogv//Y5IEWccxa/ZnEsP7iivenRQWvmsZibIIN/36TkRXnrTQlXA+/vW aYqUAaO2tMOpRv9JJsr6/DBAWwVy7j3SRlnyPp5RET4L9UkI3S3h7kmacM9Jd+gB9vYH 9fcg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=cr/W34PCQ0jRykdhfg80VXv5W+pmG+k6UQUukwu1AKM=; b=iPnSO4YxYaL5mRuD4nyYGJ8A2vBelbCooWL09mOkuVO85CsGz0uILdXFznwAqlbhin a5hSLVDG5qLjczNdsqxk8ErLJaUquaZJzcM4jKIQM4q176SdZ26Mxu4HIKujovxbpavO 3K4pBQBrkqwQ/rwQ9DcpLjBZQUDJfz48a5CilsMZ9nKRLwtiubsACEeDeS5QvZtGTaYB UYpDzas9RvlPtYmRM3iUzAIFz7WBFlccVbUF02aI0+M/J12tJn/4Rzen9kKr2mLwLxsv HGKzoPU4+v8pM7fP1Uh+Mv+v9ljdtNsIGJXWtCdZ3rLhUn6zijNz7UPQMCDz1vcLyYkA OEgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rMzBmoS0; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si1371938ejc.317.2021.06.03.16.26.30; Thu, 03 Jun 2021 16:26:53 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rMzBmoS0; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbhFCXYK (ORCPT + 99 others); Thu, 3 Jun 2021 19:24:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbhFCXYJ (ORCPT ); Thu, 3 Jun 2021 19:24:09 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12AAC06174A; Thu, 3 Jun 2021 16:22:07 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id jt22so11673276ejb.7; Thu, 03 Jun 2021 16:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=cr/W34PCQ0jRykdhfg80VXv5W+pmG+k6UQUukwu1AKM=; b=rMzBmoS0a8UrOPfPp2DWc30WeIA4v2R5A8u86TA6B3W0K1LZtXURReMUUga0DBrw4S DuWbUtup1Aiem/4pRbmdvbWITrjBmifjxtUfQ7OuQLLqpv8dC+JM5w12S3wDF6bkZe43 3xmcl2y+brCEWOSoGpr5eAg9oiv1/qcKLNb1HQJsAw5INZK1STGrGiwoE7uBwmEU2qox gLDFO3r0HxsWgOsnbHjmHlIyk1BbX3h+s0Sb9JOlgRzQ2wm0cz1UJoWSijV71UMPETfm bSqODbZpzpvR7GD5+4xJ7KkARH6DFkDfFVcHSRguqh60o3qBF++QwN6ia8qsPUyuHQbf C73A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=cr/W34PCQ0jRykdhfg80VXv5W+pmG+k6UQUukwu1AKM=; b=cVW84gkKR5bjRIXV4eSjcCv++hI/M60jspwM814Oqb62aNdfl1SsLa7RZqpDRFpTni FUeLzRNCsshaWs3pswbvfcT34b/sjOsFNaOuZvkAWJW5iqYx+Xu6n1iUVXmd4n9H1t62 IM2TQGGnEHTlQL0xXn2M0eaDIxAUMvf6gaCFZmWj9cXIJ7sOZpG4FHtvMTD9edtlERun DnAmygoTlF9gRKT5+JYpV1HrONMcsSA/4AzOZR/Siaa8LA45EppJO5ZbYYFshdUIeshC AktBg+7wLfZM/gulT9w9DM5PiT7pJSLiT69/Vai55o6xoXKuZYQnlap2VjfjdW4IWRsg ekjg== X-Gm-Message-State: AOAM533q/0pMOH7/uWAbO52UbCCzSQUl0QA7JaJjrcJP8VNdeyFrJLoa laQ+WWtXI92x/r2Ft5OjlxI= X-Received: by 2002:a17:906:c1d3:: with SMTP id bw19mr1480400ejb.145.1622762524381; Thu, 03 Jun 2021 16:22:04 -0700 (PDT) Received: from [192.168.1.15] ([151.29.179.73]) by smtp.gmail.com with ESMTPSA id h22sm2405074edv.0.2021.06.03.16.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 16:22:04 -0700 (PDT) Message-ID: Subject: Re: [PATCH v6 16/20] perf session: Introduce decompressor into trace reader object From: Riccardo Mancini To: Alexey Bayduraev Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , linux-perf-users@vger.kernel.org, Ian Rogers , Arnaldo Carvalho de Melo Date: Fri, 04 Jun 2021 01:22:02 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.1 (3.40.1-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, 2021-05-26 at 13:53 +0300, Alexey Bayduraev wrote: > Introduce decompressor into trace reader object so that decompression > could be executed on per data file basis separately for every data > file located in data directory. > > Signed-off-by: Alexey Bayduraev > --- >  tools/perf/util/session.c | 51 +++++++++++++++++++++++++++++---------- >  tools/perf/util/session.h |  1 + >  2 files changed, 39 insertions(+), 13 deletions(-) > > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index 335c073bae87..6c9a682eb291 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -73,6 +73,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; >         struct reader_state state; >  }; >   > @@ -85,7 +88,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; > @@ -113,7 +119,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); > @@ -123,12 +129,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); > @@ -319,11 +335,10 @@ 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) > @@ -336,6 +351,8 @@ static void perf_session__release_decomp_events(struct > perf_session *session) >   >  void perf_session__delete(struct perf_session *session) >  { > +       int r; > + >         if (session == NULL) >                 return; >         auxtrace__free(session); > @@ -343,10 +360,12 @@ void perf_session__delete(struct perf_session *session) >         perf_session__destroy_kernel_maps(session); >         perf_session__delete_threads(session); >         if (session->readers) { > +               for (r = 0; r < session->nr_readers; r++) > +                       perf_decomp__release_events(session- > >readers[r].decomp); >                 zfree(&session->readers); >                 session->nr_readers = 0; >         } > -       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) > @@ -2157,7 +2176,8 @@ static int __perf_session__process_decomp_events(struct > perf_session *session) >  { >         s64 skip; >         u64 size; > -       struct decomp *decomp = session->decomp_last; > +       struct decomp *decomp = session->active_reader ? > +               session->active_reader->decomp_last : session->decomp_last; >   >         if (!decomp) >                 return 0; > @@ -2214,6 +2234,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; zstd_fini is never called on zstd_data. Thanks, Riccardo > @@ -2257,12 +2280,13 @@ reader__process_events(struct reader *rd, struct > perf_session *session, >                 goto remap; >         } >   > +       session->active_reader = rd; >         size = event->header.size; >   >         skip = -EINVAL; >   >         if (size < sizeof(struct perf_event_header) || > -           (skip = rd->process(session, event, st->file_pos, rd->path)) < 0) > { > +           (skip = perf_session__process_event(session, event, st->file_pos, > rd->path)) < 0) { >                 pr_err("%#" PRIx64 " [%s] [%#x]: failed to process type: %d > [%s]\n", >                        st->file_offset + st->head, rd->path, event- > >header.size, >                        event->header.type, strerror(-skip)); > @@ -2289,6 +2313,7 @@ reader__process_events(struct reader *rd, struct > perf_session *session, >                 goto more; >   >  out: > +       session->active_reader = NULL; >         return err; >  } >   > diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h > index 2815d00b5467..e0a8712f8770 100644 > --- a/tools/perf/util/session.h > +++ b/tools/perf/util/session.h > @@ -44,6 +44,7 @@ struct perf_session { >         struct decomp           *decomp_last; >         struct reader           *readers; >         int                     nr_readers; > +       struct reader           *active_reader; >  }; >   >  struct decomp {