From 3778059a51fcbc6b989ca7503a3ff89f6945ddd2 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 30 May 2013 17:12:36 +0000 Subject: [PATCH] timer: optimize for empty case In many application there are no timers queued, and the call to rte_timer_managecan be optimized in that case avoid reading HPET and lock overhead. Signed-off-by: Stephen Hemminger Reviewed-by: Vincent Jardin --- lib/librte_timer/rte_timer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 095547a5b6..c9b253a820 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -403,9 +403,14 @@ void rte_timer_manage(void) union rte_timer_status status; struct rte_timer *tim, *tim2; unsigned lcore_id = rte_lcore_id(); - uint64_t cur_time = rte_get_hpet_cycles(); + uint64_t cur_time; int ret; + /* optimize for the case where per-cpu list is empty */ + if (LIST_EMPTY(&priv_timer[lcore_id].pending)) + return; + + cur_time = rte_get_hpet_cycles(); __TIMER_STAT_ADD(manage, 1); /* browse ordered list, add expired timers in 'expired' list */ -- 2.20.1