Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp440367pxv; Wed, 30 Jun 2021 09:02:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5XO17cDfHYUY21V04mWL1UlGWiEcxoI3rpLAGKV23PCzK56wI2Nf6uSXMHOQybtTrfgeD X-Received: by 2002:a17:906:f256:: with SMTP id gy22mr35570084ejb.103.1625068930944; Wed, 30 Jun 2021 09:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625068930; cv=none; d=google.com; s=arc-20160816; b=TKl8Eu+D9MLBxXaapRkOKXdxMqQVI/jaio3Xz/JP8pASDzr+bqv/MOHDcHoKHAk9Wz PemzQGAZJ5NCCc3kD2B+iCOzNkA4tWOjrVP5a+SNHV0TedjxoqerIF/BLLPsMqB5mu0J HBArs2VUVLPX4SrgDTao5f7W2rk4vIADuBMs1E+BQSyMx7zUqG41TMLm+jlwrLJfLb/P S/komvnn4sfsEOidGRnlWe7MdHLzpkgkH/ti+SMmGMLklxhOHa5ZOwXHkEwGsWQoU60h zA6H9YzL8711IHnK7EZWVwmV/il0OOdVSzfoeuY6FCbQyJDHo09rWXVVYTRsn8+ILTlO i6iA== 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=LQKyUBtYJhPzbqENcltsuC2laRmkSdy0Qkn1clmT1ck=; b=B/fVKMnIf3TNpXkZcBekwPMU7hX24rjYdg8My1F3JWpbln5UqhkzuxhSGJ/25RPlYm HWSkLL0GxrhRge5oOLAZA7T60rm3UnPgXFEmDwM9KZ5iWMYMyAHIEB+yNO0JNlsrgcw4 /MsnVXCbE5xDzQXw88BKAb2mDVmTeJcku7aWKTUpiN/zMy2XpCqR7KVp4k0n5WcrIa20 cU+es0twpIj+2fEkGlemEUA7FXF9l/m2Ovpg1p2xkY3bDxhDZcNXvrBqACt9RTf4zDRT v6rmLL1jmH8hHUwIDikLG5imEbtpJvqHm66wTE21d5D6AivYe5L7pUC8M7WEhQnBUbxH dxtA== 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 b22si20641718edw.104.2021.06.30.09.01.42; Wed, 30 Jun 2021 09:02:10 -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 S236129AbhF3QB4 (ORCPT + 99 others); Wed, 30 Jun 2021 12:01:56 -0400 Received: from mga01.intel.com ([192.55.52.88]:4080 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236098AbhF3QBE (ORCPT ); Wed, 30 Jun 2021 12:01:04 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="230016065" X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="230016065" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 08:56:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="559099874" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga001.fm.intel.com with ESMTP; 30 Jun 2021 08:56:05 -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 v8 19/22] perf session: Load single file for analysis Date: Wed, 30 Jun 2021 18:54:58 +0300 Message-Id: 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 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 Acked-by: Namhyung Kim 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 f956f078e047..a4296dfd6554 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, }; struct reader { @@ -2246,6 +2252,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; @@ -2274,36 +2285,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; @@ -2325,18 +2326,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; @@ -2380,9 +2375,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