|
|
|
@ -276,7 +276,7 @@ static grpc_fd* fd_create(int fd, const char* name) { |
|
|
|
|
gpr_asprintf(&fd_name, "%s fd=%d", name, fd); |
|
|
|
|
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); |
|
|
|
|
#ifndef NDEBUG |
|
|
|
|
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { |
|
|
|
|
if (grpc_trace_fd_refcount.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
@ -651,7 +651,7 @@ static grpc_error* do_epoll_wait(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, |
|
|
|
|
|
|
|
|
|
GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, r); |
|
|
|
|
|
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, "ps: %p poll got %d events", ps, r); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -673,7 +673,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; |
|
|
|
|
pollset->begin_refs++; |
|
|
|
|
|
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, "PS:%p BEGIN_STARTS:%p", pollset, worker); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -692,7 +692,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
retry_lock_neighborhood: |
|
|
|
|
gpr_mu_lock(&neighborhood->mu); |
|
|
|
|
gpr_mu_lock(&pollset->mu); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d", |
|
|
|
|
pollset, worker, kick_state_string(worker->state), |
|
|
|
|
is_reassigning); |
|
|
|
@ -744,7 +744,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
worker->initialized_cv = true; |
|
|
|
|
gpr_cv_init(&worker->cv); |
|
|
|
|
while (worker->state == UNKICKED && !pollset->shutting_down) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d", |
|
|
|
|
pollset, worker, kick_state_string(worker->state), |
|
|
|
|
pollset->shutting_down); |
|
|
|
@ -761,7 +761,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
grpc_exec_ctx_invalidate_now(exec_ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, |
|
|
|
|
"PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " |
|
|
|
|
"kicked_without_poller: %d", |
|
|
|
@ -806,7 +806,7 @@ static bool check_neighborhood_for_available_poller( |
|
|
|
|
case UNKICKED: |
|
|
|
|
if (gpr_atm_no_barrier_cas(&g_active_poller, 0, |
|
|
|
|
(gpr_atm)inspect_worker)) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, " .. choose next poller to be %p", |
|
|
|
|
inspect_worker); |
|
|
|
|
} |
|
|
|
@ -817,7 +817,7 @@ static bool check_neighborhood_for_available_poller( |
|
|
|
|
gpr_cv_signal(&inspect_worker->cv); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, " .. beaten to choose next poller"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -835,7 +835,7 @@ static bool check_neighborhood_for_available_poller( |
|
|
|
|
} while (!found_worker && inspect_worker != inspect->root_worker); |
|
|
|
|
} |
|
|
|
|
if (!found_worker) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, " .. mark pollset %p inactive", inspect); |
|
|
|
|
} |
|
|
|
|
inspect->seen_inactive = true; |
|
|
|
@ -857,7 +857,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
grpc_pollset_worker* worker, |
|
|
|
|
grpc_pollset_worker** worker_hdl) { |
|
|
|
|
GPR_TIMER_BEGIN("end_worker", 0); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, "PS:%p END_WORKER:%p", pollset, worker); |
|
|
|
|
} |
|
|
|
|
if (worker_hdl != NULL) *worker_hdl = NULL; |
|
|
|
@ -867,7 +867,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
&exec_ctx->closure_list); |
|
|
|
|
if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { |
|
|
|
|
if (worker->next != worker && worker->next->state == UNKICKED) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, " .. choose next poller to be peer %p", worker); |
|
|
|
|
} |
|
|
|
|
GPR_ASSERT(worker->next->initialized_cv); |
|
|
|
@ -921,7 +921,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
if (worker->initialized_cv) { |
|
|
|
|
gpr_cv_destroy(&worker->cv); |
|
|
|
|
} |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_DEBUG, " .. remove worker"); |
|
|
|
|
} |
|
|
|
|
if (EMPTIED == worker_remove(pollset, worker)) { |
|
|
|
@ -993,7 +993,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
GPR_TIMER_BEGIN("pollset_kick", 0); |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK(exec_ctx); |
|
|
|
|
grpc_error* ret_err = GRPC_ERROR_NONE; |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_strvec log; |
|
|
|
|
gpr_strvec_init(&log); |
|
|
|
|
char* tmp; |
|
|
|
@ -1026,7 +1026,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
if (root_worker == NULL) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); |
|
|
|
|
pollset->kicked_without_poller = true; |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kicked_without_poller"); |
|
|
|
|
} |
|
|
|
|
goto done; |
|
|
|
@ -1034,14 +1034,14 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
grpc_pollset_worker* next_worker = root_worker->next; |
|
|
|
|
if (root_worker->state == KICKED) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. already kicked %p", root_worker); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(root_worker, KICKED); |
|
|
|
|
goto done; |
|
|
|
|
} else if (next_worker->state == KICKED) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. already kicked %p", next_worker); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(next_worker, KICKED); |
|
|
|
@ -1052,7 +1052,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
root_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load( |
|
|
|
|
&g_active_poller)) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kicked %p", root_worker); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(root_worker, KICKED); |
|
|
|
@ -1060,7 +1060,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
goto done; |
|
|
|
|
} else if (next_worker->state == UNKICKED) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kicked %p", next_worker); |
|
|
|
|
} |
|
|
|
|
GPR_ASSERT(next_worker->initialized_cv); |
|
|
|
@ -1069,7 +1069,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
goto done; |
|
|
|
|
} else if (next_worker->state == DESIGNATED_POLLER) { |
|
|
|
|
if (root_worker->state != DESIGNATED_POLLER) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log( |
|
|
|
|
GPR_ERROR, |
|
|
|
|
" .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)", |
|
|
|
@ -1083,7 +1083,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
goto done; |
|
|
|
|
} else { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker, |
|
|
|
|
root_worker); |
|
|
|
|
} |
|
|
|
@ -1099,7 +1099,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kicked while waking up"); |
|
|
|
|
} |
|
|
|
|
goto done; |
|
|
|
@ -1109,14 +1109,14 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (specific_worker->state == KICKED) { |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. specific worker already kicked"); |
|
|
|
|
} |
|
|
|
|
goto done; |
|
|
|
|
} else if (gpr_tls_get(&g_current_thread_worker) == |
|
|
|
|
(intptr_t)specific_worker) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(specific_worker, KICKED); |
|
|
|
@ -1124,7 +1124,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
} else if (specific_worker == |
|
|
|
|
(grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kick active poller"); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(specific_worker, KICKED); |
|
|
|
@ -1132,7 +1132,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
goto done; |
|
|
|
|
} else if (specific_worker->initialized_cv) { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kick waiting worker"); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(specific_worker, KICKED); |
|
|
|
@ -1140,7 +1140,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, |
|
|
|
|
goto done; |
|
|
|
|
} else { |
|
|
|
|
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); |
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { |
|
|
|
|
if (grpc_polling_trace.enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, " .. kick non-waiting worker"); |
|
|
|
|
} |
|
|
|
|
SET_KICK_STATE(specific_worker, KICKED); |
|
|
|
|