Re: git: d9d5f2c042a5 - main - cpuset: add --count

From: Mateusz Guzik <mjguzik_at_gmail.com>
Date: Sat, 04 Feb 2023 22:14:46 UTC
On 2/4/23, Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
> Mateusz Guzik wrote in
>  <202302041751.314HpRrn042970@gitrepo.freebsd.org>:
>  |The branch main has been updated by mjg:
>  |
>  |URL: https://cgit.FreeBSD.org/src/commit/?id=d9d5f2c042a51a9f0dd69eb1fc3\
>  |49efd81ffa483
>  |
>  |commit d9d5f2c042a51a9f0dd69eb1fc349efd81ffa483
>  |Author:     Mateusz Guzik <mjg@FreeBSD.org>
>  |AuthorDate: 2023-02-04 17:47:41 +0000
>  |Commit:     Mateusz Guzik <mjg@FreeBSD.org>
>  |CommitDate: 2023-02-04 17:50:41 +0000
>  |
>  |    cpuset: add --count
>  |
>  |    Can be used to count the number of hardware threads in the cpu set.
>  ...
>  |    The intent is to replace calls to sysctl hw.ncpu and kern.smp.cpus \
>  |    which
>  |    can be found in the tree, which are not adequate given existence of
>  |    cpusets.
>
> This is great (in respect to a #freebsd IRC from 2021-07-02)!
> Are there plans to address
>
>   19:26 < RhodiumToad> and in fact sysconf(_SC_NPROCESSORS_ONLN) is
> implemented as  sysctl hw.ncpu
>
> or
>
>   19:25 < RhodiumToad> on fbsd 13 on a 4-cpu box, cpuset -l 0-1 getconf
> _NPROCESSORS_ONLN   returns 4 rather than 2
>

So I just checked on Linux and get:
$ taskset --cpu-list 0 getconf _NPROCESSORS_ONLN
4

iow the current behavior is probably the expected one.

> or even add a shallow usr.bin/nproc(1) that does only this
> operation, as in Linux?  (Or ln(1) it and check out argv[0] to do
> so?)  Having a "portable" thing would be great.
>

I have no opinion on this one, looks a trivial addition, but someone
else will have to ack it (most notably whether to add it to cpuset as
you suggested above or create new utility altogether).

That said, happy to take a look at a patch which adds a *new*
nproc utility.

-- 
Mateusz Guzik <mjguzik gmail.com>