proxygen
ParkingLotBenchmark.cpp File Reference

Go to the source code of this file.

Functions

 DEFINE_uint64 (threads, 32,"Number of threads for benchmark")
 
 BENCHMARK (FutexNoWaitersWake, iters)
 
 BENCHMARK_RELATIVE (ParkingLotNoWaitersWake, iters)
 
 BENCHMARK (FutexWakeOne, iters)
 
 BENCHMARK_RELATIVE (ParkingLotWakeOne, iters)
 
 BENCHMARK (FutexWakeAll, iters)
 
 BENCHMARK_RELATIVE (ParkingLotWakeAll, iters)
 
int main (int argc, char **argv)
 

Variables

ParkingLot lot
 

Function Documentation

BENCHMARK ( FutexNoWaitersWake  ,
iters   
)

Definition at line 32 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), folly::detail::futexWake(), i, folly::pushmi::detail::t, threads, and folly::test::Barrier::wait().

32  {
33  BenchmarkSuspender susp;
35  Barrier b(FLAGS_threads + 1);
36 
37  std::vector<std::thread> threads{FLAGS_threads};
38  for (auto& t : threads) {
39  t = std::thread([&]() {
40  b.wait();
41  for (auto i = 0u; i < iters; i++) {
42  detail::futexWake(&fu, 1);
43  }
44  });
45  }
46  susp.dismiss();
47  b.wait();
48 
49  for (auto& t : threads) {
50  t.join();
51  }
52 }
char b
Atom< std::uint32_t > Futex
Definition: Futex.h:51
std::vector< std::thread::id > threads
int futexWake(const Futex *futex, int count, uint32_t wakeMask)
Definition: Futex-inl.h:107
BENCHMARK ( FutexWakeOne  ,
iters   
)

Definition at line 75 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), folly::detail::futexWait(), folly::detail::futexWake(), i, folly::pushmi::detail::t, threads, and folly::test::Barrier::wait().

75  {
76  BenchmarkSuspender susp;
78  Barrier b(FLAGS_threads + 1);
79 
80  std::vector<std::thread> threads{FLAGS_threads};
81  for (auto& t : threads) {
82  t = std::thread([&]() {
83  b.wait();
84  while (true) {
85  detail::futexWait(&fu, 0);
86  if (fu.load(std::memory_order_relaxed)) {
87  return;
88  }
89  }
90  });
91  }
92  susp.dismiss();
93  b.wait();
94  for (auto i = 0u; i < iters; i++) {
95  detail::futexWake(&fu, 1);
96  }
97  fu.store(1);
98  detail::futexWake(&fu, threads.size());
99 
100  for (auto& t : threads) {
101  t.join();
102  }
103 }
char b
Atom< std::uint32_t > Futex
Definition: Futex.h:51
std::vector< std::thread::id > threads
FutexResult futexWait(const Futex< MockAtom > *futex, uint32_t expected, uint32_t waitMask)
int futexWake(const Futex *futex, int count, uint32_t wakeMask)
Definition: Futex-inl.h:107
BENCHMARK ( FutexWakeAll  ,
iters   
)

Definition at line 140 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), folly::detail::futexWait(), folly::detail::futexWake(), i, folly::pushmi::detail::t, threads, and folly::test::Barrier::wait().

140  {
141  BenchmarkSuspender susp;
142  Barrier b(FLAGS_threads + 1);
144  std::atomic<bool> done{false};
145 
146  std::vector<std::thread> threads{FLAGS_threads};
147  for (auto& t : threads) {
148  t = std::thread([&]() {
149  b.wait();
150  while (true) {
151  detail::futexWait(&fu, 0);
152  if (done.load(std::memory_order_relaxed)) {
153  return;
154  }
155  }
156  });
157  }
158  susp.dismiss();
159  b.wait();
160  for (auto i = 0u; i < iters; i++) {
161  detail::futexWake(&fu, threads.size());
162  }
163  fu.store(1);
164  done = true;
165  detail::futexWake(&fu, threads.size());
166 
167  for (auto& t : threads) {
168  t.join();
169  }
170 }
char b
Atom< std::uint32_t > Futex
Definition: Futex.h:51
std::vector< std::thread::id > threads
FutexResult futexWait(const Futex< MockAtom > *futex, uint32_t expected, uint32_t waitMask)
int futexWake(const Futex *futex, int count, uint32_t wakeMask)
Definition: Futex-inl.h:107
BENCHMARK_RELATIVE ( ParkingLotNoWaitersWake  ,
iters   
)

Definition at line 54 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), i, folly::RetainContinue, folly::pushmi::detail::t, threads, folly::ParkingLot< Data >::unpark(), and folly::test::Barrier::wait().

54  {
55  BenchmarkSuspender susp;
56  Barrier b(FLAGS_threads + 1);
57 
58  std::vector<std::thread> threads{FLAGS_threads};
59  for (auto& t : threads) {
60  t = std::thread([&]() {
61  b.wait();
62  for (auto i = 0u; i < iters; i++) {
63  lot.unpark(&lot, [](Unit) { return UnparkControl::RetainContinue; });
64  }
65  });
66  }
67  susp.dismiss();
68  b.wait();
69 
70  for (auto& t : threads) {
71  t.join();
72  }
73 }
char b
void unpark(const Key key, Unparker &&func)
ParkingLot lot
std::vector< std::thread::id > threads
BENCHMARK_RELATIVE ( ParkingLotWakeOne  ,
iters   
)

Definition at line 105 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), f, i, folly::ParkingLot< Data >::park(), folly::RemoveBreak, folly::RemoveContinue, folly::pushmi::detail::t, threads, folly::ParkingLot< Data >::unpark(), and folly::test::Barrier::wait().

105  {
106  BenchmarkSuspender susp;
107  std::atomic<bool> done{false};
108  Barrier b(FLAGS_threads + 1);
109 
110  std::vector<std::thread> threads{FLAGS_threads};
111  for (auto& t : threads) {
112  t = std::thread([&]() {
113  b.wait();
114  while (true) {
115  Unit f;
116  lot.park(
117  &done,
118  f,
119  [&] { return done.load(std::memory_order_relaxed) == 0; },
120  [] {});
121  if (done.load(std::memory_order_relaxed)) {
122  return;
123  }
124  }
125  });
126  }
127  susp.dismiss();
128  b.wait();
129  for (auto i = 0u; i < iters; i++) {
130  lot.unpark(&done, [](Unit) { return UnparkControl::RemoveBreak; });
131  }
132  done = true;
133  lot.unpark(&done, [](Unit) { return UnparkControl::RemoveContinue; });
134 
135  for (auto& t : threads) {
136  t.join();
137  }
138 }
auto f
char b
void unpark(const Key key, Unparker &&func)
ParkingLot lot
ParkResult park(const Key key, D &&data, ToPark &&toPark, PreWait &&preWait)
Definition: ParkingLot.h:189
std::vector< std::thread::id > threads
BENCHMARK_RELATIVE ( ParkingLotWakeAll  ,
iters   
)

Definition at line 172 of file ParkingLotBenchmark.cpp.

References b, folly::BenchmarkSuspender::dismiss(), f, i, folly::ParkingLot< Data >::park(), folly::RemoveContinue, folly::pushmi::detail::t, threads, folly::ParkingLot< Data >::unpark(), and folly::test::Barrier::wait().

172  {
173  BenchmarkSuspender susp;
174  Barrier b(FLAGS_threads + 1);
175  std::atomic<bool> done{false};
176 
177  std::vector<std::thread> threads{FLAGS_threads};
178  for (auto& t : threads) {
179  t = std::thread([&]() {
180  b.wait();
181  while (true) {
182  Unit f;
183  lot.park(
184  &done,
185  f,
186  [&] { return done.load(std::memory_order_relaxed) == 0; },
187  [] {});
188  if (done.load(std::memory_order_relaxed)) {
189  return;
190  }
191  }
192  });
193  }
194  susp.dismiss();
195  b.wait();
196  for (auto i = 0u; i < iters; i++) {
197  lot.unpark(&done, [](Unit) { return UnparkControl::RemoveContinue; });
198  }
199  done = true;
200  lot.unpark(&done, [](Unit) { return UnparkControl::RemoveContinue; });
201 
202  for (auto& t : threads) {
203  t.join();
204  }
205 }
auto f
char b
void unpark(const Key key, Unparker &&func)
ParkingLot lot
ParkResult park(const Key key, D &&data, ToPark &&toPark, PreWait &&preWait)
Definition: ParkingLot.h:189
std::vector< std::thread::id > threads
DEFINE_uint64 ( threads  ,
32  ,
"Number of threads for benchmark  
)
int main ( int  argc,
char **  argv 
)

Definition at line 207 of file ParkingLotBenchmark.cpp.

References folly::runBenchmarks().

207  {
208  gflags::ParseCommandLineFlags(&argc, &argv, true);
209 
211 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv

Variable Documentation

Definition at line 30 of file ParkingLotBenchmark.cpp.

Referenced by TEST().