Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5141886pxj; Wed, 26 May 2021 03:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxygSE78WLhEHcqc1+HeWQ378/hV1jkN5pgOK4kF7r87JdzHKdhQBhty5KH818gDMoBtSpJ X-Received: by 2002:a17:906:15c2:: with SMTP id l2mr33086189ejd.348.1622026761126; Wed, 26 May 2021 03:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622026761; cv=none; d=google.com; s=arc-20160816; b=s0fJu/W4XZYzFE+VzfTaMPf9Bjn/hrE1io2rDtfHgt4PCngjkcpPYPL1APNCByW5cf phuHOR15098mzjJY/T+O5cakgGcLPO9HKTHgIqSiuZfp+4qMA+YqAutVQKn0dNEwXA2E agns31O5UrENB/LIAvLOdppM/UNoZtgMzTbYbFsNyh/kiEULEuiPHU9+1EUtTV15e72V dwfvd8I5S/07srJ/7OR3+3eZv9QDwDv1lhyla5xsWpbK4xsyrFsA/iQsxWTZ5SbA3326 tf6zWcdHSmEENLLH97rKH+kRZPReKxE3gKu1YGcrXd7jBFEHrieD56cL+js4pOU8IWcA dBjA== 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 :ironport-sdr:ironport-sdr; bh=u8WVMhUVTAmzmMmFA3eorq1r4zHo5AwMBOejHn71W54=; b=WZrI7pLzKP/KXPU0wJSmrS0mB8egDWgSvImqwOzStQ453RrGsWc29kHgmHFEf9F7P/ 43XRweT8uKe3Y7vinuiHm4uRV3hgqZBGRuIEy0aXwLCp876tbkMC5HXzr9DKNk8ktYrh 9PaI/D1l3tLKiIhhdvWtMX4WW1Awnnatx8sODkV0mj7HakAm45Qw+q24VVRA4OgIKrws G8DxHfYjXsPdrL/YHUCTjASSkAzhSVS0BMtZ6LKhwI8s6lW1El2R5IwvJ7fOfKCE3Zqy QnJGCeF3IPWSmU7xmp0U8FL+69T1nlr76w74TxuOljwPnYkNBdlmri8eYsWGWLQ/4kw3 zbcg== 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 kl10si8950244ejc.361.2021.05.26.03.58.57; Wed, 26 May 2021 03:59:21 -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 S234382AbhEZK45 (ORCPT + 99 others); Wed, 26 May 2021 06:56:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:1596 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234294AbhEZK4b (ORCPT ); Wed, 26 May 2021 06:56:31 -0400 IronPort-SDR: axjbGePL2wYHyUDKYLLxLKO8z26bvnUUb+oXRG3Wy84VcXkwQVHNzb7AbVAmAZoiEto3B42slO JWoT7gltr00Q== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="189556531" X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="189556531" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 03:54:14 -0700 IronPort-SDR: WhEGkr58l9YzN+65UNt9IA9A9n7t8DG4lCCjsjhpxR3mPQQ7lvPZQddBo98NW5ZlCxkJz4aaz2 9ZURIFTg7ASg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="436079427" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga007.jf.intel.com with ESMTP; 26 May 2021 03:54: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 Subject: [PATCH v6 18/20] perf session: Move map/unmap into reader__mmap function Date: Wed, 26 May 2021 13:53:11 +0300 Message-Id: <8954fc81104609449e10f7920511bf8622bdf135.1622025774.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 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. Design and implementation are based on the prototype [1], [2]. [1] git clone https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git -b perf/record_threads [2] https://lore.kernel.org/lkml/20180913125450.21342-1-jolsa@kernel.org/ Suggested-by: Jiri Olsa Signed-off-by: Alexey Bayduraev --- tools/perf/util/session.c | 60 +++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index b63d28554ad2..7879b54b7030 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2211,14 +2211,11 @@ static int reader__init(struct reader *rd, bool *one_mmap) { struct reader_state *st = &rd->state; - u64 page_offset; char **mmaps = st->mmaps; pr_debug("reader processing %s\n", rd->path); - 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; @@ -2238,15 +2235,12 @@ reader__init(struct reader *rd, bool *one_mmap) } 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; @@ -2257,20 +2251,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: @@ -2279,17 +2298,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_reader = rd; size = event->header.size; -- 2.19.0