aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreecha@users.noreply.github.com>2017-12-12 11:25:17 -0800
committerGravatar GitHub <noreply@github.com>2017-12-12 11:25:17 -0800
commit66d10191b0c677174284b9e0f47dc4799f1013d3 (patch)
treeeddce129c44919580a1cc6c01e53ea015c715f31 /src/core
parent8cfaf4ec4fd2aa5197487664aea3a586f1217bad (diff)
parentca398ee74a7aed2a45ae58e3c5753c4c99e4d683 (diff)
Merge pull request #13631 from sreecha/cv-wait-monotonic
Use monotonic clock type for gpr_cv_wait
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lib/iomgr/ev_epoll1_linux.cc2
-rw-r--r--src/core/lib/iomgr/ev_poll_posix.cc8
-rw-r--r--src/core/lib/iomgr/executor.cc2
-rw-r--r--src/core/lib/iomgr/iomgr.cc2
-rw-r--r--src/core/lib/iomgr/timer_manager.cc4
-rw-r--r--src/core/lib/support/sync_posix.cc11
-rw-r--r--src/core/lib/surface/completion_queue.cc2
-rw-r--r--src/core/lib/surface/server.cc2
8 files changed, 21 insertions, 12 deletions
diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc
index d9e8a30f5e..ae9d47ece5 100644
--- a/src/core/lib/iomgr/ev_epoll1_linux.cc
+++ b/src/core/lib/iomgr/ev_epoll1_linux.cc
@@ -738,7 +738,7 @@ static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}
if (gpr_cv_wait(&worker->cv, &pollset->mu,
- grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME)) &&
+ grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)) &&
worker->state == UNKICKED) {
/* If gpr_cv_wait returns true (i.e a timeout), pretend that the worker
received a kick */
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc
index 006e3ddd2f..53de94fb6e 100644
--- a/src/core/lib/iomgr/ev_poll_posix.cc
+++ b/src/core/lib/iomgr/ev_poll_posix.cc
@@ -1471,7 +1471,7 @@ static void run_poll(void* args) {
decref_poll_result(result);
// Leave this polling thread alive for a grace period to do another poll()
// op
- gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME);
+ gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC);
deadline = gpr_time_add(deadline, thread_grace);
pargs->trigger_set = 0;
gpr_cv_wait(&pargs->trigger, &g_cvfds.mu, deadline);
@@ -1526,9 +1526,9 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) {
}
}
- gpr_timespec deadline = gpr_now(GPR_CLOCK_REALTIME);
+ gpr_timespec deadline = gpr_now(GPR_CLOCK_MONOTONIC);
if (timeout < 0) {
- deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+ deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
} else {
deadline =
gpr_time_add(deadline, gpr_time_from_millis(timeout, GPR_TIMESPAN));
@@ -1631,7 +1631,7 @@ static void global_cv_fd_table_shutdown() {
// Not doing so will result in reported memory leaks
if (!gpr_unref(&g_cvfds.pollcount)) {
int res = gpr_cv_wait(&g_cvfds.shutdown_cv, &g_cvfds.mu,
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_seconds(3, GPR_TIMESPAN)));
GPR_ASSERT(res == 0);
}
diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc
index b45223ce16..b7288d5bf3 100644
--- a/src/core/lib/iomgr/executor.cc
+++ b/src/core/lib/iomgr/executor.cc
@@ -155,7 +155,7 @@ static void executor_thread(void* arg) {
ts->depth -= subtract_depth;
while (grpc_closure_list_empty(ts->elems) && !ts->shutdown) {
ts->queued_long_job = false;
- gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
+ gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
if (ts->shutdown) {
if (executor_trace.enabled()) {
diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc
index dacf08ea9e..70807c479d 100644
--- a/src/core/lib/iomgr/iomgr.cc
+++ b/src/core/lib/iomgr/iomgr.cc
@@ -118,7 +118,7 @@ void grpc_iomgr_shutdown() {
abort();
}
gpr_timespec short_deadline =
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_millis(100, GPR_TIMESPAN));
if (gpr_cv_wait(&g_rcv, &g_mu, short_deadline)) {
if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) >
diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc
index 8ca6a3c23e..7fb068f10f 100644
--- a/src/core/lib/iomgr/timer_manager.cc
+++ b/src/core/lib/iomgr/timer_manager.cc
@@ -192,7 +192,7 @@ static bool wait_until(grpc_millis next) {
}
gpr_cv_wait(&g_cv_wait, &g_mu,
- grpc_millis_to_timespec(next, GPR_CLOCK_REALTIME));
+ grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "wait ended: was_timed:%d kicked:%d",
@@ -317,7 +317,7 @@ static void stop_threads(void) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
}
while (g_thread_count > 0) {
- gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME));
+ gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
}
diff --git a/src/core/lib/support/sync_posix.cc b/src/core/lib/support/sync_posix.cc
index dfdd233bf4..c3f6b10463 100644
--- a/src/core/lib/support/sync_posix.cc
+++ b/src/core/lib/support/sync_posix.cc
@@ -66,7 +66,12 @@ int gpr_mu_trylock(gpr_mu* mu) {
/*----------------------------------------*/
void gpr_cv_init(gpr_cv* cv) {
- GPR_ASSERT(pthread_cond_init(cv, nullptr) == 0);
+ pthread_condattr_t attr;
+ GPR_ASSERT(pthread_condattr_init(&attr) == 0);
+#if GPR_LINUX
+ GPR_ASSERT(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0);
+#endif // GPR_LINUX
+ GPR_ASSERT(pthread_cond_init(cv, &attr) == 0);
}
void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); }
@@ -78,7 +83,11 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
err = pthread_cond_wait(cv, mu);
} else {
struct timespec abs_deadline_ts;
+#if GPR_LINUX
+ abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_MONOTONIC);
+#else
abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME);
+#endif // GPR_LINUX
abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec;
abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc
index 12385b7130..aa5808da4c 100644
--- a/src/core/lib/surface/completion_queue.cc
+++ b/src/core/lib/surface/completion_queue.cc
@@ -115,7 +115,7 @@ static grpc_error* non_polling_poller_work(grpc_pollset* pollset,
}
w.kicked = false;
gpr_timespec deadline_ts =
- grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME);
+ grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC);
while (!npp->shutdown && !w.kicked &&
!gpr_cv_wait(&w.cv, &npp->mu, deadline_ts))
;
diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc
index 4f07183180..f1d428f0a1 100644
--- a/src/core/lib/surface/server.cc
+++ b/src/core/lib/surface/server.cc
@@ -1170,7 +1170,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server,
gpr_mu_lock(&server->mu_global);
while (server->starting) {
gpr_cv_wait(&server->starting_cv, &server->mu_global,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
/* stay locked, and gather up some stuff to do */