DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [RFC] rte_timer: add rte_timer_next_ticks
@ 2019-06-10 22:44 Stephen Hemminger
  2019-06-11 13:37 ` Sanford, Robert
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Stephen Hemminger @ 2019-06-10 22:44 UTC (permalink / raw)
  To: rsanford, erik.g.carrillo; +Cc: dev, Stephen Hemminger

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 <stephen@networkplumber.org>
---
 lib/librte_timer/rte_timer.c           | 21 +++++++++++++++++++++
 lib/librte_timer/rte_timer.h           | 14 ++++++++++++++
 lib/librte_timer/rte_timer_version.map |  1 +
 3 files changed, 36 insertions(+)

diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c
index dd795392244c..e9bd3c845470 100644
--- a/lib/librte_timer/rte_timer.c
+++ b/lib/librte_timer/rte_timer.c
@@ -1032,6 +1032,27 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
 	return 0;
 }
 
+int64_t __rte_experimental
+rte_timer_next_ticks(void)
+{
+	struct priv_timer *priv_timer = default_timer_data.priv_timer;
+	unsigned int lcore_id = rte_lcore_id();
+	uint64_t cur_time = rte_get_timer_cycles();
+	const struct rte_timer *tm;
+	int64_t left = -1;
+
+	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 2196934b2e29..1c1d3cfd6d4f 100644
--- a/lib/librte_timer/rte_timer.h
+++ b/lib/librte_timer/rte_timer.h
@@ -338,6 +338,20 @@ void rte_timer_stop_sync(struct rte_timer *tim);
  */
 int rte_timer_pending(struct rte_timer *tim);
 
+/**
+ * Time until the next timer
+ *
+ * This function gives the interval until the next timer
+ * will be active.
+ *
+ * @return
+ *   0: A timer is already pending
+ *   -1: No timer is pending
+ *   otherwise ticks until the next timer.
+ */
+int64_t __rte_experimental
+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 72f75c818134..d64400bcc7bd 100644
--- a/lib/librte_timer/rte_timer_version.map
+++ b/lib/librte_timer/rte_timer_version.map
@@ -33,6 +33,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;
 };
-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-20  0:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 22:44 [dpdk-dev] [RFC] rte_timer: add rte_timer_next_ticks Stephen Hemminger
2019-06-11 13:37 ` Sanford, Robert
2019-06-11 14:27   ` Stephen Hemminger
2019-06-11 14:45     ` Sanford, Robert
2019-06-12 18:19 ` Carrillo, Erik G
2019-12-17  0:55 ` [dpdk-dev] [PATCH v1] " Stephen Hemminger
2019-12-20 22:43   ` Carrillo, Erik G
2020-01-20  0:38     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).