]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle linux CPU masks up to 64k CPUs
authorRuss Cox <rsc@golang.org>
Wed, 22 Jul 2015 20:12:26 +0000 (16:12 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 22 Jul 2015 20:53:01 +0000 (20:53 +0000)
Fixes #11823.

Change-Id: Ic949ccb9657478f8ca34fdf1a6fe88f57db69f24
Reviewed-on: https://go-review.googlesource.com/12535
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/os1_linux.go

index dd64afca2caab351a63950057870b1953f6ae465..6410801d8ed096a6f854b4c52a22275ef9600c49 100644 (file)
@@ -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
                }