From cfe3cd903f018dec3cb5997d53b1744df4e53909 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 13 Jan 2020 12:17:26 -0800 Subject: runtime: keep P's first timer when in new atomically accessed field This reduces lock contention when only a few P's are running and checking for whether they need to run timers on the sleeping P's. Without this change the running P's would get lock contention while looking at the sleeping P's timers. With this change a single atomic load suffices to determine whether there are any ready timers. Change-Id: Ie843782bd56df49867a01ecf19c47498ec827452 Reviewed-on: https://go-review.googlesource.com/c/go/+/214185 Run-TryBot: Ian Lance Taylor Reviewed-by: Michael Knyszek Reviewed-by: David Chase --- src/runtime/runtime2.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/runtime/runtime2.go') diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 10d8d8c043..97f0f7a662 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -613,6 +613,11 @@ type p struct { _ uint32 // Alignment for atomic fields below + // The when field of the first entry on the timer heap. + // This is updated using atomic functions. + // This is 0 if the timer heap is empty. + timer0When uint64 + // Per-P GC state gcAssistTime int64 // Nanoseconds in assistAlloc gcFractionalMarkTime int64 // Nanoseconds in fractional mark worker (atomic) -- cgit v1.3