aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/defs_freebsd.go
diff options
context:
space:
mode:
authorDavid NewHamlet <david@newhamlet.com>2017-03-11 09:13:20 +1300
committerIan Lance Taylor <iant@golang.org>2017-03-10 22:06:24 +0000
commite19f184b8f61529980c24973d5522dc67e3d8525 (patch)
tree253572abfe37550316bd052889ffca6644705e07 /src/runtime/defs_freebsd.go
parent135ce43c8731506d541329a1dfea2c737c6dd0b1 (diff)
downloadgo-e19f184b8f61529980c24973d5522dc67e3d8525.tar.gz
go-e19f184b8f61529980c24973d5522dc67e3d8525.zip
runtime: use cpuset_getaffinity for runtime.NumCPU() on FreeBSD
In FreeBSD when run Go proc under a given sub-list of processors(e.g. 'cpuset -l 0 ./a.out' in multi-core system), runtime.NumCPU() still return all physical CPUs from sysctl hw.ncpu instead of account from sub-list. Fix by use syscall cpuset_getaffinity to account the number of sub-list. Fixes #15206 Change-Id: If87c4b620e870486efa100685db5debbf1210a5b Reviewed-on: https://go-review.googlesource.com/29341 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/defs_freebsd.go')
-rw-r--r--src/runtime/defs_freebsd.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/defs_freebsd.go b/src/runtime/defs_freebsd.go
index 73422b7af2..0a11d09db2 100644
--- a/src/runtime/defs_freebsd.go
+++ b/src/runtime/defs_freebsd.go
@@ -28,9 +28,20 @@ package runtime
#include <sys/thr.h>
#include <sys/_sigset.h>
#include <sys/unistd.h>
+#include <sys/sysctl.h>
+#include <sys/cpuset.h>
+#include <sys/param.h>
*/
import "C"
+// Local consts.
+const (
+ _NBBY = C.NBBY // Number of bits in a byte.
+ _CTL_MAXNAME = C.CTL_MAXNAME // Largest number of components supported.
+ _CPU_LEVEL_WHICH = C.CPU_LEVEL_WHICH // Actual mask/id for which.
+ _CPU_WHICH_PID = C.CPU_WHICH_PID // Specifies a process id.
+)
+
const (
EINTR = C.EINTR
EFAULT = C.EFAULT