[compiler-rt] Revert "[scudo] Use getMonotonicTimeFast for tryLock." (PR #86590)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 25 14:52:45 PDT 2024
https://github.com/ChiaHungDuan created https://github.com/llvm/llvm-project/pull/86590
This reverts commit 36ca9a29025a2f678096e9545fa2ec44e8432592.
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.
>From feed0f6bef5625acbdda838f36d9f7de1b7e3cd0 Mon Sep 17 00:00:00 2001
From: Chia-hung Duan <chiahungduan at google.com>
Date: Mon, 25 Mar 2024 21:30:15 +0000
Subject: [PATCH] Revert "[scudo] Use getMonotonicTimeFast for tryLock."
This reverts commit 36ca9a29025a2f678096e9545fa2ec44e8432592.
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.
---
compiler-rt/lib/scudo/standalone/tsd.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/tsd.h b/compiler-rt/lib/scudo/standalone/tsd.h
index b2108a01900bcc..72773f2f72b116 100644
--- a/compiler-rt/lib/scudo/standalone/tsd.h
+++ b/compiler-rt/lib/scudo/standalone/tsd.h
@@ -41,9 +41,9 @@ template <class Allocator> struct alignas(SCUDO_CACHE_LINE_SIZE) TSD {
return true;
}
if (atomic_load_relaxed(&Precedence) == 0)
- atomic_store_relaxed(&Precedence,
- static_cast<uptr>(getMonotonicTimeFast() >>
- FIRST_32_SECOND_64(16, 0)));
+ atomic_store_relaxed(
+ &Precedence,
+ static_cast<uptr>(getMonotonicTime() >> FIRST_32_SECOND_64(16, 0)));
return false;
}
inline void lock() NO_THREAD_SAFETY_ANALYSIS {
More information about the llvm-commits
mailing list