Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4451795pxb; Tue, 5 Oct 2021 03:28:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0IZPGq/hd6usXwziFOoV5gRRQEsY+bZNfGl9bYaNvAhZ1Uqc6Oi2qXCBIukFCFHobibV9 X-Received: by 2002:a17:902:d2c4:b0:13e:d77a:ecd2 with SMTP id n4-20020a170902d2c400b0013ed77aecd2mr4524186plc.50.1633429735999; Tue, 05 Oct 2021 03:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633429735; cv=none; d=google.com; s=arc-20160816; b=xm6jKUhV2UjqEy/8evdC9+p15B2+V45jQR6R3vAJx1Wu8C+tv4FxsnIkW+v/hW/UP6 0gafNrs+202iPGSPcmZvr0gO+Nxeq9D8DPf7QehcOtnxTm+dTB0Y1AfL0jAO+Py2zNOj TefMKE2adKDdbbtJo52HzJbrFoDpn5pTfawjrwYrE00eB6EFlRkXgnuVmi1z+tvL6+jP NUdOd76OVmgRzP5k+ZnIeEvOJVoG1CM6+jO8bbflEE1L9t1fitoAwupRsYyQX0X4WpSY nhnAuxygAPuPSYm+IVpBzew6R+FxrzjuJKGtLDnT1IDPad0w1+0zwEvryO4JRgsWjAZR 1PCQ== 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=kOZA8UnweQ7AJe4eaXsDxVyqAWtRQcu4afdn5+doSEo=; b=MAJ32YhF4I7/L7jVhNXI6TKGBQCrSn2ben8VjB+azneG7hpDcxzCk1uXHZa01AigYZ HA44d/+Md4M3XvT7UBputNoExsbiY3CSGHUOabVHUT9+yJa4EncfMTC+A1J7FEwAKy5c 5ffjdBUDD74h01NFDHNpqA4O/bdwcYnEiR38w1q3dI1EF3gQ96y2GAsKkns9ekMK1HTx JhCPcl+ZKUvMI9PdLcoHGHO2yaO87Z+Hc/a8mU8ueDzqGyc6yDP/wowwPSlQKmZsoDI4 wxqk16mjEX5Qx9va8dKVrsbz9K5v6IDor4pNR2Uja7H+Yiz4gnEY7n2Dsu6dUroJ38rC zB8w== 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 y68si27690927pgy.100.2021.10.05.03.28.43; Tue, 05 Oct 2021 03:28:55 -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 S234095AbhJEK3Y (ORCPT + 99 others); Tue, 5 Oct 2021 06:29:24 -0400 Received: from mga09.intel.com ([134.134.136.24]:46740 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234091AbhJEK3T (ORCPT ); Tue, 5 Oct 2021 06:29:19 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="225603044" X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="225603044" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 03:27:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="714164551" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga005.fm.intel.com with ESMTP; 05 Oct 2021 03:27:24 -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 v2 5/5] perf session: Load single file for analysis Date: Tue, 5 Oct 2021 13:27:02 +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 reader EOF return code and moving the check of EOF state to reader__mmap. Adding reader OK and NODATA return codes to simplify the code and separating reading code of single event into reader__read_event function. Introducing read_event/remap loop in __perf_session__process_events. 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 | 74 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 6c825e4a9dfe..1915714747a1 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2167,6 +2167,12 @@ typedef s64 (*reader_cb_t)(struct perf_session *session, union perf_event *event, u64 file_offset); +enum { + READER_OK, + READER_NODATA, + READER_EOF, +}; + struct reader_state { char *mmaps[NUM_MMAPS]; size_t mmap_size; @@ -2229,6 +2235,9 @@ reader__mmap(struct reader *rd, struct perf_session *session) char *buf, **mmaps = st->mmaps; u64 page_offset; + if (st->file_pos >= st->data_size) + return READER_EOF; + mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2257,36 +2266,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_decomp = &rd->decomp_data; size = event->header.size; @@ -2308,18 +2307,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_decomp = &session->decomp_data; return err; @@ -2356,9 +2349,36 @@ 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 < 0) { goto out_err; + } else 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) { + goto out_err; + } else if (err == READER_NODATA) { + err = reader__mmap(&rd, session); + if (err < 0) + goto out_err; + else if (err == READER_EOF) + break; + } + } + /* do the final flush for ordered samples */ err = ordered_events__flush(oe, OE_FLUSH__FINAL); if (err) -- 2.19.0