Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4454092pxb; Tue, 5 Oct 2021 03:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIQtdAPxZ9HoL8/sFs4jvvEk4odNqkMlDrNSLx8vPBEfKWaAIQJUeZwMBeB7QWxy0uxtsP X-Received: by 2002:a17:906:6448:: with SMTP id l8mr23798646ejn.301.1633429907734; Tue, 05 Oct 2021 03:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633429907; cv=none; d=google.com; s=arc-20160816; b=O96i3YU4oW0WE5Nb9/vgt/uOQOpNNdqiYnpaHh8ETwpBBQkbJpF+Q4uV1MLXqabPS5 qsAoCduy1xeUp6/L8WeCp7PTRe2QySMbo44YSzf17Tdnuz+pAHc9GQnOrTMjbDTSxKEl hVP7sJ+G9cYNG4tEE05QXM/MkCv5aUDg8gRM8NqI8wVKxJDFJoUC4xINybOA8oX2oFyg KSvKhHNW/uHzWy3FSy0JIF4OwWVfVI3/nqjwtDGFfQdkLSnI1kpG3FIxww2s4I72LBSW yyyjJFs8vvoaDddhjnXcXjdBFzQUYvoYQGUPN6d1Q0ai0V3TgbRuuUTN1QmRZtrBYsjF x1GA== 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=HWStRm75P/1JzEdDw1wraSHQSH8tahHRd1r6f0UkSoM=; b=Ki383YekxUa5A3lNVihUAKeNXyXJ4NAEQQbMtGbUGEWIfsqJL+zpEh80FqY20i8jGK mZh9M1LBVInLUsnhLeX6335OYdVsqB8SGNz626WnMZj1UlfNKcLhHvJ36NNBVBodTJ6a zaKIADHuxsbD9g9rIbE9sq4GaFHVYtCrtzNXl7rG0EPWbOIdj/FIADS1x0kdUe7To05D fA4kmwOojge95J48XwHasJYtIP6UbjYpclCJmXLRGQAjTOXhbSsluqUOEZVzsVjxUCUu xVhUwXIx9/Xqp7BqEaKMumXaMIqZ4h7YxaZSSx47WQQn4YORQlVQXMTF1pP/8HyLG/F/ qEhw== 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 m23si12614375eje.259.2021.10.05.03.31.23; Tue, 05 Oct 2021 03:31:47 -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 S233967AbhJEK3Q (ORCPT + 99 others); Tue, 5 Oct 2021 06:29:16 -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 S234144AbhJEK3P (ORCPT ); Tue, 5 Oct 2021 06:29:15 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="225603035" X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="225603035" 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:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,348,1624345200"; d="scan'208";a="714164532" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga005.fm.intel.com with ESMTP; 05 Oct 2021 03:27:20 -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 4/5] perf session: Move map/unmap to separate function Date: Tue, 5 Oct 2021 13:27:01 +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 mapping and 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 | 61 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 53cd7a3b5efd..6c825e4a9dfe 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2193,13 +2193,9 @@ static int reader__init(struct reader *rd, bool *one_mmap) { struct reader_state *st = &rd->state; - u64 page_offset; char **mmaps = st->mmaps; - page_offset = page_size * (rd->data_offset / page_size); - st->file_offset = page_offset; - st->head = rd->data_offset - page_offset; - + st->head = rd->data_offset; st->data_size = rd->data_size + rd->data_offset; st->mmap_size = MMAP_SIZE; @@ -2226,15 +2222,12 @@ reader__exit(struct reader *rd) } static int -reader__process_events(struct reader *rd, struct perf_session *session, - struct ui_progress *prog) +reader__mmap(struct reader *rd, struct perf_session *session) { struct reader_state *st = &rd->state; - u64 page_offset, size; - int err = 0, mmap_prot, mmap_flags; + int mmap_prot, mmap_flags; char *buf, **mmaps = st->mmaps; - union perf_event *event; - s64 skip; + u64 page_offset; mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2245,20 +2238,45 @@ reader__process_events(struct reader *rd, struct perf_session *session, mmap_prot |= PROT_WRITE; mmap_flags = MAP_PRIVATE; } -remap: + + if (mmaps[st->mmap_idx]) { + munmap(mmaps[st->mmap_idx], st->mmap_size); + mmaps[st->mmap_idx] = NULL; + } + + page_offset = page_size * (st->head / page_size); + st->file_offset += page_offset; + st->head -= page_offset; + buf = mmap(NULL, st->mmap_size, mmap_prot, mmap_flags, rd->fd, st->file_offset); if (buf == MAP_FAILED) { pr_err("failed to mmap file\n"); - err = -errno; - goto out; + return -errno; } 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; +} + +static int +reader__process_events(struct reader *rd, struct perf_session *session, + struct ui_progress *prog) +{ + struct reader_state *st = &rd->state; + u64 size; + int err = 0; + union perf_event *event; + s64 skip; + +remap: + err = reader__mmap(rd, session); + if (err) + goto out; if (session->one_mmap) { - session->one_mmap_addr = buf; - session->one_mmap_offset = st->file_offset; + session->one_mmap_addr = rd->state.mmap_cur; + session->one_mmap_offset = rd->state.file_offset; } more: @@ -2267,17 +2285,8 @@ reader__process_events(struct reader *rd, struct perf_session *session, if (IS_ERR(event)) return PTR_ERR(event); - if (!event) { - if (mmaps[st->mmap_idx]) { - munmap(mmaps[st->mmap_idx], st->mmap_size); - mmaps[st->mmap_idx] = NULL; - } - - page_offset = page_size * (st->head / page_size); - st->file_offset += page_offset; - st->head -= page_offset; + if (!event) goto remap; - } session->active_decomp = &rd->decomp_data; size = event->header.size; -- 2.19.0