Skip to content

Commit 2e7e920

Browse files
sunshinecogitster
authored andcommitted
chainlint.pl: latch CPU count directly reported by /proc/cpuinfo
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 <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45db5ed commit 2e7e920

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

t/chainlint.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ sub ncores {
715715
if (open my $fh, '<', '/proc/cpuinfo') {
716716
my $cpuinfo = do { local $/; <$fh> };
717717
close($fh);
718+
if ($cpuinfo =~ /^n?cpus active\s*:\s*(\d+)/m) {
719+
return $1 if $1 > 0;
720+
}
718721
my @matches = ($cpuinfo =~ /^(processor|CPU)[\s\d]*:/mg);
719722
return @matches ? scalar(@matches) : 1;
720723
}

0 commit comments

Comments
 (0)