Resolve data races found by ThreadSanitizer#121
Resolve data races found by ThreadSanitizer#121eszpotanski wants to merge 1 commit intoparallaxsw:masterfrom
Conversation
graph/Graph.cc
Outdated
| unsigned char expected = bfs_in_queue_; | ||
| unsigned char desired; | ||
| do { | ||
| if ((value && IN_QUEUE(expected, index)) || (!value && !IN_QUEUE(expected, index))) { | ||
| return false; | ||
| } | ||
| desired = expected; | ||
| SET_IN_QUEUE(value ? desired : expected, index); | ||
| CLEAR_IN_QUEUE(value ? expected : desired, index); | ||
| } while (!bfs_in_queue_.compare_exchange_weak(expected, desired)); | ||
| return true; |
There was a problem hiding this comment.
How does this compare to just locking. I wonder if the additional memory locality and smaller memory footprint make up for the coarser lock
There was a problem hiding this comment.
Locking is slightly slower - a few benchmarks show slowdown between 0.5% and 2%
30209e0 to
1a3f0b7
Compare
|
@jjcherry56 Do these changes seem reasonable, or is there a better way to address these data races? The atomic bitset seems a bit complicated to me, but it might be worth the speed up. |
1a3f0b7 to
4ccc9d8
Compare
|
As b4be3c5 fixed part of the data races, I've updated this PR to contain fixes for remaining ones - caused by:
|
Signed-off-by: Eryk Szpotanski <eszpotanski@antmicro.com> Co-authored-by: Krzysztof Bieganski <kbieganski@antmicro.com>
4ccc9d8 to
aa94722
Compare
|
TSan still complains on current OpenSTA
|
|
It looks like in the latest version bfs_in_queue_ has been moved to std::atomic it looks safe to me. Is that your understanding as well @kbieganski |
|
The The remaining TSan warnings relate to the bitfields – you can't read or write a single bit, so reading the object index on one thread and setting a flag on another thread is seen as a data race as they're under the same address. I guess the object index doesn't change? So it could be safe. But last time we looked at it, we still observed some crashes. We can take a look again. |
This PR fixes following data races found by ThreadSanitizer when OpenSTA is run by OpenROAD-flow-scripts:
These changes incur a significant slowdown (between 10% and 40%, depending on number of threads, used design or stage).
Note that these are only the races found by ThreadSanitizer, not necessarily all of them.