From 84066f1b0b68761a75ce9064f4c412f751ee2168 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 18 Dec 2018 16:41:57 -0800 Subject: [PATCH] runtime: use QPC to implement cputicks() on windows/arm Tracing uses cputicks() to generate trace event timestamps. cputicks() is expected to be a high resolution clock source. On Windows/ARM, call QueryPerformanceCounter() which is the highest resolution clock source available. Updates #26148 Change-Id: I987fa556060b3d60c02f07b87b9e6320b9b026e2 Reviewed-on: https://go-review.googlesource.com/c/154762 Reviewed-by: Brad Fitzpatrick Reviewed-by: Austin Clements Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/os_windows.go | 7 +++++++ src/runtime/os_windows_arm.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 9b34589874..2e1ec58a0d 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -198,6 +198,13 @@ func loadOptionalSyscalls() { } _NtWaitForSingleObject = windowsFindfunc(n32, []byte("NtWaitForSingleObject\000")) + if GOARCH == "arm" { + _QueryPerformanceCounter = windowsFindfunc(k32, []byte("QueryPerformanceCounter\000")) + if _QueryPerformanceCounter == nil { + throw("could not find QPC syscalls") + } + } + if windowsFindfunc(n32, []byte("wine_get_version\000")) != nil { // running on Wine initWine(k32) diff --git a/src/runtime/os_windows_arm.go b/src/runtime/os_windows_arm.go index 3115f7241d..10aff75e31 100644 --- a/src/runtime/os_windows_arm.go +++ b/src/runtime/os_windows_arm.go @@ -4,9 +4,13 @@ package runtime +import "unsafe" + //go:nosplit func cputicks() int64 { - return nanotime() + var counter int64 + stdcall1(_QueryPerformanceCounter, uintptr(unsafe.Pointer(&counter))) + return counter } func checkgoarm() { -- 2.50.0