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 1/3] chainlint.pl: make CPU count computation more robust
Date: Mon, 20 May 2024 15:01:29 -0400 [thread overview]
Message-ID: <20240520190131.94904-2-ericsunshine@charter.net> (raw)
In-Reply-To: <20240520190131.94904-1-ericsunshine@charter.net>
From: Eric Sunshine <sunshine@sunshineco.com>
There have been reports[1,2] of chainlint.pl failing to produce output
when output is expected. In fact, the underlying problem is more severe:
in these cases, it isn't doing any work at all, thus not checking Git
tests for semantic problems. In the reported cases, the problem was
tracked down to ncores() returning 0 for the CPU count, which resulted
in chainlint.pl not performing any work (since it thought it had no
cores on which to process).
In the reported cases, the reason for the failure was that the regular
expression counting the number of processors reported by /proc/cpuinfo
failed to find any matches, hence it counted 0 processors. Although
fixing each case as it is reported allows chaining.pl to work correctly
on that architecture, it does nothing to improve the overall robustness
of the core count computation which may still return 0 on some yet
untested architecture.
Address this shortcoming by ensuring that ncores() returns a sensible
fallback value in all cases.
[1]: https://lore.kernel.org/git/pull.1385.git.git.1669148861635.gitgitgadget@gmail.com/
[2]: https://lore.kernel.org/git/8baa12f8d044265f1ddeabd64209e7ac0d3700ae.camel@physik.fu-berlin.de/
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
t/chainlint.pl | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/t/chainlint.pl b/t/chainlint.pl
index 556ee91a15..d9a2691889 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -716,11 +716,22 @@ sub fd_colors {
sub ncores {
# Windows
- return $ENV{NUMBER_OF_PROCESSORS} if exists($ENV{NUMBER_OF_PROCESSORS});
+ if (exists($ENV{NUMBER_OF_PROCESSORS})) {
+ my $ncpu = $ENV{NUMBER_OF_PROCESSORS};
+ return $ncpu > 0 ? $ncpu : 1;
+ }
# Linux / MSYS2 / Cygwin / WSL
- do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:/, <>)); } if -r '/proc/cpuinfo';
+ if (open my $fh, '<', '/proc/cpuinfo') {
+ my $cpuinfo = do { local $/; <$fh> };
+ close($fh);
+ my @matches = ($cpuinfo =~ /^processor[\s\d]*:/mg);
+ return @matches ? scalar(@matches) : 1;
+ }
# macOS & BSD
- return qx/sysctl -n hw.ncpu/ if $^O =~ /(?:^darwin$|bsd)/;
+ if ($^O =~ /(?:^darwin$|bsd)/) {
+ my $ncpu = qx/sysctl -n hw.ncpu/;
+ return $ncpu > 0 ? $ncpu : 1;
+ }
return 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 ` Eric Sunshine [this message]
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 ` [PATCH 3/3] chainlint.pl: latch CPU count directly reported by /proc/cpuinfo Eric Sunshine
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-2-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).