Skip to content

Commit f1ac559

Browse files
authored
Revert "[scudo] Use getMonotonicTimeFast for tryLock." (#86590)
This reverts commit 36ca9a2. We were using the `time` as the seed while choosing a new TSD. To make the access of TSDs evenly distributed, we require a higher precision in `time`. Otherwise, many threads may result in having the same random access pattern on TSDs because they share the same `time` in certain period. On Linux, CLOCK_MONOTONIC_COARSE usually adopts 4 ms precision. This is way higher than the average accessing time of TSD (which is usually less than 1 us). As a result, when multiple threads try to select a new TSD in a 4 ms interval, they share the same `time` seed and end up choosing and congesting on the same TSD.
1 parent 2598aa6 commit f1ac559

File tree

1 file changed

+3
-3
lines changed
  • compiler-rt/lib/scudo/standalone

1 file changed

+3
-3
lines changed

compiler-rt/lib/scudo/standalone/tsd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ template <class Allocator> struct alignas(SCUDO_CACHE_LINE_SIZE) TSD {
4141
return true;
4242
}
4343
if (atomic_load_relaxed(&Precedence) == 0)
44-
atomic_store_relaxed(&Precedence,
45-
static_cast<uptr>(getMonotonicTimeFast() >>
46-
FIRST_32_SECOND_64(16, 0)));
44+
atomic_store_relaxed(
45+
&Precedence,
46+
static_cast<uptr>(getMonotonicTime() >> FIRST_32_SECOND_64(16, 0)));
4747
return false;
4848
}
4949
inline void lock() NO_THREAD_SAFETY_ANALYSIS {

0 commit comments

Comments
 (0)