mirror of https://github.com/golang/go.git
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 <austin@google.com>
This commit is contained in:
parent
daaa45073e
commit
77d38d9cbe
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue