From 7b2dd93362099eef75b49fe33b93692bb148b93f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 16 Mar 2017 16:25:12 -0700 Subject: Track milliseconds since process start in timer heap Allows reducing a lock-then-check to an atomic load and check on the fast path of timer checks. Reduces locks per RPC by about 5. --- test/core/iomgr/timer_heap_test.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'test/core/iomgr/timer_heap_test.c') diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c index 410d972313..153304fa7b 100644 --- a/test/core/iomgr/timer_heap_test.c +++ b/test/core/iomgr/timer_heap_test.c @@ -47,13 +47,7 @@ #include "test/core/util/test_config.h" -static gpr_timespec random_deadline(void) { - gpr_timespec ts; - ts.tv_sec = rand(); - ts.tv_nsec = rand(); - ts.clock_type = GPR_CLOCK_REALTIME; - return ts; -} +static gpr_atm random_deadline(void) { return rand(); } static grpc_timer *create_test_elements(size_t num_elements) { grpc_timer *elems = gpr_malloc(num_elements * sizeof(grpc_timer)); @@ -78,12 +72,10 @@ static void check_valid(grpc_timer_heap *pq) { size_t left_child = 1u + 2u * i; size_t right_child = left_child + 1u; if (left_child < pq->timer_count) { - GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline, - pq->timers[left_child]->deadline) <= 0); + GPR_ASSERT(pq->timers[i]->deadline <= pq->timers[left_child]->deadline); } if (right_child < pq->timer_count) { - GPR_ASSERT(gpr_time_cmp(pq->timers[i]->deadline, - pq->timers[right_child]->deadline) <= 0); + GPR_ASSERT(pq->timers[i]->deadline <= pq->timers[right_child]->deadline); } } } @@ -227,20 +219,19 @@ static void test2(void) { } if (num_inserted) { - gpr_timespec *min_deadline = NULL; + gpr_atm *min_deadline = NULL; for (size_t i = 0; i < elems_size; i++) { if (elems[i].inserted) { if (min_deadline == NULL) { min_deadline = &elems[i].elem.deadline; } else { - if (gpr_time_cmp(elems[i].elem.deadline, *min_deadline) < 0) { + if (elems[i].elem.deadline < *min_deadline) { min_deadline = &elems[i].elem.deadline; } } } } - GPR_ASSERT( - 0 == gpr_time_cmp(grpc_timer_heap_top(&pq)->deadline, *min_deadline)); + GPR_ASSERT(grpc_timer_heap_top(&pq)->deadline == *min_deadline); } } -- cgit v1.2.3