About this Learning Path

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.metal instance type.

Summary

AI-assisted

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.

Close
?
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

AI-assisted

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.

Close
?
How do I know the system counter example produced a valid measurement?
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.
Which Arm instructions are used to access system registers for counting?
Use MRS to read a system register and MSR to write a system register. These two instructions are sufficient for the system counter example.
PAPI cannot find its headers or libraries at build or runtime. What should I check?
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.
What should I do before using PAPI or `perf_event_open` to access counters from user space?
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.
When using `perf_event_open`, which example should I use to read multiple counters at once?
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.
Next