aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks/bm_closure.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:05:05 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:05:05 -0800
commitad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch)
tree6a657f8c6179d873b34505cdc24bce9462ca68eb /test/cpp/microbenchmarks/bm_closure.cc
parenta3df36cc2505a89c2f481eea4a66a87b3002844a (diff)
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'test/cpp/microbenchmarks/bm_closure.cc')
-rw-r--r--test/cpp/microbenchmarks/bm_closure.cc196
1 files changed, 101 insertions, 95 deletions
diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc
index 4d5a82c3f6..2434d4e84e 100644
--- a/test/cpp/microbenchmarks/bm_closure.cc
+++ b/test/cpp/microbenchmarks/bm_closure.cc
@@ -34,7 +34,8 @@ auto& force_library_initialization = Library::get();
static void BM_NoOpExecCtx(benchmark::State& state) {
TrackCounters track_counters;
while (state.KeepRunning()) {
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_exec_ctx_finish(&exec_ctx);
}
track_counters.Finish(state);
}
@@ -42,16 +43,16 @@ BENCHMARK(BM_NoOpExecCtx);
static void BM_WellFlushed(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- grpc_core::ExecCtx::Get()->Flush();
+ grpc_exec_ctx_flush(&exec_ctx);
}
-
+ 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;
@@ -68,13 +69,13 @@ static void BM_ClosureInitAgainstCombiner(benchmark::State& state) {
TrackCounters track_counters;
grpc_combiner* combiner = grpc_combiner_create();
grpc_closure c;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
benchmark::DoNotOptimize(GRPC_CLOSURE_INIT(
&c, DoNothing, nullptr, grpc_combiner_scheduler(combiner)));
}
- GRPC_COMBINER_UNREF(combiner, "finished");
-
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureInitAgainstCombiner);
@@ -83,39 +84,41 @@ static void BM_ClosureRunOnExecCtx(benchmark::State& state) {
TrackCounters track_counters;
grpc_closure c;
GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_RUN(&c, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->Flush();
+ GRPC_CLOSURE_RUN(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureRunOnExecCtx);
static void BM_ClosureCreateAndRun(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
GRPC_CLOSURE_RUN(
+ &exec_ctx,
GRPC_CLOSURE_CREATE(DoNothing, nullptr, grpc_schedule_on_exec_ctx),
GRPC_ERROR_NONE);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureCreateAndRun);
static void BM_ClosureInitAndRun(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_closure c;
while (state.KeepRunning()) {
GRPC_CLOSURE_RUN(
+ &exec_ctx,
GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx),
GRPC_ERROR_NONE);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureInitAndRun);
@@ -124,12 +127,12 @@ static void BM_ClosureSchedOnExecCtx(benchmark::State& state) {
TrackCounters track_counters;
grpc_closure c;
GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->Flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSchedOnExecCtx);
@@ -140,13 +143,13 @@ static void BM_ClosureSched2OnExecCtx(benchmark::State& state) {
grpc_closure c2;
GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->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(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched2OnExecCtx);
@@ -159,14 +162,14 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_schedule_on_exec_ctx);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
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_core::ExecCtx::Get()->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(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched3OnExecCtx);
@@ -176,13 +179,13 @@ static void BM_AcquireMutex(benchmark::State& state) {
// for comparison with the combiner stuff below
gpr_mu mu;
gpr_mu_init(&mu);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
gpr_mu_lock(&mu);
- DoNothing(nullptr, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE);
gpr_mu_unlock(&mu);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_AcquireMutex);
@@ -192,16 +195,16 @@ static void BM_TryAcquireMutex(benchmark::State& state) {
// for comparison with the combiner stuff below
gpr_mu mu;
gpr_mu_init(&mu);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
if (gpr_mu_trylock(&mu)) {
- DoNothing(nullptr, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE);
gpr_mu_unlock(&mu);
} else {
abort();
}
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_TryAcquireMutex);
@@ -210,13 +213,13 @@ static void BM_AcquireSpinlock(benchmark::State& state) {
TrackCounters track_counters;
// for comparison with the combiner stuff below
gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
gpr_spinlock_lock(&mu);
- DoNothing(nullptr, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE);
gpr_spinlock_unlock(&mu);
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_AcquireSpinlock);
@@ -225,16 +228,16 @@ static void BM_TryAcquireSpinlock(benchmark::State& state) {
TrackCounters track_counters;
// for comparison with the combiner stuff below
gpr_spinlock mu = GPR_SPINLOCK_INITIALIZER;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
if (gpr_spinlock_trylock(&mu)) {
- DoNothing(nullptr, GRPC_ERROR_NONE);
+ DoNothing(&exec_ctx, nullptr, GRPC_ERROR_NONE);
gpr_spinlock_unlock(&mu);
} else {
abort();
}
}
-
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_TryAcquireSpinlock);
@@ -244,13 +247,13 @@ static void BM_ClosureSchedOnCombiner(benchmark::State& state) {
grpc_combiner* combiner = grpc_combiner_create();
grpc_closure c;
GRPC_CLOSURE_INIT(&c, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->Flush();
+ GRPC_CLOSURE_SCHED(&exec_ctx, &c, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
}
- GRPC_COMBINER_UNREF(combiner, "finished");
-
+ GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSchedOnCombiner);
@@ -262,14 +265,14 @@ static void BM_ClosureSched2OnCombiner(benchmark::State& state) {
grpc_closure c2;
GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->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_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched2OnCombiner);
@@ -283,15 +286,15 @@ static void BM_ClosureSched3OnCombiner(benchmark::State& state) {
GRPC_CLOSURE_INIT(&c1, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
GRPC_CLOSURE_INIT(&c3, DoNothing, nullptr, grpc_combiner_scheduler(combiner));
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
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_core::ExecCtx::Get()->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_COMBINER_UNREF(&exec_ctx, combiner, "finished");
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureSched3OnCombiner);
@@ -306,15 +309,15 @@ static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) {
grpc_combiner_scheduler(combiner1));
GRPC_CLOSURE_INIT(&c2, DoNothing, nullptr,
grpc_combiner_scheduler(combiner2));
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
while (state.KeepRunning()) {
- GRPC_CLOSURE_SCHED(&c1, GRPC_ERROR_NONE);
- GRPC_CLOSURE_SCHED(&c2, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->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_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);
@@ -335,17 +338,17 @@ static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) {
grpc_combiner_scheduler(combiner1));
GRPC_CLOSURE_INIT(&c4, DoNothing, nullptr,
grpc_combiner_scheduler(combiner2));
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
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_core::ExecCtx::Get()->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_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);
@@ -359,11 +362,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);
}
@@ -371,46 +376,47 @@ 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);
}
}
};
static void BM_ClosureReschedOnExecCtx(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Rescheduler r(state, grpc_schedule_on_exec_ctx);
- r.ScheduleFirst();
-
+ r.ScheduleFirst(&exec_ctx);
+ grpc_exec_ctx_finish(&exec_ctx);
track_counters.Finish(state);
}
BENCHMARK(BM_ClosureReschedOnExecCtx);
static void BM_ClosureReschedOnCombiner(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_combiner* combiner = grpc_combiner_create();
Rescheduler r(state, grpc_combiner_scheduler(combiner));
- r.ScheduleFirst();
- grpc_core::ExecCtx::Get()->Flush();
- GRPC_COMBINER_UNREF(combiner, "finished");
-
+ 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);
static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) {
TrackCounters track_counters;
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_combiner* combiner = grpc_combiner_create();
Rescheduler r(state, grpc_combiner_finally_scheduler(combiner));
- r.ScheduleFirstAgainstDifferentScheduler(grpc_combiner_scheduler(combiner));
- grpc_core::ExecCtx::Get()->Flush();
- GRPC_COMBINER_UNREF(combiner, "finished");
-
+ 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);