Commit e2ae9f55 authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Reland "Fix thread checks in HangWatcher"

This is a reland of 07c000ce

This CL fixes use of initialized memory which was detected by msan.

Original change's description:
> Fix thread checks in HangWatcher
>
> Remove the thread check that would never pass and make the variable
> that is used by multiple threads thread safe.
>
> Bug: 1142155
> Change-Id: Iae33e15733eb78a47a664515e1abec671edbb64d
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495579
> Reviewed-by: François Doray <fdoray@chromium.org>
> Commit-Queue: Oliver Li <olivierli@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#820817}

Bug: 1142155
Change-Id: I9b642bacbf8b801cd3a549c642c1687449edab86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2502748Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Oliver Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821385}
parent 994bc2bd
......@@ -264,7 +264,9 @@ HangWatcher::GetTimeSinceLastCriticalMemoryPressureCrashKey() {
static debug::CrashKeyString* crash_key = AllocateCrashKeyString(
"seconds-since-last-memory-pressure", kCrashKeyContentSize);
if (last_critical_memory_pressure_.is_null()) {
const base::TimeTicks last_critical_memory_pressure_time =
last_critical_memory_pressure_.load(std::memory_order_relaxed);
if (last_critical_memory_pressure_time.is_null()) {
constexpr char kNoMemoryPressureMsg[] = "No critical memory pressure";
static_assert(
base::size(kNoMemoryPressureMsg) <=
......@@ -273,7 +275,7 @@ HangWatcher::GetTimeSinceLastCriticalMemoryPressureCrashKey() {
return debug::ScopedCrashKeyString(crash_key, kNoMemoryPressureMsg);
} else {
base::TimeDelta time_since_last_critical_memory_pressure =
base::TimeTicks::Now() - last_critical_memory_pressure_;
base::TimeTicks::Now() - last_critical_memory_pressure_time;
return debug::ScopedCrashKeyString(
crash_key, base::NumberToString(
time_since_last_critical_memory_pressure.InSeconds()));
......@@ -283,11 +285,10 @@ HangWatcher::GetTimeSinceLastCriticalMemoryPressureCrashKey() {
void HangWatcher::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
DCHECK_CALLED_ON_VALID_THREAD(hang_watcher_thread_checker_);
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
last_critical_memory_pressure_ = base::TimeTicks::Now();
last_critical_memory_pressure_.store(base::TimeTicks::Now(),
std::memory_order_relaxed);
}
}
......
......@@ -334,8 +334,10 @@ class BASE_EXPORT HangWatcher : public DelegateSimpleThread::Delegate {
base::MemoryPressureListener memory_pressure_listener_;
// The last time at which a critical memory pressure signal was received, or
// null if no signal was ever received.
base::TimeTicks last_critical_memory_pressure_;
// null if no signal was ever received. Atomic because it's set and read from
// different threads.
std::atomic<base::TimeTicks> last_critical_memory_pressure_{
base::TimeTicks()};
// The time after which all deadlines in |watch_states_| need to be for a hang
// to be reported.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment