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=-22.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 CD140C432C3 for ; Thu, 14 Jan 2021 02:09:54 +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 9C58D235F8 for ; Thu, 14 Jan 2021 02:09:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C58D235F8 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=Y7S85jk3zr8UgYRg3+7NadK1klSNH9UU0970Ia2gt0s=; b=cwPmxATNUjIWZzkxdcqLPvSER GBg4yPasosq5oydYSCmIaAkOmBOBCtu9YQ50OlDKCIYDe6wKwRm9NkKizPJuyrkrnQKE6tWmpkrO5 dOJJ5iZMJi1TuOKlY2jtIUPVAK1GkM7PIZYoQIUzyHgKL5l4cxVoFQkKpv6CweZuJNiHjbYJEWqjU Ow1O6Aehv0o2Oq9JjA2riDQbNYXFnrF6XOIzi8t0GJQDAYSvOTqJMpCnwdBGlYMpAgD6K7ZVaijXo p/wyWpEBQ9Fh0b0I2+p9N2rlcPP6nCCln9kD/BQVAGmVEon2EIccISb8nY5k9XkAHu5eDEgTuS2+v nZuB49dFw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzs2O-0001tD-Fz; Thu, 14 Jan 2021 02:07:00 +0000 Received: from mail-oi1-f177.google.com ([209.85.167.177]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzs1m-0001f3-Qy for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 02:06:29 +0000 Received: by mail-oi1-f177.google.com with SMTP id 15so4386438oix.8 for ; Wed, 13 Jan 2021 18:06:22 -0800 (PST) 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=ywCwTteEL8FmAOB6/EJSt97SYTx9HbQYPm8RsU3BKaY=; b=cKKF76MqM4K0BT6wkZGojWW/ZEcSyOUKS+HKkt56k32nqlT6BPXRFBVFgG/lZdRjd0 y3SkKI2WdfzBnO1x2V9dEAM7M1qb4siSEZqVhphDrylS7JWT1dEGj6YVNE9R/J2i2Rki EvAzFZylvxiUC9N461ArHLZX3Vb4x0D+AyZYiCmL9V1ilAL1orTAK0CUsn45FNUAPjZ6 SwS6z8WRaWqx/4yZXztl22e7F2XIMiZc2IjR5I2e2H8UsmYphVhug5ixAzVd/PTNQm87 kZ9UT8mevPsZLtIPiNoi0vsCfhsSOD/yaaLa+4bSCsfXAeE+xWWYGtwTyeeaxHQaroJn DCkw== X-Gm-Message-State: AOAM530zO/6FfaEDqacc0L2fkntbPuPGd3f1WsKbzcg4IjmI2isaqNQo maftjAK5RCZ5xetrTW5YTA== X-Google-Smtp-Source: ABdhPJxWaHkeHGvpZSJJSX9BlXzfQxAUjUqrMA47FUhzf7oeCRCAeTQsFvO/MyEgsOBFUn/IInFwnA== X-Received: by 2002:aca:f594:: with SMTP id t142mr1271255oih.162.1610589981584; Wed, 13 Jan 2021 18:06:21 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id x20sm814272oov.33.2021.01.13.18.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 18:06:20 -0800 (PST) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland Subject: [PATCH v5 9/9] Documentation: arm64: Document PMU counters access from userspace Date: Wed, 13 Jan 2021 20:06:05 -0600 Message-Id: <20210114020605.3943992-10-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210114020605.3943992-1-robh@kernel.org> References: <20210114020605.3943992-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210113_210622_986433_0355FFC4 X-CRM114-Status: GOOD ( 21.36 ) 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: Ian Rogers , Alexander Shishkin , linux-kernel@vger.kernel.org, honnappa.nagarahalli@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , 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 From: Raphael Gault Add a documentation file to describe the access to the pmu hardware counters from userspace Signed-off-by: Raphael Gault Signed-off-by: Rob Herring --- v2: - Update links to test examples Changes from Raphael's v4: - Convert to rSt - Update chained event status - Add section for heterogeneous systems --- Documentation/arm64/index.rst | 1 + .../arm64/perf_counter_user_access.rst | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Documentation/arm64/perf_counter_user_access.rst diff --git a/Documentation/arm64/index.rst b/Documentation/arm64/index.rst index 97d65ba12a35..eb7b1cabbf08 100644 --- a/Documentation/arm64/index.rst +++ b/Documentation/arm64/index.rst @@ -18,6 +18,7 @@ ARM64 Architecture memory memory-tagging-extension perf + perf_counter_user_access pointer-authentication silicon-errata sve diff --git a/Documentation/arm64/perf_counter_user_access.rst b/Documentation/arm64/perf_counter_user_access.rst new file mode 100644 index 000000000000..e49e141f10cc --- /dev/null +++ b/Documentation/arm64/perf_counter_user_access.rst @@ -0,0 +1,56 @@ +============================================= +Access to PMU hardware counter from userspace +============================================= + +Overview +-------- +The perf userspace tool relies on the PMU to monitor events. It offers an +abstraction layer over the hardware counters since the underlying +implementation is cpu-dependent. +Arm64 allows userspace tools to have access to the registers storing the +hardware counters' values directly. + +This targets specifically self-monitoring tasks in order to reduce the overhead +by directly accessing the registers without having to go through the kernel. + +How-to +------ +The focus is set on the armv8 pmuv3 which makes sure that the access to the pmu +registers is enabled and that the userspace has access to the relevant +information in order to use them. + +In order to have access to the hardware counter it is necessary to open the event +using the perf tool interface: the sys_perf_event_open syscall returns a fd which +can subsequently be used with the mmap syscall in order to retrieve a page of +memory containing information about the event. +The PMU driver uses this page to expose to the user the hardware counter's +index and other necessary data. Using this index enables the user to access the +PMU registers using the `mrs` instruction. + +The userspace access is supported in libperf using the perf_evsel__mmap() +and perf_evsel__read() functions. See `tools/lib/perf/tests/test-evsel.c`_ for +an example. + +About heterogeneous systems +--------------------------- +On heterogeneous systems such as big.LITTLE, userspace PMU counter access can +only be enabled when the tasks are pinned to a homogeneous subset of cores and +the corresponding PMU instance is opened by specifying the 'type' attribute. +The use of generic event types is not supported in this case. + +Have a look at `tools/perf/arch/arm64/tests/user-events.c`_ for an example. It +can be run using the perf tool to check that the access to the registers works +correctly from userspace: + +.. code-block:: sh + + perf test -v user + +About chained events +-------------------- +Chained events are not supported in userspace. If a 64-bit counter is requested, +userspace access will only be enabled if the underlying counter is 64-bit. + +.. Links +.. _tools/perf/arch/arm64/tests/user-events.c: + https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/perf/arch/arm64/tests/user-events.c -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel