How to use the Arm Performance Monitoring Unit and System Counter
Introduction
Counter access options
Use a system counter
Use PAPI for counting
Use perf_event_open for counting
Next Steps
How to use the Arm Performance Monitoring Unit and System Counter
Who is this for?
This is an advanced topic for software developers who want to instrument hardware event counters or the system counter in software applications.
What will you learn?
Upon completion of this Learning Path, you will be able to:
- Understand different options for accessing counters from user space
- Use the system counter to measure time in code
- Use PAPI to instrument event counters in code
- Use the Linux perf_event_open system call to instrument event counters in code
Prerequisites
Before starting, you will need the following:
- An Arm computer running Linux. A bare metal or cloud metal instance is best because they expose more counters. You can use a virtual machine (VM), but fewer counters may be available. These instructions have been tested on the
a1.metalinstance type.
Summary
This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.
You’ll access Arm hardware event counters and the system counter from user space on Linux using the PMU. First, you’ll distinguish software and hardware events, then use a minimal assembly approach with
MRS and MSR to read the system counter and measure time around a function. You’ll then instrument event counters with PAPI, including environment configuration and user-space counter access. You’ll finish with two C examples that use perf_event_open to read either a single counter or a group of counters without multiplexing. By the end, you’ll build and run working code that returns measurable counter values suitable for basic performance instrumentation on Arm systems.Frequently asked questions
These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.
The program should report a positive difference in system counter ticks between the two reads that bracket the target function. A zero or negative value usually means the reads are not placed correctly around the region being measured.
Use
MRS to read a system register and MSR to write a system register. These two instructions are sufficient for the system counter example.Set
PAPI_DIR to the location where PAPI is installed. Depending on your system, you might also need LD_LIBRARY_PATH to include $PAPI_DIR/lib.Run the
sudo command in the steps that writes the recommended value to the file under /proc/sys/kernel. This enables user-space access to the counters for the examples.Use the group example to read several counters together without multiplexing. The single-counter example configures just one event, and
perf_event_open in this Learning Path does not support multiplexing.