diff options
| author | Rhys Hiltner <rhys.hiltner@gmail.com> | 2025-05-08 10:59:18 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-05-08 12:07:41 -0700 |
| commit | ac645eaa0efc982eb238188a5f14835d2c1f8d18 (patch) | |
| tree | f6d274a52db259a6af91a7563144354d0278be3d /src/runtime | |
| parent | 60d3bcdec38eafbffe3086d8aea190ff8bcdece7 (diff) | |
| download | go-ac645eaa0efc982eb238188a5f14835d2c1f8d18.tar.xz | |
runtime: avoid overflow in mutex delay calculation
If cputicks is in the top quarter of the int64's range, adding two
values together will overflow and confuse the subsequent calculations,
leading to zero-duration contention events in the profile.
This fixes the TestRuntimeLockMetricsAndProfile failures on the
linux-s390x builder.
Change-Id: Icb814c39a8702379dfd71c06a53b2618e3589e07
Reviewed-on: https://go-review.googlesource.com/c/go/+/671115
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Rhys Hiltner <rhys.hiltner@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/lock_spinbit.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/lock_spinbit.go b/src/runtime/lock_spinbit.go index c2a6c76629..f90698a4c9 100644 --- a/src/runtime/lock_spinbit.go +++ b/src/runtime/lock_spinbit.go @@ -404,7 +404,7 @@ useStackLock: n++ next := node.mWaitList.next.ptr() if next == nil { - cycles := endTicks - (head.mWaitList.startTicks+node.mWaitList.startTicks)/2 + cycles := ((endTicks - head.mWaitList.startTicks) + (endTicks - node.mWaitList.startTicks)) / 2 node.mWaitList.startTicks = endTicks head.mWaitList.startTicks = endTicks getg().m.mLockProfile.recordUnlock(cycles * int64(n)) |
