From: Alex Brainman Date: Thu, 17 Sep 2015 00:43:18 +0000 (+1000) Subject: runtime: account for cpu affinity in windows NumCPU X-Git-Tag: go1.6beta1~733 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6410e67a1eb38df3cc72cef818ed392bea907251;p=gostls13.git runtime: account for cpu affinity in windows NumCPU Fixes #11671 Change-Id: Ide1f8d92637dad2a2faed391329f9b6001789b76 Reviewed-on: https://go-review.googlesource.com/14742 Reviewed-by: Russ Cox Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/export_windows_test.go b/src/runtime/export_windows_test.go index 6322ee2804..703b422ac2 100644 --- a/src/runtime/export_windows_test.go +++ b/src/runtime/export_windows_test.go @@ -6,7 +6,15 @@ package runtime +import "unsafe" + var ( TestingWER = &testingWER TimeBeginPeriodRetValue = &timeBeginPeriodRetValue ) + +func NumberOfProcessors() int32 { + var info systeminfo + stdcall1(_GetSystemInfo, uintptr(unsafe.Pointer(&info))) + return int32(info.dwnumberofprocessors) +} diff --git a/src/runtime/os1_windows.go b/src/runtime/os1_windows.go index b6da4df7c7..99c6df4008 100644 --- a/src/runtime/os1_windows.go +++ b/src/runtime/os1_windows.go @@ -22,6 +22,7 @@ import ( //go:cgo_import_dynamic runtime._FreeEnvironmentStringsW FreeEnvironmentStringsW%1 "kernel32.dll" //go:cgo_import_dynamic runtime._GetEnvironmentStringsW GetEnvironmentStringsW%0 "kernel32.dll" //go:cgo_import_dynamic runtime._GetProcAddress GetProcAddress%2 "kernel32.dll" +//go:cgo_import_dynamic runtime._GetProcessAffinityMask GetProcessAffinityMask%3 "kernel32.dll" //go:cgo_import_dynamic runtime._GetQueuedCompletionStatus GetQueuedCompletionStatus%5 "kernel32.dll" //go:cgo_import_dynamic runtime._GetStdHandle GetStdHandle%1 "kernel32.dll" //go:cgo_import_dynamic runtime._GetSystemInfo GetSystemInfo%1 "kernel32.dll" @@ -63,6 +64,7 @@ var ( _FreeEnvironmentStringsW, _GetEnvironmentStringsW, _GetProcAddress, + _GetProcessAffinityMask, _GetQueuedCompletionStatus, _GetStdHandle, _GetSystemInfo, @@ -126,6 +128,21 @@ func getGetProcAddress() uintptr { } func getproccount() int32 { + var mask, sysmask uintptr + ret := stdcall3(_GetProcessAffinityMask, currentProcess, uintptr(unsafe.Pointer(&mask)), uintptr(unsafe.Pointer(&sysmask))) + if ret != 0 { + n := 0 + maskbits := int(unsafe.Sizeof(mask) * 8) + for i := 0; i < maskbits; i++ { + if mask&(1<