[logging] Fix tsan errro between Profiler::Insert and

... Profiler::Remove.

In Profiler::Insert and Profiler::Remove, TSAN cannot
figure out that when head_ and tail_ equals, Profiler::Insert
will always execute before Profiler::Remove, and tsan
will report data race between buffer_[head] write and
buffer_[base::Relaxed_Load(&tail_)]. This CL changes the
tail_ atomic load and store memory order to gurantee that
buffer_ read and write always after and before tail_ load
and store, which gives tsan more constraint.

Bug: v8:12838
Change-Id: I50296ffa4606b288e9ad9edc15d42f21ca1c7d2a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3626454
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80421}
This commit is contained in:
jameslahm 2022-05-04 16:15:53 +08:00 committed by V8 LUCI CQ
parent 3e43010abb
commit 4fb91a0f2b

View File

@ -913,7 +913,7 @@ class Profiler : public base::Thread {
// Inserts collected profiling data into buffer.
void Insert(TickSample* sample) {
if (Succ(head_) == static_cast<int>(base::Relaxed_Load(&tail_))) {
if (Succ(head_) == static_cast<int>(base::Acquire_Load(&tail_))) {
overflow_ = true;
} else {
buffer_[head_] = *sample;
@ -930,7 +930,7 @@ class Profiler : public base::Thread {
buffer_semaphore_.Wait(); // Wait for an element.
*sample = buffer_[base::Relaxed_Load(&tail_)];
bool result = overflow_;
base::Relaxed_Store(
base::Release_Store(
&tail_, static_cast<base::Atomic32>(Succ(base::Relaxed_Load(&tail_))));
overflow_ = false;
return result;