Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3254057pxb; Wed, 13 Oct 2021 02:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU0ump7cKfZ3cYe389DT/bpwF6L9X3HDxHdD/CSqCZJf1Y1dH3/4d59yq9lKOGtRkZClEy X-Received: by 2002:a17:90a:4b47:: with SMTP id o7mr12444475pjl.198.1634116209106; Wed, 13 Oct 2021 02:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634116209; cv=none; d=google.com; s=arc-20160816; b=B1fncXx2nQf05H2ROx8JWfvxjLbAJTaeD4sRGBbzviiL73bQ2XLLysfkYa2numzuWc jKB/XDBvKjgT7w+Oe/6b9tjXcRnY7369ajIisvSJyNAzajbCMHJVRlW0nnfdnEND+hA0 0GAR3OT2dmKx0ygBRkjr4Sa3jy8fFSZB7ST4hWZO8adv8DPqCHsLiQCuJi8EB5Qq9Ywg sEh/++GYAsBnlXQApa3pZJKzDGsoEfvk7IbKJNPJ3asfs+kc8cJhGO2lbyCmzoS+l7UC F38Vdcr2TCDauxiQtKf/f2JXeVFA0LOiCS/6fSnNoBmEq+WOzz4WWBAOZLRjP2Ryc0m6 44WA== 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=sqjtApgT2TGBDZr2l2oXt6RjkjOqO1FBJZbGV9n0tOY=; b=iqE2IE4bJ5K0Fw2DNhchGmi/GxRzjUw6xV48MPhgODSGQV84FE/Mqlw6q73L3Fxwyb QgI4tgtufsemKgcbjxJ4ng1zVsnIz+0Y9rcI1HVCPh4a4usU2XFHIUzYiOwcDi+baZzx Cuyk8CpPOShkuo/Ll0bgk/lWJZU4Ey+/k+ypVkJ8KFz48kc7icfQrH4p42B6oSpLfZ8y 7D/CEk4CK9Y5UM9U+hBu5QM6pRR948v/tP03nkT70NYbWuFmDwQBRMmhODZnBWZUVY7d 8uH2G3SmR86v34yCOItXfKhoK9RJk5g3IcWUqltTtTjaBTZGMe1G4AoIK5mx2XMERsev qFbg== 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 s7si18769456plr.455.2021.10.13.02.09.56; Wed, 13 Oct 2021 02:10:09 -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 S239066AbhJMJJb (ORCPT + 99 others); Wed, 13 Oct 2021 05:09:31 -0400 Received: from mga07.intel.com ([134.134.136.100]:48249 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239008AbhJMJJ0 (ORCPT ); Wed, 13 Oct 2021 05:09:26 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10135"; a="290877023" X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="290877023" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 02:07:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="460706030" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga002.jf.intel.com with ESMTP; 13 Oct 2021 02:07:10 -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 5/8] perf session: Move unmap code to reader__mmap Date: Wed, 13 Oct 2021 12:06:39 +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 Moving unmapping code into reader__mmap, so the mmap code is located together. Moving head/file_offset computation into reader__mmap function, so all the offset computation is located together and in one place only. 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 | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 50258319bb26..d7b008837fd6 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2187,13 +2187,9 @@ static int reader__init(struct reader *rd, bool *one_mmap) { u64 data_size = rd->data_size; - u64 page_offset; char **mmaps = rd->mmaps; - page_offset = page_size * (rd->data_offset / page_size); - rd->file_offset = page_offset; - rd->head = rd->data_offset - page_offset; - + rd->head = rd->data_offset; data_size += rd->data_offset; rd->mmap_size = MMAP_SIZE; @@ -2224,6 +2220,7 @@ reader__mmap(struct reader *rd, struct perf_session *session) { int mmap_prot, mmap_flags; char *buf, **mmaps = rd->mmaps; + u64 page_offset; mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2235,6 +2232,15 @@ reader__mmap(struct reader *rd, struct perf_session *session) mmap_flags = MAP_PRIVATE; } + if (mmaps[rd->mmap_idx]) { + munmap(mmaps[rd->mmap_idx], rd->mmap_size); + mmaps[rd->mmap_idx] = NULL; + } + + page_offset = page_size * (rd->head / page_size); + rd->file_offset += page_offset; + rd->head -= page_offset; + buf = mmap(NULL, rd->mmap_size, mmap_prot, mmap_flags, rd->fd, rd->file_offset); if (buf == MAP_FAILED) { @@ -2256,9 +2262,8 @@ static int reader__process_events(struct reader *rd, struct perf_session *session, struct ui_progress *prog) { - u64 page_offset, size; + u64 size; int err = 0; - char **mmaps = rd->mmaps; union perf_event *event; s64 skip; @@ -2279,17 +2284,8 @@ reader__process_events(struct reader *rd, struct perf_session *session, if (IS_ERR(event)) return PTR_ERR(event); - if (!event) { - if (mmaps[rd->mmap_idx]) { - munmap(mmaps[rd->mmap_idx], rd->mmap_size); - mmaps[rd->mmap_idx] = NULL; - } - - page_offset = page_size * (rd->head / page_size); - rd->file_offset += page_offset; - rd->head -= page_offset; + if (!event) goto remap; - } size = event->header.size; -- 2.19.0