Skip to contentSkip to conversation

examples/link_status_interrupt: fix stats refresh rate

PATCH In review Raja Zidane 3 participants 4 messages May 30, 2022 – Jul 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/link_status_interrupt: fix stats refresh rate

TIMER_MILLISECOND is defined as the number of cpu cycles per millisecond, current definition is correct for cores with frequency of 2GHZ, for cores with different frequency, it caused different periods between refresh, (i.e. the definition is about 14ms on ARM cores).

Use dpdk API to get CPU frequency, to define TIMER_MILLISECOND.

Fixes af75078fece3 ("first public release")
---
 examples/link_status_interrupt/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
examples/link_status_interrupt/main.c +4 -2
index 551f0524da..eb7a74d37c 100644
@@ -101,9 +101,10 @@ struct lsi_port_statistics {
 struct lsi_port_statistics port_statistics[RTE_MAX_ETHPORTS];
 
 /* A tsc-based timer responsible for triggering statistics printout */
-#define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */
+#define TIMER_MILLISECOND (rte_get_tsc_hz() / 1000)
 #define MAX_TIMER_PERIOD 86400 /* 1 day max */
-static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */
+#define DEFAULT_TIMER_PERIOD 10UL /* default period is 10 seconds */
+static int64_t timer_period;
 
 /* Print out statistics on packets dropped */
 static void
@@ -371,6 +372,7 @@ lsi_parse_args(int argc, char **argv)
 	};
 
 	argvopt = argv;
+	timer_period = DEFAULT_TIMER_PERIOD;
 
 	while ((opt = getopt_long(argc, argvopt, "p:q:T:",
 				  lgopts, &option_index)) != EOF) {
Signature · 1 line
2.21.0
#1 lore raw

30/05/2022 11:37, Raja Zidane:

Quoted 15 lines

TIMER_MILLISECOND is defined as the number of cpu cycles per millisecond, current definition is correct for cores with frequency of 2GHZ, for cores with different frequency, it caused different periods between refresh, (i.e. the definition is about 14ms on ARM cores).

Use dpdk API to get CPU frequency, to define TIMER_MILLISECOND.

Fixes af75078fece3 ("first public release")

---

examples/link_status_interrupt/main.c struct lsi_port_statistics { · line 104

Quoted 3 lines
examples/link_status_interrupt/main.c +1 -1
 /* A tsc-based timer responsible for triggering statistics printout */
-#define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */
+#define TIMER_MILLISECOND (rte_get_tsc_hz() / 1000)

It is preferred to use rte_get_timer_hz().

Quoted 4 lines

#define MAX_TIMER_PERIOD 86400 /* 1 day max */

examples/link_status_interrupt/main.c +2 -1
-static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */
+#define DEFAULT_TIMER_PERIOD 10UL /* default period is 10 seconds */
+static int64_t timer_period;

[...]

examples/link_status_interrupt/main.c lsi_parse_args(int argc, char **argv) · line 375

Quoted 1 line
examples/link_status_interrupt/main.c +1 -0
+	timer_period = DEFAULT_TIMER_PERIOD;

After a quick look, it seems we are missing the operation
* TIMER_MILLISECOND * 1000
Isn't it?

#2 lore raw

PATCH v2 1/1 examples/link_status_interrupt: fix stats refresh rate

In reply to Raja Zidane

From: Raja Zidane <[email protected]>

TIMER_MILLISECOND is defined as the number of cpu cycles per millisecond, current definition is correct for cores with frequency of 2GHZ, for cores with different frequency, it caused different periods between refresh, (i.e. the definition is about 14ms on ARM cores).

Use dpdk API to get CPU frequency, to define TIMER_MILLISECOND.

Fixes af75078fece3 ("first public release")

---
v2: use rte_get_timer_hz instead of rte_get_tsc_hz
update initial timer value to be in seconds
---

---
 examples/link_status_interrupt/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
examples/link_status_interrupt/main.c +5 -2
index 551f0524da..79dd7461fd 100644
@@ -101,9 +101,10 @@ struct lsi_port_statistics {
 struct lsi_port_statistics port_statistics[RTE_MAX_ETHPORTS];
 
 /* A tsc-based timer responsible for triggering statistics printout */
-#define TIMER_MILLISECOND 2000000ULL /* around 1ms at 2 Ghz */
+#define TIMER_MILLISECOND (rte_get_timer_hz() / 1000)
 #define MAX_TIMER_PERIOD 86400 /* 1 day max */
-static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */
+#define DEFAULT_TIMER_PERIOD 10UL /* default period is 10 seconds */
+static int64_t timer_period;
 
 /* Print out statistics on packets dropped */
 static void
@@ -370,6 +371,8 @@ lsi_parse_args(int argc, char **argv)
 		{NULL, 0, 0, 0}
 	};
 
+        timer_period = DEFAULT_TIMER_PERIOD * TIMER_MILLISECOND * 1000;
+
 	argvopt = argv;
 
 	while ((opt = getopt_long(argc, argvopt, "p:q:T:",
Signature · 1 line
2.17.1
#3 lore raw

07/07/2022 10:22, Omar Awaysa:

Quoted 7 lines

From: Raja Zidane <[email protected]>

TIMER_MILLISECOND is defined as the number of cpu cycles per millisecond, current definition is correct for cores with frequency of 2GHZ, for cores with different frequency, it caused different periods between refresh, (i.e. the definition is about 14ms on ARM cores).

Quoted 6 lines

Use dpdk API to get CPU frequency, to define TIMER_MILLISECOND.

Fixes af75078fece3 ("first public release")

Applied (with indent fixed), thanks.