Commit 77d38d9c authored by Russ Cox's avatar Russ Cox

runtime: handle linux CPU masks up to 64k CPUs

Fixes #11823.

Change-Id: Ic949ccb9657478f8ca34fdf1a6fe88f57db69f24
Reviewed-on: https://go-review.googlesource.com/12535Reviewed-by: default avatarAustin Clements <austin@google.com>
parent daaa4507
...@@ -75,11 +75,19 @@ func futexwakeup(addr *uint32, cnt uint32) { ...@@ -75,11 +75,19 @@ func futexwakeup(addr *uint32, cnt uint32) {
} }
func getproccount() int32 { func getproccount() int32 {
var buf [16]uintptr // This buffer is huge (8 kB) but we are on the system stack
// and there should be plenty of space (64 kB).
// Also this is a leaf, so we're not holding up the memory for long.
// See golang.org/issue/11823.
// The suggested behavior here is to keep trying with ever-larger
// 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 / (ptrSize * 8)]uintptr
r := sched_getaffinity(0, unsafe.Sizeof(buf), &buf[0]) r := sched_getaffinity(0, unsafe.Sizeof(buf), &buf[0])
n := int32(0) n := int32(0)
for _, v := range buf[:r/ptrSize] { for _, v := range buf[:r/ptrSize] {
for i := 0; i < 64; i++ { for v != 0 {
n += int32(v & 1) n += int32(v & 1)
v >>= 1 v >>= 1
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment