You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-1.md
+23-10Lines changed: 23 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,20 +9,29 @@ layout: learningpathall
9
9
## What is the Arm Statistical Profiling Extension (SPE), and what does it do?
10
10
11
11
{{% notice Learning goal%}}
12
-
In this section, you will learn how the Arm Statistical Profiling Extension (SPE) gives you deeper visibility into how your applications interact with the CPU. It covers how to detect and fix false sharing, which is a hidden performance problem in multithreaded code, by using cache line alignment in C++ and tools like Perf C2C.
12
+
In this section, you’ll learn how to use SPE to gain low-level insight into how your applications interact with the CPU. You’ll explore how to detect and resolve false sharing. By combining cache line alignment techniques with `perf c2c`, you can identify inefficient memory access patterns and significantly boost CPU performance on Arm-based systems.
13
13
{{% /notice %}}
14
14
15
-
Arm’s Statistical Profiling Extension (SPE) gives you a powerful way to understand what’s really happening inside your applications at the microarchitecture level. Introduced in Armv8.2, SPE captures a statistical view of how instructions move through the CPU, which allows you to dig into issues like memory access latency, cache misses, and pipeline behavior.
15
+
Arm’s Statistical Profiling Extension (SPE) gives you a powerful way to understand what’s really happening inside your applications at the microarchitecture level.
16
16
17
-
Most Linux profiling tools focus on retired instruction counts, which means they miss key details like memory addresses, cache latency, and micro-operation behavior. This can lead to misleading results — especially due to a phenomenon called “skid,” where events are falsely attributed to later instructions.
17
+
Introduced in Armv8.2, SPE captures a statistical view of how instructions move through the CPU, which allows you to dig into issues like memory access latency, cache misses, and pipeline behavior.
18
18
19
-
SPE integrates sampling directly into the CPU pipeline, triggering on individual micro-operations instead of retired instructions. This approach eliminates skid and blind spots. Each SPE sample record includes relevant metadata, such as data addresses, per-µop pipeline latency, triggered PMU event masks, and the memory hierarchy source, enabling fine-grained, precise cache analysis.
19
+
Most Linux profiling tools focus on retired instruction counts, which means they miss key details like memory addresses, cache latency, and micro-operation behavior. This can lead to misleading results, especially due to a phenomenon called “skid,” where events are falsely attributed to later instructions.
20
20
21
-
SPE helps developers optimize user-space applications by showing where cache latency or memory access delays are happening. Importantly, cache statistics are enabled with the Linux Perf cache-to-cache (C2C) utility.
21
+
SPE integrates sampling directly into the CPU pipeline, triggering on individual micro-operations instead of retired instructions. This approach eliminates skid and blind spots. Each SPE sample record includes relevant metadata, such as:
22
+
23
+
* Data addresses
24
+
* Per-µop pipeline latency
25
+
* Triggered PMU event masks
26
+
* Memory hierarchy source
27
+
28
+
This enables fine-grained, precise cache analysis.
29
+
30
+
SPE helps developers optimize user-space applications by showing where cache latency or memory access delays are happening. Importantly, cache statistics are enabled with the Linux `perf` cache-to-cache (C2C) utility.
22
31
23
32
For more information, see the [*Arm Statistical Profiling Extension: Performance Analysis Methodology White Paper*](https://developer.arm.com/documentation/109429/latest/).
24
33
25
-
In this Learning Path, you will use SPE and Perf C2C to diagnose a cache issue for an application running on a Neoverse server.
34
+
In this Learning Path, you will use SPE and `perf c2c` to diagnose a cache issue for an application running on a Neoverse server.
26
35
27
36
## What is false sharing and why should I care about it?
28
37
@@ -36,13 +45,17 @@ The diagram below, taken from the Arm SPE white paper, provides a visual represe
36
45
37
46

38
47
39
-
Because false sharing hides behind ordinary writes, the easiest time to eliminate it is while reading or refactoring the source code by padding or realigning the offending variables before compilation. In large, highly concurrent codebases, however, data structures are often accessed through several layers of abstraction, and many threads touch memory via indirection, so the subtle cache-line overlap may not surface until profiling or performance counters reveal unexpected coherence misses.
48
+
## Why false sharing is hard to spot and fix
49
+
50
+
False sharing often hides behind seemingly ordinary writes, making it tricky to catch without tooling. The best time to eliminate it is early, while reading or refactoring code, by padding or realigning variables before compilation. But in large, highly concurrent C++ codebases, memory is frequently accessed through multiple layers of abstraction. Threads may interact with shared data indirectly, causing subtle cache line overlaps that don’t become obvious until performance profiling reveals unexpected coherence misses. Tools like `perf c2c` can help uncover these issues by tracing cache-to-cache transfers and identifying hot memory locations affected by false sharing.
40
51
41
52
From a source-code perspective nothing is “shared,” but at the hardware level both variables are implicitly coupled by their physical location.
42
53
43
54
## Alignment to cache lines
44
55
45
-
In C++11, you can manually specify the alignment of an object with the `alignas` specifier. For example, the C++11 source code below manually aligns the `struct` every 64 bytes (typical cache line size on a modern processor). This ensures that each instance of `AlignedType` is on a separate cache line.
56
+
In C++11, you can manually specify the alignment of an object with the `alignas` specifier.
57
+
58
+
For example, the C++11 source code below manually aligns the `struct` every 64 bytes (typical cache line size on a modern processor). This ensures that each instance of `AlignedType` is on a separate cache line.
46
59
47
60
```cpp
48
61
#include<atomic>
@@ -88,7 +101,7 @@ int main() {
88
101
89
102
The output below shows that the variables e, f, g and h occur at least 64 bytes apart in the byte-addressable architecture. Whereas variables a, b, c, and d occur 8 bytes apart, occupying the same cache line.
90
103
91
-
Although this is a contrived example, in a production workload there might be several layers of indirection that unintentionally result in false sharing. For these complex cases, to understand the root cause, you can use Perf C2C.
104
+
Although this is a simplified example, in a production workload there might be several layers of indirection that unintentionally result in false sharing. For these complex cases, use `perf c2c`to trace cache line interactions and pinpoint the root cause of performance issues.
92
105
93
106
```output
94
107
Without Alignment can occupy same cache line
@@ -112,6 +125,6 @@ Address of AlignedType h - 0xffffeb6c6080
112
125
113
126
In this section, you explored what Arm SPE is and why it offers a deeper, more accurate view of application performance. You also examined how a subtle issue like false sharing can impact multithreaded code, and how to mitigate it using data alignment techniques in C++.
114
127
115
-
Next, you'll set up your environment and use Perf C2C to capture and analyze real cache behavior on an Arm Neoverse system.
128
+
Next, you'll set up your environment and use `perf c2c` to capture and analyze real-world cache behavior on an Arm Neoverse system.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/false-sharing-arm-spe/how-to-2.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Environment setup for Arm SPE profiling
2
+
title: Set up your environment for Arm SPE and perf c2c profiling
3
3
weight: 3
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,7 +8,7 @@ layout: learningpathall
8
8
## Select a system with SPE support
9
9
10
10
{{% notice Learning goal%}}
11
-
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 right 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.
11
+
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.
12
12
{{% /notice %}}
13
13
14
14
SPE requires support from both your hardware and the operating system. Many cloud instances running Linux do not enable SPE-based profiling.
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.
41
+
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.
42
42
43
43
Run the following command to confirm if the SPE kernel module is loaded:
44
44
@@ -86,9 +86,9 @@ Performance features:
86
86
perf in userspace: disabled
87
87
```
88
88
89
-
## Confirm Arm SPE is available to Perf
89
+
## Confirm Arm SPE is available to perf
90
90
91
-
Run the following command to confirm SPE is available to Perf:
91
+
Run the following command to confirm SPE is available to `perf`:
If `arm_spe` isn’t available due to your system configuration or limited PMU access, the `perf c2c` command will fail.
112
112
113
-
To confirm Perf can access SPE, run:
113
+
To confirm `perf` can access SPE, run:
114
114
115
115
```bash
116
116
perf c2c record
@@ -132,4 +132,4 @@ For more information about enabling SPE, see the [perf-arm-spe manual page](http
132
132
133
133
## Summary
134
134
135
-
You've confirmed that your system supports Arm SPE, installed the necessary tools, and verified that perf 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.
135
+
You've confirmed that your system supports Arm SPE, installed the necessary tools, and verified that `perf` 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.
0 commit comments