-
Notifications
You must be signed in to change notification settings - Fork 17.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: NumCPU() does not match "the number of cpus usable by the current process" in FreeBSD #15206
Comments
FYI: |
Hi folks, |
You also need to take care of the system call number between major releases on BSD variants. Luckily, it's still the same as 8 years ago; https://svnweb.freebsd.org/base/head/sys/kern/syscalls.master?view=log. |
In FreeBSD when run Go proc under a given sub-list of processors(e.g. 'cpuset -l 0 ./goutil' in multicore system), runtime.NumCPU() still return all actived CPUs instead of the number of sub-list. Fix by use syscall cpuset_getaffinity to account the number of sub-list. Fixes golang#15206 Tested: FreeBSD amd64 10/11/12 FreeBSD i386 10/11/12 FreeBSD arm 10/11/12 This is inspired by golang@4f308ed (runtime: use sched_getaffinity for runtime.NumCPU() on Linux)
In FreeBSD when run Go proc under a given sub-list of processors(e.g. 'cpuset -l 0 ./goutil' in multicore system), runtime.NumCPU() still return all actived CPUs instead of the number of sub-list. Fix by use syscall cpuset_getaffinity to account the number of sub-list. Fixes golang#15206 Tested: FreeBSD amd64 10/11/12 FreeBSD i386 10/11/12 FreeBSD arm 10/11/12 Inspired by golang@4f308ed (runtime: use sched_getaffinity for runtime.NumCPU() on Linux)
CL https://golang.org/cl/29341 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version
What operating system and processor architecture are you using (
go env
)?go env
uname -a
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
cpuset is a util to configure/limit processes available for a processor, just like taskset in Linux.
save follow code to freebsdncpu.go
go build -o freebsdncpu freebsdncpu.go and run as:
from top -IaP we see Go processor using only CPU0
from top -IaP we see Go processor using only CPU0
as https://github.com/golang/go/blob/master/src/runtime/os1_freebsd.go#L20 showed, NumCPU()/ncpu is direct probe from sysctl item hw.ncpu, but in
https://www.freebsd.org/cgi/man.cgi?sysctl(3) and /usr/include/sys/sysctl.h, it's say "hw.ncpu" is "The number of cpus", is not the "usable by the current process" in https://github.com/golang/go/blob/master/src/runtime/debug.go#L32
And please note, cpuset already limit the CPU list "befor" Go processes start, not the case in #11609 (change usable cpu list on the fly).
The text was updated successfully, but these errors were encountered: