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>
184 jobs for consider-cpu-affinity
Status Job ID Name Coverage
  Container
manual #10902147
aarch64 manual
arm_build
manual #10902148
windows shell 1809 mesa manual
windows_build_vs2019
manual #10902145
manual
x86_build-base
manual #10902146
manual
x86_test-base
 
  Container 2
created #10902153
android_build
created #10902150
i386_build
created #10902156
kernel+rootfs_amd64
created #10902157
aarch64
kernel+rootfs_arm64
created #10902158
aarch64
kernel+rootfs_armhf
created #10902151
ppc64el_build
created #10902152
s390x_build
created #10902149
x86_build
created #10902154
x86_test-gl
created #10902155
x86_test-vk
 
  Meson X86 64
created #10902164
meson-clang
created #10902165
meson-clover
created #10902161
meson-clover-testing
created #10902162
meson-gallium
created #10902163
meson-release
created #10902159
meson-testing
created #10902160
meson-testing-asan
created #10902166
meson-vulkan
 
  Build Misc
created #10902167
arm_test
created #10902168
meson-android
created #10902170
aarch64
meson-arm64
created #10902171
aarch64
meson-arm64-asan
created #10902172
aarch64
meson-arm64-build-test
created #10902169
aarch64
meson-armhf
created #10902174
meson-i386
created #10902177
meson-mingw32-x86_64
created #10902176
meson-ppc64el
created #10902175
kvm
meson-s390x
created #10902173
windows docker 1809 mesa
meson-windows-vs2019
 
  Amd
created #10902186
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles2:amd64
created #10902189
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 1/2
created #10902190
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles31:amd64 2/2
created #10902187
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 1/2
created #10902188
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-gles3:amd64 2/2
created #10902192
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-piglit-gl:amd64
created #10902191
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radeonsi-stoney-traces:amd64
created #10902185
radv-fossils
created #10902179
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-traces
created #10902178
amdgpu:codename:NAVY_FLOUNDER manual
radv-navy_flounder-vkd3d-proton
created #10902181
polaris10 manual
radv_polaris10_vkcts
created #10902180
amdgpu:codename:RAVEN manual
radv-raven-traces
created #10902182
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 1/3
created #10902183
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 2/3
created #10902184
mesa-ci-x86-64-lava-hp-11A-G6-EE-grunt
radv_stoney_vkcts:amd64 3/3
 
  Intel
created #10902193
anholt-g33 manual
i915-g33-deqp
created #10902194
anholt-g33 manual
i915-g33-khr-deqp
created #10902195
anholt-g33 manual
i915-g33-piglit
created #10902196
anholt-g33 manual
i915-g33-traces
created #10902211
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-egl
created #10902210
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gl
created #10902207
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-gles2
created #10902208
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles3
created #10902209
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus manual
iris-amly-gles31
created #10902212
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 1/3
created #10902213
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 2/3
created #10902214
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-piglit 3/3
created #10902217
mesa-ci-x86-64-lava-asus-C433TA-AJ0005-rammus
iris-amly-traces
created #10902201
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-egl
created #10902200
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral manual
iris-apl-gl
created #10902197
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles2
created #10902198
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles3
created #10902199
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-gles31
created #10902215
mesa-ci-x86-64-lava-asus-C523NA-A20057-coral
iris-apl-traces
created #10902206
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-egl
created #10902205
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gl
created #10902202
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles2
created #10902203
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles3
created #10902204
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-gles31
created #10902216
mesa-ci-x86-64-lava-hp-x360-12b-n4000-octopus manual
iris-glk-traces
created #10902218
mesa-ci-x86-64-lava-hp-x360-14-G1-sona manual
iris-kbl-traces
 
  Arm
created #10902228
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles31:arm64
created #10902226
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 1/2
created #10902227
mesa-ci-x86-64-lava-meson-g12b-a311d-khadas-vim3
panfrost-g52-gles3:arm64 2/2
created #10902219
mesa-ci-x86-64-lava-sun50i-h6-pine-h64
panfrost-t720-gles2:arm64
created #10902220
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-gles2:armhf
created #10902221
mesa-ci-x86-64-lava-rk3288-veyron-jaq
panfrost-t760-traces:armhf
created #10902224
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles31:arm64
created #10902222
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 1/2
created #10902223
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-gles3:arm64 2/2
created #10902225
mesa-ci-x86-64-lava-rk3399-gru-kevin
panfrost-t860-traces:arm64
 
  Broadcom
created #10902253
igalia-rpi4
v3d-rpi4-egl:armhf
created #10902248
igalia-rpi4
v3d-rpi4-gles2:armhf
created #10902241
igalia-rpi4
v3d-rpi4-gles31:armhf 1/2
created #10902242
igalia-rpi4
v3d-rpi4-gles31:armhf 2/2
created #10902244
igalia-rpi4
v3d-rpi4-gles3:armhf 1/4
created #10902245
igalia-rpi4
v3d-rpi4-gles3:armhf 2/4
created #10902246
igalia-rpi4
v3d-rpi4-gles3:armhf 3/4
created #10902247
igalia-rpi4
v3d-rpi4-gles3:armhf 4/4
created #10902252
igalia-rpi4
v3d-rpi4-khr-gles2:armhf
created #10902250
igalia-rpi4
v3d-rpi4-khr-gles31:armhf
created #10902251
igalia-rpi4
v3d-rpi4-khr-gles3:armhf
created #10902254
igalia-rpi4
v3d-rpi4-piglit:armhf 1/3
created #10902256
igalia-rpi4
v3d-rpi4-piglit:armhf 2/3
created #10902257
igalia-rpi4
v3d-rpi4-piglit:armhf 3/3
created #10902258
igalia-rpi4
v3dv-rpi4-vk:arm64 1/6
created #10902259
igalia-rpi4
v3dv-rpi4-vk:arm64 2/6
created #10902260
igalia-rpi4
v3dv-rpi4-vk:arm64 3/6
created #10902262
igalia-rpi4
v3dv-rpi4-vk:arm64 4/6
created #10902263
igalia-rpi4
v3dv-rpi4-vk:arm64 5/6
created #10902264
igalia-rpi4
v3dv-rpi4-vk:arm64 6/6
created #10902234
igalia-rpi3
vc4-rpi3-egl:armhf
created #10902229
igalia-rpi3
vc4-rpi3-gles2:armhf 1/4
created #10902230
igalia-rpi3
vc4-rpi3-gles2:armhf 2/4
created #10902231
igalia-rpi3
vc4-rpi3-gles2:armhf 3/4
created #10902232
igalia-rpi3
vc4-rpi3-gles2:armhf 4/4
created #10902233
igalia-rpi3
vc4-rpi3-khr-gles2:armhf
created #10902235
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 1/4
created #10902236
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 2/4
created #10902237
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 3/4
created #10902238
igalia-rpi3 manual
vc4-rpi3-piglit-quick_gl:armhf 4/4
created #10902239
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 1/2
created #10902240
igalia-rpi3 manual
vc4-rpi3-piglit-quick_shader:armhf 2/2
 
  Freedreno
created #10902265
google-freedreno-db410c
a306_gles2
created #10902266
google-freedreno-db410c
a306_gles3 1/3
created #10902267
google-freedreno-db410c
a306_gles3 2/3
created #10902268
google-freedreno-db410c
a306_gles3 3/3
created #10902269
google-freedreno-db410c
a306_gles3_options
created #10902270
google-freedreno-db410c
a306-traces
created #10902271
google-freedreno-db820c
a530_gles2
created #10902274
google-freedreno-db820c
a530_gles31 1/2
created #10902272
google-freedreno-db820c
a530_gles3 1/2
created #10902275
google-freedreno-db820c
a530_gles31 2/2
created #10902273
google-freedreno-db820c
a530_gles3 2/2
created #10902276
google-freedreno-db820c manual
a530_piglit_gl
created #10902277
google-freedreno-db820c
a530_piglit_shader 1/2
created #10902278
google-freedreno-db820c
a530_piglit_shader 2/2
created #10902279
google-freedreno-db820c
a530-traces
created #10902284
google-freedreno-cheza
a630_egl
created #10902283
google-freedreno-cheza
a630_gl
created #10902280
google-freedreno-cheza
a630_gles2
created #10902282
google-freedreno-cheza
a630_gles3
created #10902281
google-freedreno-cheza
a630_gles31
created #10902286
google-freedreno-cheza manual
a630_gles_asan
created #10902285
google-freedreno-cheza
a630_gles_others
created #10902291
google-freedreno-cheza
a630_piglit
created #10902292
google-freedreno-cheza
a630-traces
created #10902287
google-freedreno-cheza
a630_vk 1/2
created #10902288
google-freedreno-cheza
a630_vk 2/2
created #10902289
google-freedreno-cheza manual
a630_vk_asan
created #10902290
google-freedreno-cheza
a630_vk_sysmem
 
  Software Renderer
created #10902316
lavapipe-nir-stress
created #10902315
lavapipe-vk
created #10902304
llvmpipe-egl
created #10902302
llvmpipe-gl
created #10902298
llvmpipe-gles2
created #10902300
llvmpipe-gles3
created #10902301
llvmpipe-gles31
created #10902303
llvmpipe-khr-gles2
created #10902293
llvmpipe-piglit-cl
created #10902295
llvmpipe-piglit-glslparser
created #10902294
llvmpipe-piglit-quick_gl
created #10902296
llvmpipe-piglit-quick_shader
created #10902297
llvmpipe-traces
created #10902312
softpipe-asan-gles31
created #10902314
softpipe-gl
created #10902305
softpipe-gles2
created #10902306
softpipe-gles3
created #10902307
softpipe-gles31 1/2
created #10902308
softpipe-gles31 2/2
created #10902309
softpipe-khr-gles2
created #10902310
softpipe-khr-gles3
created #10902311
softpipe-khr-gles31
created #10902313
softpipe-piglit-quick
 
  Layered Backends
created #10902338
windows docker 1809 mesa
test-d3d12-windows
created #10902321
virgl-gl30-on-gl
created #10902322
virgl-gl31-on-gl
created #10902323
virgl-gl32-on-gl
created #10902317
virgl-gles2-on-gl
created #10902324
manual
virgl-gles2-on-gles
created #10902319
virgl-gles31-on-gl 1/2
created #10902320
virgl-gles31-on-gl 2/2
created #10902326
manual
virgl-gles31-on-gles 1/2
created #10902327
manual
virgl-gles31-on-gles 2/2
created #10902318
virgl-gles3-on-gl
created #10902325
manual
virgl-gles3-on-gles
created #10902328
kvm
virgl-traces
created #10902337
zink-lvp-gl
created #10902332
zink-lvp-gles2
created #10902334
zink-lvp-gles3
created #10902330
zink-piglit-quick_gl