Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1013757pxb; Tue, 17 Aug 2021 01:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNq+R85Rxben6vUy7OkD3YR2XcnglakbOg8rM9jEvmreLdzb7JC4027mS8KUNFPXDDS9b7 X-Received: by 2002:aa7:de98:: with SMTP id j24mr2918553edv.139.1629188877965; Tue, 17 Aug 2021 01:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629188877; cv=none; d=google.com; s=arc-20160816; b=Glm96w6XMvUpkeLeNC5xGORXjQmXT3X49tytYRxX8GewGAhMY2M2/Kz1vpQpYvS7Ok BM1c5aU+C88gQFcO1ZZvvSVsaYPq64zthQAmnwMJ+ewkhPL+2NGFU49gxQMzkNyGSCuL 6zXmMZW6JaOKC8V2QGHldENnCurj2LTNZCVawG1XnGZG1rTidKJugU+n7d+ooPBgNlo+ /KNbVC/BFU7X3WAoSt/7lZKz1vODzNO5O7oh5DzEnKCHjzPt1lBGDHdZ57G0FPuy3lT5 1obRiffNx94zcoVmRffrXYbo/iZZfhQoPsbfZNsmMl68IPDU7vHa4YwH8Ob58/A9aoUO 7gOw== 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=cspOhyTeEyEEMgQeI/D51Z37m2COirWKEa8ozhdXvuM=; b=wi/G6MGfWHkpgA5ZdtGq1huHMB1L5Y5Y4UUeH9N4H/FslNBQK0vCorDjRSkh7b0YjK gDM7oHwlxXnoEdGNgzgSk5HfxHBtZzY9MiOhKI22mIZGBT42fWIOBKATiZc0bI7upyBW YFqAxL8mVnghHqtqz1bZXfth0tnCkQquYhsVAP5+3wAIZN6DEod2CTZepwmvS9/px85b q9Nut4c6L+y5LhImQIgGI8VN55z9dhlZHuz0mji16o5ebTbiK3z7gUga81PmDYp+1gdt AKYCzsF0gwEuqQZYDvqxKBdUXdKcLZxQ/bCEDB5SXl8o++S6RJmNQdO2qiiEyd3/Vc0v TEjw== 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 s27si1588990edw.384.2021.08.17.01.27.35; Tue, 17 Aug 2021 01:27:57 -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 S239719AbhHQIZ7 (ORCPT + 99 others); Tue, 17 Aug 2021 04:25:59 -0400 Received: from mga04.intel.com ([192.55.52.120]:18151 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239407AbhHQIZR (ORCPT ); Tue, 17 Aug 2021 04:25:17 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10078"; a="214171976" X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="214171976" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2021 01:24:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="471080453" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga008.jf.intel.com with ESMTP; 17 Aug 2021 01:24:41 -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 v11 23/24] perf session: Load single file for analysis Date: Tue, 17 Aug 2021 11:23:26 +0300 Message-Id: <90484cdd55c4b995def42e01e35c5c2fef1f673d.1629186429.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 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 Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini Signed-off-by: Alexey Bayduraev --- tools/perf/util/session.c | 72 ++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index e9a7cba31194..b49b52768681 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -64,6 +64,13 @@ struct reader_state { u64 file_offset; u64 data_size; u64 head; + bool eof; +}; + +enum { + READER_EOF, + READER_NODATA, + READER_OK, }; struct reader { @@ -2250,6 +2257,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; @@ -2278,36 +2290,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_NODATA; session->active_reader = rd; size = event->header.size; @@ -2329,18 +2331,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; @@ -2384,9 +2380,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_NODATA) { + 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