Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1244956pxb; Thu, 7 Oct 2021 04:03:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCYqD0trBf6lFIiGoQMEy0+MK4Aqw/zgJKcMgaoF/pDD5S5XJnEcdaDRmhPJsvlReDOA7Q X-Received: by 2002:a05:6402:3547:: with SMTP id f7mr1606093edd.77.1633604595496; Thu, 07 Oct 2021 04:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633604595; cv=none; d=google.com; s=arc-20160816; b=aJcfuBaIFIq2SSKjhXFGZcDK9YYzno7UzBydE7h9Wz/2cUv7LiUCp9xSJQ6GD/2DDy VF1oVxiPWZ7P8RIvwAYobntvNP7vkS6o1QF521AxBTYliKUFX8Or3J+y2MyaWnvRm6Iw GcjQye710t118qG5hQeDTFpdIlRi6gut6rseD0qwsIIBYUBXVVTtZBG+NijMLGwZAnUQ jbd1H11JotOplQsjzMbNu98r06elZWKI5bCjfb44huIspakksy+Wee4rySGiE22FY1A0 eR2Nqq62U61H7Xf+bQ2qIo4kkTxC9a1ImN4bRe1bOpJjcCsCROmWR6xD/RqrCxSbDhSM K7Qw== 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=GakRImNKzROQWF0xkM3GBDxzmt71QcPYSwTq+pFVYvg=; b=fm6NafnRKFKl0O1zOJ6IiK+wrmRcGOC8Dtqa6FWdXFurYUAljv+LgPOTnUKHwQ/A3H piEip2ScmoDmVNVOHQkNp5XXFWNmWF4PiwoTF6ZZTrgV7mM+gUOFywOqLjhqVLt2/uqL aDCuaF0m/pUFm1w6VyBGm7FCcaxuqcaloZDnwDz28nhGtY1PNUXMvVzL93tZnWl8mh4l E8CKiKvSS95AlC7eP7q/Dt0cln5XgGwQGz6KO8hZIIqaELpfqYuwhbPBBKSoOeReClfy RNnKLCl4PMdLCGCAAh7PrA6nGaVEdDffpadKj/cmw/vSDYrA6xDx/Ou247gl/DsofzSs 4SPw== 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 a4si5435271edm.508.2021.10.07.04.02.48; Thu, 07 Oct 2021 04:03:15 -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 S240883AbhJGK1p (ORCPT + 99 others); Thu, 7 Oct 2021 06:27:45 -0400 Received: from mga01.intel.com ([192.55.52.88]:3730 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbhJGK1o (ORCPT ); Thu, 7 Oct 2021 06:27:44 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10129"; a="249532628" X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="249532628" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 03:25:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="657335446" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga005.jf.intel.com with ESMTP; 07 Oct 2021 03:25:48 -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 v3 1/8] perf session: Move all state items to reader object Date: Thu, 7 Oct 2021 13:25:36 +0300 Message-Id: <2e1b853bfd413d7c654999fa46bd178d01f46f33.1633596227.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 We need all the state info about reader in separate object to load data from multiple files, so we can keep multiple readers at the same time. Moving all items that need to be kept from reader__process_events to the reader object. Introducing mmap_cur to keep current mapping. 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 | 63 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 069c2cfdd3be..bf73e8c1f15c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2171,6 +2171,13 @@ struct reader { u64 data_offset; reader_cb_t process; bool in_place_update; + char *mmaps[NUM_MMAPS]; + size_t mmap_size; + int mmap_idx; + char *mmap_cur; + u64 file_pos; + u64 file_offset; + u64 head; }; static int @@ -2178,28 +2185,27 @@ reader__process_events(struct reader *rd, struct perf_session *session, struct ui_progress *prog) { u64 data_size = rd->data_size; - u64 head, page_offset, file_offset, file_pos, size; - int err = 0, mmap_prot, mmap_flags, map_idx = 0; - size_t mmap_size; - char *buf, *mmaps[NUM_MMAPS]; + u64 page_offset, size; + int err = 0, mmap_prot, mmap_flags; + char *buf, **mmaps = rd->mmaps; union perf_event *event; s64 skip; page_offset = page_size * (rd->data_offset / page_size); - file_offset = page_offset; - head = rd->data_offset - page_offset; + rd->file_offset = page_offset; + rd->head = rd->data_offset - page_offset; ui_progress__init_size(prog, data_size, "Processing events..."); data_size += rd->data_offset; - mmap_size = MMAP_SIZE; - if (mmap_size > data_size) { - mmap_size = data_size; + rd->mmap_size = MMAP_SIZE; + if (rd->mmap_size > data_size) { + rd->mmap_size = data_size; session->one_mmap = true; } - memset(mmaps, 0, sizeof(mmaps)); + memset(mmaps, 0, sizeof(rd->mmaps)); mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2211,35 +2217,36 @@ reader__process_events(struct reader *rd, struct perf_session *session, mmap_flags = MAP_PRIVATE; } remap: - buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, rd->fd, - file_offset); + buf = mmap(NULL, rd->mmap_size, mmap_prot, mmap_flags, rd->fd, + rd->file_offset); if (buf == MAP_FAILED) { pr_err("failed to mmap file\n"); err = -errno; goto out; } - mmaps[map_idx] = buf; - map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); - file_pos = file_offset + head; + mmaps[rd->mmap_idx] = rd->mmap_cur = buf; + rd->mmap_idx = (rd->mmap_idx + 1) & (ARRAY_SIZE(rd->mmaps) - 1); + rd->file_pos = rd->file_offset + rd->head; if (session->one_mmap) { session->one_mmap_addr = buf; - session->one_mmap_offset = file_offset; + session->one_mmap_offset = rd->file_offset; } more: - event = fetch_mmaped_event(head, mmap_size, buf, session->header.needs_swap); + event = fetch_mmaped_event(rd->head, rd->mmap_size, rd->mmap_cur, + session->header.needs_swap); if (IS_ERR(event)) return PTR_ERR(event); if (!event) { - if (mmaps[map_idx]) { - munmap(mmaps[map_idx], mmap_size); - mmaps[map_idx] = NULL; + if (mmaps[rd->mmap_idx]) { + munmap(mmaps[rd->mmap_idx], rd->mmap_size); + mmaps[rd->mmap_idx] = NULL; } - page_offset = page_size * (head / page_size); - file_offset += page_offset; - head -= page_offset; + page_offset = page_size * (rd->head / page_size); + rd->file_offset += page_offset; + rd->head -= page_offset; goto remap; } @@ -2248,9 +2255,9 @@ reader__process_events(struct reader *rd, struct perf_session *session, skip = -EINVAL; if (size < sizeof(struct perf_event_header) || - (skip = rd->process(session, event, file_pos)) < 0) { + (skip = rd->process(session, event, rd->file_pos)) < 0) { pr_err("%#" PRIx64 " [%#x]: failed to process type: %d [%s]\n", - file_offset + head, event->header.size, + rd->file_offset + rd->head, event->header.size, event->header.type, strerror(-skip)); err = skip; goto out; @@ -2259,8 +2266,8 @@ reader__process_events(struct reader *rd, struct perf_session *session, if (skip) size += skip; - head += size; - file_pos += size; + rd->head += size; + rd->file_pos += size; err = __perf_session__process_decomp_events(session); if (err) @@ -2271,7 +2278,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, if (session_done()) goto out; - if (file_pos < data_size) + if (rd->file_pos < data_size) goto more; out: -- 2.19.0