Skip to content

Commit 4beb330

Browse files
committed
runtime: remove slow time compatibility hacks for wine
This reapplies CL 191759, which was reverted in CL 192622. Wine fixed the compatibility issue more than 3 years ago, in version 5.10 (see [1]). We no longer have to keep the compatibility hack on our side. Updates #34021 [1]: wine-mirror/wine@1ae1088 Change-Id: I3b77701d01fdf58fbf350321fc0a957c0f247d32 Reviewed-on: https://go-review.googlesource.com/c/go/+/526358 Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Quim Muntal <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 31c1f4a commit 4beb330

9 files changed

+0
-123
lines changed

src/runtime/os_windows.go

-78
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ var (
9191
_GetStdHandle,
9292
_GetSystemDirectoryA,
9393
_GetSystemInfo,
94-
_GetSystemTimeAsFileTime,
9594
_GetThreadContext,
9695
_SetThreadContext,
9796
_LoadLibraryExW,
9897
_LoadLibraryW,
9998
_PostQueuedCompletionStatus,
10099
_QueryPerformanceCounter,
101-
_QueryPerformanceFrequency,
102100
_RaiseFailFastException,
103101
_ResumeThread,
104102
_SetConsoleCtrlHandler,
@@ -300,11 +298,6 @@ func loadOptionalSyscalls() {
300298
if _WSAGetOverlappedResult == nil {
301299
throw("WSAGetOverlappedResult not found")
302300
}
303-
304-
if windowsFindfunc(n32, []byte("wine_get_version\000")) != nil {
305-
// running on Wine
306-
initWine(k32)
307-
}
308301
}
309302

310303
func monitorSuspendResume() {
@@ -548,77 +541,6 @@ func osinit() {
548541
stdcall2(_SetProcessPriorityBoost, currentProcess, 1)
549542
}
550543

551-
// useQPCTime controls whether time.now and nanotime use QueryPerformanceCounter.
552-
// This is only set to 1 when running under Wine.
553-
var useQPCTime uint8
554-
555-
var qpcStartCounter int64
556-
var qpcMultiplier int64
557-
558-
//go:nosplit
559-
func nanotimeQPC() int64 {
560-
var counter int64 = 0
561-
stdcall1(_QueryPerformanceCounter, uintptr(unsafe.Pointer(&counter)))
562-
563-
// returns number of nanoseconds
564-
return (counter - qpcStartCounter) * qpcMultiplier
565-
}
566-
567-
//go:nosplit
568-
func nowQPC() (sec int64, nsec int32, mono int64) {
569-
var ft int64
570-
stdcall1(_GetSystemTimeAsFileTime, uintptr(unsafe.Pointer(&ft)))
571-
572-
t := (ft - 116444736000000000) * 100
573-
574-
sec = t / 1000000000
575-
nsec = int32(t - sec*1000000000)
576-
577-
mono = nanotimeQPC()
578-
return
579-
}
580-
581-
func initWine(k32 uintptr) {
582-
_GetSystemTimeAsFileTime = windowsFindfunc(k32, []byte("GetSystemTimeAsFileTime\000"))
583-
if _GetSystemTimeAsFileTime == nil {
584-
throw("could not find GetSystemTimeAsFileTime() syscall")
585-
}
586-
587-
_QueryPerformanceCounter = windowsFindfunc(k32, []byte("QueryPerformanceCounter\000"))
588-
_QueryPerformanceFrequency = windowsFindfunc(k32, []byte("QueryPerformanceFrequency\000"))
589-
if _QueryPerformanceCounter == nil || _QueryPerformanceFrequency == nil {
590-
throw("could not find QPC syscalls")
591-
}
592-
593-
// We can not simply fallback to GetSystemTimeAsFileTime() syscall, since its time is not monotonic,
594-
// instead we use QueryPerformanceCounter family of syscalls to implement monotonic timer
595-
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx
596-
597-
var tmp int64
598-
stdcall1(_QueryPerformanceFrequency, uintptr(unsafe.Pointer(&tmp)))
599-
if tmp == 0 {
600-
throw("QueryPerformanceFrequency syscall returned zero, running on unsupported hardware")
601-
}
602-
603-
// This should not overflow, it is a number of ticks of the performance counter per second,
604-
// its resolution is at most 10 per usecond (on Wine, even smaller on real hardware), so it will be at most 10 millions here,
605-
// panic if overflows.
606-
if tmp > (1<<31 - 1) {
607-
throw("QueryPerformanceFrequency overflow 32 bit divider, check nosplit discussion to proceed")
608-
}
609-
qpcFrequency := int32(tmp)
610-
stdcall1(_QueryPerformanceCounter, uintptr(unsafe.Pointer(&qpcStartCounter)))
611-
612-
// Since we are supposed to run this time calls only on Wine, it does not lose precision,
613-
// since Wine's timer is kind of emulated at 10 Mhz, so it will be a nice round multiplier of 100
614-
// but for general purpose system (like 3.3 Mhz timer on i7) it will not be very precise.
615-
// We have to do it this way (or similar), since multiplying QPC counter by 100 millions overflows
616-
// int64 and resulted time will always be invalid.
617-
qpcMultiplier = int64(timediv(1000000000, qpcFrequency, nil))
618-
619-
useQPCTime = 1
620-
}
621-
622544
//go:nosplit
623545
func getRandomData(r []byte) {
624546
n := 0

src/runtime/sys_windows_386.s

-5
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ TEXT runtime·switchtothread(SB),NOSPLIT,$0
251251
RET
252252

253253
TEXT runtime·nanotime1(SB),NOSPLIT,$0-8
254-
CMPB runtime·useQPCTime(SB), $0
255-
JNE useQPC
256254
loop:
257255
MOVL (_INTERRUPT_TIME+time_hi1), AX
258256
MOVL (_INTERRUPT_TIME+time_lo), CX
@@ -269,9 +267,6 @@ loop:
269267
MOVL AX, ret_lo+0(FP)
270268
MOVL DX, ret_hi+4(FP)
271269
RET
272-
useQPC:
273-
JMP runtime·nanotimeQPC(SB)
274-
RET
275270

276271
// This is called from rt0_go, which runs on the system stack
277272
// using the initial stack allocated by the OS.

src/runtime/sys_windows_amd64.s

-5
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,11 @@ TEXT runtime·switchtothread(SB),NOSPLIT,$0
265265
RET
266266

267267
TEXT runtime·nanotime1(SB),NOSPLIT,$0-8
268-
CMPB runtime·useQPCTime(SB), $0
269-
JNE useQPC
270268
MOVQ $_INTERRUPT_TIME, DI
271269
MOVQ time_lo(DI), AX
272270
IMULQ $100, AX
273271
MOVQ AX, ret+0(FP)
274272
RET
275-
useQPC:
276-
JMP runtime·nanotimeQPC(SB)
277-
RET
278273

279274
// func osSetupTLS(mp *m)
280275
// Setup TLS. for use by needm on Windows.

src/runtime/sys_windows_arm.s

-7
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ TEXT runtime·read_tls_fallback(SB),NOSPLIT,$0
231231
RET
232232

233233
TEXT runtime·nanotime1(SB),NOSPLIT,$0-8
234-
MOVW $0, R0
235-
MOVB runtime·useQPCTime(SB), R0
236-
CMP $0, R0
237-
BNE useQPC
238-
MOVW $_INTERRUPT_TIME, R3
239234
loop:
240235
MOVW time_hi1(R3), R1
241236
DMB MB_ISH
@@ -254,8 +249,6 @@ loop:
254249
MOVW R3, ret_lo+0(FP)
255250
MOVW R4, ret_hi+4(FP)
256251
RET
257-
useQPC:
258-
RET runtime·nanotimeQPC(SB) // tail call
259252

260253
// save_g saves the g register (R10) into thread local memory
261254
// so that we can call externally compiled

src/runtime/sys_windows_arm64.s

-5
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,12 @@ TEXT runtime·switchtothread(SB),NOSPLIT,$16-0
249249
RET
250250

251251
TEXT runtime·nanotime1(SB),NOSPLIT,$0-8
252-
MOVB runtime·useQPCTime(SB), R0
253-
CMP $0, R0
254-
BNE useQPC
255252
MOVD $_INTERRUPT_TIME, R3
256253
MOVD time_lo(R3), R0
257254
MOVD $100, R1
258255
MUL R1, R0
259256
MOVD R0, ret+0(FP)
260257
RET
261-
useQPC:
262-
RET runtime·nanotimeQPC(SB) // tail call
263258

264259
// This is called from rt0_go, which runs on the system stack
265260
// using the initial stack allocated by the OS.

src/runtime/time_windows_386.s

-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "time_windows.h"
1010

1111
TEXT time·now(SB),NOSPLIT,$0-20
12-
CMPB runtime·useQPCTime(SB), $0
13-
JNE useQPC
1412
loop:
1513
MOVL (_INTERRUPT_TIME+time_hi1), AX
1614
MOVL (_INTERRUPT_TIME+time_lo), CX
@@ -79,6 +77,3 @@ wall:
7977
MOVL AX, sec+0(FP)
8078
MOVL DX, sec+4(FP)
8179
RET
82-
useQPC:
83-
JMP runtime·nowQPC(SB)
84-
RET

src/runtime/time_windows_amd64.s

-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include "time_windows.h"
1010

1111
TEXT time·now(SB),NOSPLIT,$0-24
12-
CMPB runtime·useQPCTime(SB), $0
13-
JNE useQPC
14-
1512
MOVQ $_INTERRUPT_TIME, DI
1613
MOVQ time_lo(DI), AX
1714
IMULQ $100, AX
@@ -37,6 +34,3 @@ TEXT time·now(SB),NOSPLIT,$0-24
3734
SUBQ DX, CX
3835
MOVL CX, nsec+8(FP)
3936
RET
40-
useQPC:
41-
JMP runtime·nowQPC(SB)
42-
RET

src/runtime/time_windows_arm.s

-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#include "time_windows.h"
1010

1111
TEXT time·now(SB),NOSPLIT,$0-20
12-
MOVW $0, R0
13-
MOVB runtime·useQPCTime(SB), R0
14-
CMP $0, R0
15-
BNE useQPC
1612
MOVW $_INTERRUPT_TIME, R3
1713
loop:
1814
MOVW time_hi1(R3), R1
@@ -85,6 +81,4 @@ wall:
8581
MOVW R7,sec_hi+4(FP)
8682
MOVW R1,nsec+8(FP)
8783
RET
88-
useQPC:
89-
RET runtime·nowQPC(SB) // tail call
9084

src/runtime/time_windows_arm64.s

-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#include "time_windows.h"
1010

1111
TEXT time·now(SB),NOSPLIT,$0-24
12-
MOVB runtime·useQPCTime(SB), R0
13-
CMP $0, R0
14-
BNE useQPC
15-
1612
MOVD $_INTERRUPT_TIME, R3
1713
MOVD time_lo(R3), R0
1814
MOVD $100, R1
@@ -42,6 +38,4 @@ TEXT time·now(SB),NOSPLIT,$0-24
4238
MSUB R1, R0, R2, R0
4339
MOVW R0, nsec+8(FP)
4440
RET
45-
useQPC:
46-
RET runtime·nowQPC(SB) // tail call
4741

0 commit comments

Comments
 (0)