I’m running a large test suite for a project that gets a significant performance benefit from CPU pinning. Currently we disable this feature in our test suite, since otherwise parallel tests would try to pin to the same CPUs.
I recently came across the PROCESSOR_AFFINITY property, which seems like it should solve this problem for us (our software checks its starting affinity and only pins to CPUs in that set). However, when I use it, it appears to have no effect.
Here is a small test I wrote that just uses the taskset
command-line utility to report its own CPU affinity. Below I’d expect the two versions with PROCESSOR_AFFINITY
set to get distinct affinity masks with 1 bit set in each, and the one without it set to get 0xfff
. Instead, they all get 0xfff
.
add_test(NAME taskset-affinity1 COMMAND sh -c "taskset -p $$")
set_property(TEST taskset-affinity1 PROPERTY PROCESSOR_AFFINITY True)
add_test(NAME taskset-affinity2 COMMAND sh -c "taskset -p $$")
set_property(TEST taskset-affinity2 PROPERTY PROCESSOR_AFFINITY True)
add_test(NAME taskset-noaffinity COMMAND sh -c "taskset -p $$")
Output:
$ ctest -j12 --verbose -R taskset
UpdateCTestConfiguration from :/home/jnewsome/projects/shadow/dev/build/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/jnewsome/projects/shadow/dev/build/DartConfiguration.tcl
Test project /home/jnewsome/projects/shadow/dev/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 103
Start 103: taskset-noaffinity
103: Test command: /usr/bin/sh "-c" "taskset -p $$"
103: Test timeout computed to be: 10000000
test 101
Start 101: taskset-affinity1
101: Test command: /usr/bin/sh "-c" "taskset -p $$"
101: Test timeout computed to be: 10000000
test 102
Start 102: taskset-affinity2
102: Test command: /usr/bin/sh "-c" "taskset -p $$"
102: Test timeout computed to be: 10000000
103: pid 370645's current affinity mask: fff
101: pid 370647's current affinity mask: fff
1/3 Test #103: taskset-noaffinity ............... Passed 0.00 sec
2/3 Test #101: taskset-affinity1 ................ Passed 0.00 sec
102: pid 370649's current affinity mask: fff
3/3 Test #102: taskset-affinity2 ................ Passed 0.00 sec
The following tests passed:
taskset-noaffinity
taskset-affinity1
taskset-affinity2
100% tests passed, 0 tests failed out of 3
I’m using CMake version 3.16.3 on Ubuntu 20.04.3