]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: cpu profiler to use high resolution timers on Windows
authorqmuntal <quimmuntal@gmail.com>
Mon, 31 Jul 2023 15:33:40 +0000 (17:33 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Wed, 2 Aug 2023 15:25:43 +0000 (15:25 +0000)
The CPU profiler skip samples if the sampling rate is too high
for the system timer resolution. This CL uses high resolution
timers on Windows when available, to avoid this problem.

Note that the default sampling rate (100Hz) is already too high
for the Windows timer resolution (15.6ms), so this CL also improves
the default Windows sampling coverage.

Not adding regression tests, as they would be too flaky.

Fixes #61665

Change-Id: Ifdadabc9ebaf56f397eac517bd0e5f1502b956b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/514375
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
src/runtime/os_windows.go

index f5c2429a05d1460fc01072e3687001af9e79b7a0..6686a9053476d3edd032dda22b2c2cee802fc6d2 100644 (file)
@@ -1266,7 +1266,12 @@ func profileLoop() {
 
 func setProcessCPUProfiler(hz int32) {
        if profiletimer == 0 {
-               timer := stdcall3(_CreateWaitableTimerA, 0, 0, 0)
+               var timer uintptr
+               if haveHighResTimer {
+                       timer = createHighResTimer()
+               } else {
+                       timer = stdcall3(_CreateWaitableTimerA, 0, 0, 0)
+               }
                atomic.Storeuintptr(&profiletimer, timer)
                newm(profileLoop, nil, -1)
        }