Skip to contentSkip to conversation

rte_timer: add rte_timer_next_ticks

RFC In review Stephen Hemminger 4 participants 8 messages Jun 10, 2019 – Jan 20, 2020

lore
Share & tools
lore
#0 lore raw

RFC 1/1 rte_timer: add rte_timer_next_ticks

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.

---
 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(+)
lib/librte_timer/rte_timer.c +21 -0
index dd795392244c..e9bd3c845470 100644
@@ -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)
lib/librte_timer/rte_timer.h +14 -0
index 2196934b2e29..1c1d3cfd6d4f 100644
@@ -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.
  *
lib/librte_timer/rte_timer_version.map +1 -0
index 72f75c818134..d64400bcc7bd 100644
@@ -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;
 };
Signature · 1 line
2.20.1
#1 lore raw

Hi Stephen,

The code seems fine. My only comment is that there is not a blank line before the new code, in both the .c and .h.

--
Regards,
Robert

On 6/10/19, 6:45 PM, "Stephen Hemminger" <[email protected]> wrote:

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.

---
 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(+)
lib/librte_timer/rte_timer.c +21 -0
index dd795392244c..e9bd3c845470 100644
@@ -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)
lib/librte_timer/rte_timer.h +14 -0
index 2196934b2e29..1c1d3cfd6d4f 100644
@@ -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.
  *
lib/librte_timer/rte_timer_version.map +1 -0
index 72f75c818134..d64400bcc7bd 100644
@@ -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;
 };
Signature · 1 line
2.20.1
#2 lore raw
Quoted 6 lines · Robert

Hi Stephen,

The code seems fine. My only comment is that there is not a blank line before the new code, in both the .c and .h.

--
Regards

Where, I see the blank line between functions and checkpatch is happy.

#3 lore raw

You are correct. I just looked at it in Patchwork. Sorry about that. (I should learn never to trust Outlook for Mac.)

On 6/11/19, 10:27 AM, "Stephen Hemminger" <[email protected]> wrote:

Quoted 6 lines · Robert

Hi Stephen,

The code seems fine. My only comment is that there is not a blank line before the new code, in both the .c and .h.

--
Regards

Where, I see the blank line between functions and checkpatch is happy.

#4 lore raw
In reply to Stephen Hemminger

Hi Stephen,

This looks like a useful addition. Some comments in-line:

Quoted 23 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, June 10, 2019 5:45 PM
To: [email protected]; Carrillo, Erik G <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>
Subject: [RFC] rte_timer: add rte_timer_next_ticks

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.

---
 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(+)
lib/librte_timer/rte_timer.c index renamed from lib/librte_timer/rte_timer.c +0 -0

dd795392244c..e9bd3c845470 100644

lib/librte_timer/rte_timer.c rte_timer_stop_all(uint32_t timer_data_id, · line 1039

Quoted 8 lines
lib/librte_timer/rte_timer.c +4 -0
@@ -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;

The timer data instance used above is used by the legacy API. We should do something like the following instead:

lib/librte_timer/rte_timer.c +4 -1
@@ -1035,15 +1035,24 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
 int64_t __rte_experimental
 rte_timer_next_ticks(void)
 {
-       struct priv_timer *priv_timer = default_timer_data.priv_timer;
+       struct priv_timer *priv_timer;
+       struct rte_timer_data *timer_data;
        unsigned int lcore_id = rte_lcore_id();
        uint64_t cur_time = rte_get_timer_cycles();
        const struct rte_timer *tm;
        int64_t left = -1;
 
+       TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVAL);
+       priv_timer = timer_data->priv_timer;
 

This will select the correct instance that was allocated in shared memory.

Quoted 25 lines
lib/librte_timer/rte_timer.c +17 -0
+	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

lib/librte_timer/rte_timer.h void rte_timer_stop_sync(struct rte_timer *tim); · line 341

Quoted 4 lines
lib/librte_timer/rte_timer.h +1 -0
@@ -338,6 +338,20 @@ void rte_timer_stop_sync(struct rte_timer *tim);
  */
 int rte_timer_pending(struct rte_timer *tim);
 
+/**

This comment is missing the "@warning" and "@b EXPERIMENTAL" lines.

lib/librte_timer/rte_timer.h void rte_timer_stop_sync(struct rte_timer *tim); · line 344

Quoted 3 lines
lib/librte_timer/rte_timer.h +3 -0
+ * Time until the next timer
+ *
+ * This function gives the interval until the next timer

s/interval/interval in ticks/ ?

lib/librte_timer/rte_timer.h void rte_timer_stop_sync(struct rte_timer *tim); · line 348

Quoted 4 lines
lib/librte_timer/rte_timer.h +4 -0
+ * will be active.
+ *
+ * @return
+ *   0: A timer is already pending

I would say "The next timer has already expired" or "A timer is already running" here... the timer library describes timers that have been started but have not yet expired as "pending".

Quoted 23 lines
lib/librte_timer/rte_timer.h +6 -0
+ *   -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.
  *
lib/librte_timer/rte_timer_version.map +1 -1
index 72f75c818134..d64400bcc7bd 100644
@@ -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;
 };
--
Quoted 1 line

2.20.1

Thanks,
Erik

#5 lore raw

PATCH 1/1 rte_timer: add rte_timer_next_ticks

In reply to 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.

---
v1 - incorporate feedback from old RFC

 lib/librte_timer/rte_timer.c           | 27 ++++++++++++++++++++++++++
 lib/librte_timer/rte_timer.h           | 16 +++++++++++++++
 lib/librte_timer/rte_timer_version.map |  1 +
 3 files changed, 44 insertions(+)
lib/librte_timer/rte_timer.c +27 -0
index ca88454ff68a..a1ed186cf591 100644
@@ -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)
lib/librte_timer/rte_timer.h +16 -0
index 9dc5fc309249..c5031d0448ba 100644
@@ -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
+ * 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.
  *
lib/librte_timer/rte_timer_version.map +1 -0
index 2a59d3f081c4..4471cef92be5 100644
@@ -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;
 };
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#6 lore raw

Hi Stephen,

I added a comment in-line. With that change, it looks good to me:

Regards,
Erik

Quoted 66 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, December 16, 2019 6:55 PM
To: [email protected]
Cc: Carrillo, Erik G <[email protected]>; Stephen Hemminger <[email protected]>
Subject: [PATCH v1] rte_timer: add rte_timer_next_ticks

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.

---
v1 - incorporate feedback from old RFC

 lib/librte_timer/rte_timer.c           | 27 ++++++++++++++++++++++++++
 lib/librte_timer/rte_timer.h           | 16 +++++++++++++++
 lib/librte_timer/rte_timer_version.map |  1 +
 3 files changed, 44 insertions(+)
lib/librte_timer/rte_timer.c index renamed from lib/librte_timer/rte_timer.c +0 -0

ca88454ff68a..a1ed186cf591 100644

lib/librte_timer/rte_timer.c +27 -0
@@ -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 9dc5fc309249..c5031d0448ba 100644

lib/librte_timer/rte_timer.h void rte_timer_stop_sync(struct rte_timer *tim); · line 338

Quoted 8 lines
lib/librte_timer/rte_timer.h +5 -0
@@ -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

s/next timer/next timer on the current lcore

Quoted 29 lines
lib/librte_timer/rte_timer.h +11 -0
+ * 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.
  *
lib/librte_timer/rte_timer_version.map +1 -1
index 2a59d3f081c4..4471cef92be5 100644
@@ -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;
 };
--

2.20.1

#7 lore raw

20/12/2019 23:43, Carrillo, Erik G:

Quoted 5 lines

Hi Stephen,

I added a comment in-line. With that change, it looks good to me:

Applied with below change, thanks.

Quoted 11 lines

From: Stephen Hemminger <[email protected]>

Quoted 7 lines

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.

---
+ * Time until the next timer

s/next timer/next timer on the current lcore