Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1467112pxb; Thu, 7 Oct 2021 08:21:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6YFw7MMg6j2Ya+PPf4C1EBdJniOWD6BrFnWSA/Zw+m3ZZlOIwtaDVCBn85f8/J7tl7OWX X-Received: by 2002:a17:906:e089:: with SMTP id gh9mr6547354ejb.320.1633620073464; Thu, 07 Oct 2021 08:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633620073; cv=none; d=google.com; s=arc-20160816; b=lXA/7uHvC1R5AEajl3tokgqPRDxmFKQ8+pZ9+Bc2cEDlx3rpnq8Wyj+A0gfa22JhB/ 37ki7B0TUtn9bs41gebx9+s1ANmGisDXWDtJJU96YXF5JPodr4a9jcok6P5KNEz+Pg3t C/s5qYhQYTfJ3EA97TNhDMywSFmu7mxyiaPtGBBQ6Jl+PmhKgP2pTeRubzVERM+AHOKS Kd1OCm+1xabVTBqTYzkdWHUSSgwFauU9zAbLg6i2N9UykO5WEUqOODxX/m4GPgPZUnL2 WV06xkxfpXYpoCTfYPr8A1HNQ5gBYM1E/ssTZvqrCQ0nIzOmz+LJnpA6P9LC6xSG27SO ncjQ== 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=06fj3IsqpF0sl22jsJq3juNytFrkUJl3/LcOPNFW6aA=; b=XWrJgVDSL9RUhAw3sKPWBbSbK+vbXTqBDYvQNe7pjduBdPii4mMIhwCxhL/YEJqsCf nJ72QD5ri/6d5jK54X2pYDRBnNfzAt248LPHMVM86Kq1AT/2RQy3qAX0Sdyo5r5KpNxl zV0U37SE7APT4a+TucVvEPWb8KtddspUoF9jqVTHoaIht7gyVOEtT463sOeOSGk7lFzB d+MKhWcFxQ/sCK+5cFkNiKHSVoVhZQzlokmHvnyutfSY+5sGklent4ZylwHtsW4QEMdd D1DdS510g6NcW5uAlvYvfeGJEwBxdZliBzULP4udvYxNqzrY6kDG38bLU3MWiW3QA54/ 9i1A== 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 b15si8972167edj.23.2021.10.07.08.20.47; Thu, 07 Oct 2021 08:21:13 -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 S240913AbhJGK2J (ORCPT + 99 others); Thu, 7 Oct 2021 06:28:09 -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 S240895AbhJGK2A (ORCPT ); Thu, 7 Oct 2021 06:28:00 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10129"; a="249532667" X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="249532667" 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:26:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="657335510" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga005.jf.intel.com with ESMTP; 07 Oct 2021 03:26:00 -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 5/8] perf session: Move unmap code to reader__mmap Date: Thu, 7 Oct 2021 13:25:40 +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 36faa2d598b2..6289fcafdc86 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; @@ -2277,17 +2282,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; - } session->active_decomp = &rd->decomp_data; size = event->header.size; -- 2.19.0