[ScopedSpinGuard] Use std::atomic::compare_exchange_strong() for spinlock [crashpad/crashpad : main]

4 views
Skip to first unread message

Ben Hamilton (Gerrit)

unread,
May 16, 2024, 4:47:22 PMMay 16
to Mark Mentovai, Justin Cohen, Tim Sergeant, Crashpad LUCI CQ, crashp...@chromium.org
Attention needed from Justin Cohen and Mark Mentovai

Ben Hamilton added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Ben Hamilton . resolved

Mark, I'm trying to write an arm64 test to reproduce the spurious failure from
`std::atomic::compare_exchange_weak()`, but I'm not able to reproduce it.

Do you have any thoughts on how I can test this?

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Cohen
  • Mark Mentovai
Submit Requirements:
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Gerrit-Change-Number: 5545257
Gerrit-PatchSet: 2
Gerrit-Owner: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-CC: Tim Sergeant <tser...@chromium.org>
Gerrit-CC: Wolfgang Billenstein <bwol...@google.com>
Gerrit-Attention: Justin Cohen <justi...@chromium.org>
Gerrit-Attention: Mark Mentovai <ma...@chromium.org>
Gerrit-Comment-Date: Thu, 16 May 2024 20:47:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Mark Mentovai (Gerrit)

unread,
May 16, 2024, 6:03:49 PMMay 16
to Ben Hamilton, Justin Cohen, Tim Sergeant, Crashpad LUCI CQ, crashp...@chromium.org
Attention needed from Ben Hamilton and Justin Cohen

Mark Mentovai voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Ben Hamilton
  • Justin Cohen
Submit Requirements:
  • requirement satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Gerrit-Change-Number: 5545257
Gerrit-PatchSet: 2
Gerrit-Owner: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-CC: Tim Sergeant <tser...@chromium.org>
Gerrit-CC: Wolfgang Billenstein <bwol...@google.com>
Gerrit-Attention: Ben Hamilton <benha...@google.com>
Gerrit-Attention: Justin Cohen <justi...@chromium.org>
Gerrit-Comment-Date: Thu, 16 May 2024 22:03:45 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Mark Mentovai (Gerrit)

unread,
May 16, 2024, 6:05:29 PMMay 16
to Ben Hamilton, Justin Cohen, Tim Sergeant, Crashpad LUCI CQ, crashp...@chromium.org
Attention needed from Ben Hamilton and Justin Cohen

Mark Mentovai added 1 comment

Patchset-level comments
Ben Hamilton . resolved

Mark, I'm trying to write an arm64 test to reproduce the spurious failure from
`std::atomic::compare_exchange_weak()`, but I'm not able to reproduce it.

Do you have any thoughts on how I can test this?

Mark Mentovai

Mark, I'm trying to write an arm64 test to reproduce the spurious failure from
`std::atomic::compare_exchange_weak()`, but I'm not able to reproduce it.

Do you have any thoughts on how I can test this?

Nothing immediately comes to mind.

Open in Gerrit

Related details

Attention is currently required from:
  • Ben Hamilton
  • Justin Cohen
Submit Requirements:
  • requirement satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Gerrit-Change-Number: 5545257
Gerrit-PatchSet: 2
Gerrit-Owner: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-CC: Tim Sergeant <tser...@chromium.org>
Gerrit-CC: Wolfgang Billenstein <bwol...@google.com>
Gerrit-Attention: Ben Hamilton <benha...@google.com>
Gerrit-Attention: Justin Cohen <justi...@chromium.org>
Gerrit-Comment-Date: Thu, 16 May 2024 22:05:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Ben Hamilton <benha...@google.com>
satisfied_requirement
open
diffy

Ben Hamilton (Gerrit)

unread,
May 16, 2024, 6:16:55 PMMay 16
to Mark Mentovai, Justin Cohen, Tim Sergeant, Crashpad LUCI CQ, crashp...@chromium.org
Attention needed from Justin Cohen

Ben Hamilton voted Commit-Queue+2

Commit-Queue+2
Open in Gerrit

Related details

Attention is currently required from:
  • Justin Cohen
Submit Requirements:
  • requirement satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Gerrit-Change-Number: 5545257
Gerrit-PatchSet: 2
Gerrit-Owner: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-CC: Tim Sergeant <tser...@chromium.org>
Gerrit-CC: Wolfgang Billenstein <bwol...@google.com>
Gerrit-Attention: Justin Cohen <justi...@chromium.org>
Gerrit-Comment-Date: Thu, 16 May 2024 22:16:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Crashpad LUCI CQ (Gerrit)

unread,
May 16, 2024, 6:17:05 PMMay 16
to Ben Hamilton, Mark Mentovai, Justin Cohen, Tim Sergeant, crashp...@chromium.org

Crashpad LUCI CQ submitted the change

Change information

Commit message:
[ScopedSpinGuard] Use std::atomic::compare_exchange_strong() for spinlock

Previously, ScopedSpinGuard used std::atomic::compare_exchange_weak()
in a loop to implement a spinlock. After looping for the specified
number of nanoseconds, it would give up and return an error.

A few bugs have come in on ARM platforms (https://crbug.com/340980960,
http://b/296082201) which indicate that this can fail even in
single-threaded cases where nothing else has the spinlock.

From https://cbloomrants.blogspot.com/2011/07/07-14-11-compareexchangestrong-vs.html :

> compare_exchange_weak exists for LL-SC (load linked/store
> conditional) type architectures (Power, ARM, basically everything
> except x86), because on them compare_exchange_strong must be
> implemented as a loop, while compare_exchange_weak can be
> non-looping.

and:

https://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange#Notes

> compare_exchange_weak is allowed to fail spuriously, that is, acts
> as if *this != expected even if they are equal. When a
> compare-and-exchange is in a loop, compare_exchange_weak will yield
> better performance on some platforms.
>
> When compare_exchange_weak would require a loop and
> compare_exchange_strong would not, compare_exchange_strong is
> preferable [...]

My conclusion is that this logic needs to use
`compare_exchange_strong` to avoid spurious failures on ARM in the
common case when there's no other thread holding the spinlock.

Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Bug: b:340980960
Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Reviewed-by: Mark Mentovai <ma...@chromium.org>
Commit-Queue: Ben Hamilton <benha...@google.com>
Files:
  • M util/synchronization/scoped_spin_guard.h
Change size: S
Delta: 1 file changed, 11 insertions(+), 4 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Mark Mentovai
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I2a08031db6b219d7d14a5cd02b3634985f81ab06
Gerrit-Change-Number: 5545257
Gerrit-PatchSet: 3
Gerrit-Owner: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Ben Hamilton <benha...@google.com>
Gerrit-Reviewer: Crashpad LUCI CQ <crashpa...@luci-project-accounts.iam.gserviceaccount.com>
Gerrit-Reviewer: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages