Inhaltsverzeichnis

CPU affinity

Introduction

Normally the Linux scheduler chooses on which CPU core a process should be executed.

However, the various processes of Linux can also be pinned to one CPU core and all realtime processes to another core. This can reduce the jitter of real-time processes.

Pin all Linux Processes to a Certain CPU Core

Add the following kernel parameter:

isolcpus=1

This will pin all Linux processes to CPU core 1.

To pin the processes to core 0 and core 1 use:

isolcpus=0,1

Pin a Process to Another CPU Core

To pin a certain process to CPU core 1 use:

taskset 0x2 <rt-process>

Hint: This will pin the process to core 1, not core 2, see Bitmask further down.

Bitmask

The argument of taskset is a bitmask of all cpu cores, which can be used for this process.

Application example in a script

PID_SCRIPT=$$
taskset 0x2 $PID_SCRIPT

This will pin the process of the script and all of its child processes to CPU 1. Every program and application which is startet after this lines will run CPU 1.

Check CPU affinity