Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3252905pxb; Wed, 13 Oct 2021 02:09:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLnaquseI7Lr2eHOw0/5P3+yB4ihieepMXqwFr4oH3sfnP//GJIifzDgh9atmh8CgT1mEl X-Received: by 2002:a05:6402:90c:: with SMTP id g12mr7687374edz.140.1634116151055; Wed, 13 Oct 2021 02:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634116151; cv=none; d=google.com; s=arc-20160816; b=i9TDC0IkZdnFLYB0vKeGMSM70QwL7O9Ye0nG1xDyi3iY+S8fgwz6o5Pfryp3InKZX1 /OkGMTrqdvzdo1X3fHeeL4CEkDie5Bto8dzvEClqhc7dCCDFdq4Xn47t7LHtlsRxvSZf eiQN5qVcEhf+EQt/X8EinGXSd8nO1OIM1D5FPvoqHCzj7nsvyTg/DArQmVNgcjGkZ3gq s5qG3XbBIyv54472DPQYak8j4EUbF3KvL8BvqdLUxV/KvdCtGNxNd6fOq34/1qX3+lM7 DOk6MFWX6veioU+rNCMp5EnMzjcCDKO65PAmnrrJaEQm69r0Evnz6JYHidkqrgMHv9zu WGpQ== 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=gPKvWlS9/EhHYDtNeV4FpsVkd6grMgWvjypoJfymohB9wCYrM3NshRzYirNVW3UErk /TH3xyuJBsIu/37o7bDrRb3zSIG0XkuAqJ71ICQFGajfWsMCAbwrJctLFubevSHRtgbn nzikzdLJ6UM9AXhHlr9uAduNfbxyyxmsU1WLBLqndc/Ezm5FNwMouD3dv8UWA8cceDtf 3xSPxJ82hOFYlBRvie8vf9IGmFe2zuwde5kL+Cui/eUiBDi3a2YP4isilWeOjVlLDmip AOWc4O5EU5tQuP1guwsVkYzlkE8fR2uyfsmren762vKqfWHDNDD8rL53Oj1/V2oEu5fb oB9g== 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 s12si18834113ejc.488.2021.10.13.02.08.47; Wed, 13 Oct 2021 02:09:11 -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 S238974AbhJMJI7 (ORCPT + 99 others); Wed, 13 Oct 2021 05:08:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:55079 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238971AbhJMJI6 (ORCPT ); Wed, 13 Oct 2021 05:08:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10135"; a="227281648" X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="227281648" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 02:06:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="460705920" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga002.jf.intel.com with ESMTP; 13 Oct 2021 02:06:50 -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 v4 1/8] perf session: Move all state items to reader object Date: Wed, 13 Oct 2021 12:06:35 +0300 Message-Id: <5c7bdebfaadd7fcb729bd999b181feccaa292e8e.1634113027.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