util: Consider CPU affinity when detecting number of CPUs

A similar path can be used on at least FreeBSD using cpuset_getaffinity.
This is how Ninja determines the number of available CPUs on that
platform.  See the GetProcessorCount functin in util.cc:

https://github.com/ninja-build/ninja/blob/master/src/util.cc

v2: Fix counting the number of available CPUs.  The CPU_COUNT API does
not work the way I thought it did. 🤦 Noticed by Marek.

Reviewed-by: Adam Jackson <ajax@redhat.com> [v1]
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> [v1]
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
185 jobs for consider-cpu-affinity
Status Job ID Name Coverage
  Container
manual #10898002
aarch64 manual
arm_build
manual #10898003
windows shell 1809 mesa manual
windows_build_vs2019
manual #10898000
manual
x86_build-base
manual #10898001
manual
x86_test-base
 
  Container 2
created #10898008
android_build
created #10898005
i386_build
created #10898011
kernel+rootfs_amd64
created #10898012
aarch64
kernel+rootfs_arm64
created #10898013
aarch64
kernel+rootfs_armhf
created #10898006
ppc64el_build
created #10898007
s390x_build
created #10898004
x86_build
created #10898009
x86_test-gl
created #10898010
x86_test-vk
 
  Meson X86 64
created #10898019
meson-clang
created #10898020
meson-clover
created #10898016
meson-clover-testing
created #10898017
meson-gallium
created #10898018
meson-release
created #10898014
meson-testing
created #10898015
meson-testing-asan
created #10898021
meson-vulkan
 
  Build Misc
created #10898022
arm_test
created #10898023
meson-android
created #10898025
aarch64
meson-arm64
created #10898026
aarch64
meson-arm64-asan
created #10898027
aarch64
meson-arm64-build-test
created #10898024
aarch64
meson-armhf
created #10898029
meson-i386
created #10898032
meson-mingw32-x86_64
created #10898031
meson-ppc64el
created #10898030
kvm
meson-s390x
created #10898028
windows docker 1809 mesa
meson-windows-vs2019
 
  Amd
created #10898041
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles2:amd64
created #10898044
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 1/2
created #10898045
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 2/2
created #10898042
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 1/2
created #10898043
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 2/2
created #10898047
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-piglit-gl:amd64
created #10898046
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-traces:amd64
created #10898040
radv-fossils
created #10898034
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-traces
created #10898033
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-vkd3d-proton
created #10898036
polaris10 manual
radv_polaris10_vkcts
created #10898035
amdgpu:codename:RAVEN manual
radv-raven-traces
created #10898037
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 1/3
created #10898038
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 2/3
created #10898039
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 3/3
 
  Intel
created #10898048
anholt-g33 manual
i915-g33-deqp
created #10898049
anholt-g33 manual
i915-g33-khr-deqp
created #10898050
anholt-g33 manual
i915-g33-piglit
created #10898051
anholt-g33 manual
i915-g33-traces
created #10898071
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-egl
created #10898070
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gl
created #10898063
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gles2
created #10898066
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles3
created #10898068
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles31
created #10898074
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 1/3
created #10898076
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 2/3
created #10898078
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 3/3
created #10898085
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-traces
created #10898056
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-egl
created #10898055
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral manual
iris-apl-gl
created #10898052
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles2
created #10898053
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles3
created #10898054
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles31
created #10898080
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-traces
created #10898061
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-egl
created #10898060
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gl
created #10898057
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles2
created #10898058
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles3
created #10898059
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles31
created #10898083
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-traces
created #10898087
mesa-ci-x86-64-lava-hp-x360-14-G1-sona manual
iris-kbl-traces
 
  Arm
created #10898110
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles31:arm64
created #10898106
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 1/2
created #10898108
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 2/2
created #10898089
mesa-ci-x86-64-lava-sun50i-h6-pine-h64
panfrost-t720-gles2:arm64
created #10898091
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-gles2:armhf
created #10898094
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-traces:armhf
created #10898101
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles31:arm64
created #10898096
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 1/2
created #10898099
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 2/2
created #10898103
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-traces:arm64
 
  Broadcom
created #10898156
igalia-rpi4
v3d-rpi4-egl:armhf
created #10898148
igalia-rpi4
v3d-rpi4-gles2:armhf
created #10898137
igalia-rpi4
v3d-rpi4-gles31:armhf 1/2
created #10898139
igalia-rpi4
v3d-rpi4-gles31:armhf 2/2
created #10898141
igalia-rpi4
v3d-rpi4-gles3:armhf 1/4
created #10898142
igalia-rpi4
v3d-rpi4-gles3:armhf 2/4
created #10898144
igalia-rpi4
v3d-rpi4-gles3:armhf 3/4
created #10898146
igalia-rpi4
v3d-rpi4-gles3:armhf 4/4
created #10898154
igalia-rpi4
v3d-rpi4-khr-gles2:armhf
created #10898150
igalia-rpi4
v3d-rpi4-khr-gles31:armhf
created #10898152
igalia-rpi4
v3d-rpi4-khr-gles3:armhf
created #10898158
igalia-rpi4
v3d-rpi4-piglit:armhf 1/3
created #10898160
igalia-rpi4
v3d-rpi4-piglit:armhf 2/3
created #10898162
igalia-rpi4
v3d-rpi4-piglit:armhf 3/3
created #10898164
igalia-rpi4
v3dv-rpi4-vk:arm64 1/6
created #10898166
igalia-rpi4
v3dv-rpi4-vk:arm64 2/6
created #10898168
igalia-rpi4
v3dv-rpi4-vk:arm64 3/6
created #10898170
igalia-rpi4
v3dv-rpi4-vk:arm64 4/6
created #10898172
igalia-rpi4
v3dv-rpi4-vk:arm64 5/6
created #10898174
igalia-rpi4
v3dv-rpi4-vk:arm64 6/6
created #10898122
igalia-rpi3
vc4-rpi3-egl:armhf
created #10898112
igalia-rpi3
vc4-rpi3-gles2:armhf 1/4
created #10898114
igalia-rpi3
vc4-rpi3-gles2:armhf 2/4
created #10898116
igalia-rpi3
vc4-rpi3-gles2:armhf 3/4
created #10898117
igalia-rpi3
vc4-rpi3-gles2:armhf 4/4
created #10898119
igalia-rpi3
vc4-rpi3-khr-gles2:armhf
created #10898124
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 1/4
created #10898126
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 2/4
created #10898128
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 3/4
created #10898130
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 4/4
created #10898133
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 1/2
created #10898135
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 2/2
 
  Freedreno
created #10898177
google-freedreno-db410c
a306_gles2
created #10898179
google-freedreno-db410c
a306_gles3 1/3
created #10898181
google-freedreno-db410c
a306_gles3 2/3
created #10898183
google-freedreno-db410c
a306_gles3 3/3
created #10898185
google-freedreno-db410c
a306_gles3_options
created #10898187
google-freedreno-db410c
a306-traces
created #10898189
google-freedreno-db820c
a530_gles2
created #10898196
google-freedreno-db820c
a530_gles31 1/2
created #10898191
google-freedreno-db820c
a530_gles3 1/2
created #10898198
google-freedreno-db820c
a530_gles31 2/2
created #10898193
google-freedreno-db820c
a530_gles3 2/2
created #10898200
google-freedreno-db820c manual
a530_piglit_gl
created #10898202
google-freedreno-db820c
a530_piglit_shader 1/2
created #10898204
google-freedreno-db820c
a530_piglit_shader 2/2
created #10898206
google-freedreno-db820c
a530-traces
created #10898216
google-freedreno-cheza
a630_egl
created #10898214
google-freedreno-cheza
a630_gl
created #10898208
google-freedreno-cheza
a630_gles2
created #10898212
google-freedreno-cheza
a630_gles3
created #10898210
google-freedreno-cheza
a630_gles31
created #10898219
google-freedreno-cheza manual
a630_gles_asan
created #10898217
google-freedreno-cheza
a630_gles_others
created #10898229
google-freedreno-cheza
a630_piglit
created #10898231
google-freedreno-cheza
a630-traces
created #10898221
google-freedreno-cheza
a630_vk 1/2
created #10898223
google-freedreno-cheza
a630_vk 2/2
created #10898225
google-freedreno-cheza manual
a630_vk_asan
created #10898227
google-freedreno-cheza
a630_vk_sysmem
 
  Software Renderer
created #10898270
lavapipe-nir-stress
created #10898269
lavapipe-vk
created #10898250
llvmpipe-egl
created #10898247
llvmpipe-gl
created #10898242
llvmpipe-gles2
created #10898243
llvmpipe-gles3
created #10898245
llvmpipe-gles31
created #10898248
llvmpipe-khr-gles2
created #10898233
llvmpipe-piglit-cl
created #10898237
llvmpipe-piglit-glslparser
created #10898235
llvmpipe-piglit-quick_gl
created #10898238
llvmpipe-piglit-quick_shader
created #10898240
llvmpipe-traces
created #10898264
softpipe-asan-gles31
created #10898267
softpipe-gl
created #10898252
softpipe-gles2
created #10898253
softpipe-gles3
created #10898255
softpipe-gles31 1/2
created #10898257
softpipe-gles31 2/2
created #10898259
softpipe-khr-gles2
created #10898260
softpipe-khr-gles3
created #10898262
softpipe-khr-gles31
created #10898266
softpipe-piglit-quick
 
  Layered Backends
created #10898300
windows docker 1809 mesa
test-d3d12-windows
created #10898279
virgl-gl30-on-gl
created #10898280
virgl-gl31-on-gl
created #10898283
virgl-gl32-on-gl
created #10898272
virgl-gles2-on-gl
created #10898284
manual
virgl-gles2-on-gles
created #10898276
virgl-gles31-on-gl 1/2
created #10898277
virgl-gles31-on-gl 2/2
created #10898288
manual
virgl-gles31-on-gles 1/2
created #10898289
manual
virgl-gles31-on-gles 2/2
created #10898274
virgl-gles3-on-gl
created #10898286
manual
virgl-gles3-on-gles
created #10898291
kvm
virgl-traces
created #10898298
zink-lvp-gl
created #10898295
zink-lvp-gles2
created #10898296
zink-lvp-gles3
created #10898293
zink-piglit-quick_gl
 
  Deploy
manual #10898302
manual
test-docs