|
|
|
@ -66,9 +66,8 @@ |
|
|
|
|
#include "src/core/lib/support/block_annotate.h" |
|
|
|
|
|
|
|
|
|
/* TODO: sreek - Move this to init.c and initialize this like other tracers. */ |
|
|
|
|
static int grpc_polling_trace = 0; /* Disabled by default */ |
|
|
|
|
#define GRPC_POLLING_TRACE(fmt, ...) \ |
|
|
|
|
if (grpc_polling_trace) { \
|
|
|
|
|
if (GRPC_TRACER_ON(grpc_polling_trace)) { \
|
|
|
|
|
gpr_log(GPR_INFO, (fmt), __VA_ARGS__); \
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -77,13 +76,10 @@ static int grpc_polling_trace = 0; /* Disabled by default */ |
|
|
|
|
* alarm 'epoch'). This wakeup_fd gives us something to alert on when such a |
|
|
|
|
* case occurs. */ |
|
|
|
|
|
|
|
|
|
/* TODO: sreek: Right now, this wakes up all pollers. In future we should make
|
|
|
|
|
* sure to wake up one polling thread (which can wake up other threads if |
|
|
|
|
* needed) */ |
|
|
|
|
static grpc_wakeup_fd global_wakeup_fd; |
|
|
|
|
|
|
|
|
|
struct epoll_set; |
|
|
|
|
|
|
|
|
|
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1) |
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Fd Declarations |
|
|
|
|
*/ |
|
|
|
@ -362,7 +358,7 @@ static void epoll_set_add_wakeup_fd_locked(epoll_set *eps, |
|
|
|
|
gpr_asprintf(&err_msg, |
|
|
|
|
"epoll_ctl (epoll_fd: %d) add wakeup fd: %d failed with " |
|
|
|
|
"error: %d (%s)", |
|
|
|
|
eps->epoll_fd, GRPC_WAKEUP_FD_GET_READ_FD(&global_wakeup_fd), |
|
|
|
|
eps->epoll_fd, GRPC_WAKEUP_FD_GET_READ_FD(wakeup_fd), |
|
|
|
|
errno, strerror(errno)); |
|
|
|
|
append_error(error, GRPC_OS_ERROR(errno, err_msg), err_desc); |
|
|
|
|
gpr_free(err_msg); |
|
|
|
@ -423,7 +419,6 @@ static epoll_set *epoll_set_create(grpc_error **error) { |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
epoll_set_add_wakeup_fd_locked(eps, &global_wakeup_fd, error); |
|
|
|
|
epoll_set_add_wakeup_fd_locked(eps, &eps->workqueue_wakeup_fd, error); |
|
|
|
|
|
|
|
|
|
done: |
|
|
|
@ -703,11 +698,10 @@ static void pollset_worker_init(grpc_pollset_worker *worker) { |
|
|
|
|
static grpc_error *pollset_global_init(void) { |
|
|
|
|
gpr_tls_init(&g_current_thread_pollset); |
|
|
|
|
gpr_tls_init(&g_current_thread_worker); |
|
|
|
|
return grpc_wakeup_fd_init(&global_wakeup_fd); |
|
|
|
|
return GRPC_ERROR_NONE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void pollset_global_shutdown(void) { |
|
|
|
|
grpc_wakeup_fd_destroy(&global_wakeup_fd); |
|
|
|
|
gpr_tls_destroy(&g_current_thread_pollset); |
|
|
|
|
gpr_tls_destroy(&g_current_thread_worker); |
|
|
|
|
} |
|
|
|
@ -802,10 +796,6 @@ static grpc_error *pollset_kick(grpc_pollset *p, |
|
|
|
|
return error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_error *kick_poller(void) { |
|
|
|
|
return grpc_wakeup_fd_wakeup(&global_wakeup_fd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void pollset_init(grpc_pollset *pollset, gpr_mu **mu) { |
|
|
|
|
gpr_mu_init(&pollset->mu); |
|
|
|
|
*mu = &pollset->mu; |
|
|
|
@ -870,7 +860,7 @@ static void pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, |
|
|
|
|
/* pollset_shutdown is guaranteed to be called before pollset_destroy. So other
|
|
|
|
|
* than destroying the mutexes, there is nothing special that needs to be done |
|
|
|
|
* here */ |
|
|
|
|
static void pollset_destroy(grpc_pollset *pollset) { |
|
|
|
|
static void pollset_destroy(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset) { |
|
|
|
|
GPR_ASSERT(!pollset_has_workers(pollset)); |
|
|
|
|
gpr_mu_destroy(&pollset->mu); |
|
|
|
|
} |
|
|
|
@ -944,11 +934,7 @@ static void do_epoll_wait(grpc_exec_ctx *exec_ctx, int epoll_fd, epoll_set *eps, |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ep_rv; ++i) { |
|
|
|
|
void *data_ptr = ep_ev[i].data.ptr; |
|
|
|
|
if (data_ptr == &global_wakeup_fd) { |
|
|
|
|
grpc_timer_consume_kick(); |
|
|
|
|
append_error(error, grpc_wakeup_fd_consume_wakeup(&global_wakeup_fd), |
|
|
|
|
err_desc); |
|
|
|
|
} else if (data_ptr == &eps->workqueue_wakeup_fd) { |
|
|
|
|
if (data_ptr == &eps->workqueue_wakeup_fd) { |
|
|
|
|
append_error(error, |
|
|
|
|
grpc_wakeup_fd_consume_wakeup(&eps->workqueue_wakeup_fd), |
|
|
|
|
err_desc); |
|
|
|
@ -1152,8 +1138,6 @@ static const grpc_event_engine_vtable vtable = { |
|
|
|
|
.pollset_set_add_fd = pollset_set_add_fd, |
|
|
|
|
.pollset_set_del_fd = pollset_set_del_fd, |
|
|
|
|
|
|
|
|
|
.kick_poller = kick_poller, |
|
|
|
|
|
|
|
|
|
.workqueue_ref = workqueue_ref, |
|
|
|
|
.workqueue_unref = workqueue_unref, |
|
|
|
|
.workqueue_scheduler = workqueue_scheduler, |
|
|
|
@ -1227,11 +1211,12 @@ static void shutdown_epoll_sets() { |
|
|
|
|
for (size_t i = 0; i < g_num_eps; i++) { |
|
|
|
|
EPS_UNREF(&exec_ctx, g_epoll_sets[i], "shutdown_epoll_sets"); |
|
|
|
|
} |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
|
|
|
|
|
|
gpr_free(g_epoll_sets); |
|
|
|
|
g_epoll_sets = NULL; |
|
|
|
|
pollset_destroy(&g_read_notifier); |
|
|
|
|
pollset_destroy(&exec_ctx, &g_read_notifier); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void poller_thread_loop(void *arg) { |
|
|
|
@ -1306,7 +1291,9 @@ static bool is_epoll_available() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const grpc_event_engine_vtable *grpc_init_epoll_thread_pool_linux(void) { |
|
|
|
|
const grpc_event_engine_vtable *grpc_init_epoll_thread_pool_linux(bool requested_explicitly) { |
|
|
|
|
if (!requested_explicitly) return NULL; |
|
|
|
|
|
|
|
|
|
if (!grpc_has_wakeup_fd()) { |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
@ -1341,6 +1328,6 @@ const grpc_event_engine_vtable *grpc_init_epoll_thread_pool_linux(void) { |
|
|
|
|
#include "src/core/lib/iomgr/ev_posix.h" |
|
|
|
|
/* If GRPC_LINUX_EPOLL is not defined, it means epoll is not available. Return
|
|
|
|
|
* NULL */ |
|
|
|
|
const grpc_event_engine_vtable *grpc_init_epoll_linux(void) { return NULL; } |
|
|
|
|
const grpc_event_engine_vtable *grpc_init_epoll_linux(bool requested_explicitly) { return NULL; } |
|
|
|
|
#endif /* defined(GRPC_POSIX_SOCKET) */ |
|
|
|
|
#endif /* !defined(GRPC_LINUX_EPOLL) */ |
|
|
|
|