Closed Bug 1963506 Opened 24 days ago Closed 7 days ago

TSan data race on PerfStats::sCollectionMask

Categories

(Core :: Performance Engineering, defect)

defect

Tracking

()

RESOLVED FIXED
140 Branch
Tracking Status
firefox140 --- fixed

People

(Reporter: Jamie, Assigned: bas.schouten)

References

Details

Attachments

(1 file)

While working on an initial framework for accessibility engine performance tests in bug 1962317, I hit a data race in PerfStats in TSan builds. This seems to be caused by my test calling PerfStats::SetCollectionMask on the main thread, while the GPU thread happens to be calling PerfStats::RecordMeasurement. This causes a race on PerfStats::sCollectionMask.

It's probably unusual to run a perf test with TSan anyway, so the solution for my case is simple: disable the tests for TSan. However, this isn't obvious to a newcomer.

There are a few paths forward:

  1. Leave this as is but document it somewhere.
  2. Use Atomic<uint64_t, Relaxed> for sCollectionMask.
  3. Suppress this error using no_sanitize("thread") as documented here.

Discussion from Matrix:

[Bas] That race is gauged to be acceptable and worth the performance advantage of fencing the read.
It is known but we could do a better job documenting it. The race should be benign.
[mstange] The right way to express to the compiler that it's fine for an integer variable to be accessed from multiple threads is to make it an atomic
And you can make it an atomic with Relaxed ordering to say that you don't care about ordering with anything else
Racy reads and writes of a non atomic integer are undefined behavior at the C++ semantics level and we definitely don't want that

See Also: → 1962317

2 is the only correct solution, the two others are simply UB as Markus say.

https://web.archive.org/web/20141225111616/http://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong goes a bit deeper and explain why it is the only correct solution.

The severity field is not set for this bug.
:bas.schouten, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(bas)

I don't think any of the concerns in the cited article apply here, other than the theoretical undefined behavior one. Since we compile with C++11 or higher I think that's a fair reason to do it, even if it makes the code a little uglier. I will put up a patch.

Flags: needinfo?(bas)
Component: Performance: General → Performance Engineering
Assignee: nobody → bas
Status: NEW → ASSIGNED

I confirmed there's no difference in the generated code on either ARM or x64 as far as I can tell. So that does seem to make this the better option.

Pushed by bschouten@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b43bcc44e94b Mark PerfStats::sCollectionMask as a relaxed ordering atomic. r=mstange
Status: ASSIGNED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
Target Milestone: --- → 140 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: