brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 5c82b8e Raw
79 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// This benchmark is very expensive and we don't want to run it on a regular basis,12// only to ensure the code doesn't rot.13// REQUIRES: enable-benchmarks=dry-run14 15#include "atomic_wait_helper.h"16 17#include <atomic>18#include <array>19#include <chrono>20#include <cstdint>21#include <numeric>22#include <stop_token>23#include <thread>24 25#include "benchmark/benchmark.h"26#include "make_test_thread.h"27 28using namespace std::chrono_literals;29 30template <class NotifyPolicy, class NumPrioTasks>31void BM_1_atomic_1_waiter_1_notifier(benchmark::State& state) {32  [[maybe_unused]] std::array<HighPrioTask, NumPrioTasks::value> tasks{};33  std::atomic<std::uint64_t> a;34  auto thread_func = [&](std::stop_token st) { NotifyPolicy::notify(a, st); };35 36  std::uint64_t total_loop_test_param = state.range(0);37 38  auto thread = support::make_test_jthread(thread_func);39 40  for (auto _ : state) {41    for (std::uint64_t i = 0; i < total_loop_test_param; ++i) {42      auto old = a.load(std::memory_order_relaxed);43      a.wait(old);44    }45  }46}47 48BENCHMARK(BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<0>>)49    ->RangeMultiplier(2)50    ->Range(1 << 16, 1 << 18);51BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<0>>)52    ->RangeMultiplier(2)53    ->Range(1 << 10, 1 << 12);54BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<0>>)55    ->RangeMultiplier(2)56    ->Range(1 << 10, 1 << 12);57 58BENCHMARK(BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<4>>)59    ->RangeMultiplier(2)60    ->Range(1 << 16, 1 << 18);61BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<4>>)62    ->RangeMultiplier(2)63    ->Range(1 << 10, 1 << 12);64BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<4>>)65    ->RangeMultiplier(2)66    ->Range(1 << 10, 1 << 12);67 68BENCHMARK(BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<7>>)69    ->RangeMultiplier(2)70    ->Range(1 << 4, 1 << 6);71BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<7>>)72    ->RangeMultiplier(2)73    ->Range(1 << 3, 1 << 5);74BENCHMARK(BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<7>>)75    ->RangeMultiplier(2)76    ->Range(1 << 3, 1 << 5);77 78BENCHMARK_MAIN();79