Skip to content
Snippets Groups Projects
Commit ac645eaa authored by Rhys Hiltner's avatar Rhys Hiltner Committed by Gopher Robot
Browse files

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: default avatarMichael 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: default avatarCherry Mui <cherryyz@google.com>
parent 60d3bcde
No related branches found
No related tags found
No related merge requests found
...@@ -404,7 +404,7 @@ useStackLock: ...@@ -404,7 +404,7 @@ useStackLock:
n++ n++
next := node.mWaitList.next.ptr() next := node.mWaitList.next.ptr()
if next == nil { 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 node.mWaitList.startTicks = endTicks
head.mWaitList.startTicks = endTicks head.mWaitList.startTicks = endTicks
getg().m.mLockProfile.recordUnlock(cycles * int64(n)) getg().m.mLockProfile.recordUnlock(cycles * int64(n))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment