From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B1EAC43461 for ; Fri, 11 Sep 2020 21:53:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B843F22207 for ; Fri, 11 Sep 2020 21:53:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eFRtg39u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B843F22207 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LtYFLEJpOhsw9HHJJlhrNFzXItKmj5wsh3FGtDgZreE=; b=eFRtg39uuxMhXQ3DbjzEjSUZi U4DIXSrf26FladGRXq0i2IlhdegnOwwetI9G0KPdIrIuDiF2iK1YWLM6ZlIe/WbE9jbjhvW+Fpvkk 4yXEDvltvuVHhIm7rJXL9BlQ6IWwU+CkSJZ8febF/iCIvhIk5jtEBoLzO+vngRbiReHTHU4dHuJbF ppHR3BmaYeHBPzZXN71mLdw7Y/pf5BBQEop3LZ9ytQKURrpTjh2G5I7cUutai/gla5OlGcWB0gyx3 TgfaUr9OGY4unG0BagJq0fqnTi3XIy5nPulMSbm2xmR/lTGvXyI8MQxkS4Yw9I77oZLJeNO+hp/k3 hO7aNv+ZQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGqxU-00041C-VO; Fri, 11 Sep 2020 21:51:53 +0000 Received: from mail-io1-f68.google.com ([209.85.166.68]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGqx6-0003sH-IP for linux-arm-kernel@lists.infradead.org; Fri, 11 Sep 2020 21:51:33 +0000 Received: by mail-io1-f68.google.com with SMTP id u126so12599384iod.12 for ; Fri, 11 Sep 2020 14:51:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uoRTJ1GTM0hHb04cikkrusS/NF+YUeVQS6ejGPzaSu0=; b=or9a/mF6cSfXU9Ov7Lionp+xP3lLE0Uie4OctWpCy26gKh3fro9t5gsaUmhBAFOWT7 Y/maIaNaBWGQ5NOUyGlMxbCyKjTMUr4Xe1gs+yLgzkJIyYSEr58ehnl1p53jKIearPOc BiUV0Pq6i5wr4nxzDZ7Bpn1OlhqT3mztANbun51ENrzmWQIZe2fGJ6TNp2HeSG81g/ez qtzwNb3twI33m6e/6A8M5n1slYf6EZPzAgfLOVvtwkiwBFpGSR4a1CVjqfLSfrQmQzgd FWSf4zE5T4/WbwW965DicXEOfjRLhzJ9lf0PKKXKeFi9B+Usi9ti68XzrK6PxNwuQPQ8 ljhQ== X-Gm-Message-State: AOAM532I7VYYn9H/z0KIzAPSiNwCvH3uhAZWludAIbN2VY/t4+Kuqrm0 stcQk3NOPKF8+hfb1hY+Qg== X-Google-Smtp-Source: ABdhPJyYWgYlSGN/yvMykl6ATwk8lIgusBARePWSb6d3Uof3/ieuq/5p7OJ5lQsvXd89iNGjNqlnPg== X-Received: by 2002:a02:1a83:: with SMTP id 125mr3938444jai.48.1599861088048; Fri, 11 Sep 2020 14:51:28 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.251]) by smtp.googlemail.com with ESMTPSA id a20sm1927966ilq.57.2020.09.11.14.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 14:51:27 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Subject: [PATCH v3 05/10] libperf: Add libperf_evsel__mmap() Date: Fri, 11 Sep 2020 15:51:13 -0600 Message-Id: <20200911215118.2887710-6-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200911215118.2887710-1-robh@kernel.org> References: <20200911215118.2887710-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200911_175129_071572_781B9DD2 X-CRM114-Status: GOOD ( 20.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ian Rogers , Alexander Shishkin , linux-kernel@vger.kernel.org, honnappa.nagarahalli@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In order to support usersapce access, an event must be mmapped. While there's already mmap support for evlist, the usecase is a bit different than the self monitoring with userspace access. So let's add a new perf_evsel__mmap() function to mmap an evsel. This allows implementing userspace access as a fastpath for perf_evsel__read(). The mmapped address is returned by perf_evsel__mmap() primarily for users/tests to check if userspace access is enabled. Signed-off-by: Rob Herring --- v3: - New patch split out from user access patch --- tools/lib/perf/Documentation/libperf.txt | 1 + tools/lib/perf/evsel.c | 31 ++++++++++++++++++++++++ tools/lib/perf/include/internal/evsel.h | 2 ++ tools/lib/perf/include/perf/evsel.h | 2 ++ tools/lib/perf/libperf.map | 1 + 5 files changed, 37 insertions(+) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index 0c74c30ed23a..0b4694ce42b9 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -136,6 +136,7 @@ SYNOPSIS struct perf_thread_map *threads); void perf_evsel__close(struct perf_evsel *evsel); void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu); + void *perf_evsel__mmap(struct perf_evsel *evsel, size_t length); int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, struct perf_counts_values *count); int perf_evsel__enable(struct perf_evsel *evsel); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 4dc06289f4c7..99fa53dc0887 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -11,10 +11,12 @@ #include #include #include +#include #include #include #include #include +#include void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr) { @@ -156,6 +158,35 @@ void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu) perf_evsel__close_fd_cpu(evsel, cpu); } +void *perf_evsel__mmap(struct perf_evsel *evsel, size_t length) +{ + int ret; + struct perf_mmap *map; + struct perf_mmap_param mp = { + .prot = PROT_READ | PROT_WRITE, + }; + + if (FD(evsel, 0, 0) < 0) + return NULL; + + mp.mask = length - page_size - 1; + + map = zalloc(sizeof(*map)); + if (!map) + return NULL; + + perf_mmap__init(map, NULL, false, NULL); + + ret = perf_mmap__mmap(map, &mp, FD(evsel, 0, 0), 0); + if (ret) { + free(map); + return NULL; + } + + evsel->mmap = map; + return map->base; +} + int perf_evsel__read_size(struct perf_evsel *evsel) { u64 read_format = evsel->attr.read_format; diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 1ffd083b235e..a7985dbb68ff 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -9,6 +9,7 @@ struct perf_cpu_map; struct perf_thread_map; +struct perf_mmap; struct xyarray; /* @@ -40,6 +41,7 @@ struct perf_evsel { struct perf_cpu_map *cpus; struct perf_cpu_map *own_cpus; struct perf_thread_map *threads; + struct perf_mmap *mmap; struct xyarray *fd; struct xyarray *sample_id; u64 *id; diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h index c82ec39a4ad0..28f1354e52df 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -3,6 +3,7 @@ #define __LIBPERF_EVSEL_H #include +#include #include struct perf_evsel; @@ -27,6 +28,7 @@ LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map * struct perf_thread_map *threads); LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel); LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu); +LIBPERF_API void *perf_evsel__mmap(struct perf_evsel *evsel, size_t length); LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, struct perf_counts_values *count); LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 7be1af8a546c..733a0647be8b 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -23,6 +23,7 @@ LIBPERF_0.0.1 { perf_evsel__disable; perf_evsel__open; perf_evsel__close; + perf_evsel__mmap; perf_evsel__read; perf_evsel__cpus; perf_evsel__threads; -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel