Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Feb 2023 17:07:00 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 117d4cafdcb8 - stable/13 - nproc: denote an incompatiblity with Linux
Message-ID:  <202302231707.31NH70RH005416@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=117d4cafdcb806407e38266de44aebe0b4e62b6f

commit 117d4cafdcb806407e38266de44aebe0b4e62b6f
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-02-15 20:17:27 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-02-23 17:06:41 +0000

    nproc: denote an incompatiblity with Linux
    
    On Linux _NPROCESSORS_CONF reports CPU threads disabled by the kernel,
    while it does not on FreeBSD.
    
    Flip _NPROCESSORS_ONLN to _NPROCESSORS_CONF. While it keeps reporting
    the same value, it will automagically unbreak should someone change the
    above.
    
    (cherry picked from commit 059320b8c8de73a90514879cd1e2da397584cfde)
---
 bin/nproc/nproc.1 | 7 ++++++-
 bin/nproc/nproc.c | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/bin/nproc/nproc.1 b/bin/nproc/nproc.1
index ae252fe0f50c..d4d97ccbb5be 100644
--- a/bin/nproc/nproc.1
+++ b/bin/nproc/nproc.1
@@ -3,7 +3,7 @@
 .\"
 .\" * SPDX-License-Identifier: BSD-2-Clause
 .\"
-.Dd February 5, 2023
+.Dd February 15, 2023
 .Dt NPROC 1
 .Os
 .Sh NAME
@@ -39,6 +39,11 @@ Print usage information and exit.
 .El
 .Sh COMPATIBILITY
 This program is intended to be compatible with nproc as found in GNU coreutils.
+.Sh BUGS
+If HyperThreading is enabled in BIOS and disabled in the kernel, the
+.Fl -all
+option on Linux will still report all possible CPU threads.
+On FreeBSD only active threads will be reported.
 .Sh SEE ALSO
 .Xr cpuset 1
 .Sh HISTORY
diff --git a/bin/nproc/nproc.c b/bin/nproc/nproc.c
index 9037c74dbfff..c2ab75826ce1 100644
--- a/bin/nproc/nproc.c
+++ b/bin/nproc/nproc.c
@@ -110,7 +110,7 @@ main(int argc, char *argv[])
 		usage();
 
 	if (all_flag) {
-		cpus = sysconf(_SC_NPROCESSORS_ONLN);
+		cpus = sysconf(_SC_NPROCESSORS_CONF);
 		if (cpus == -1)
 			err(1, "sysconf");
 	} else {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302231707.31NH70RH005416>