Thread (13 messages) 13 messages, 4 authors, 2024-05-22
STALE785d

[PATCH 3/3] chainlint.pl: latch CPU count directly reported by /proc/cpuinfo

From: Eric Sunshine <hidden>
Date: 2024-05-20 19:03:28
Subsystem: the rest · Maintainer: Linus Torvalds

From: Eric Sunshine <redacted>

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/ (local)
[2]: https://lore.kernel.org/git/7acbd5c6c68bd7ba020e2d1cc457a8954fd6edf4.camel@physik.fu-berlin.de/ (local)

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Eric Sunshine <redacted>
---
 t/chainlint.pl | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/t/chainlint.pl b/t/chainlint.pl
index d593cb95e7..1bbd985b78 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -724,6 +724,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;
 	}
-- 
2.45.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help