diff options
author | Abseil Team <absl-team@google.com> | 2021-12-14 12:42:15 -0800 |
---|---|---|
committer | rogeeff <rogeeff@google.com> | 2021-12-15 09:56:15 -0500 |
commit | 52d41a9ec23e39db7e2cbce5c9449506cf2d3a5c (patch) | |
tree | 8dd98e467b4808228e1da309abf11f85b2062c0e /absl/synchronization | |
parent | 1065514ef332d036f3437e950e78d35ce6b7c740 (diff) |
Export of internal Abseil changes
--
81f95fcf85b75b84f9892c73123501472b9cff33 by Martijn Vels <mvels@google.com>:
Introduce GetEstimatedMemoryUsage(CordMemoryAccounting::kFairShare)
Memory usage analysis is moved into a separate cord_analysis.cc source.
PiperOrigin-RevId: 416370158
--
6bc7b1348fd27fe53f100c9eabd47f4f2cb9c19c by Abseil Team <absl-team@google.com>:
Support scoped enum in absl::Substitute.
PiperOrigin-RevId: 416345422
--
6399f4f6ae05ebcd67664ebd844902f699ab8ec7 by Abseil Team <absl-team@google.com>:
Correct the computation of contention cycles
Currently, we record contention cycles from the first time a thread started
waiting on a mutex. Consider a situation in which two threads, T1 and T2, run
a loop at the top of which they acquire a common mutex and release it at the
end of the loop body. Further assume that T2 is never able to acquire the
mutex as T1 repeatedly acquires and then releases the mutex. In this case, we
would expect that the reported contention cycles would be increase linearly
over time. But currently we observe a quadratic behavior in the reported
waiting time as mentioned in b/14684244#comment10.
To fix the issue, this CL records the contention cycles experienced by all the threads woken up when the mutex is released. Further, contention_start_cycles is set to the current time since the contention cycles for the time already passed has been taken into account. With this CL, we get a linear increase in the waiting time, the expected behavior.
PiperOrigin-RevId: 416322593
--
149c1637c8a0f1a38e5a8f9f27e5803a2015a554 by Jorg Brown <jorg@google.com>:
Make Status::EmptyString more efficient by constructing it in global space, rather than on the heap. See https://godbolt.org/z/8M9n7YqcY for reduced code size.
PiperOrigin-RevId: 416307833
--
3b4562a8be5a3c80077cb67b0a32c97419058380 by Abseil Team <absl-team@google.com>:
Clarify the usage of RegisterMutexProfiler
PiperOrigin-RevId: 416146130
GitOrigin-RevId: 81f95fcf85b75b84f9892c73123501472b9cff33
Change-Id: Iccb72d7ee617e6ebe226a38170d62e0849b43480
Diffstat (limited to 'absl/synchronization')
-rw-r--r-- | absl/synchronization/mutex.cc | 18 | ||||
-rw-r--r-- | absl/synchronization/mutex.h | 7 |
2 files changed, 14 insertions, 11 deletions
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index 3af4cda9..376ea794 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -109,7 +109,7 @@ static inline bool EvalConditionAnnotated(const Condition *cond, Mutex *mu, bool locking, bool trylock, bool read_lock); -void RegisterMutexProfiler(void (*fn)(int64_t wait_timestamp)) { +void RegisterMutexProfiler(void (*fn)(int64_t wait_cycles)) { submit_profile_data.Store(fn); } @@ -2315,16 +2315,18 @@ ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) { } // end of for(;;)-loop if (wake_list != kPerThreadSynchNull) { - int64_t enqueue_timestamp = wake_list->waitp->contention_start_cycles; - bool cond_waiter = wake_list->cond_waiter; + int64_t wait_cycles = 0; + int64_t now = base_internal::CycleClock::Now(); do { + // Sample lock contention events only if the waiter was trying to acquire + // the lock, not waiting on a condition variable or Condition. + if (!wake_list->cond_waiter) { + wait_cycles += (now - wake_list->waitp->contention_start_cycles); + wake_list->waitp->contention_start_cycles = now; + } wake_list = Wakeup(wake_list); // wake waiters } while (wake_list != kPerThreadSynchNull); - if (!cond_waiter) { - // Sample lock contention events only if the (first) waiter was trying to - // acquire the lock, not waiting on a condition variable or Condition. - int64_t wait_cycles = - base_internal::CycleClock::Now() - enqueue_timestamp; + if (wait_cycles > 0) { mutex_tracer("slow release", this, wait_cycles); ABSL_TSAN_MUTEX_PRE_DIVERT(this, 0); submit_profile_data(wait_cycles); diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h index 38338f24..9a3e438f 100644 --- a/absl/synchronization/mutex.h +++ b/absl/synchronization/mutex.h @@ -984,14 +984,15 @@ inline Condition::Condition(const T *object, // Register a hook for profiling support. // // The function pointer registered here will be called whenever a mutex is -// contended. The callback is given the absl/base/cycleclock.h timestamp when -// waiting began. +// contended. The callback is given the cycles for which waiting happened (as +// measured by //absl/base/internal/cycleclock.h, and which may not +// be real "cycle" counts.) // // Calls to this function do not race or block, but there is no ordering // guaranteed between calls to this function and call to the provided hook. // In particular, the previously registered hook may still be called for some // time after this function returns. -void RegisterMutexProfiler(void (*fn)(int64_t wait_timestamp)); +void RegisterMutexProfiler(void (*fn)(int64_t wait_cycles)); // Register a hook for Mutex tracing. // |