Re: git: 48bfd3597654 - main - Add nproc(1)
- Reply: Steffen Nurpmeso : "Re: git: 48bfd3597654 - main - Add nproc(1)"
- In reply to: Steffen Nurpmeso : "Re: git: 48bfd3597654 - main - Add nproc(1)"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 09 Feb 2023 01:05:47 UTC
On 2/8/23, Steffen Nurpmeso <steffen@sdaoden.eu> wrote: > Mateusz Guzik wrote in > <202302081947.318Jlbt6052826@gitrepo.freebsd.org>: > ... > |URL: https://cgit.FreeBSD.org/src/commit/?id=48bfd3597654490cdc43bf0f591\ > |a539d3a28b590 > ... > | Add nproc(1) > > Hey! Great. (NPROC is mentioned in POSIX for environment > variables, as well as a make macro that did not make it, .. and > nproc(1) is commonly used on Linux it seems.) Thanks. > > | This program prints the number of CPU threads it can run on, while > | respecting cpusets (or not, depending on switches). > | > | It aims to be compatible with nproc as found in GNU coreutils. > > That, "however", > > ... > |+ if (all_flag) { > |+ cpus = sysconf(_SC_NPROCESSORS_ONLN); > > is not compatible -- note i like the FreeBSD way better, and maybe > someone should make a bug report even. > > #?0|kent:$ getconf -a|grep NPROC > _NPROCESSORS_CONF 8 > _NPROCESSORS_ONLN 4 > #?0|kent:$ nproc > 4 > #?0|kent:$ nproc --all > 8 > #?0|kent:$ > Is this from disabling hyperthreading? I have a 40-way box, after doing it I see: NPROCESSORS_CONF: 20 NPROCESSORS_ONLN: 20 _NPROCESSORS_CONF: 20 _NPROCESSORS_ONLN: 20 iow it wont make a difference. I'm going to sleep on it, will probably add BUGS to the manpage. I do think linux nproc behavior on this is one peculiar at best though. Thanks for reporting. > > |+ if (cpus == -1) > |+ err(1, "sysconf"); > |+ } else { > |+ CPU_ZERO(&mask); > |+ if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, > |+ sizeof(mask), &mask) != 0) > |+ err(1, "cpuset_getaffinity"); > |+ cpus = CPU_COUNT(&mask); > > That is the right thing to do, imho! > > Thank you. > > --steffen > | > |Der Kragenbaer, The moon bear, > |der holt sich munter he cheerfully and one by one > |einen nach dem anderen runter wa.ks himself off > |(By Robert Gernhardt) > -- Mateusz Guzik <mjguzik gmail.com>