diff options
| author | Russ Cox <rsc@swtch.com> | 2024-02-13 22:31:33 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2024-02-28 16:43:44 +0000 |
| commit | 77f0bd01fbc9cc7e77d86756d273b69a5855c2c3 (patch) | |
| tree | 0917cccb1ad0fb1c487c68a1487b8c7b4b13f7bc /src/runtime/proc.go | |
| parent | 0728e2b139b63cf203487bd5f76b64507392b780 (diff) | |
| download | go-77f0bd01fbc9cc7e77d86756d273b69a5855c2c3.tar.xz | |
runtime: delete clearDeletedTimers
adjusttimers already contains the same logic. Use it instead.
This avoids having two copies of the code and is faster.
adjusttimers was formerly O(n log n) but is now O(n).
clearDeletedTimers was formerly O(n² log n) and is now gone!
[This is one CL in a refactoring stack making very small changes
in each step, so that any subtle bugs that we miss can be more
easily pinpointed to a small change.]
Change-Id: I32bf24817a589033dc304b359f8df10ea21f48fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/564116
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index cbd3022802..d2903910be 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -3990,7 +3990,11 @@ func checkTimers(pp *p, now int64) (rnow, pollUntil int64, ran bool) { lock(&pp.timersLock) if len(pp.timers) > 0 { - adjusttimers(pp, now) + // If this is the local P, and there are a lot of deleted timers, + // clear them out. We only do this for the local P to reduce + // lock contention on timersLock. + force := pp == getg().m.p.ptr() && int(pp.deletedTimers.Load()) > len(pp.timers)/4 + adjusttimers(pp, now, force) for len(pp.timers) > 0 { // Note that runtimer may temporarily unlock // pp.timersLock. @@ -4004,13 +4008,6 @@ func checkTimers(pp *p, now int64) (rnow, pollUntil int64, ran bool) { } } - // If this is the local P, and there are a lot of deleted timers, - // clear them out. We only do this for the local P to reduce - // lock contention on timersLock. - if pp == getg().m.p.ptr() && int(pp.deletedTimers.Load()) > len(pp.timers)/4 { - clearDeletedTimers(pp) - } - unlock(&pp.timersLock) return now, pollUntil, ran |
