aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks/bm_closure.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
commit4e9265c828f0b559b5fdba04913fed46bf771399 (patch)
tree4a379fc2bdc037753cf8d81f8b86327e4bc50a42 /test/cpp/microbenchmarks/bm_closure.cc
parent0ee7574732a06e8cace4e099a678f4bd5dbff679 (diff)
parentd9da7387b8057f3bd99a417a5ee905377bce9296 (diff)
Merge with master
Diffstat (limited to 'test/cpp/microbenchmarks/bm_closure.cc')
-rw-r--r--test/cpp/microbenchmarks/bm_closure.cc157
1 files changed, 80 insertions, 77 deletions
diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc
index 2375fc0133..a09475b2d1 100644
--- a/test/cpp/microbenchmarks/bm_closure.cc
+++ b/test/cpp/microbenchmarks/bm_closure.cc
@@ -22,12 +22,10 @@
#include <grpc/grpc.h>
#include <sstream>
-extern "C" {
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/support/spinlock.h"
-}
#include "test/cpp/microbenchmarks/helpers.h"
@@ -37,7 +35,7 @@ static void BM_NoOpExecCtx(benchmark::State& state) {
TrackCounters track_counters;
while (state.KeepRunning()) {
ExecCtx _local_exec_ctx;
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
}
track_counters.Finish(state);
}
@@ -47,14 +45,14 @@ static void BM_WellFlushed(benchmark::State& state) {
TrackCounters track_counters;
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- grpc_exec_ctx_flush();
+ grpc_exec_ctx_flush(&exec_ctx);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_WellFlushed);
-static void DoNothing(void* arg, grpc_error* error) {}
+static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {}
static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) {
TrackCounters track_counters;
@@ -76,8 +74,8 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) {
benchmark::DoNotOptimize(GRPC_CLOSURE_INIT(
&c, DoNothing, NULL, grpc_combiner_scheduler(combiner)));
}
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureInitAgainstCombiner);
@@ -88,10 +86,10 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx);
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_RUN(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureRunOnExecCtx);
@@ -101,10 +99,11 @@ static void BM_ClosureCreateAndRun(benchmark::State& state) {
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
GRPC_CLOSURE_RUN(
+ &exec_ctx,
GRPC_CLOSURE_CREATE(DoNothing, NULL, grpc_schedule_on_exec_ctx),
GRPC_ERROR_NONE);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureCreateAndRun);
@@ -115,10 +114,11 @@ static void BM_ClosureInitAndRun(benchmark::State& state) {
grpc_closure c;
while (state.KeepRunning()) {
GRPC_CLOSURE_RUN(
+ &exec_ctx,
GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx),
GRPC_ERROR_NONE);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureInitAndRun);
@@ -129,10 +129,10 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx);
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSchedOnExecCtx);
@@ -145,11 +145,11 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_schedule_on_exec_ctx);
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched2OnExecCtx);
@@ -164,12 +164,12 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c3, DoNothing, NULL, grpc_schedule_on_exec_ctx);
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched3OnExecCtx);
@@ -182,10 +182,10 @@ static void BM_AcquireMutex(benchmark::State& state) {
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
gpr_mu_lock(&mu);
- DoNothing(NULL, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE);
gpr_mu_unlock(&mu);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_AcquireMutex);
@@ -198,13 +198,13 @@ static void BM_TryAcquireMutex(benchmark::State& state) {
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
if (gpr_mu_trylock(&mu)) {
- DoNothing(NULL, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE);
gpr_mu_unlock(&mu);
} else {
abort();
}
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_TryAcquireMutex);
@@ -216,10 +216,10 @@ static void BM_AcquireSpinlock(benchmark::State& state) {
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
gpr_spinlock_lock(&mu);
- DoNothing(NULL, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE);
gpr_spinlock_unlock(&mu);
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_AcquireSpinlock);
@@ -231,13 +231,13 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) {
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
if (gpr_spinlock_trylock(&mu)) {
- DoNothing(NULL, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE);
gpr_spinlock_unlock(&mu);
} else {
abort();
}
}
- grpc_exec_ctx_finish();
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_TryAcquireSpinlock);
@@ -249,11 +249,11 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c, DoNothing, NULL, grpc_combiner_scheduler(combiner));
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSchedOnCombiner);
@@ -267,12 +267,12 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner));
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched2OnCombiner);
@@ -288,13 +288,13 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c3, DoNothing, NULL, grpc_combiner_scheduler(combiner));
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched3OnCombiner);
@@ -309,13 +309,13 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c2, DoNothing, NULL, grpc_combiner_scheduler(combiner2));
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner1, "finished");
- GRPC_COMBINER_UNREF(combiner2, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished");
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched2OnTwoCombiners);
@@ -334,15 +334,15 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c4, DoNothing, NULL, grpc_combiner_scheduler(combiner2));
ExecCtx _local_exec_ctx;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c3, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c4, GRPC_ERROR_NONE);
- grpc_exec_ctx_flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c1, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c2, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c3, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c4, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner1, "finished");
- GRPC_COMBINER_UNREF(combiner2, "finished");
- grpc_exec_ctx_finish();
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished");
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched4OnTwoCombiners);
@@ -356,11 +356,13 @@ class Rescheduler {
GRPC_CLOSURE_INIT(&closure_, Step, this, scheduler);
}
- void ScheduleFirst() { GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); }
+ void ScheduleFirst(grpc_exec_ctx* exec_ctx) {
+ GRPC_CLOSURE_SCHED(exec_ctx, &closure_, GRPC_ERROR_NONE);
+ }
void ScheduleFirstAgainstDifferentScheduler(
- grpc_closure_scheduler* scheduler) {
- GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(Step, this, scheduler),
+ grpc_exec_ctx* exec_ctx, grpc_closure_scheduler* scheduler) {
+ GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(Step, this, scheduler),
GRPC_ERROR_NONE);
}
@@ -368,10 +370,10 @@ class Rescheduler {
benchmark::State& state_;
grpc_closure closure_;
- static void Step(void* arg, grpc_error* error) {
+ static void Step(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
Rescheduler* self = static_cast<Rescheduler*>(arg);
if (self->state_.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&self->closure_, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(exec_ctx, &self->closure_, GRPC_ERROR_NONE);
}
}
};
@@ -380,8 +382,8 @@ static void BM_ClosureReschedOnExecCtx(benchmark::State& state) {
TrackCounters track_counters;
ExecCtx _local_exec_ctx;
Rescheduler r(state, grpc_schedule_on_exec_ctx);
- r.ScheduleFirst();
- grpc_exec_ctx_finish();
+ r.ScheduleFirst(&exec_ctx);
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureReschedOnExecCtx);
@@ -391,10 +393,10 @@ static void BM_ClosureReschedOnCombiner(benchmark::State& state) {
ExecCtx _local_exec_ctx;
grpc_combiner* combiner = grpc_combiner_create();
Rescheduler r(state, grpc_combiner_scheduler(combiner));
- r.ScheduleFirst();
- grpc_exec_ctx_flush();
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ r.ScheduleFirst(&exec_ctx);
+ grpc_exec_ctx_flush(&exec_ctx);
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureReschedOnCombiner);
@@ -404,10 +406,11 @@ static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) {
ExecCtx _local_exec_ctx;
grpc_combiner* combiner = grpc_combiner_create();
Rescheduler r(state, grpc_combiner_finally_scheduler(combiner));
- r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner));
- grpc_exec_ctx_flush();
- GRPC_COMBINER_UNREF(combiner, "finished");
- grpc_exec_ctx_finish();
+ r.ScheduleFirstAgainstDifferentScheduler(&exec_ctx,
+ grpc_combiner_scheduler(combiner));
+ grpc_exec_ctx_flush(&exec_ctx);
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureReschedOnCombinerFinally);