Linux pinning multiple user space threads to a core in isolated cpu list

91 Views Asked by At

I am doing an experiment on Ubuntu 7.9. My C++ app pins one thread onto a core (say 18, which is from isolated cpu list, picked from /sys/devices/system/cpu/isolated) using pthread_setaffinity_np.

While my app is running, top does confirm that core 18 is 100% and my app thread is running there. However, I am able to run the following command multiple times, which indicates multiple user space threads are able to be pinned to core 18 as well. top confirms that.

taskset -c 18 sleep 200000 &

I am curious why it is allowed? given core 18 is in isolated cpu list.

1

There are 1 best solutions below

0
On

CPU affinity is setting a mask that limits which CPUs a given thread can be scheduled on. It doesn't guarantee that the thread will get exclusive use of the core; it's restricting the thread to be unable to be scheduled anywhere else.

There's thus no reason you can't specify any number of threads to be pinned to a single core. It might be counterproductive performance-wise to do so, since all the threads you pin will be competing over that single core, but it's entirely semantically legal (and one might intentionally do so to put all low-priority processes on one core, f/e, while letting higher-priority processes be invoked anywhere the OS scheduler can fit them).

See the docs for the underlying syscalls: