examples/timer: fix incorrect time interval
PATCH 1/1 examples/timer: fix incorrect time interval
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.
This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the rte_rdtsc() is replaced with the more recommended rte_get_timer_cycles function in this patch.
--- examples/timer/main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
examples/timer/main.c +12 -10
@@ -18,8 +18,7 @@#include <rte_timer.h> #include <rte_debug.h> -#define TIMER_RESOLUTION_CYCLES 20000000ULL/* around 10ms at 2 Ghz */ - +static uint64_t timer_resolution_cycles;static struct rte_timer timer0;static struct rte_timer timer1;
@@ -66,15 +65,16 @@ lcore_mainloop(__rte_unused void *arg)while (1 ) {/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. since rte_eal_hpet_init() has not been +* called, the rte_rdtsc() will be used at runtime. +* In a real application, this will enhance performances +* as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles (); diff_tsc = cur_tsc - prev_tsc; -if (diff_tsc >TIMER_RESOLUTION_CYCLES ) { +if (diff_tsc > timer_resolution_cycles) {rte_timer_manage (); prev_tsc = cur_tsc; }
@@ -100,8 +100,10 @@ main(int argc, char **argv)rte_timer_init (&timer0);rte_timer_init (&timer1); -/* load timer0, every second, on main lcore, reloaded automatically */ hz =rte_get_timer_hz (); + timer_resolution_cycles = hz *10 /1000 ;/* around 10ms */ + +/* load timer0, every second, on main lcore, reloaded automatically */ lcore_id =rte_lcore_id ();rte_timer_reset (&timer0, hz,PERIODICAL , lcore_id, timer0_cb,NULL );
Signature · 1 line
2.7.4
15/04/2021 09:12, Min Hu (Connor):
Quoted 6 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.
So rte_timer_manage() will be called less often, yes.
Quoted 2 lines
This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
I am not sure about making the example more complex. What is the issue with the previous value?
Hi
Quoted 8 lines · Thomas Monjalon
15/04/2021 09:12, Min Hu (Connor):
Quoted 6 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.
Quoted 8 lines
So
rte_timer_manage()will be called less often, yes.Quoted 2 lines
This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
I am not sure about making the example more complex. What is the issue with the previous value?
In my understanding, the example should illustrate the standard usage of related functions. Some of our customers did not know the difference in tsc frequency between arm and x86 when using our SoC. As a result, some misunderstanding are caused. So I think I could explain a more general approach in the example, which will help these new users. When using a timer, we must first know its frequency. So I've added a frequency acquisition process to the example, so that new users can realize that there are differences between different platforms, so that they can design more general programs.
Quoted 5 lines
.
Quoted 18 lines
-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 15, 2021 2:12 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; [email protected]; Carrillo, Erik G <[email protected]>
Subject: [PATCH] examples/timer: fix incorrect time intervalFrom: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
Quoted 8 lines
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
This LGTM - thanks.
15/04/2021 09:12, Min Hu (Connor):
Quoted 18 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
[...]
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 71
Quoted 10 lines
examples/timer/main.c +4
-5/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. since rte_eal_hpet_init() has not been +* called, the rte_rdtsc() will be used at runtime.
I don't understand this last sentence.
Quoted 5 lines
examples/timer/main.c +3
-1+* In a real application, this will enhance performances +* as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles ();
Quoted 20 lines · Thomas Monjalon
15/04/2021 09:12, Min Hu (Connor):
Quoted 18 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>[...]
Quoted 13 lines
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 71
Quoted 10 lines
examples/timer/main.c +4
-5/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. since rte_eal_hpet_init() has not been +* called, the rte_rdtsc() will be used at runtime. I don't understand this last sentence.
This is explaining why we can use rte_get_timer_cycles() instead of rte_rdtsc(). In this example, we call tsc to improve its performance. So, we invoked rte_rdtsc() here. Now the function rte_get_timer_cycles() encapsulates these counters. It will invoke the corresponding counter according to the user's initialization of the counter.
Quoted 11 lines
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 75
Quoted 5 lines
examples/timer/main.c +3
-1+* In a real application, this will enhance performances +* as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles ();.
06/05/2021 04:06, Chengchang Tang:
Quoted 36 lines · Thomas Monjalon
Quoted 20 lines
15/04/2021 09:12, Min Hu (Connor):
Quoted 18 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>[...]
Quoted 13 lines
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 71
Quoted 10 lines
examples/timer/main.c +4
-5/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. since rte_eal_hpet_init() has not been +* called, the rte_rdtsc() will be used at runtime. I don't understand this last sentence.
Quoted 4 lines
This is explaining why we can use
rte_get_timer_cycles()instead ofrte_rdtsc(). In this example, we call tsc to improve its performance. So, we invokedrte_rdtsc()here. Now the functionrte_get_timer_cycles()encapsulates these counters. It will invoke the corresponding counter according to the user's initialization of the counter.
That's very confusing. Better to drop.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
examples/timer/main.c +3
-1+* In a real application, this will enhance performances +* as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles ();
Quoted 37 lines · Thomas Monjalon
06/05/2021 04:06, Chengchang Tang:
Quoted 36 lines · Thomas Monjalon
Quoted 33 lines
15/04/2021 09:12, Min Hu (Connor):
Quoted 18 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>[...]
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 71
Quoted 10 lines
examples/timer/main.c +4
-5/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. since rte_eal_hpet_init() has not been +* called, the rte_rdtsc() will be used at runtime. I don't understand this last sentence.
Quoted 7 lines
Quoted 4 lines
This is explaining why we can use
rte_get_timer_cycles()instead ofrte_rdtsc(). In this example, we call tsc to improve its performance. So, we invokedrte_rdtsc()here. Now the functionrte_get_timer_cycles()encapsulates these counters. It will invoke the corresponding counter according to the user's initialization of the counter.That's very confusing. Better to drop.
OK, I will remove this sentence in the next version.
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
examples/timer/main.c lcore_mainloop(__rte_unused void *arg) · line 75
Quoted 6 lines
examples/timer/main.c +3
-1+* In a real application, this will enhance performances +* as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles ();.
PATCH v2 1/1 examples/timer: fix incorrect time interval
In reply to Min Hu (Connor)From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.
This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
In addition, the rte_rdtsc() is replaced with the more recommended rte_get_timer_cycles function in this patch.
---
v2:
* delete confusing comments.
--- examples/timer/main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
examples/timer/main.c +10 -10
@@ -18,8 +18,7 @@#include <rte_timer.h> #include <rte_debug.h> -#define TIMER_RESOLUTION_CYCLES 20000000ULL/* around 10ms at 2 Ghz */ - +static uint64_t timer_resolution_cycles;static struct rte_timer timer0;static struct rte_timer timer1;
@@ -66,15 +65,14 @@ lcore_mainloop(__rte_unused void *arg)while (1 ) {/* -* Call the timer handler on each core: as we don't -* need a very precise timer, so only call -* rte_timer_manage() every ~10ms (at 2Ghz). In a real -* application, this will enhance performances as -* reading the HPET timer is not efficient. +* Call the timer handler on each core: as we don't need a +* very precise timer, so only call rte_timer_manage() +* every ~10ms. In a real application, this will enhance +* performances as reading the HPET timer is not efficient. */ - cur_tsc =rte_rdtsc (); + cur_tsc =rte_get_timer_cycles (); diff_tsc = cur_tsc - prev_tsc; -if (diff_tsc >TIMER_RESOLUTION_CYCLES ) { +if (diff_tsc > timer_resolution_cycles) {rte_timer_manage (); prev_tsc = cur_tsc; }
@@ -100,8 +98,10 @@ main(int argc, char **argv)rte_timer_init (&timer0);rte_timer_init (&timer1); -/* load timer0, every second, on main lcore, reloaded automatically */ hz =rte_get_timer_hz (); + timer_resolution_cycles = hz *10 /1000 ;/* around 10ms */ + +/* load timer0, every second, on main lcore, reloaded automatically */ lcore_id =rte_lcore_id ();rte_timer_reset (&timer0, hz,PERIODICAL , lcore_id, timer0_cb,NULL );
Signature · 1 line
2.7.4
Thomas Monjalon
Applied06/05/2021 11:29, Min Hu (Connor):
Quoted 10 lines
From: Chengchang Tang <[email protected]>
Timer sample example assumes that the frequency of the timer is about 2Ghz to control the period of calling
rte_timer_manage(). But this assumption is easy to fail. For example. the frequency of tsc on ARM64 is much less than 2Ghz.This patch uses the frequency of the current timer to calculate the correct time interval to ensure consistent result on all platforms.
Quoted 8 lines
In addition, the
rte_rdtsc()is replaced with the more recommendedrte_get_timer_cyclesfunction in this patch.Fixes af75078fece3 ("first public release")Signed-off-by Chengchang Tang <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
Applied, thanks