]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.18] runtime: clear timerModifiedEarliest when last timer is deleted
authorMichael Pratt <mpratt@google.com>
Wed, 13 Jul 2022 15:48:04 +0000 (11:48 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 25 Jul 2022 23:11:17 +0000 (23:11 +0000)
commit4782f4275c8d006e0346026585e50633a5a31007
tree4cab1939a17645fae85a16de5251efeacbc3c577
parent12e00f6c6b5f37eb8b268a8eaa64d80b7f5b6dcc
[release-branch.go1.18] runtime: clear timerModifiedEarliest when last timer is deleted

timerModifiedEarliest contains the lowest possible expiration for a
modified earlier timer, which may be earlier than timer0When because we
haven't yet updated the heap. Note "may", as the modified earlier timer
that set timerModifiedEarliest may have since been modified later or
deleted.

We can clear timerModifiedEarliest when the last timer is deleted
because by definition there must not be any modified earlier timers.

Why does this matter? checkTimersNoP claims that there is work to do if
timerModifiedEarliest has passed, causing findRunnable to loop back
around to checkTimers. But the code to clean up timerModifiedEarliest in
checkTimers (i.e., the call to adjusttimers) is conditional behind a
check that len(pp.timers) > 0.

Without clearing timerModifiedEarliest, a spinning M that would
otherwise go to sleep will busy loop in findRunnable until some other
work is available.

Note that changing the condition on the call to adjusttimers would also
be a valid fix. I took this approach because it feels a bit cleaner to
clean up timerModifiedEarliest as soon as it is known to be irrelevant.

For #51654.
Fixes #53847.

Change-Id: I3f3787c67781cac7ce87939c5706cef8db927dd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/417434
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
(cherry picked from commit c006b7ac2765252f397dec40fef610a3c17d956d)
Reviewed-on: https://go-review.googlesource.com/c/go/+/417475
src/runtime/time.go