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 @@
#include <folly/synchronization/example/HazptrLockFreeLIFO.h>
#include <folly/synchronization/example/HazptrSWMRSet.h>
#include <folly/synchronization/example/HazptrWideCAS.h>
#include <folly/synchronization/test/Barrier.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>
......@@ -45,6 +46,7 @@ using folly::hazptr_tc;
using folly::HazptrLockFreeLIFO;
using folly::HazptrSWMRSet;
using folly::HazptrWideCAS;
using folly::test::Barrier;
using folly::test::DeterministicAtomic;
using DSched = folly::test::DeterministicSchedule;
......@@ -1046,37 +1048,28 @@ TEST(HazptrTest, dsched_wide_cas) {
// Benchmark drivers
template <
typename InitFunc,
typename Func,
typename EndFunc,
template <typename> class Atom = std::atomic>
template <typename InitFunc, typename Func, typename EndFunc>
uint64_t run_once(
int nthreads,
const InitFunc& init,
const Func& fn,
const EndFunc& endFn) {
Atom<bool> start{false};
Atom<int> started{0};
std::atomic<bool> start{false};
Barrier b(nthreads + 1);
init();
std::vector<std::thread> threads(nthreads);
for (int tid = 0; tid < nthreads; ++tid) {
threads[tid] = DSched::thread([&, tid] {
started.fetch_add(1);
while (!start.load()) {
/* spin */;
}
threads[tid] = std::thread([&, tid] {
b.wait();
fn(tid);
});
}
while (started.load() < nthreads) {
/* spin */;
}
b.wait();
// begin time measurement
auto tbegin = std::chrono::steady_clock::now();
start.store(true);
for (auto& t : threads) {
DSched::join(t);
t.join();
}
hazptr_cleanup();
// 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