aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-06-16 16:53:59 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-06-16 19:20:12 -0700
commit2e12db9c319bcbdbb2fa570149f88e4b496b558c (patch)
tree6cd2e5d495050de06c0d526419ea38a84034abdc /src
parent812c66ba1bd811efb10457cb0e8b4d1f22329167 (diff)
Test polling island merges
Diffstat (limited to 'src')
-rw-r--r--src/core/lib/iomgr/ev_epoll_linux.c51
-rw-r--r--src/core/lib/iomgr/ev_epoll_linux.h6
-rw-r--r--src/core/lib/iomgr/ev_posix.c7
-rw-r--r--src/core/lib/iomgr/ev_posix.h3
4 files changed, 65 insertions, 2 deletions
diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c
index 1fb5947464..ed2c494b78 100644
--- a/src/core/lib/iomgr/ev_epoll_linux.c
+++ b/src/core/lib/iomgr/ev_epoll_linux.c
@@ -317,8 +317,9 @@ static void polling_island_remove_all_fds_locked(polling_island *pi,
if (err < 0 && errno != ENOENT) {
/* TODO: sreek - We need a better way to bubble up this error instead of
* just logging a message */
- gpr_log(GPR_ERROR, "epoll_ctl deleting fds[%zu]: %d failed with error: %s",
- i, pi->fds[i]->fd, strerror(errno));
+ gpr_log(GPR_ERROR,
+ "epoll_ctl deleting fds[%zu]: %d failed with error: %s", i,
+ pi->fds[i]->fd, strerror(errno));
}
if (remove_fd_refs) {
@@ -1458,6 +1459,52 @@ static void pollset_set_del_pollset_set(grpc_exec_ctx *exec_ctx,
gpr_mu_unlock(&bag->mu);
}
+/* Test helper functions
+ * */
+void *grpc_fd_get_polling_island(grpc_fd *fd) {
+ polling_island *pi;
+
+ gpr_mu_lock(&fd->pi_mu);
+ pi = fd->polling_island;
+ gpr_mu_unlock(&fd->pi_mu);
+
+ return pi;
+}
+
+void *grpc_pollset_get_polling_island(grpc_pollset *ps) {
+ polling_island *pi;
+
+ gpr_mu_lock(&ps->pi_mu);
+ pi = ps->polling_island;
+ gpr_mu_unlock(&ps->pi_mu);
+
+ return pi;
+}
+
+static polling_island *get_polling_island(polling_island *p) {
+ if (p == NULL) {
+ return NULL;
+ }
+
+ polling_island *next;
+ gpr_mu_lock(&p->mu);
+ while (p->merged_to != NULL) {
+ next = p->merged_to;
+ gpr_mu_unlock(&p->mu);
+ p = next;
+ gpr_mu_lock(&p->mu);
+ }
+ gpr_mu_unlock(&p->mu);
+
+ return p;
+}
+
+bool grpc_are_polling_islands_equal(void *p, void *q) {
+ p = get_polling_island(p);
+ q = get_polling_island(q);
+ return p == q;
+}
+
/*******************************************************************************
* Event engine binding
*/
diff --git a/src/core/lib/iomgr/ev_epoll_linux.h b/src/core/lib/iomgr/ev_epoll_linux.h
index 8c819975a4..7a494aba19 100644
--- a/src/core/lib/iomgr/ev_epoll_linux.h
+++ b/src/core/lib/iomgr/ev_epoll_linux.h
@@ -38,4 +38,10 @@
const grpc_event_engine_vtable *grpc_init_epoll_linux(void);
+#ifdef GPR_LINUX_EPOLL
+void *grpc_fd_get_polling_island(grpc_fd *fd);
+void *grpc_pollset_get_polling_island(grpc_pollset *ps);
+bool grpc_are_polling_islands_equal(void *p, void *q);
+#endif /* defined(GPR_LINUX_EPOLL) */
+
#endif /* GRPC_CORE_LIB_IOMGR_EV_EPOLL_LINUX_H */
diff --git a/src/core/lib/iomgr/ev_posix.c b/src/core/lib/iomgr/ev_posix.c
index 2b15967adc..5b20600a6f 100644
--- a/src/core/lib/iomgr/ev_posix.c
+++ b/src/core/lib/iomgr/ev_posix.c
@@ -54,6 +54,7 @@
grpc_poll_function_type grpc_poll_function = poll;
static const grpc_event_engine_vtable *g_event_engine;
+static const char* g_poll_strategy_name = NULL;
typedef const grpc_event_engine_vtable *(*event_engine_factory_fn)(void);
@@ -101,6 +102,7 @@ static void try_engine(const char *engine) {
for (size_t i = 0; i < GPR_ARRAY_SIZE(g_factories); i++) {
if (is(engine, g_factories[i].name)) {
if ((g_event_engine = g_factories[i].factory())) {
+ g_poll_strategy_name = g_factories[i].name;
gpr_log(GPR_DEBUG, "Using polling engine: %s", g_factories[i].name);
return;
}
@@ -108,6 +110,11 @@ static void try_engine(const char *engine) {
}
}
+/* Call this only after calling grpc_event_engine_init() */
+const char *grpc_get_poll_strategy_name() {
+ return g_poll_strategy_name;
+}
+
void grpc_event_engine_init(void) {
char *s = gpr_getenv("GRPC_POLL_STRATEGY");
if (s == NULL) {
diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h
index 344bf63438..3ed5a5f956 100644
--- a/src/core/lib/iomgr/ev_posix.h
+++ b/src/core/lib/iomgr/ev_posix.h
@@ -98,6 +98,9 @@ typedef struct grpc_event_engine_vtable {
void grpc_event_engine_init(void);
void grpc_event_engine_shutdown(void);
+/* Return the name of the poll strategy */
+const char* grpc_get_poll_strategy_name();
+
/* Create a wrapped file descriptor.
Requires fd is a non-blocking file descriptor.
This takes ownership of closing fd. */