From: Stephen Hemminger Date: Tue, 17 Dec 2019 00:55:03 +0000 (-0800) Subject: timer: add API to query ticks until the next timer X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=cd7c59dc044bab88c632f9916428331203a824b6;p=dpdk.git timer: add API to query ticks until the next timer It is useful to know when the next timer will expire when using rte_epoll_wait (or sleep when idle). This experimental API provides a hook to query the number of ticks remaining. Signed-off-by: Stephen Hemminger Acked-by: Erik Gabriel Carrillo --- diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index ca88454ff6..a1ed186cf5 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -978,6 +978,33 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores, return 0; } +int64_t +rte_timer_next_ticks(void) +{ + unsigned int lcore_id = rte_lcore_id(); + struct rte_timer_data *timer_data; + struct priv_timer *priv_timer; + const struct rte_timer *tm; + uint64_t cur_time; + int64_t left = -ENOENT; + + TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVAL); + + priv_timer = timer_data->priv_timer; + cur_time = rte_get_timer_cycles(); + + rte_spinlock_lock(&priv_timer[lcore_id].list_lock); + tm = priv_timer[lcore_id].pending_head.sl_next[0]; + if (tm) { + left = tm->expire - cur_time; + if (left < 0) + left = 0; + } + rte_spinlock_unlock(&priv_timer[lcore_id].list_lock); + + return left; +} + /* dump statistics about timers */ static void __rte_timer_dump_stats(struct rte_timer_data *timer_data __rte_unused, FILE *f) diff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h index 9dc5fc3092..c6b3d450df 100644 --- a/lib/librte_timer/rte_timer.h +++ b/lib/librte_timer/rte_timer.h @@ -331,6 +331,22 @@ void rte_timer_stop_sync(struct rte_timer *tim); */ int rte_timer_pending(struct rte_timer *tim); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Time until the next timer on the current lcore + * This function gives the ticks until the next timer will be active. + * + * @return + * - -EINVAL: invalid timer data instance identifier + * - -ENOENT: no timer pending + * - 0: a timer is pending and will run at next rte_timer_manage() + * - >0: ticks until the next timer is ready + */ +__rte_experimental +int64_t rte_timer_next_ticks(void); + /** * Manage the timer list and execute callback functions. * diff --git a/lib/librte_timer/rte_timer_version.map b/lib/librte_timer/rte_timer_version.map index 2a59d3f081..4471cef92b 100644 --- a/lib/librte_timer/rte_timer_version.map +++ b/lib/librte_timer/rte_timer_version.map @@ -23,6 +23,7 @@ EXPERIMENTAL { rte_timer_alt_stop; rte_timer_data_alloc; rte_timer_data_dealloc; + rte_timer_next_ticks; rte_timer_stop_all; rte_timer_subsystem_finalize; };