]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chainlint.pl: latch CPU count directly reported by /proc/cpuinfo
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 20 May 2024 19:01:31 +0000 (15:01 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 May 2024 18:58:56 +0000 (11:58 -0700)
On Linux, ncores() computes the number of CPUs by counting the
"processor" or "CPU" lines emitted by /proc/cpuinfo. However, on some
platforms, /proc/cpuinfo does not enumerate the CPUs at all, but
instead merely mentions the total number of CPUs. In such cases, pluck
the CPU count directly from the /proc/cpuinfo line which reports the
number of active CPUs. (In particular, check for "cpus active: NN" and
"ncpus active: NN" since both variants have been seen in the
wild[1,2].)

[1]: https://lore.kernel.org/git/503a99f3511559722a3eeef15d31027dfe617fa1.camel@physik.fu-berlin.de/
[2]: https://lore.kernel.org/git/7acbd5c6c68bd7ba020e2d1cc457a8954fd6edf4.camel@physik.fu-berlin.de/

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/chainlint.pl

index ea154a206ac2a81c319b12db97d75ae65850b591..f00a3b937b9e9b1556204cc30cbd0b4dd32c0d4d 100755 (executable)
@@ -715,6 +715,9 @@ sub ncores {
        if (open my $fh, '<', '/proc/cpuinfo') {
                my $cpuinfo = do { local $/; <$fh> };
                close($fh);
+               if ($cpuinfo =~ /^n?cpus active\s*:\s*(\d+)/m) {
+                       return $1 if $1 > 0;
+               }
                my @matches = ($cpuinfo =~ /^(processor|CPU)[\s\d]*:/mg);
                return @matches ? scalar(@matches) : 1;
        }