# Set up your environment for Arm SPE and Perf C2C profiling

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/)
- [Arm Statistical Profiling Extension and false sharing](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-1/)
- [Set up your environment for Arm SPE and Perf C2C profiling](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-2/)
- [False sharing example](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-3/)
- [Perform root cause analysis with Perf C2C](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-4/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/_next-steps/)

## Select a system with SPE support

Before you can start profiling cache behavior with Arm SPE and Perf C2C, your system needs to meet a few requirements. In this section, you’ll learn how to check whether your hardware and kernel support Arm SPE, install the necessary tools, and validate that Linux Perf can access the correct performance monitoring events. By the end, your environment will be ready to record and analyze memory access patterns using `perf c2c` on an Arm Neoverse system.

SPE requires support from both your hardware and the operating system. Many cloud instances running Linux do not enable SPE-based profiling.

You need to identify a system that supports SPE using the information below.

If you are looking for an AWS system, you can use a `c6g.metal` instance running Amazon Linux 2023 (AL2023).

Check the underlying Neoverse processor and operating system kernel version with the following commands:

```
lscpu | grep -i "model name"
uname -r
```

The output includes the CPU type and kernel release version:

```
__output__ 
Model name:                           Neoverse-N1
__output__ 
6.1.134-152.225.amzn2023.aarch64
```

Next, install the prerequisite packages using the package manager:

```
sudo dnf update -y
sudo dnf install perf git gcc cmake numactl-devel -y
```

Linux Perf is a userspace process and SPE is a hardware feature. The Linux kernel must be compiled with SPE support or the kernel module named `arm_spe_pmu` must be loaded.

Run the following command to confirm if the SPE kernel module is loaded:

```
sudo modprobe arm_spe_pmu
```

If the module is not loaded (and there is blank output), SPE might still be available.

Run this command to check if SPE is included in the kernel:

```
ls /sys/bus/event_source/devices/ | grep arm_spe
```

If SPE is available, the output you will see is:

```
__output__ 
arm_spe_0
```

If the output is blank then SPE is not available.

## Run Sysreport

You can install and run a Python script named Sysreport to summarize your system’s performance profiling capabilities.

See the Learning Path [Get ready for performance analysis with Sysreport](https://learn.arm.com/learning-paths/servers-and-cloud-computing/sysreport/) to learn how to install and run it.

Look at the Sysreport output and confirm SPE is available by checking the `perf sampling` field.

If the printed value is SPE, then SPE is available.

```
__output__ 
...
__output__ 
Performance features:
__output__ 
  perf tools:          True
__output__ 
  perf installed at:   /usr/bin/perf
__output__ 
  perf with OpenCSD:   False
__output__ 
  perf counters:       6
__output__ 
  perf sampling:       SPE
__output__ 
  perf HW trace:       None
__output__ 
  perf paranoid:       -1
__output__ 
  kptr_restrict:       0
__output__ 
  perf in userspace:   disabled
```

## Confirm Arm SPE is available to Perf

Run the following command to confirm SPE is available to `perf`:

```
sudo perf list "arm_spe*"
```

You should see the output below indicating the PMU event is available.

```
__output__ 
List of pre-defined events (to be used in -e or -M):
__output__ 
arm_spe_0//                                        [Kernel PMU event]
```

Assign capabilities to `perf` by running:

```
sudo setcap cap_perfmon,cap_sys_ptrace,cap_sys_admin+ep $(which perf)
```

If `arm_spe` isn’t available due to your system configuration or limited PMU access, the `perf c2c` command will fail.

To confirm `perf` can access SPE, run:

```
perf c2c record
```

If SPE access is blocked, you’ll see output like this:

```
__output__ 
failed: memory events not supported
```

### Note

If you are unable to use SPE it might be a restriction based on your cloud instance size or operating system.

Generally, access to a full server (also known as metal instances) with a relatively new kernel is required for Arm SPE support.

For more information about enabling SPE, see the [perf-arm-spe manual page](https://man7.org/linux/man-pages/man1/perf-arm-spe.1.html).

## Summary

You’ve confirmed that your system supports Arm SPE, installed the necessary tools, and verified that Perf C2C can access SPE events. You’re now ready to start collecting detailed performance data using Perf C2C. In the next section, you’ll run a real application and use Perf C2C to capture cache sharing behavior and uncover memory performance issues.
