diff options
author | Abseil Team <absl-team@google.com> | 2023-11-06 08:32:58 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-11-06 08:33:59 -0800 |
commit | 3be31775945aa843c230afc77bb63a98450a413d (patch) | |
tree | 1579bf2dded8bda19d4790bd79e0c98f2f364892 /absl/base | |
parent | 1cb3345dac55cdc5c2961d60de4d1e2e636773e9 (diff) |
Add a new microbenchmark for spinlock TryLock and codegen functions.
PiperOrigin-RevId: 579852413
Change-Id: I1eddd70a4bee974e3a5109109ddfc4b4fd8f421e
Diffstat (limited to 'absl/base')
-rw-r--r-- | absl/base/internal/spinlock_benchmark.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/absl/base/internal/spinlock_benchmark.cc b/absl/base/internal/spinlock_benchmark.cc index 0451c65f..7135d3f5 100644 --- a/absl/base/internal/spinlock_benchmark.cc +++ b/absl/base/internal/spinlock_benchmark.cc @@ -24,8 +24,22 @@ namespace { template <absl::base_internal::SchedulingMode scheduling_mode> +static void BM_TryLock(benchmark::State& state) { + // Ensure a ThreadIdentity is installed so that KERNEL_ONLY has an effect. + ABSL_INTERNAL_CHECK( + absl::synchronization_internal::GetOrCreateCurrentThreadIdentity() != + nullptr, + "GetOrCreateCurrentThreadIdentity() failed"); + + static auto* spinlock = new absl::base_internal::SpinLock(scheduling_mode); + for (auto _ : state) { + if (spinlock->TryLock()) spinlock->Unlock(); + } +} + +template <absl::base_internal::SchedulingMode scheduling_mode> static void BM_SpinLock(benchmark::State& state) { - // Ensure a ThreadIdentity is installed. + // Ensure a ThreadIdentity is installed so that KERNEL_ONLY has an effect. ABSL_INTERNAL_CHECK( absl::synchronization_internal::GetOrCreateCurrentThreadIdentity() != nullptr, @@ -49,4 +63,15 @@ BENCHMARK_TEMPLATE(BM_SpinLock, ->Threads(1) ->ThreadPerCpu(); +BENCHMARK_TEMPLATE(BM_TryLock, absl::base_internal::SCHEDULE_KERNEL_ONLY) + ->UseRealTime() + ->Threads(1) + ->ThreadPerCpu(); + +BENCHMARK_TEMPLATE(BM_TryLock, + absl::base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL) + ->UseRealTime() + ->Threads(1) + ->ThreadPerCpu(); + } // namespace |