Commit 1d005b45 authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Use Barrier in benchmark

Summary:
Use folly::test::Barrier in benchmark instead of spin-waiting.  Benchmarks are more consistent now,
and perf output is useful instead of showing a bunch of spinning.

Also remove the DSched stuff from bench(), we don't want to benchmark DSched.

Reviewed By: davidtgoldblatt

Differential Revision: D8162600

fbshipit-source-id: 52a1218e7fc2b87f0926dbc29c13bf0c9478e804
parent 97027cbe
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <folly/synchronization/example/HazptrLockFreeLIFO.h> #include <folly/synchronization/example/HazptrLockFreeLIFO.h>
#include <folly/synchronization/example/HazptrSWMRSet.h> #include <folly/synchronization/example/HazptrSWMRSet.h>
#include <folly/synchronization/example/HazptrWideCAS.h> #include <folly/synchronization/example/HazptrWideCAS.h>
#include <folly/synchronization/test/Barrier.h>
#include <folly/portability/GFlags.h> #include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
...@@ -45,6 +46,7 @@ using folly::hazptr_tc; ...@@ -45,6 +46,7 @@ using folly::hazptr_tc;
using folly::HazptrLockFreeLIFO; using folly::HazptrLockFreeLIFO;
using folly::HazptrSWMRSet; using folly::HazptrSWMRSet;
using folly::HazptrWideCAS; using folly::HazptrWideCAS;
using folly::test::Barrier;
using folly::test::DeterministicAtomic; using folly::test::DeterministicAtomic;
using DSched = folly::test::DeterministicSchedule; using DSched = folly::test::DeterministicSchedule;
...@@ -1046,37 +1048,28 @@ TEST(HazptrTest, dsched_wide_cas) { ...@@ -1046,37 +1048,28 @@ TEST(HazptrTest, dsched_wide_cas) {
// Benchmark drivers // Benchmark drivers
template < template <typename InitFunc, typename Func, typename EndFunc>
typename InitFunc,
typename Func,
typename EndFunc,
template <typename> class Atom = std::atomic>
uint64_t run_once( uint64_t run_once(
int nthreads, int nthreads,
const InitFunc& init, const InitFunc& init,
const Func& fn, const Func& fn,
const EndFunc& endFn) { const EndFunc& endFn) {
Atom<bool> start{false}; std::atomic<bool> start{false};
Atom<int> started{0}; Barrier b(nthreads + 1);
init(); init();
std::vector<std::thread> threads(nthreads); std::vector<std::thread> threads(nthreads);
for (int tid = 0; tid < nthreads; ++tid) { for (int tid = 0; tid < nthreads; ++tid) {
threads[tid] = DSched::thread([&, tid] { threads[tid] = std::thread([&, tid] {
started.fetch_add(1); b.wait();
while (!start.load()) {
/* spin */;
}
fn(tid); fn(tid);
}); });
} }
while (started.load() < nthreads) { b.wait();
/* spin */;
}
// begin time measurement // begin time measurement
auto tbegin = std::chrono::steady_clock::now(); auto tbegin = std::chrono::steady_clock::now();
start.store(true); start.store(true);
for (auto& t : threads) { for (auto& t : threads) {
DSched::join(t); t.join();
} }
hazptr_cleanup(); hazptr_cleanup();
// end time measurement // end time measurement
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment