minor optimizations

pull/10507/head
Craig Tiller 8 years ago
parent 05da6e98c1
commit 7f5fac9054
  1. 10
      src/core/lib/iomgr/ev_epollex_linux.c
  2. 6
      test/cpp/microbenchmarks/bm_pollset.cc

@ -566,19 +566,17 @@ static void pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
static int poll_deadline_to_millis_timeout(gpr_timespec deadline, static int poll_deadline_to_millis_timeout(gpr_timespec deadline,
gpr_timespec now) { gpr_timespec now) {
gpr_timespec timeout; gpr_timespec timeout;
static const int64_t max_spin_polling_us = 10;
if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) { if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) == 0) {
return -1; return -1;
} }
if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros( if (gpr_time_cmp(deadline, now) <= 0) {
max_spin_polling_us,
GPR_TIMESPAN))) <= 0) {
return 0; return 0;
} }
static const gpr_timespec round_up = {.clock_type = GPR_TIMESPAN, .tv_sec = 0, .tv_nsec = GPR_NS_PER_MS-1};
timeout = gpr_time_sub(deadline, now); timeout = gpr_time_sub(deadline, now);
int millis = gpr_time_to_millis(gpr_time_add( int millis = gpr_time_to_millis(gpr_time_add(timeout, round_up));
timeout, gpr_time_from_nanos(GPR_NS_PER_MS - 1, GPR_TIMESPAN)));
return millis >= 1 ? millis : 1; return millis >= 1 ? millis : 1;
} }

@ -136,8 +136,7 @@ static void BM_PollEmptyPollset(benchmark::State& state) {
gpr_timespec deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC); gpr_timespec deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC);
gpr_mu_lock(mu); gpr_mu_lock(mu);
while (state.KeepRunning()) { while (state.KeepRunning()) {
grpc_pollset_worker* worker; GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, NULL, now, deadline));
GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, &worker, now, deadline));
} }
grpc_closure shutdown_ps_closure; grpc_closure shutdown_ps_closure;
grpc_closure_init(&shutdown_ps_closure, shutdown_ps, ps, grpc_closure_init(&shutdown_ps_closure, shutdown_ps, ps,
@ -233,8 +232,7 @@ static void BM_SingleThreadPollOneFd(benchmark::State& state) {
grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure); grpc_fd_notify_on_read(&exec_ctx, wakeup, continue_closure);
gpr_mu_lock(mu); gpr_mu_lock(mu);
while (!done) { while (!done) {
grpc_pollset_worker* worker; GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, NULL, now, deadline));
GRPC_ERROR_UNREF(grpc_pollset_work(&exec_ctx, ps, &worker, now, deadline));
} }
grpc_fd_orphan(&exec_ctx, wakeup, NULL, NULL, "done"); grpc_fd_orphan(&exec_ctx, wakeup, NULL, NULL, "done");
wakeup_fd.read_fd = 0; wakeup_fd.read_fd = 0;

Loading…
Cancel
Save