Add the possibility to set CPU affinity on thread creation
Description
Add the possibility to set CPU affinity on thread creation. The goal is to be able to choose which thread is assigned to which processor in the system.
Code version identification
master 3a9a4f10
Current behavior
Not possible to choose the CPU, system organized as it want, where (on what CPU) are execute threads. It is impossible to choose the CPU on which a thread runs. The system organizes where (on which CPU) the threads run as it sees fit.
Expected behavior
Add the ability to force a thread to run on a specific CPU.
Security impact
No
Implementation
Base : Thread
- Add to (S2OPC thread API) SOPC_Thread_CreatePrioritized an argument to set the value of cpuAffinity.
- Define default value for priority (0) and CPU affinity (-1) which are accepted parameter without any effect.
- A thread can be created without priority and/or affinity (when default values are used)
- Complete the associated documentation
- Add a log when setting CPU affinity is impossible
- Add implementation for Linux and Windows for priority and CPU affinity
- See thread_windows.c for Windows priority implementation
- See branch
sta_1663_cpu_affinityfor Linux affinity - See https://learn.microsoft.com/fr-fr/windows/win32/api/winbase/nf-winbase-setthreadaffinitymask for Windows affinity documentation
Tests:
- Manuals tests on Linux (with PS) and Windows
- CI tests will be added in another enhancement
Looper
- Add to (S2OPC Looper API) an SOPC_Looper_CreatePrioritized(...) with arguments to set the value of threadPriority and cpuAffinity.
Questions
- Root access may be required to set these options. Is this a problem?
- Prioritization and affinity tests require additional Docker options (in addition to root privileges : manage with
.set-bin-root.sh) that will be difficult to add to continuous integration. The only option seems to be to use a homemade runner with the appropriate options.
docker options :--ulimit rtprio=99 --cap-add=sys_niceThese questions will be addressed in ticket #1669
Edited by Cinthya Kouamou