enum rand_type {
rand_type_64,
+ rand_type_float,
rand_type_bounded_best_case,
rand_type_bounded_worst_case
};
switch (rand_type) {
case rand_type_64:
return "Full 64-bit [rte_rand()]";
+ case rand_type_float:
+ return "Floating point [rte_drand()]";
case rand_type_bounded_best_case:
return "Bounded average best-case [rte_rand_max()]";
case rand_type_bounded_worst_case:
case rand_type_64:
sum += rte_rand();
break;
+ case rand_type_float:
+ sum += 1000. * rte_drand();
+ break;
case rand_type_bounded_best_case:
sum += rte_rand_max(BEST_CASE_BOUND);
break;
printf("Pseudo-random number generation latencies:\n");
test_rand_perf_type(rand_type_64);
+ test_rand_perf_type(rand_type_float);
test_rand_perf_type(rand_type_bounded_best_case);
test_rand_perf_type(rand_type_bounded_worst_case);
(seqlock). A seqlock allows for low overhead, parallel reads. The
DPDK seqlock uses a spinlock to serialize multiple writing threads.
+* ** Added function get random floating point number.**
+
+ Added the function ``rte_drand()`` to provide a pseudo-random
+ floating point number.
+
* **Added protocol based input color selection for meter.**
Added new functions ``rte_mtr_color_in_protocol_set()``,
return res;
}
+double
+rte_drand(void)
+{
+ static const uint64_t denom = (uint64_t)1 << 53;
+ uint64_t rand64 = rte_rand();
+
+ /*
+ * The double mantissa only has 53 bits, so we uniformly mask off the
+ * high 11 bits and then floating-point divide by 2^53 to achieve a
+ * result in [0, 1).
+ *
+ * We are not allowed to emit 1.0, so denom must be one greater than
+ * the possible range of the preceding step.
+ */
+
+ rand64 &= denom - 1;
+ return (double)rand64 / denom;
+}
+
static uint64_t
__rte_random_initial_seed(void)
{
uint64_t
rte_rand_max(uint64_t upper_bound);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Generates a pseudo-random floating point number.
+ *
+ * This function returns a non-negative double-precision floating random
+ * number uniformly distributed over the interval [0.0, 1.0).
+ *
+ * The generator is not cryptographically secure.
+ * If called from lcore threads, this function is thread-safe.
+ *
+ * @return
+ * A pseudo-random value between 0 and 1.0.
+ */
+__rte_experimental
+double rte_drand(void);
+
#ifdef __cplusplus
}
#endif
rte_intr_type_set;
# added in 22.07
+ rte_drand;
rte_thread_get_affinity_by_id;
rte_thread_get_priority;
rte_thread_self;