Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2343345pxv; Sat, 26 Jun 2021 17:50:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZ7jJ1KbqwjOCzKgGtqEUAtG85IpkWSvqs3tFqA0Z4ZJrVVmuzWibpN8yrhGda66RgWvPc X-Received: by 2002:a92:dc48:: with SMTP id x8mr13059659ilq.213.1624755009166; Sat, 26 Jun 2021 17:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624755009; cv=none; d=google.com; s=arc-20160816; b=P1W5cw8dwmLYdv8M3X0eEoLhVFUmRkhZziGY7PhICD3pZlTdXNWFyydSYT80+A5ZpD bNOyHpl6HgMjC0xBWLmaH9JYKDROurZNG1YWoSGoDWGcmoYm8JVSGVdTDPp0d8+ZKMf6 RukUXKPN/I5v2neTXgWWBs6bt8ou5b9WuEEuIYUSHVt7fHty70yeiBtfUUYIPYtEsWFp /47X9VttVeV9WY3BjdbU2N6pGc72kvzsBOui0XA68FJFUBge6HyxPN/Yro8pCzQhRfmY 0IKtwCjlzXPBdZABfPlreMKX8Y9j7AC81kcjUC6yYRO1E2FRJhjGF9dqDssb7DPD+mGf //3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=jQccB20CQF5Dr5LsObv3HRFh/UxoVEFfeObD4BLsXKY=; b=LCBZfGZNpVeGC4cfJCgYYOU7k/w6DLjAPrz6P1kB6ZAn3BGtSGspv9MSG1JT48VlWb jTN6STL5lAqeEgllJtj00+r0YYwqtCWs6PFy93P1W6VHA38XP/9Yjzyf54j44hlP7ub5 hM6TnlqGwYm1DJIXlL/DWq66IcPWSDt/t7BkVH7VIBUMp5VFB/gtFDS7zKqqeBtv8S5l hsgO+dZJ1wuM8STkG7oMrJLlEkKItg85w2q5ha7DbjFcAKTPyshbcg56GCTJRYsJiGZU 2UdDodOVFGlaPGVK+VY93mzRIwbWFg2fzX2zCtFOZCN8OqacmxpmsB9wMpbPouX4phtE ygNw== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si13030800ilr.53.2021.06.26.17.49.57; Sat, 26 Jun 2021 17:50:09 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbhF0Avt (ORCPT + 99 others); Sat, 26 Jun 2021 20:51:49 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:41930 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbhF0Avt (ORCPT ); Sat, 26 Jun 2021 20:51:49 -0400 Received: by mail-lf1-f44.google.com with SMTP id j4so23989652lfc.8 for ; Sat, 26 Jun 2021 17:49:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jQccB20CQF5Dr5LsObv3HRFh/UxoVEFfeObD4BLsXKY=; b=gWbxf83r3lrfcCgW4h/laqRJGtNeLMvDuNsYAzTssoJE4yQHG8KMxKfi0tVUlbwWBm 9+AgINwoVl5rslJj0AEdubdl1RuG/L3kFlf1wdrUT6tUyD1SIoOHS+Fh5308Y0qkaTHI 8XYcCMVhdyoztC6W4uQf9O9zPAoaBVJyt5XKgyzY1KVUtuTiaLL5dwBFRZ5axkxQ2go8 uHm1tVeLUloC429waMhL99G9QfP/UVctAR9KfKAGlqThKOFHdtxSlJEb/+TBtBSfRaCa iI52Ngn9kHEq4183YmseN9cEnblv+e4rbz/B0aY6tdSlKSLJA/DNvNYJ2qY7R6ytwszt a8HA== X-Gm-Message-State: AOAM531zJte8bnRszyyXIC4Exqi1TU5hyfBdmZ9ItztSmOOCxedliBFz q2fM5/aJfEPe6C/eRpTeloEqPFyOSph/gYanzg4= X-Received: by 2002:a05:6512:1291:: with SMTP id u17mr7613772lfs.300.1624754964035; Sat, 26 Jun 2021 17:49:24 -0700 (PDT) MIME-Version: 1.0 References: <32d8135b4d3b5df28c234bab774b65e7f0b85727.1624350588.git.alexey.v.bayduraev@linux.intel.com> In-Reply-To: <32d8135b4d3b5df28c234bab774b65e7f0b85727.1624350588.git.alexey.v.bayduraev@linux.intel.com> From: Namhyung Kim Date: Sat, 26 Jun 2021 17:49:13 -0700 Message-ID: Subject: Re: [PATCH v7 19/20] perf session: Load single file for analysis To: Alexey Bayduraev Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 22, 2021 at 1:43 AM Alexey Bayduraev wrote: > > Adding eof flag to reader state and moving the check to reader__mmap. > Separating reading code of single event into reader__read_event function. > Adding basic reader return codes to simplify the code and introducing > reader remmap/read_event loop based on them. > > Design and implementation are based on the prototype [1], [2]. > > [1] git clone https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git -b perf/record_threads > [2] https://lore.kernel.org/lkml/20180913125450.21342-1-jolsa@kernel.org/ > > Suggested-by: Jiri Olsa > Signed-off-by: Alexey Bayduraev > --- > tools/perf/util/session.c | 71 ++++++++++++++++++++++++--------------- > 1 file changed, 44 insertions(+), 27 deletions(-) > > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index 7d91205a6a47..fe25abf83b80 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -64,6 +64,12 @@ struct reader_state { > u64 file_offset; > u64 data_size; > u64 head; > + bool eof; > +}; > + > +enum { > + READER_EOF = 0, > + READER_OK = 1, Just a nitpick, it might be better to add READER_NODATA state to differentiate it from the real end-of-file state. Thanks, Namhyung > }; > > struct reader { > @@ -2245,6 +2251,11 @@ reader__mmap(struct reader *rd, struct perf_session *session) > char *buf, **mmaps = st->mmaps; > u64 page_offset; > > + if (st->file_pos >= st->data_size) { > + st->eof = true; > + return READER_EOF; > + } > + > mmap_prot = PROT_READ; > mmap_flags = MAP_SHARED; > > @@ -2273,36 +2284,26 @@ reader__mmap(struct reader *rd, struct perf_session *session) > mmaps[st->mmap_idx] = st->mmap_cur = buf; > st->mmap_idx = (st->mmap_idx + 1) & (ARRAY_SIZE(st->mmaps) - 1); > st->file_pos = st->file_offset + st->head; > - return 0; > + return READER_OK; > } > > static int > -reader__process_events(struct reader *rd, struct perf_session *session, > - struct ui_progress *prog) > +reader__read_event(struct reader *rd, struct perf_session *session, > + struct ui_progress *prog) > { > struct reader_state *st = &rd->state; > - u64 size; > - int err = 0; > + int err = READER_OK; > union perf_event *event; > + u64 size; > s64 skip; > > -remap: > - err = reader__mmap(rd, session); > - if (err) > - goto out; > - if (session->one_mmap) { > - session->one_mmap_addr = rd->state.mmap_cur; > - session->one_mmap_offset = rd->state.file_offset; > - } > - > -more: > event = fetch_mmaped_event(st->head, st->mmap_size, st->mmap_cur, > session->header.needs_swap); > if (IS_ERR(event)) > return PTR_ERR(event); > > if (!event) > - goto remap; > + return READER_EOF; > > session->active_reader = rd; > size = event->header.size; > @@ -2324,18 +2325,12 @@ reader__process_events(struct reader *rd, struct perf_session *session, > st->head += size; > st->file_pos += size; > > - err = __perf_session__process_decomp_events(session); > - if (err) > - goto out; > + skip = __perf_session__process_decomp_events(session); > + if (skip) > + err = skip; > > ui_progress__update(prog, size); > > - if (session_done()) > - goto out; > - > - if (st->file_pos < st->data_size) > - goto more; > - > out: > session->active_reader = NULL; > return err; > @@ -2379,9 +2374,31 @@ static int __perf_session__process_events(struct perf_session *session) > err = reader__init(rd, &session->one_mmap); > if (err) > goto out_err; > - err = reader__process_events(rd, session, &prog); > - if (err) > + err = reader__mmap(rd, session); > + if (err != READER_OK) { > + if (err == READER_EOF) > + err = -EINVAL; > goto out_err; > + } > + if (session->one_mmap) { > + session->one_mmap_addr = rd->state.mmap_cur; > + session->one_mmap_offset = rd->state.file_offset; > + } > + > + while (true) { > + if (session_done()) > + break; > + > + err = reader__read_event(rd, session, &prog); > + if (err < 0) > + break; > + if (err == READER_EOF) { > + err = reader__mmap(rd, session); > + if (err <= 0) > + break; > + } > + } > + > /* do the final flush for ordered samples */ > err = ordered_events__flush(oe, OE_FLUSH__FINAL); > if (err) > -- > 2.19.0 >