From 77d38d9cbe9b4047e7155569e7b9485093807e17 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 22 Jul 2015 16:12:26 -0400 Subject: [PATCH] runtime: handle linux CPU masks up to 64k CPUs Fixes #11823. Change-Id: Ic949ccb9657478f8ca34fdf1a6fe88f57db69f24 Reviewed-on: https://go-review.googlesource.com/12535 Reviewed-by: Austin Clements --- src/runtime/os1_linux.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/runtime/os1_linux.go b/src/runtime/os1_linux.go index dd64afca2c..6410801d8e 100644 --- a/src/runtime/os1_linux.go +++ b/src/runtime/os1_linux.go @@ -75,11 +75,19 @@ func futexwakeup(addr *uint32, cnt uint32) { } 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]) n := int32(0) for _, v := range buf[:r/ptrSize] { - for i := 0; i < 64; i++ { + for v != 0 { n += int32(v & 1) v >>= 1 } -- 2.50.0