Explicitly call out round up vs round down

pull/11866/head
Craig Tiller 7 years ago
parent 9d0463b3f3
commit 9a8c3f398a
  1. 3
      src/core/ext/filters/client_channel/channel_connectivity.c
  2. 2
      src/core/ext/filters/client_channel/client_channel.c
  3. 17
      src/core/lib/iomgr/exec_ctx.c
  4. 3
      src/core/lib/iomgr/exec_ctx.h
  5. 4
      src/core/lib/surface/alarm.c
  6. 4
      src/core/lib/surface/channel.c
  7. 4
      src/core/lib/surface/completion_queue.c
  8. 3
      test/core/http/httpcli_test.c
  9. 3
      test/core/http/httpscli_test.c
  10. 4
      test/core/iomgr/endpoint_tests.c
  11. 3
      test/core/iomgr/resolve_address_posix_test.c
  12. 3
      test/core/iomgr/resolve_address_test.c
  13. 8
      test/core/iomgr/tcp_client_posix_test.c
  14. 10
      test/core/iomgr/tcp_posix_test.c
  15. 2
      test/core/iomgr/tcp_server_posix_test.c
  16. 3
      test/core/iomgr/udp_server_test.c
  17. 4
      test/core/util/test_tcp_server.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);
}

@ -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;

@ -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};

@ -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 */

@ -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;
}

@ -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;
}

@ -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),

@ -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) {

@ -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) {

@ -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;

@ -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) {

@ -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) {

@ -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);

@ -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;

@ -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 =

@ -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. */

@ -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",

Loading…
Cancel
Save