[PATCH 3/6] examples/l2fwd-keepalive: use rte_drand_max
Stephen Hemminger
stephen at networkplumber.org
Fri Mar 1 18:57:08 CET 2024
There is a better way than using rand() to compute a random interval.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
examples/l2fwd-keepalive/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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< */
--
2.43.0
More information about the dev
mailing list