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 function 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>
Part-of: <mesa/mesa!11228>
Status Job ID Name Coverage
  Container
manual #10905983
aarch64 manual
arm_build
manual #10905984
windows shell 1809 mesa manual
windows_build_vs2019
manual #10905981
manual
x86_build-base
manual #10905982
manual
x86_test-base
 
  Container 2
created #10905989
android_build
created #10905986
i386_build
created #10905992
kernel+rootfs_amd64
created #10905993
aarch64
kernel+rootfs_arm64
created #10905994
aarch64
kernel+rootfs_armhf
created #10905987
ppc64el_build
created #10905988
s390x_build
created #10905985
x86_build
created #10905990
x86_test-gl
created #10905991
x86_test-vk
 
  Meson X86 64
created #10906000
meson-clang
created #10906001
meson-clover
created #10905997
meson-clover-testing
created #10905998
meson-gallium
created #10905999
meson-release
created #10905995
meson-testing
created #10905996
meson-testing-asan
created #10906002
meson-vulkan
 
  Build Misc
created #10906003
arm_test
created #10906004
meson-android
created #10906006
aarch64
meson-arm64
created #10906007
aarch64
meson-arm64-asan
created #10906008
aarch64
meson-arm64-build-test
created #10906005
aarch64
meson-armhf
created #10906010
meson-i386
created #10906013
meson-mingw32-x86_64
created #10906012
meson-ppc64el
created #10906011
kvm
meson-s390x
created #10906009
windows docker 1809 mesa
meson-windows-vs2019
 
  Amd
created #10906018
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles2:amd64
created #10906021
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 1/2
created #10906022
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 2/2
created #10906019
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 1/2
created #10906020
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 2/2
created #10906024
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-piglit-gl:amd64
created #10906023
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-traces:amd64
created #10906015
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-traces
created #10906014
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-vkd3d-proton
created #10906017
polaris10 manual
radv_polaris10_vkcts
created #10906016
amdgpu:codename:RAVEN manual
radv-raven-traces
 
  Intel
created #10906025
anholt-g33 manual
i915-g33-deqp
created #10906026
anholt-g33 manual
i915-g33-khr-deqp
created #10906027
anholt-g33 manual
i915-g33-piglit
created #10906028
anholt-g33 manual
i915-g33-traces
created #10906043
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-egl
created #10906042
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gl
created #10906039
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gles2
created #10906040
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles3
created #10906041
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles31
created #10906044
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 1/3
created #10906045
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 2/3
created #10906046
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 3/3
created #10906049
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-traces
created #10906033
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-egl
created #10906032
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral manual
iris-apl-gl
created #10906029
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles2
created #10906030
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles3
created #10906031
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles31
created #10906047
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-traces
created #10906038
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-egl
created #10906037
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gl
created #10906034
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles2
created #10906035
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles3
created #10906036
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles31
created #10906048
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-traces
created #10906050
mesa-ci-x86-64-lava-hp-x360-14-G1-sona manual
iris-kbl-traces
 
  Arm
created #10906071
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles31:arm64
created #10906066
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 1/2
created #10906069
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 2/2
created #10906051
mesa-ci-x86-64-lava-sun50i-h6-pine-h64
panfrost-t720-gles2:arm64
created #10906054
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-gles2:armhf
created #10906056
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-traces:armhf
created #10906061
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles31:arm64
created #10906058
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 1/2
created #10906060
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 2/2
created #10906064
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-traces:arm64
 
  Broadcom
created #10906121
igalia-rpi4
v3d-rpi4-egl:armhf
created #10906113
igalia-rpi4
v3d-rpi4-gles2:armhf
created #10906101
igalia-rpi4
v3d-rpi4-gles31:armhf 1/2
created #10906103
igalia-rpi4
v3d-rpi4-gles31:armhf 2/2
created #10906105
igalia-rpi4
v3d-rpi4-gles3:armhf 1/4
created #10906106
igalia-rpi4
v3d-rpi4-gles3:armhf 2/4
created #10906109
igalia-rpi4
v3d-rpi4-gles3:armhf 3/4
created #10906111
igalia-rpi4
v3d-rpi4-gles3:armhf 4/4
created #10906119
igalia-rpi4
v3d-rpi4-khr-gles2:armhf
created #10906115
igalia-rpi4
v3d-rpi4-khr-gles31:armhf
created #10906117
igalia-rpi4
v3d-rpi4-khr-gles3:armhf
created #10906123
igalia-rpi4
v3d-rpi4-piglit:armhf 1/3
created #10906125
igalia-rpi4
v3d-rpi4-piglit:armhf 2/3
created #10906127
igalia-rpi4
v3d-rpi4-piglit:armhf 3/3
created #10906085
igalia-rpi3
vc4-rpi3-egl:armhf
created #10906074
igalia-rpi3
vc4-rpi3-gles2:armhf 1/4
created #10906076
igalia-rpi3
vc4-rpi3-gles2:armhf 2/4
created #10906078
igalia-rpi3
vc4-rpi3-gles2:armhf 3/4
created #10906080
igalia-rpi3
vc4-rpi3-gles2:armhf 4/4
created #10906082
igalia-rpi3
vc4-rpi3-khr-gles2:armhf
created #10906087
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 1/4
created #10906090
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 2/4
created #10906092
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 3/4
created #10906095
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 4/4
created #10906097
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 1/2
created #10906099
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 2/2
 
  Freedreno
created #10906130
google-freedreno-db410c
a306_gles2
created #10906132
google-freedreno-db410c
a306_gles3 1/3
created #10906134
google-freedreno-db410c
a306_gles3 2/3
created #10906136
google-freedreno-db410c
a306_gles3 3/3
created #10906138
google-freedreno-db410c
a306_gles3_options
created #10906140
google-freedreno-db410c
a306-traces
created #10906142
google-freedreno-db820c
a530_gles2
created #10906148
google-freedreno-db820c
a530_gles31 1/2
created #10906144
google-freedreno-db820c
a530_gles3 1/2
created #10906150
google-freedreno-db820c
a530_gles31 2/2
created #10906146
google-freedreno-db820c
a530_gles3 2/2
created #10906152
google-freedreno-db820c manual
a530_piglit_gl
created #10906154
google-freedreno-db820c
a530_piglit_shader 1/2
created #10906156
google-freedreno-db820c
a530_piglit_shader 2/2
created #10906158
google-freedreno-db820c
a530-traces
created #10906167
google-freedreno-cheza
a630_egl
created #10906166
google-freedreno-cheza
a630_gl
created #10906159
google-freedreno-cheza
a630_gles2
created #10906164
google-freedreno-cheza
a630_gles3
created #10906161
google-freedreno-cheza
a630_gles31
created #10906171
google-freedreno-cheza manual
a630_gles_asan
created #10906169
google-freedreno-cheza
a630_gles_others
created #10906181
google-freedreno-cheza
a630_piglit
created #10906183
google-freedreno-cheza
a630-traces
created #10906173
google-freedreno-cheza
a630_vk 1/2
created #10906175
google-freedreno-cheza
a630_vk 2/2
created #10906177
google-freedreno-cheza manual
a630_vk_asan
created #10906179
google-freedreno-cheza
a630_vk_sysmem
 
  Software Renderer
created #10906223
lavapipe-nir-stress
created #10906221
lavapipe-vk
created #10906203
llvmpipe-egl
created #10906199
llvmpipe-gl
created #10906194
llvmpipe-gles2
created #10906196
llvmpipe-gles3
created #10906198
llvmpipe-gles31
created #10906201
llvmpipe-khr-gles2
created #10906186
llvmpipe-piglit-cl
created #10906189
llvmpipe-piglit-glslparser
created #10906187
llvmpipe-piglit-quick_gl
created #10906191
llvmpipe-piglit-quick_shader
created #10906193
llvmpipe-traces
created #10906216
softpipe-asan-gles31
created #10906219
softpipe-gl
created #10906204
softpipe-gles2
created #10906206
softpipe-gles3
created #10906207
softpipe-gles31 1/2
created #10906209
softpipe-gles31 2/2
created #10906211
softpipe-khr-gles2
created #10906213
softpipe-khr-gles3
created #10906214
softpipe-khr-gles31
created #10906218
softpipe-piglit-quick
 
  Layered Backends
created #10906252
windows docker 1809 mesa
test-d3d12-windows
created #10906231
virgl-gl30-on-gl
created #10906233
virgl-gl31-on-gl
created #10906235
virgl-gl32-on-gl
created #10906225
virgl-gles2-on-gl
created #10906237
manual
virgl-gles2-on-gles
created #10906228
virgl-gles31-on-gl 1/2
created #10906230
virgl-gles31-on-gl 2/2
created #10906240
manual
virgl-gles31-on-gles 1/2
created #10906242
manual
virgl-gles31-on-gles 2/2
created #10906226
virgl-gles3-on-gl
created #10906238
manual
virgl-gles3-on-gles
created #10906243
kvm
virgl-traces
created #10906250
zink-lvp-gl
created #10906247
zink-lvp-gles2
created #10906249
zink-lvp-gles3
created #10906245
zink-piglit-quick_gl