1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Ericsson AB
8 #include <rte_common.h>
9 #include <rte_cycles.h>
10 #include <rte_random.h>
14 static volatile uint64_t vsum;
16 #define ITERATIONS (100000000)
18 #define BEST_CASE_BOUND (1<<16)
19 #define WORST_CASE_BOUND (BEST_CASE_BOUND + 1)
23 rand_type_bounded_best_case,
24 rand_type_bounded_worst_case
28 rand_type_desc(enum rand_type rand_type)
32 return "Full 64-bit [rte_rand()]";
33 case rand_type_bounded_best_case:
34 return "Bounded average best-case [rte_rand_max()]";
35 case rand_type_bounded_worst_case:
36 return "Bounded average worst-case [rte_rand_max()]";
42 static __rte_always_inline void
43 test_rand_perf_type(enum rand_type rand_type)
53 for (i = 0; i < ITERATIONS; i++) {
58 case rand_type_bounded_best_case:
59 sum += rte_rand_max(BEST_CASE_BOUND);
61 case rand_type_bounded_worst_case:
62 sum += rte_rand_max(WORST_CASE_BOUND);
69 /* to avoid an optimizing compiler removing the whole loop */
72 op_latency = (end - start) / ITERATIONS;
74 printf("%s: %"PRId64" TSC cycles/op\n", rand_type_desc(rand_type),
83 printf("Pseudo-random number generation latencies:\n");
85 test_rand_perf_type(rand_type_64);
86 test_rand_perf_type(rand_type_bounded_best_case);
87 test_rand_perf_type(rand_type_bounded_worst_case);
92 REGISTER_TEST_COMMAND(rand_perf_autotest, test_rand_perf);