Skip to content

Commit a524c55

Browse files
Update skill level to Advanced and improve clarity in taskset documentation
1 parent 19d420f commit a524c55

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

content/learning-paths/servers-and-cloud-computing/pinning-threads/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ prerequisites:
2020
author: Kieran Hejmadi
2121

2222
### Tags
23-
skilllevels: Introductory
23+
skilllevels: Advanced
2424
subjects: Performance and Architecture
2525
armips:
2626
- Neoverse

content/learning-paths/servers-and-cloud-computing/pinning-threads/using_taskset.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ layout: learningpathall
88

99
## Create a single-threaded Python benchmark
1010

11-
Now that you have a program that utilizes all available CPU cores, you'll create a single-threaded program that's sensitive to execution variations. This simulates scenarios like a log ingesting process or a single-threaded consumer that needs to maintain a steady pace.
11+
Create a single-threaded program that's sensitive to execution variations. This simulates scenarios like a log ingesting process or a single-threaded consumer that needs to maintain a steady pace.
1212

1313
Check that you have Python installed:
1414

1515
```bash
1616
python --version
1717
```
1818

19-
You should see the version of Python:
19+
The output is similar to:
2020

2121
```output
2222
Python 3.12.3
2323
```
2424

25-
If Python isn't installed, use your Linux package manager to install it or refer to the [Python downloads page](https://www.python.org/downloads/).
25+
If Python isn't installed, use your Linux package manager to install it or see the [Python downloads page](https://www.python.org/downloads/).
2626

2727
Next, create a virtual environment to install packages without interfering with system packages:
2828

@@ -32,7 +32,7 @@ source venv/bin/activate
3232
pip install matplotlib
3333
```
3434

35-
Use an editor to create a file named `single_threaded_python_script.py` with the following code. This script repeatedly measures the execution time of a computational function and writes the results to `data.txt`. It then generates time-series graphs to illustrate the effects of thread pinning:
35+
Create a file named `single_threaded_python_script.py` with the following code. This script measures the execution time of a computational function, writes results to `data.txt`, and generates time-series graphs to illustrate the effects of thread pinning:
3636

3737
```python
3838
#!/usr/bin/env python3
@@ -119,7 +119,7 @@ chmod +x single_threaded_python_script.py
119119

120120
## Compare thread pinning strategies
121121

122-
You'll explore three different scenarios to understand the trade-offs of thread pinning:
122+
Explore three different scenarios to understand the trade-offs of thread pinning:
123123

124124
1. Free: The operating system allocates both programs to any of four cores
125125
2. Shared-pinned: The Python script is pinned to core 0, but `prog` can run on any core
@@ -149,9 +149,9 @@ wait
149149

150150
#### Shared script
151151

152-
The next script pins the Python script to core 0, while `prog` can use any of the first four cores:
152+
The next script pins the Python script to core 0, while `prog` can use any of the first four cores.
153153

154-
Use an editor to create a file named `shared-pinned.sh` with the following code:
154+
Create a file named `shared-pinned.sh` with the following code:
155155

156156
```bash
157157
#!/bin/bash
@@ -167,9 +167,9 @@ wait
167167

168168
#### Exclusive script
169169

170-
The last one gives the Python script exclusive access to core 0, and `prog` uses cores 1-3:
170+
The last one gives the Python script exclusive access to core 0, and `prog` uses cores 1-3.
171171

172-
Use a text editor to create a file named `exclusive.sh` with the following code:
172+
Create a file named `exclusive.sh` with the following code:
173173

174174
```bash
175175
#!/bin/bash
@@ -198,7 +198,7 @@ chmod +x free-script.sh shared-pinned.sh exclusive.sh
198198

199199
The terminal output shows the execution time for `prog` under the three scenarios. The Python script also generates three files: `Free.jpg`, `Exclusive.jpg`, and `Shared.jpg`.
200200

201-
As the terminal output below shows, the `free-script.sh` scenario (where the Linux scheduler assigns threads to cores without restriction) completes `prog` the fastest at 5.8 seconds. The slowest execution occurs when the Python script has exclusive access to CPU 0, which is expected because you've constrained `prog` to fewer cores:
201+
The terminal output shows the `free-script.sh` scenario (where the Linux scheduler assigns threads to cores without restriction) completes `prog` the fastest at 5.8 seconds. The slowest execution occurs when the Python script has exclusive access to CPU 0, which is expected because `prog` is constrained to fewer cores:
202202

203203
```output
204204
Answer = 3.14159 5 iterations took 5838 milliseconds
@@ -210,21 +210,21 @@ However, this represents a trade-off with the Python script's performance.
210210

211211
### Free scenario results
212212

213-
Looking at `Free.jpg`, you can see periodic zones of high latency (3.5 ms) that likely occur when there's contention between `prog` and the Python script:
213+
The `Free.jpg` graph shows periodic zones of high latency (3.5 ms) that likely occur when there's contention between `prog` and the Python script:
214214

215-
![Time-series graph showing execution time varying between 0.5ms and 3.5ms with periodic spikes, indicating contention between processes when both are free to run on any core](free.jpg "Free scenario: both programs can run on any of four cores")
215+
![Time-series line graph plotting execution time in milliseconds on the y-axis against sample number on the x-axis. The line fluctuates between approximately 0.5ms and 3.5ms, showing periodic spikes and zones of higher latency. The graph has a grid background and is titled 'Free'. The pattern indicates contention between processes when both can run on any core](free.jpg "Free scenario: both programs can run on any of four cores")
216216

217217
### Shared-pinned scenario results
218218

219-
When pinning the Python script to core 0 while `prog` remains free to use any cores, you observe similar behavior:
219+
When pinning the Python script to core 0 while `prog` remains free to use any cores, the behavior is similar:
220220

221-
![Time-series graph showing execution time with similar periodic spikes as the free scenario, indicating continued contention despite pinning the Python script](pinned_shared.jpg "Shared-pinned scenario: Python script pinned to core 0, prog free to run on any core")
221+
![Time-series line graph plotting execution time in milliseconds against sample number. The line shows similar behavior to the free scenario with fluctuations between approximately 0.5ms and 3.5ms and periodic spikes. The graph has a grid background and is titled 'Shared'. The pattern shows continued contention despite pinning the Python script to a specific core](pinned_shared.jpg "Shared-pinned scenario: Python script pinned to core 0, prog free to run on any core")
222222

223223
### Exclusive scenario results
224224

225-
When the Python script has exclusive access to core 0, you observe more consistent execution time around 0.49 ms because the script doesn't contend with any other demanding processes:
225+
When the Python script has exclusive access to core 0, the execution time is more consistent around 0.49 ms because the script doesn't contend with any other demanding processes:
226226

227-
![Time-series graph showing consistent execution time around 0.49ms with minimal variation, demonstrating stable performance when the Python script has exclusive core access](exclusive.jpg "Exclusive scenario: Python script has exclusive access to core 0, prog runs on cores 1-3")
227+
![Time-series line graph plotting execution time in milliseconds against sample number. The line shows consistent, stable execution time around 0.49ms with minimal variation throughout the entire sample range. The graph has a grid background and is titled 'Exclusively Pinned'. The flat, steady pattern demonstrates stable performance when the Python script has exclusive access to a dedicated core](exclusive.jpg "Exclusive scenario: Python script has exclusive access to core 0, prog runs on cores 1-3")
228228

229229
## Understanding the trade-offs
230230

@@ -238,10 +238,10 @@ Multiple factors influence this behavior, including the Linux scheduler algorith
238238

239239
## What you've accomplished and what's next
240240

241-
In this section, you've:
241+
In this section:
242242
- Created a single-threaded Python benchmark that measures execution time variations
243243
- Used `taskset` to pin processes to specific CPU cores
244244
- Compared three thread pinning strategies: free, shared-pinned, and exclusive
245245
- Analyzed the trade-offs between throughput and latency consistency
246246

247-
In the next section, you'll learn how to use source code modifications and environment variables to control thread affinity programmatically.
247+
Next, you learn how to control thread affinity programmatically using source code modifications.

0 commit comments

Comments
 (0)