From: Eric Sunshine <ericsunshine@charter.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 3/3] chainlint.pl: latch CPU count directly reported by /proc/cpuinfo
Date: Mon, 20 May 2024 15:01:31 -0400 [thread overview]
Message-ID: <20240520190131.94904-4-ericsunshine@charter.net> (raw)
In-Reply-To: <20240520190131.94904-1-ericsunshine@charter.net>
From: Eric Sunshine <sunshine@sunshineco.com>
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>
---
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
next prev parent reply other threads:[~2024-05-20 19:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-20 11:11 [PATCH] chainlint.pl: Extend regexp pattern for /proc/cpuinfo on Linux SPARC John Paul Adrian Glaubitz
2024-05-20 16:16 ` Junio C Hamano
2024-05-20 16:48 ` John Paul Adrian Glaubitz
2024-05-20 16:52 ` Eric Sunshine
2024-05-20 16:50 ` Eric Sunshine
2024-05-20 17:07 ` Eric Sunshine
2024-05-20 17:23 ` Junio C Hamano
2024-05-20 19:01 ` [PATCH 0/3] improve chainlint.pl CPU count computation Eric Sunshine
2024-05-20 19:01 ` [PATCH 1/3] chainlint.pl: make CPU count computation more robust Eric Sunshine
2024-05-20 19:01 ` [PATCH 2/3] chainlint.pl: fix incorrect CPU count on Linux SPARC Eric Sunshine
2024-05-22 8:32 ` Carlo Marcelo Arenas Belón
2024-05-22 8:47 ` John Paul Adrian Glaubitz
2024-05-22 9:05 ` Eric Sunshine
2024-05-22 19:00 ` Junio C Hamano
2024-05-22 19:11 ` Eric Sunshine
2024-05-27 19:48 ` John Paul Adrian Glaubitz
2024-05-27 20:12 ` Eric Sunshine
2024-05-20 19:01 ` Eric Sunshine [this message]
2024-05-20 19:17 ` [PATCH 0/3] improve chainlint.pl CPU count computation John Paul Adrian Glaubitz
2024-05-20 19:19 ` Eric Sunshine
2024-05-20 19:23 ` John Paul Adrian Glaubitz
2024-05-21 14:28 ` John Paul Adrian Glaubitz
2024-05-21 16:18 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240520190131.94904-4-ericsunshine@charter.net \
--to=ericsunshine@charter.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).