Skip to content

Commit cfc589f

Browse files
Merge pull request #1458 from madeline-underwood/Sampling
Sample Instructions with WindowsPerf and Arm SPE - can now be merged
2 parents dc01467 + 82084aa commit cfc589f

File tree

7 files changed

+153
-173
lines changed

7 files changed

+153
-173
lines changed

content/learning-paths/cross-platform/windowsperf_sampling_cpython_spe/_index.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
2-
title: Sampling CPython with WindowsPerf and Arm SPE
3-
draft: true
4-
cascade:
5-
draft: true
2+
title: Sample Instructions with WindowsPerf and Arm SPE
63

74
minutes_to_complete: 30
85

9-
who_is_this_for: This is an introductory topic for developers keen to understand sampling with the Arm Statistical Profiling Extension (SPE).
6+
who_is_this_for: This is an introductory topic for developers who would like to learn about sampling CPU instructions with WindowsPerf and the Arm Statistical Profiling Extension (SPE).
107

118
learning_objectives:
129
- Use WindowsPerf with a native Windows on Arm workload.
13-
- Understand the basics of sampling with Arm SPE.
10+
- Describe the basic concepts of sampling with Arm SPE.
1411
- Explore the WindowsPerf command line.
15-
- Build CPython from sources for Windows on Arm (ARM64).
12+
- Build CPython from sources for Windows on Arm (AArch64).
1613

1714
prerequisites:
18-
- Windows on Arm desktop or development machine with [WindowsPerf](/install-guides/wperf), [Visual Studio](/install-guides/vs-woa/), and [Git](/install-guides/git-woa/) installed.
19-
- The Windows on Arm system must have an Arm CPU with SPE support.
20-
15+
- A Windows on Arm desktop or development machine, with CPU support for SPE.
16+
- An installation of [WindowsPerf](/install-guides/wperf).
17+
- An installation of [Visual Studio](/install-guides/vs-woa/).
18+
- An installation of [Git](/install-guides/git-woa/).
19+
2120
author_primary: Przemyslaw Wirkus
2221

2322
### Tags

content/learning-paths/cross-platform/windowsperf_sampling_cpython_spe/_review.md

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,88 +9,36 @@
99
# correct_answer: An integer indicating what answer is correct (index starts from 0)
1010
# explanation: A short (1-3 sentence) explanation of why the correct answer is correct. Can add additional context if desired
1111

12-
review:
12+
review:
1313
- questions:
1414
question: >
15-
The counting model is used for obtaining aggregate counts of occurrences of special events.
15+
The Arm Statistical Profiling Extension (SPE) is an optional feature in Armv8-A.2 hardware.
1616
answers:
17-
- "True"
18-
- "False"
17+
- "True."
18+
- "False."
1919
correct_answer: 1
2020
explanation: >
21-
In the counting model, the occurrences of PMU events are simply aggregated over a given time period.
22-
21+
Yes, the Arm Statistical Profiling Extension (SPE) is an optional feature in Armv8.2 hardware that allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
2322
- questions:
2423
question: >
25-
The sampling model is used for determining the frequencies of event occurrences produced by program locations at the function, basic block, and/or instruction levels.
24+
SPE is an acronym for Statistical Profiling Extension. True or false?
2625
answers:
27-
- "True"
28-
- "False"
26+
- "True."
27+
- "False."
2928
correct_answer: 1
3029
explanation: >
31-
In the sampling model, the frequencies of event occurrences produced by the program determine "hot" locations at the function, basic block, and/or instruction levels.
32-
30+
Yes, SPE is the abbreviated form of Statistical Profiling Extension.
3331
- questions:
3432
question: >
35-
WindowsPerf can be used and executed only on native Windows on Arm hardware, and not in a virtual environment.
33+
load_filter is one of SPE filters supported by WindowsPerf. True or false?
3634
answers:
37-
- "True"
38-
- "False"
35+
- "True."
36+
- "False."
3937
correct_answer: 1
4038
explanation: >
41-
Yes, WindowsPerf currently supports a native Windows on Arm environment only.
42-
43-
- questions:
44-
question: >
45-
The Arm Statistical Profiling Extension (SPE) is an optional feature in ARMv8.2 hardware.
46-
answers:
47-
- "True"
48-
- "False"
49-
correct_answer: 1
50-
explanation: >
51-
Yes, the Arm Statistical Profiling Extension (SPE) is an optional feature in ARMv8.2 hardware that allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
52-
53-
- questions:
54-
question: >
55-
SPE stands for Statistical Profiling Extension.
56-
answers:
57-
- "True"
58-
- "False"
59-
correct_answer: 1
60-
explanation: >
61-
Yes, the Arm Statistical Profiling Extension (SPE) is an optional feature in ARMv8.2 hardware.
62-
63-
- questions:
64-
question: >
65-
load_filter is one of SPE filters supported by WindowsPerf?
66-
answers:
67-
- "True"
68-
- "False"
69-
correct_answer: 1
70-
explanation: >
71-
Yes, load_filter together with store_filter and branch_filter are SPE filters supported by WindowsPerf.
72-
73-
- questions:
74-
question: >
75-
store_filter is one of SPE filters supported by WindowsPerf?
76-
answers:
77-
- "True"
78-
- "False"
79-
correct_answer: 1
80-
explanation: >
81-
Yes, load_filter together with store_filter and branch_filter are SPE filters supported by WindowsPerf.
82-
83-
- questions:
84-
question: >
85-
branch_filter is one of SPE filters supported by WindowsPerf?
86-
answers:
87-
- "True"
88-
- "False"
89-
correct_answer: 1
90-
explanation: >
91-
Yes, load_filter together with store_filter and branch_filter are SPE filters supported by WindowsPerf.
92-
39+
Yes, load_filter, store_filter, and branch_filter are SPE filters that WindowsPerf supports.
9340
41+
9442
# ================================================================================
9543
# FIXED, DO NOT MODIFY
9644
# ================================================================================
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: learningpathall
3+
title: Overview of Arm Statistical Profiling Extenstion
4+
weight: 2
5+
---
6+
7+
## Arm Statistical Profiling Extension (SPE)
8+
9+
The Arm Statistical Profiling Extension (SPE) was introduced in the Armv8.2-A architecture, and is an optional feature from Armv8.1-A.
10+
11+
SPE allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
12+
13+
It provides non-invasive, hardware-based, statistical sampling for CPUs. Unlike the Performance Monitor Unit (PMU), SPE is a different module that integrates the sampling process into the instruction execution process within the pipelines of the CPU.
14+
15+
SPE provides a statistical view of the performance characteristics of executed instructions, which can be used by software writers to optimize their code for better performance.
16+
17+
SPE is particularly useful for performance analysis and optimization, as it provides detailed insights into the behavior of the CPU during execution.
18+
19+
This can help identify performance bottlenecks and optimize software for better efficiency.
20+
21+
## Using SPE with WindowsPerf in this Learning Path
22+
23+
WindowsPerf includes `record` support for the Arm Statistical Profiling Extension (SPE).
24+
25+
You will create a debug build of CPython from source and execute simple instructions in the Python interactive mode to obtain WindowsPerf sampling results from the CPython runtime image.
26+
27+
You will use the sampling to detect CPython program hot spots identified by the Arm Statistical Profiling Extension (SPE).
28+
29+
{{% notice Note %}}
30+
SPE is only available on Windows on Arm in Test Mode.
31+
Windows Test Mode is a feature that allows you to install and test drivers that have not been digitally signed by Microsoft.
32+
{{% /notice %}}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
layout: learningpathall
3+
title: Summary
4+
weight: 7
5+
---
6+
## Summary
7+
8+
WindowsPerf is a versatile performance analysis tool that offers two kinds of support:
9+
10+
* For software, it supports CPU PMU events.
11+
* For hardware, it supports the SPE extension.
12+
13+
The type of sampling it can perform depends on the availability of the Arm Statistical Profiling Extension (SPE) in the CPU.
14+
15+
If the SPE extension is available, WindowsPerf can leverage hardware sampling to provide detailed performance insights. Otherwise, it relies on software sampling to gather performance data.
16+
17+
This flexibility ensures that WindowsPerf can adapt to different hardware configurations and consistently deliver valuable performance metrics:
18+
19+
* You can use `wperf sample`, which is sampling mode, for determining the frequencies of event occurrences produced by program locations at the function, basic block, and instruction levels.
20+
21+
* You can use `wperf record`, which is the same as sample, but also automatically spawns the process and pins it to the core specified by `-c`. You can use `record` to pass verbatim arguments to the process.

content/learning-paths/cross-platform/windowsperf_sampling_cpython_spe/windowsperf_sampling_cpython_spe.md

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,38 @@
11
---
22
layout: learningpathall
3-
title: An overview of CPython sampling with SPE
4-
weight: 2
3+
title: Setup
4+
weight: 3
55
---
66

7-
In this example, you will build a debug build of CPython from source and execute simple instructions in the Python interactive mode to obtain WindowsPerf sampling results from the CPython runtime image.
8-
9-
## Introduction to the Arm Statistical Profiling Extension (SPE)
10-
11-
The Arm Statistical Profiling Extension (SPE) is a feature defined as part of the Armv8-A architecture, starting from version 8.2. It provides non-invasive, hardware-based statistical sampling for CPUs. Unlike the Performance Monitor Unit (PMU), SPE is a different module that integrates the sampling process into the instruction execution process within the CPU's pipelines.
12-
13-
SPE is particularly useful for performance analysis and optimization, as it provides detailed insights into the behavior of the CPU during execution. This can help identify performance bottlenecks and optimize software for better efficiency.
14-
15-
## Overview
16-
17-
You will use sampling to determine the CPython program "hot" locations as provided by the Arm Statistical Profiling Extension (SPE).
18-
19-
WindowsPerf includes `record` support for the Arm Statistical Profiling Extension (SPE).
20-
21-
SPE is an optional feature in ARMv8.2 hardware that allows CPU instructions to be sampled and associated with the source code location where that instruction occurred.
22-
23-
{{% notice Note %}}
24-
SPE is only available on Windows on Arm in Test Mode.
25-
Windows Test Mode is a feature that allows you to install and test drivers that have not been digitally signed by Microsoft.
26-
{{% /notice %}}
277

288
## Before you begin
299

30-
For this Learning Path you will need:
10+
For this Learning Path, you will need:
3111

32-
* A Windows on Arm (ARM64) native machine with pre-installed WindowsPerf (both driver and `wperf` CLI tool). Refer to the [WindowsPerf Install Guide](/install-guides/wperf/) for more details.
33-
* Note: The [WindowsPerf release 3.8.0](https://github.com/arm-developer-tools/windowsperf/releases/tag/3.8.0) includes a separate build with Arm SPE (Statistical Profiling Extension) support enabled. To install this version download release asset and you will find WindowsPerf SPE build in the `SPE/` subdirectory.
34-
* [Visual Studio](/install-guides/vs-woa/) and [Git](/install-guides/git-woa/) installed.
35-
* The CPU must support the Arm SPE extension, an optional feature in ARMv8.2 hardware. You can check your CPU compatibility using the WindowsPerf command-line tool as explained below.
12+
* A Windows on Arm (AArch64) native machine with pre-installed WindowsPerf; both the driver and `wperf` CLI tool. See the [WindowsPerf Install Guide](/install-guides/wperf/) for more details.
13+
14+
{{% notice Note %}}
15+
The [WindowsPerf release 3.8.0](https://github.com/arm-developer-tools/windowsperf/releases/tag/3.8.0) includes a separate build with support for Arm SPE enabled. To install this version, download the release asset, and you will find WindowsPerf SPE build in the `SPE/` subdirectory.
16+
{{% /notice %}}
17+
* [Visual Studio](/install-guides/vs-woa/) installed.
18+
* [Git](/install-guides/git-woa/) installed.
19+
* A CPU that supports the Arm SPE extension.
3620

3721
### How do I check if my Arm CPU supports the Arm SPE extension?
3822

23+
You can check your CPU compatibility using the WindowsPerf command-line tool.
24+
3925
#### SPE hardware support detection:
4026

4127
You can check if WindowsPerf detects SPE support with the `wperf test` command.
4228

43-
Run the command below and if the `spe_device.version_name` property shows `FEAT_SPE` it means WindowsPerf can use the SPE features.
29+
Run the command below and if the `spe_device.version_name` property shows `FEAT_SPE`, it means that WindowsPerf can use the SPE features.
4430

4531
```console
4632
wperf test
4733
```
4834

49-
Here is the output for a system with SPE support:
35+
Here an example output for a system with SPE support:
5036

5137
```output
5238
Test Name Result
@@ -55,19 +41,19 @@ Here is the output for a system with SPE support:
5541
spe_device.version_name FEAT_SPE
5642
```
5743

58-
#### How do I know if my WindowsPerf binaries and driver support optional SPE?
44+
#### How do I check if the WindowsPerf binaries and driver support SPE?
5945

6046
{{% notice Note %}}
61-
Currently WindowsPerf support of SPE is in development, not all versions of WindowsPerf enable SPE support. Some WindowsPerf releases may contain separate binaries with SPE support enables.
47+
Currently, the WindowsPerf support of SPE is in development, and not all versions of WindowsPerf enable SPE support. Some WindowsPerf releases might contain separate binaries with SPE support enabled.
6248
{{% /notice %}}
6349

64-
You can check feature string `FeatureString` of both `wperf` and `wperf-driver` with `wperf --version` command:
50+
You can check the feature string `FeatureString` of both `wperf` and `wperf-driver` with `wperf --version` command:
6551

6652
```console
6753
wperf --version
6854
```
6955

70-
The output is similar to:
56+
The output should be similar to:
7157

7258
```output
7359
Component Version GitVer FeatureString
@@ -76,17 +62,17 @@ The output is similar to:
7662
wperf-driver 3.8.0 6d15ddfc +trace+spe
7763
```
7864

79-
If the `FeatureString` for both `wperf` and `wperf-driver` contains `+spe` you can use the SPE features of WindowsPerf.
65+
If the `FeatureString` for both `wperf` and `wperf-driver` contains `+spe`, the SPE features of WindowsPerf are available for you to use.
8066

81-
### Build CPython for ARM64
67+
### Build CPython for AArch64
8268

8369
Perform the build steps below on your Windows on Arm system.
8470

85-
CPython is an open-source project which includes native support for Windows on Arm starting with version 3.11.
71+
CPython is an open-source project, which includes native support for Windows on Arm starting with version 3.11.
8672

87-
The SPE features are demonstrated with a debug build of CPython. You can build [CPython](https://github.com/python/cpython) locally from sources in debug mode.
73+
The SPE features demonstrated here use a debug build of CPython. You can build [CPython](https://github.com/python/cpython) locally from sources in debug mode.
8874

89-
Open a Visual Studio `Developer Command Prompt for VS 2022` command prompt. You can find this from Windows Start by searching for "Developer Command Prompt for VS 2022".
75+
Open a Visual Studio `Developer Command Prompt for VS 2022` command prompt. You can find this from Windows **Start** by searching for **Developer Command Prompt for VS 2022**.
9076

9177
When you open the command prompt, you will see output similar to:
9278

@@ -100,14 +86,14 @@ C:\Program Files\Microsoft Visual Studio\2022\Community>
10086
```
10187

10288
{{% notice Note %}}
103-
Please use the `Developer Command Prompt for VS 2022` command prompt for the remainder of the steps.
89+
For the remaining steps, use **Developer Command Prompt for VS 2022**.
10490
{{% /notice %}}
10591

106-
You can build CPython locally in debug mode using the `build.bat` script using the steps below.
92+
You can build CPython locally in debug mode using the `build.bat` script.
10793

10894
#### Clone CPython source code
10995

110-
Get the CPython source code from GitHub:
96+
Obtain the CPython source code from GitHub:
11197

11298
```command
11399
git clone https://github.com/python/cpython.git
@@ -129,7 +115,7 @@ Updating files: 100% (4647/4647), done.
129115
#### Checkout CPython with a specific SHA
130116

131117
{{% notice Note %}}
132-
This step is optional, but you may encounter build issues unrelated to this example if the CPython mainline source code is not stable. It's best to check out a specific SHA to avoid any unexpected issues and to ensure you are working off the same code base.
118+
This step is optional, but you might encounter build issues unrelated to this example if the CPython mainline source code is not stable. It is best to checkout a specific SHA to avoid any unexpected issues and to ensure you are working off the same code base.
133119
{{% /notice %}}
134120

135121
Use a specific CPython commit to match the output for this example:
@@ -148,11 +134,11 @@ Note: switching to '1ff81c0cb67215694f084e51c4d35ae53b9f5cf9'.
148134

149135
#### Build CPython from sources
150136

151-
The `build.bat` script builds CPython from sources. Build CPython with debug symbols by invoking the `-d` command line option and select the ARM64 target with `-p ARM64`.
137+
The `build.bat` script builds CPython from sources. Build CPython with debug symbols by invoking the `-d` command line option, and selecting the ARM64 target with `-p ARM64`.
152138

153-
Make sure you are using `Developer Command Prompt for VS 2022`.
139+
Make sure you are using **Developer Command Prompt for VS 2022**.
154140

155-
Change to the `PCbuild` directory and run the build command:
141+
Change to the `PCbuild` directory, and run the build command:
156142

157143
```console
158144
cd PCbuild
@@ -193,7 +179,7 @@ cd arm64
193179
python_d.exe
194180
```
195181

196-
You see CPython being invoked in interactive mode:
182+
You can see CPython being invoked in interactive mode:
197183

198184
```output
199185
Python 3.12.0a6+ (heads/main:1ff81c0cb6, Mar 14 2023, 16:26:50) [MSC v.1935 64 bit (ARM64)] on win32
@@ -203,4 +189,4 @@ Type "help", "copyright", "credits" or "license" for more information.
203189

204190
Type `quit()` to exit CPython.
205191

206-
Your environment s now ready to use WindowsPerf with SPE on CPython.
192+
Your environment is now ready to use WindowsPerf with SPE on CPython.

0 commit comments

Comments
 (0)