diff options
-rw-r--r-- | src/core/ext/filters/client_channel/channel_connectivity.c | 3 | ||||
-rw-r--r-- | src/core/ext/filters/client_channel/client_channel.c | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/exec_ctx.c | 17 | ||||
-rw-r--r-- | src/core/lib/iomgr/exec_ctx.h | 3 | ||||
-rw-r--r-- | src/core/lib/surface/alarm.c | 4 | ||||
-rw-r--r-- | src/core/lib/surface/channel.c | 4 | ||||
-rw-r--r-- | src/core/lib/surface/completion_queue.c | 4 | ||||
-rw-r--r-- | test/core/http/httpcli_test.c | 3 | ||||
-rw-r--r-- | test/core/http/httpscli_test.c | 3 | ||||
-rw-r--r-- | test/core/iomgr/endpoint_tests.c | 4 | ||||
-rw-r--r-- | test/core/iomgr/resolve_address_posix_test.c | 3 | ||||
-rw-r--r-- | test/core/iomgr/resolve_address_test.c | 3 | ||||
-rw-r--r-- | test/core/iomgr/tcp_client_posix_test.c | 8 | ||||
-rw-r--r-- | test/core/iomgr/tcp_posix_test.c | 10 | ||||
-rw-r--r-- | test/core/iomgr/tcp_server_posix_test.c | 2 | ||||
-rw-r--r-- | test/core/iomgr/udp_server_test.c | 3 | ||||
-rw-r--r-- | test/core/util/test_tcp_server.c | 4 |
17 files changed, 51 insertions, 29 deletions
diff --git a/src/core/ext/filters/client_channel/channel_connectivity.c b/src/core/ext/filters/client_channel/channel_connectivity.c index 72324d7eb1..0a1d6f3207 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.c +++ b/src/core/ext/filters/client_channel/channel_connectivity.c @@ -186,7 +186,8 @@ static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg, watcher_timer_init_arg *wa = (watcher_timer_init_arg *)arg; grpc_timer_init(exec_ctx, &wa->w->alarm, - grpc_timespec_to_millis(wa->deadline), &wa->w->on_timeout); + grpc_timespec_to_millis_round_up(wa->deadline), + &wa->w->on_timeout); gpr_free(wa); } diff --git a/src/core/ext/filters/client_channel/client_channel.c b/src/core/ext/filters/client_channel/client_channel.c index 508c473c6a..47bbd8416e 100644 --- a/src/core/ext/filters/client_channel/client_channel.c +++ b/src/core/ext/filters/client_channel/client_channel.c @@ -956,7 +956,7 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx, if (chand->deadline_checking_enabled && calld->method_params->timeout != 0) { const grpc_millis per_method_deadline = - grpc_timespec_to_millis(calld->call_start_time) + + grpc_timespec_to_millis_round_up(calld->call_start_time) + calld->method_params->timeout; if (per_method_deadline < calld->deadline) { calld->deadline = per_method_deadline; diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c index 80aaaee0cb..884227b928 100644 --- a/src/core/lib/iomgr/exec_ctx.c +++ b/src/core/lib/iomgr/exec_ctx.c @@ -125,6 +125,16 @@ static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) { return (gpr_atm)x; } +static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) { + ts = gpr_time_sub(ts, g_start_time); + double x = GPR_MS_PER_SEC * (double)ts.tv_sec + + (double)ts.tv_nsec / GPR_NS_PER_MS + + (double)(GPR_NS_PER_SEC - 1) / (double)GPR_NS_PER_SEC; + if (x < 0) return 0; + if (x > GPR_ATM_MAX) return GPR_ATM_MAX; + return (gpr_atm)x; +} + grpc_millis grpc_exec_ctx_now(grpc_exec_ctx *exec_ctx) { if (!exec_ctx->now_is_valid) { exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC)); @@ -143,11 +153,16 @@ gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_time_from_millis(millis, GPR_TIMESPAN)); } -grpc_millis grpc_timespec_to_millis(gpr_timespec ts) { +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec ts) { return timespec_to_atm_round_down( gpr_convert_clock_type(ts, g_start_time.clock_type)); } +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) { + return timespec_to_atm_round_up( + gpr_convert_clock_type(ts, g_start_time.clock_type)); +} + static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index 87383809f3..bb561ee1c8 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -114,6 +114,7 @@ void grpc_exec_ctx_global_shutdown(void); grpc_millis grpc_exec_ctx_now(grpc_exec_ctx *exec_ctx); void grpc_exec_ctx_invalidate_now(grpc_exec_ctx *exec_ctx); gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock); -grpc_millis grpc_timespec_to_millis(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec); +grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec); #endif /* GRPC_CORE_LIB_IOMGR_EXEC_CTX_H */ diff --git a/src/core/lib/surface/alarm.c b/src/core/lib/surface/alarm.c index 5140780bac..39b9f45d05 100644 --- a/src/core/lib/surface/alarm.c +++ b/src/core/lib/surface/alarm.c @@ -52,8 +52,8 @@ grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline, grpc_cq_begin_op(cq, tag); GRPC_CLOSURE_INIT(&alarm->on_alarm, alarm_cb, alarm, grpc_schedule_on_exec_ctx); - grpc_timer_init(&exec_ctx, &alarm->alarm, grpc_timespec_to_millis(deadline), - &alarm->on_alarm); + grpc_timer_init(&exec_ctx, &alarm->alarm, + grpc_timespec_to_millis_round_up(deadline), &alarm->on_alarm); grpc_exec_ctx_finish(&exec_ctx); return alarm; } diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index b0ff428393..9013e6338b 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -276,7 +276,7 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref_internal(*host)) : GRPC_MDNULL, - grpc_timespec_to_millis(deadline)); + grpc_timespec_to_millis_round_up(deadline)); grpc_exec_ctx_finish(&exec_ctx); return call; } @@ -341,7 +341,7 @@ grpc_call *grpc_channel_create_registered_call( grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), - grpc_timespec_to_millis(deadline)); + grpc_timespec_to_millis_round_up(deadline)); grpc_exec_ctx_finish(&exec_ctx); return call; } diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index f3a8977241..25f8ff6b6a 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -815,7 +815,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline, GRPC_CQ_INTERNAL_REF(cq, "next"); - grpc_millis deadline_millis = grpc_timespec_to_millis(deadline); + grpc_millis deadline_millis = grpc_timespec_to_millis_round_up(deadline); cq_is_finished_arg is_finished_arg = { .last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever), @@ -1048,7 +1048,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, GRPC_CQ_INTERNAL_REF(cq, "pluck"); gpr_mu_lock(cq->mu); - grpc_millis deadline_millis = grpc_timespec_to_millis(deadline); + grpc_millis deadline_millis = grpc_timespec_to_millis_round_up(deadline); cq_is_finished_arg is_finished_arg = { .last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever), diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c index ea63cd1df8..3634932ef1 100644 --- a/test/core/http/httpcli_test.c +++ b/test/core/http/httpcli_test.c @@ -36,7 +36,8 @@ static gpr_mu *g_mu; static grpc_polling_entity g_pops; static grpc_millis n_seconds_time(int seconds) { - return grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(seconds)); + return grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(seconds)); } static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c index 6d575d683d..d03dcdf779 100644 --- a/test/core/http/httpscli_test.c +++ b/test/core/http/httpscli_test.c @@ -36,7 +36,8 @@ static gpr_mu *g_mu; static grpc_polling_entity g_pops; static grpc_millis n_seconds_time(int seconds) { - return grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(seconds)); + return grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(seconds)); } static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index e80dce01cf..684858088f 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -176,7 +176,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, begin_test(config, "read_and_write_test", slice_size); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(20)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); gpr_log(GPR_DEBUG, "num_bytes=%" PRIuPTR " write_size=%" PRIuPTR " slice_size=%" PRIuPTR " shutdown=%d", num_bytes, write_size, slice_size, shutdown); @@ -261,7 +261,7 @@ static void wait_for_fail_count(grpc_exec_ctx *exec_ctx, int *fail_count, grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(g_mu); grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(10)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); while (grpc_exec_ctx_now(exec_ctx) < deadline && *fail_count < want_fail_count) { grpc_pollset_worker *worker = NULL; diff --git a/test/core/iomgr/resolve_address_posix_test.c b/test/core/iomgr/resolve_address_posix_test.c index d9d200d2c4..0a18ec7508 100644 --- a/test/core/iomgr/resolve_address_posix_test.c +++ b/test/core/iomgr/resolve_address_posix_test.c @@ -71,7 +71,8 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) { } static grpc_millis n_sec_deadline(int seconds) { - return grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(seconds)); + return grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(seconds)); } static void actually_poll(void *argsp) { diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c index c6c53be5ca..d475b552b0 100644 --- a/test/core/iomgr/resolve_address_test.c +++ b/test/core/iomgr/resolve_address_test.c @@ -68,7 +68,8 @@ void args_finish(grpc_exec_ctx *exec_ctx, args_struct *args) { } static grpc_millis n_sec_deadline(int seconds) { - return grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(seconds)); + return grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(seconds)); } static void poll_pollset_until_request_done(args_struct *args) { diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 69dc82f45e..3cae13ba08 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -47,7 +47,7 @@ static int g_connections_complete = 0; static grpc_endpoint *g_connecting = NULL; static grpc_millis test_deadline(void) { - return grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(10)); + return grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); } static void finish_connection() { @@ -124,9 +124,9 @@ void test_succeeds(void) { grpc_pollset_worker *worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", - grpc_pollset_work( - &exec_ctx, g_pollset, &worker, - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(5))))); + grpc_pollset_work(&exec_ctx, g_pollset, &worker, + grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(5))))); gpr_mu_unlock(g_mu); grpc_exec_ctx_flush(&exec_ctx); gpr_mu_lock(g_mu); diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index aa55b71725..03b707c247 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -162,7 +162,7 @@ static void read_test(size_t num_bytes, size_t slice_size) { struct read_socket_state state; size_t written_bytes; grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(20)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Read test of size %" PRIuPTR ", slice size %" PRIuPTR, @@ -215,7 +215,7 @@ static void large_read_test(size_t slice_size) { struct read_socket_state state; ssize_t written_bytes; grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(20)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, "Start large read test, slice size %" PRIuPTR, slice_size); @@ -318,7 +318,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, - grpc_timespec_to_millis( + grpc_timespec_to_millis_round_up( grpc_timeout_milliseconds_to_deadline(10))))); gpr_mu_unlock(g_mu); grpc_exec_ctx_finish(&exec_ctx); @@ -353,7 +353,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { grpc_slice_buffer outgoing; grpc_closure write_done_closure; grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(20)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_INFO, @@ -419,7 +419,7 @@ static void release_fd_test(size_t num_bytes, size_t slice_size) { size_t written_bytes; int fd; grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(20)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure fd_released_cb; int fd_released_done = 0; diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index 13ff92cb5b..0cde2d0e72 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -231,7 +231,7 @@ static void test_no_op_with_port_and_start(void) { static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote, on_connect_result *result) { grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(10)); + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); int clifd; int nconnects_before; const struct sockaddr *remote_addr = diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 2f6f503443..5977da3d44 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -252,7 +252,8 @@ static void test_receive(int number_of_clients) { gpr_mu_lock(g_mu); for (i = 0; i < number_of_clients; i++) { - deadline = grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(10)); + deadline = + grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10)); number_of_reads_before = g_number_of_reads; /* Create a socket, send a packet to the UDP server. */ diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c index ce05833aa9..611ecb330c 100644 --- a/test/core/util/test_tcp_server.c +++ b/test/core/util/test_tcp_server.c @@ -80,8 +80,8 @@ void test_tcp_server_start(test_tcp_server *server, int port) { void test_tcp_server_poll(test_tcp_server *server, int seconds) { grpc_pollset_worker *worker = NULL; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_millis deadline = - grpc_timespec_to_millis(grpc_timeout_seconds_to_deadline(seconds)); + grpc_millis deadline = grpc_timespec_to_millis_round_up( + grpc_timeout_seconds_to_deadline(seconds)); gpr_mu_lock(server->mu); GRPC_LOG_IF_ERROR( "pollset_work", |