diff options
| author | Zhengyu He <hzy@google.com> | 2017-11-02 13:39:14 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-11-03 01:55:16 +0000 |
| commit | eaf603601bf79216772ba36a9b981f21b50ade96 (patch) | |
| tree | b178d4df62e2a7a92842da1ec9546be020106566 /src/runtime/os_linux.go | |
| parent | 923299a6b85d22160dfdacca18f24ac6517ec1de (diff) | |
| download | go-eaf603601bf79216772ba36a9b981f21b50ade96.tar.xz | |
runtime: fix GNU/Linux getproccount if sched_getaffinity does not return a multiple of 8
The current code can potentially return a smaller processor count on a
linux kernel when its cpumask_size (controlled by both kernel config and
boot parameter) is not a multiple of the pointer size, because
r/sys.PtrSize will be rounded down. Since sched_getaffinity returns the
size in bytes, we can just allocate the buf as a byte array to avoid the
extra calculation with the pointer size and roundups.
Change-Id: I0c21046012b88d8a56b5dd3dde1d158d94f8eea9
Reviewed-on: https://go-review.googlesource.com/75591
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/os_linux.go')
| -rw-r--r-- | src/runtime/os_linux.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 3157b21371..98e7f52b9e 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -89,13 +89,13 @@ func getproccount() int32 { // buffers, but we don't have a dynamic memory allocator at the // moment, so that's a bit tricky and seems like overkill. const maxCPUs = 64 * 1024 - var buf [maxCPUs / (sys.PtrSize * 8)]uintptr + var buf [maxCPUs / 8]byte r := sched_getaffinity(0, unsafe.Sizeof(buf), &buf[0]) if r < 0 { return 1 } n := int32(0) - for _, v := range buf[:r/sys.PtrSize] { + for _, v := range buf[:r] { for v != 0 { n += int32(v & 1) v >>= 1 @@ -385,7 +385,7 @@ func raise(sig uint32) func raiseproc(sig uint32) //go:noescape -func sched_getaffinity(pid, len uintptr, buf *uintptr) int32 +func sched_getaffinity(pid, len uintptr, buf *byte) int32 func osyield() //go:nosplit |
