LKML Archive on
help / color / mirror / Atom feed
From: Rob Herring <>
To: Will Deacon <>,
	Mark Rutland <>,
	Catalin Marinas <>,
	Peter Zijlstra <>,
	Ingo Molnar <>
	Arnaldo Carvalho de Melo <>,
	Jiri Olsa <>,
	Kan Liang <>,
	Ian Rogers <>,
	Alexander Shishkin <>,,,
	Raphael Gault <>,
	Jonathan Cameron <>,
	Namhyung Kim <>,
	Itaru Kitayama <>,
Subject: [PATCH v9 3/3] Documentation: arm64: Document PMU counters access from userspace
Date: Fri,  6 Aug 2021 16:51:23 -0600	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

From: Raphael Gault <>

Add documentation to describe the access to the pmu hardware counters from

Signed-off-by: Raphael Gault <>
Signed-off-by: Rob Herring <>
 - No change
 - Reword that config1:1 must always be set to request user access
 - Merge into existing arm64 perf.rst
  - Update the chained event section with attr.config1 details
  - Update links to test examples

Changes from Raphael's v4:
  - Convert to rSt
  - Update chained event status
  - Add section for heterogeneous systems
 Documentation/arm64/perf.rst | 68 +++++++++++++++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/Documentation/arm64/perf.rst b/Documentation/arm64/perf.rst
index b567f177d385..fa8706df2281 100644
--- a/Documentation/arm64/perf.rst
+++ b/Documentation/arm64/perf.rst
@@ -2,7 +2,10 @@
 .. _perf_index:
 Perf Event Attributes
@@ -88,3 +91,66 @@ exclude_host. However when using !exclude_hv there is a small blackout
 window at the guest entry/exit where host events are not captured.
 On VHE systems there are no blackout windows.
+Perf Userspace PMU Hardware Counter Access
+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.
+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 with config1:1 attr bit set: 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`
+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 and 64-bit counters
+Chained events are not supported in conjunction with userspace counter
+access. If a 64-bit counter is requested (attr.config1:0) with userspace
+access (attr.config1:1 set), then counter chaining will be disabled. The
+'pmc_width' in the user page will indicate the actual width of the
+counter which could be only 32-bits depending on the event and PMU
+.. Links
+.. _tools/perf/arch/arm64/tests/user-events.c:
+.. _tools/lib/perf/tests/test-evsel.c:

      parent reply	other threads:[~2021-08-06 22:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 22:51 [PATCH v9 0/3] arm64 userspace counter support Rob Herring
2021-08-06 22:51 ` [PATCH v9 1/3] arm64: perf: Add userspace counter access disable switch Rob Herring
2021-08-24 15:26   ` Will Deacon
2021-08-06 22:51 ` [PATCH v9 2/3] arm64: perf: Enable PMU counter userspace access for perf event Rob Herring
2021-08-24 15:27   ` Will Deacon
2021-08-24 21:58     ` Rob Herring
2021-08-25 19:59       ` Rob Herring
2021-08-06 22:51 ` Rob Herring [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).