git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] chainlint.pl: Extend regexp pattern for /proc/cpuinfo on Linux SPARC

From
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date
May 20, 2024, 16:48 UTC
Message-ID
<503a99f3511559722a3eeef15d31027dfe617fa1.camel@physik.fu-berlin.de>
In-Reply-To
<xmqqseyclaq8.fsf@gitster.g>
Hi Junio,
On Mon, 2024-05-20 at 09:16 -0700, Junio C Hamano wrote:
Show 26 quoted lines
> John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> writes:
> 
> > On SPARC systems running Linux, individual processors are denoted with
> > "CPUnn:" in /proc/cpuinfo instead of the usual "processor NN:" so that
> > the current regexp in ncores() returns 0. Extend the regexp to match
> > lines with "CPUnn:" as well to properly detect the number of available
> > cores on these systems.
> > 
> > Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> > ---
> >  t/chainlint.pl | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/t/chainlint.pl b/t/chainlint.pl
> > index 556ee91a15..63cac942ac 100755
> > --- a/t/chainlint.pl
> > +++ b/t/chainlint.pl
> > @@ -718,7 +718,7 @@ sub ncores {
> >  	# Windows
> >  	return $ENV{NUMBER_OF_PROCESSORS} if exists($ENV{NUMBER_OF_PROCESSORS});
> >  	# Linux / MSYS2 / Cygwin / WSL
> > -	do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:/, <>)); } if -r '/proc/cpuinfo';
> > +	do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:||^CPU[\d]*:/, <>)); } if -r '/proc/cpuinfo';
> 
> Is the doubled || intended?  Doesn't it introduce an empty pattern
> that slurps every single line of /proc/cpuinfo?

I'm not a Perl expert by any means, so I wasn't sure what the correct logical OR operator would be. If it turns out to be wrong, let's fix that.

Show 26 quoted lines
> I was wondering if we want to first add the "reasonable fallback"
> Eric mentioned ealier, and then build on top, whose result may look
> like the attached.  You can enable the STDERR thing with your double
> "||" added back and see what "cd t && perl chainlint.pl" produces.
> 
> Thanks.
> 
> diff --git i/t/chainlint.pl w/t/chainlint.pl
> index 556ee91a15..775f06281b 100755
> --- i/t/chainlint.pl
> +++ w/t/chainlint.pl
> @@ -718,7 +718,13 @@ sub ncores {
>  	# Windows
>  	return $ENV{NUMBER_OF_PROCESSORS} if exists($ENV{NUMBER_OF_PROCESSORS});
>  	# Linux / MSYS2 / Cygwin / WSL
> -	do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:/, <>)); } if -r '/proc/cpuinfo';
> +	do {
> +		local @ARGV='/proc/cpuinfo';
> +		my @num = grep(/^processor[\s\d]*:|^CPU[\d]*:/, <>);
> +# print STDERR "FOUND <@num>\n";
> +		return 1 if (!@num);
> +		return scalar(@num);
> +	} if -r '/proc/cpuinfo';
>  	# macOS & BSD
>  	return qx/sysctl -n hw.ncpu/ if $^O =~ /(?:^darwin$|bsd)/;
>  	return 1;

This seems to work fine for me as well. If you post it as a patch, I'm more than happy to give it a Tested-By.

Btw, it would be great if this could be extended to support the output for the Alpha architecture as well since the testsuite fails the same way [1]. The output for /proc/cpuinfo looks like this [2]:

(alpha-chroot)root@p100:/# cat /proc/cpuinfo cpu : Alpha cpu model : ev67 cpu variation : 0 cpu revision : 0 cpu serial number : JA00000000 system type : QEMU system variation : QEMU_v8.0.92 system revision : 0 system serial number : AY00000000 cycle frequency [Hz] : 250000000 timer frequency [Hz] : 250.00 page size [bytes] : 8192 phys. address bits : 44 max. addr. space # : 255 BogoMIPS : 2500.00 platform string : AlphaServer QEMU user-mode VM cpus detected : 8 cpus active : 4 cpu active mask : 0000000000000095 L1 Icache : n/a L1 Dcache : n/a L2 cache : n/a L3 cache : n/a

Thanks so much for helping with the fix!
Adrian
> [1] https://buildd.debian.org/status/fetch.php?pkg=git&arch=alpha&ver=1%3A2.45.1-1&stamp=1716194983&raw=0
> [2] https://lore.kernel.org/all/20230901204251.137307-4-richard.henderson@linaro.org/
-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
Previous: Junio C HamanoNext: Eric Sunshine
Message 3 of 23 in “chainlint.pl: Extend regexp pattern for /proc/cpuinfo on Linux SPARC”
  1. chainlint.pl: Extend regexp pattern for /proc/cpuinfo on Linux SPARCJohn Paul Adrian Glaubitz, May 20, 2024
  2. Junio C HamanoMay 20, 2024
  3. John Paul Adrian GlaubitzMay 20, 2024
  4. Eric SunshineMay 20, 2024
  5. Eric SunshineMay 20, 2024
  6. Eric SunshineMay 20, 2024
  7. Junio C HamanoMay 20, 2024
  8. 0/3 improve chainlint.pl CPU count computationEric Sunshine, May 20, 2024
  9. 2/3 chainlint.pl: fix incorrect CPU count on Linux SPARCEric Sunshine, May 20, 2024
  10. Carlo Marcelo Arenas BelónMay 22, 2024
  11. John Paul Adrian GlaubitzMay 22, 2024
  12. Eric SunshineMay 22, 2024
  13. Junio C HamanoMay 22, 2024
  14. Eric SunshineMay 22, 2024
  15. John Paul Adrian GlaubitzMay 27, 2024
  16. Eric SunshineMay 27, 2024
  17. 3/3 chainlint.pl: latch CPU count directly reported by /proc/cpuinfoEric Sunshine, May 20, 2024
  18. 1/3 chainlint.pl: make CPU count computation more robustEric Sunshine, May 20, 2024
  19. John Paul Adrian GlaubitzMay 20, 2024
  20. Eric SunshineMay 20, 2024
  21. John Paul Adrian GlaubitzMay 20, 2024
  22. John Paul Adrian GlaubitzMay 21, 2024
  23. Eric SunshineMay 21, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.