Skip to content

Commit

Permalink
Merge pull request #544 from dav-mac/main
Browse files Browse the repository at this point in the history
Updated PMU Learning Path.
  • Loading branch information
jasonrandrews authored Oct 24, 2023
2 parents 53cb624 + 1854a11 commit 7e25d93
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
---
title: Learn how to use the Arm Performance Monitoring Unit (PMU) & System Counter
title: How to use the Arm Performance Monitoring Unit and System Counter

minutes_to_complete: 90

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.

learning_objectives:
- 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
- Use the system counter to measure time in code

prerequisites:
- An Arm computer running Linux. A bare metal or cloud metal instance is best because they expose more counters. A virtual machine (VM) can be used, but fewer counters may be available.
- 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.

author_primary: Julio Suarez

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ weight: 2
layout: "learningpathall"
---

In this Learning Path, the terms hardware counter and event counter are used interchangeably.
In this Learning Path, we use the terms hardware counter and event counter interchangeably.

## Hardware and software events

Software events are generated by the Linux kernel or user software. Examples of software events that can be measured are context switches and system calls. Hardware events are generated by the CPU or other system hardware. Examples of hardware events are instructions executed and CPU clock cycles. The focus of this Learning Path is hardware events.
Software events are generated by the Linux kernel or user software. Examples of software events that can be measured are context switches and system calls. Hardware events are generated by the CPU or other system hardware. Examples of hardware events are instructions executed and CPU clock cycles. This Learning Path focuses on hardware events.

## Hardware events on Arm

Expand All @@ -30,15 +30,15 @@ Before you instrument counters, you should consider using tools which do not req

### Linux Perf

Linux Perf is part of the Linux source code (under tools/perf), it is capable of measuring software and hardware events. It is used for measuring events at the process or system level. Depending on what you are working on, Perf can save you the need to instrument counters directly in your code. Refer to the [Perf on Arm Linux ](/install-guides/perf/) install guide to learn how to install Perf. There is also a walk through on perf and its features [published by Brendan Gregg](https://www.brendangregg.com/perf.html).
Linux Perf is part of the Linux source code. (Under tools/perf) It is capable of measuring software and hardware events. It is used for measuring events at the process or system level. Depending on what you are working on, Perf can save you the need to instrument counters directly in your code. Refer to the [Perf on Arm Linux ](/install-guides/perf/) install guide to learn how to install Perf. There is also a walk through on perf and its features [published by Brendan Gregg](https://www.brendangregg.com/perf.html).

### Arm Telemetry Solution (Topdown Tool)

[Telemetry Solution](https://gitlab.arm.com/telemetry-solution/telemetry-solution) is a tool that is published by Arm which does not require code to be written. In fact, it uses Linux perf. This tool is accompanied with a general performance analysis methodology. It allows you to separate performance bottlenecks between the front-end and the back-end of the CPU. Using this methodology, you can measure things like branch effectiveness, cache effectiveness, instruction mix, etc. This tool will continue to grow in capabilities over time. It's strongly recommended to try this tool before instrumenting your code.
Arm publishes [Telemetry Solution](https://gitlab.arm.com/telemetry-solution/telemetry-solution) - a tool that does not require code to be written. In fact, it uses Linux perf. This tool is accompanied with a general performance analysis methodology. It allows you to separate performance bottlenecks between the front-end and the back-end of the CPU. Using this methodology, you can measure things like branch effectiveness, cache effectiveness, instruction mix, etc. This tool will continue to grow in capabilities over time. It's strongly recommended to try this tool before instrumenting your code.

## Options for instrumenting event counters from user space

If you decide you need to add counter instrumentation to your source code, there are different ways to do this from user space. The method you use should be determined by a combination of preference and whatever limitations you may have in your environment.
If you decide to add counter instrumentation to your source code, various methods allow this from user space. The method you use should be determined by a combination of preference and whatever limitations you may have in your environment.

### Counting time

Expand Down Expand Up @@ -68,4 +68,4 @@ The easiest way to instrument non-C/C++ programs is to write a C library and cal

### Arm assembly

Hardware counters can be enabled and configured using assembly code. Counting events this way requires knowledge of the specific PMU registers that are required to enable and configure the counters of interest. This method requires that you implement multiplexing if you need to count more events than the available CPU counters. This method for counter access is not covered in this learning path because the other methods outlined in this learning path are easier.
You can enable and configure hardware counters using assembly code. Counting events this way requires knowledge of the specific PMU registers that are required to enable and configure the counters of interest. This method requires that you implement multiplexing if you need to count more events than the available CPU counters. This method for counter access is not covered in this learning path because the other methods outlined in this learning path are easier.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ There are two Arm instructions that allow access to system registers. These are

## Using assembly for system counter access

If you only need to count time/cycles, then the [system counter](https://developer.arm.com/documentation/102379/0102/System-Counter?lang=en)] can be used. This can be done from user space. Below is an example of measuring system counter ticks across a function.
If you only need to count time/cycles, then the [system counter](https://developer.arm.com/documentation/102379/0102/System-Counter?lang=en)] can be used. You can do this from user space. An example of measuring system counter ticks across a function is shown below:

Use a text editor to create a file named `syscnt.c` with the code below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ layout: "learningpathall"

Use the [Performance Application Programming Interface (PAPI) install guide](/install-guides/papi/) to install PAPI on your computer.

More information is available in the [documentation](https://github.com/icl-utk-edu/papi/wiki/Downloading-and-Installing-PAPI).
You can find more information in the [documentation](https://github.com/icl-utk-edu/papi/wiki/Downloading-and-Installing-PAPI).

Set the environment variable `PAPI_DIR` to the location where PAPI is installed.

Expand Down Expand Up @@ -170,7 +170,7 @@ Run the application:
./papi_example
```

The two counters are printed:
The program prints the two counters:

```output
Instructions retired: 11000000451
Expand Down

0 comments on commit 7e25d93

Please sign in to comment.