]> Sergey Matveev's repositories - public-inbox.git/commitdiff
favor `getconf _NPROCESSORS_ONLN` over GNU nproc
authorEric Wong <e@yhbt.net>
Sat, 8 Aug 2020 11:24:05 +0000 (11:24 +0000)
committerEric Wong <e@yhbt.net>
Sun, 9 Aug 2020 18:41:42 +0000 (18:41 +0000)
getconf(1) itself is POSIX, while `_NPROCESSORS_ONLN' is not.
However, FreeBSD (tested 11.4 and 12.1) and glibc (tested CentOS
7.x and Debian 10.x) both support `getconf _NPROCESSORS_ONLN'.

GNU coreutils (and thus `nproc' or `gnproc') are not installed
by default on the *BSDs, so we'll try the option most likely
to exist on both glibc and *BSDs out-of-the-box.

Makefile.PL
lib/PublicInbox/V2Writable.pm

index 8d90ad46cf64c0753b5ad9823b1553860231d30b..831649f967f27609e79e46606707e02a10ae8ff0 100644 (file)
@@ -156,12 +156,14 @@ WriteMakefile(
 );
 
 sub MY::postamble {
-  <<EOF;
+       my $N = (`{ getconf _NPROCESSORS_ONLN || nproc; } 2>/dev/null` || 1);
+       $N += 1; # account for sleeps in some tests (and makes an IV)
+       <<EOF;
 PROVE = prove
 # support using eatmydata to speed up tests (apt-get install eatmydata):
 # https://www.flamingspork.com/projects/libeatmydata/
 EATMYDATA =
-N = \$\$(( \$\$(nproc 2>/dev/null || gnproc 2>/dev/null || echo 2) + 1 ))
+N = $N
 -include config.mak
 $VARS
 -include Documentation/include.mk
index f7a318e5b7f39f96342f65c6821a16c3edfa4b34..dfcb489723d29a6faf0283efb133585e4a5949e6 100644 (file)
@@ -35,14 +35,13 @@ my $PACKING_FACTOR = 0.4;
 our $NPROC_MAX_DEFAULT = 4;
 
 sub detect_nproc () {
-       for my $nproc (qw(nproc gnproc)) { # GNU coreutils nproc
-               `$nproc 2>/dev/null` =~ /^(\d+)$/ and return $1;
-       }
-
        # getconf(1) is POSIX, but *NPROCESSORS* vars are not
        for (qw(_NPROCESSORS_ONLN NPROCESSORS_ONLN)) {
                `getconf $_ 2>/dev/null` =~ /^(\d+)$/ and return $1;
        }
+       for my $nproc (qw(nproc gnproc)) { # GNU coreutils nproc
+               `$nproc 2>/dev/null` =~ /^(\d+)$/ and return $1;
+       }
 
        # should we bother with `sysctl hw.ncpu`?  Those only give
        # us total processor count, not online processor count.