Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4258027ybp; Mon, 7 Oct 2019 05:54:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdJgSPPCD1Jmdxbjw/tskroXRy18h98vI/sK5e4yUamZq1pRvEhvTYxWPQrIZaAn/53Ppx X-Received: by 2002:a50:c209:: with SMTP id n9mr28594375edf.215.1570452875975; Mon, 07 Oct 2019 05:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570452875; cv=none; d=google.com; s=arc-20160816; b=RAbQZkXTlQtTDc2wcDv9sWW0Je05SUy7Y4OhmLW32M6EFMWr9OyRGURs+N3LGymR9c 5gKfiKeizIgjZv1t2eUNAUBoNg4lLqh/2TS03SOXqZYydtngWAbfr7SuTmYmywXkqSBV +kMoeiYoeQSnyjIGIM0/fJ8oGPq2nRmGjZvdph932OOjX3+ylJW2a0qydOs9sHkfak1a othfpQty8P04/8zekvQ2+XvZ5DvyqMWkapk0Z0LzbwznetVHnv6ANMn5AOyVbJftHA/6 ZMLRxLkE1OfmMNxAGxU9CNGE39SjT04TuY/QjSyrsUuMmyKn3QG6WhHzGDxc45iNByzp rtKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5CUFzHuATL4+lPtmFXqmr4KtCdJA7HTc1NoXWgLwlME=; b=iGx5FCBjCLTahAZzhHpxghWNqLTsyywk/rWf/A4hRIL612Sixda1p6zz8Tayt0jRZl 6+xgZ7azfR2nt3AtMKwEEM5xHMaprIq4D0LS7GbLA+qQJKwrzvr2VWUhT7MGZ9k7B+Nt 6gPTn8JB8+eZav49nx8X9ZrtdzRATnYUaDgriJ33A6LJO6h3FtH8qBAQf9tqrgZ63wGt S2J4s/2lsiMxgVVqUCzuCBoSWoGAj9KXNaMcUB45JVPQ0n0X1ZA3lST64fzTKmowxuML BTsEJoSFSR0gvIT8i+KkH8tgTsPI65Vq+VMYZdnndVrY+Uh1Bxl6wmbALyEtLDReLGJu eU0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz26si6849950ejb.65.2019.10.07.05.54.12; Mon, 07 Oct 2019 05:54:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728033AbfJGMx7 (ORCPT + 99 others); Mon, 7 Oct 2019 08:53:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfJGMx4 (ORCPT ); Mon, 7 Oct 2019 08:53:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 049D018C8921; Mon, 7 Oct 2019 12:53:56 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D98F5D9CC; Mon, 7 Oct 2019 12:53:54 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Alexander Shishkin , Michael Petlan , Namhyung Kim , Peter Zijlstra , lkml , Ingo Molnar Subject: [PATCH 04/36] libperf: Add perf_mmap__mmap() function Date: Mon, 7 Oct 2019 14:53:12 +0200 Message-Id: <20191007125344.14268-5-jolsa@kernel.org> In-Reply-To: <20191007125344.14268-1-jolsa@kernel.org> References: <20191007125344.14268-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Mon, 07 Oct 2019 12:53:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move perf_mmap__mmap() from tools/perf to libperf, it will be used in the following patches. And rename the existing perf's function to mmap__mmap(). Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20190913132355.21634-43-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/include/internal/mmap.h | 2 ++ tools/perf/lib/mmap.c | 18 ++++++++++++++++++ tools/perf/util/evlist.c | 2 +- tools/perf/util/mmap.c | 12 +++--------- tools/perf/util/mmap.h | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h index e7a67260940c..7067b70c6f61 100644 --- a/tools/perf/lib/include/internal/mmap.h +++ b/tools/perf/lib/include/internal/mmap.h @@ -37,5 +37,7 @@ struct perf_mmap_param { size_t perf_mmap__mmap_len(struct perf_mmap *map); void perf_mmap__init(struct perf_mmap *map, bool overwrite); +int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, + int fd, int cpu); #endif /* __LIBPERF_INTERNAL_MMAP_H */ diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c index cc4284da4d99..b216a7db857f 100644 --- a/tools/perf/lib/mmap.c +++ b/tools/perf/lib/mmap.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include @@ -13,3 +14,20 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map) { return map->mask + 1 + page_size; } + +int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, + int fd, int cpu) +{ + map->prev = 0; + map->mask = mp->mask; + map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot, + MAP_SHARED, fd, 0); + if (map->base == MAP_FAILED) { + map->base = NULL; + return -1; + } + + map->fd = fd; + map->cpu = cpu; + return 0; +} diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 666339d4d1cd..055f625dc630 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -671,7 +671,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx, if (*output == -1) { *output = fd; - if (perf_mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0) + if (mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0) return -1; } else { if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index a8e81c4cbae8..acef6e3f6b80 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -353,7 +353,7 @@ static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params CPU_SET(map->core.cpu, &map->affinity_mask); } -int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) +int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) { /* * The last one will be done at perf_mmap__consume(), so that we @@ -369,18 +369,12 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) * perf_evlist__filter_pollfd(). */ refcount_set(&map->core.refcnt, 2); - map->core.prev = 0; - map->core.mask = mp->core.mask; - map->core.base = mmap(NULL, mmap__mmap_len(map), mp->core.prot, - MAP_SHARED, fd, 0); - if (map->core.base == MAP_FAILED) { + + if (perf_mmap__mmap(&map->core, &mp->core, fd, cpu)) { pr_debug2("failed to mmap perf event ring buffer, error %d\n", errno); - map->core.base = NULL; return -1; } - map->core.fd = fd; - map->core.cpu = cpu; perf_mmap__setup_affinity_mask(map, mp); diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index 2b97dc6d9ee2..a60e6ead7255 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -42,7 +42,7 @@ struct mmap_params { struct auxtrace_mmap_params auxtrace_mp; }; -int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu); +int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu); void perf_mmap__munmap(struct mmap *map); void perf_mmap__get(struct mmap *map); -- 2.21.0