Skip to content

Commit ab4c929

Browse files
committed
runtime: do not call timeBeginPeriod on windows
Calling timeBeginPeriod changes Windows global timer resolution from 15ms to 1ms. This used to improve Go runtime scheduler performance, but not anymore. Thanks to @aclements, scheduler now behaves the same way if we call timeBeginPeriod or not. Remove call to timeBeginPeriod, since it is machine global resource, and there are downsides of using low timer resolution. See issue #8687 for details. Fixes #8687 Change-Id: Ib7e41aa4a81861b62a900e0e62776c9ef19bfb73 Reviewed-on: https://go-review.googlesource.com/17164 Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Yasuhiro MATSUMOTO <[email protected]> Run-TryBot: Alex Brainman <[email protected]>
1 parent b5fe077 commit ab4c929

File tree

3 files changed

+2
-18
lines changed

3 files changed

+2
-18
lines changed

src/runtime/export_windows_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ package runtime
88

99
import "unsafe"
1010

11-
var (
12-
TestingWER = &testingWER
13-
TimeBeginPeriodRetValue = &timeBeginPeriodRetValue
14-
)
11+
var TestingWER = &testingWER
1512

1613
func NumberOfProcessors() int32 {
1714
var info systeminfo

src/runtime/os1_windows.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
//go:cgo_import_dynamic runtime._WaitForSingleObject WaitForSingleObject%2 "kernel32.dll"
4848
//go:cgo_import_dynamic runtime._WriteConsoleW WriteConsoleW%5 "kernel32.dll"
4949
//go:cgo_import_dynamic runtime._WriteFile WriteFile%5 "kernel32.dll"
50-
//go:cgo_import_dynamic runtime._timeBeginPeriod timeBeginPeriod%1 "winmm.dll"
5150

5251
var (
5352
// Following syscalls are available on every Windows PC.
@@ -90,8 +89,7 @@ var (
9089
_WSAGetOverlappedResult,
9190
_WaitForSingleObject,
9291
_WriteConsoleW,
93-
_WriteFile,
94-
_timeBeginPeriod stdFunction
92+
_WriteFile stdFunction
9593

9694
// Following syscalls are only available on some Windows PCs.
9795
// We will load syscalls, if available, before using them.
@@ -161,8 +159,6 @@ const (
161159
// in sys_windows_386.s and sys_windows_amd64.s
162160
func externalthreadhandler()
163161

164-
var timeBeginPeriodRetValue uint32
165-
166162
func osinit() {
167163
asmstdcallAddr = unsafe.Pointer(funcPC(asmstdcall))
168164

@@ -178,8 +174,6 @@ func osinit() {
178174

179175
stdcall2(_SetConsoleCtrlHandler, funcPC(ctrlhandler), 1)
180176

181-
timeBeginPeriodRetValue = uint32(stdcall1(_timeBeginPeriod, 1))
182-
183177
ncpu = getproccount()
184178

185179
// Windows dynamic priority boosting assumes that a process has different types

src/runtime/syscall_windows_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,6 @@ uintptr_t cfunc(callback f, uintptr_t n) {
642642
}
643643
}
644644

645-
func TestTimeBeginPeriod(t *testing.T) {
646-
const TIMERR_NOERROR = 0
647-
if *runtime.TimeBeginPeriodRetValue != TIMERR_NOERROR {
648-
t.Fatalf("timeBeginPeriod failed: it returned %d", *runtime.TimeBeginPeriodRetValue)
649-
}
650-
}
651-
652645
// removeOneCPU removes one (any) cpu from affinity mask.
653646
// It returns new affinity mask.
654647
func removeOneCPU(mask uintptr) (uintptr, error) {

0 commit comments

Comments
 (0)