[3/6] examples/l2fwd-keepalive: use rte_drand_max

Message ID 20240301175842.159967-4-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Coverity related fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger March 1, 2024, 5:57 p.m. UTC
  There is a better way than using rand() to compute a random interval.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/l2fwd-keepalive/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index 7e0f99a361bc..c077e7f3d4f0 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -26,6 +26,7 @@ 
 #include <rte_launch.h>
 #include <rte_cycles.h>
 #include <rte_prefetch.h>
+#include <rte_random.h>
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_branch_prediction.h>
@@ -220,7 +221,7 @@  l2fwd_main_loop(void)
 	}
 
 	uint64_t tsc_initial = rte_rdtsc();
-	uint64_t tsc_lifetime = (rand()&0x07) * rte_get_tsc_hz();
+	uint64_t tsc_lifetime = rte_rand_max(8 * rte_get_tsc_hz());
 
 	while (!terminate_signal_received) {
 		/* Keepalive heartbeat. 8< */