[dpdk-dev] [PATCH v4 2/5] eal: add pseudo-random number generation performance test

Mattias Rönnblom mattias.ronnblom at ericsson.com
Fri Jun 28 11:01:21 CEST 2019


Add performance test for rte_rand().

Signed-off-by: Mattias Rönnblom <mattias.ronnblom at ericsson.com>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
 MAINTAINERS               |  1 +
 app/test/Makefile         |  1 +
 app/test/meson.build      |  2 ++
 app/test/test_rand_perf.c | 75 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+)
 create mode 100644 app/test/test_rand_perf.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 75775129d..bbec1982c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -231,6 +231,7 @@ Pseudo-random Number Generation
 M: Mattias Rönnblom <mattias.ronnblom at ericsson.com>
 F: lib/librte_eal/common/include/rte_random.h
 F: lib/librte_eal/common/rte_random.c
+F: app/test/test_rand_perf.c
 
 ARM v7
 M: Jan Viktorin <viktorin at rehivetech.com>
diff --git a/app/test/Makefile b/app/test/Makefile
index 68d6b4fbc..be0f39227 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -73,6 +73,7 @@ SRCS-y += test_reciprocal_division.c
 SRCS-y += test_reciprocal_division_perf.c
 SRCS-y += test_fbarray.c
 SRCS-y += test_external_mem.c
+SRCS-y += test_rand_perf.c
 
 SRCS-y += test_ring.c
 SRCS-y += test_ring_perf.c
diff --git a/app/test/meson.build b/app/test/meson.build
index 4de856f93..a47e001bf 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -89,6 +89,7 @@ test_sources = files('commands.c',
 	'test_power_acpi_cpufreq.c',
 	'test_power_kvm_vm.c',
 	'test_prefetch.c',
+	'test_rand_perf.c',
 	'test_rcu_qsbr.c',
 	'test_rcu_qsbr_perf.c',
 	'test_reciprocal_division.c',
@@ -254,6 +255,7 @@ perf_test_names = [
         'pmd_perf_autotest',
         'stack_perf_autotest',
         'stack_nb_perf_autotest',
+        'rand_perf_autotest'
 ]
 
 # All test cases in driver_test_names list are non-parallel
diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c
new file mode 100644
index 000000000..771713757
--- /dev/null
+++ b/app/test/test_rand_perf.c
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Ericsson AB
+ */
+
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <rte_common.h>
+#include <rte_cycles.h>
+#include <rte_random.h>
+
+#include "test.h"
+
+static volatile uint64_t vsum;
+
+#define ITERATIONS (100000000)
+
+enum rand_type {
+	rand_type_64
+};
+
+static const char *
+rand_type_desc(enum rand_type rand_type)
+{
+	switch (rand_type) {
+	case rand_type_64:
+		return "Full 64-bit [rte_rand()]";
+	default:
+		return NULL;
+	}
+}
+
+static __rte_always_inline void
+test_rand_perf_type(enum rand_type rand_type)
+{
+	uint64_t start;
+	uint32_t i;
+	uint64_t end;
+	uint64_t sum = 0;
+	uint64_t op_latency;
+
+	start = rte_rdtsc();
+
+	for (i = 0; i < ITERATIONS; i++) {
+		switch (rand_type) {
+		case rand_type_64:
+			sum += rte_rand();
+			break;
+		}
+	}
+
+	end = rte_rdtsc();
+
+	/* to avoid an optimizing compiler removing the whole loop */
+	vsum = sum;
+
+	op_latency = (end - start) / ITERATIONS;
+
+	printf("%s: %"PRId64" TSC cycles/op\n", rand_type_desc(rand_type),
+	       op_latency);
+}
+
+static int
+test_rand_perf(void)
+{
+	rte_srand(42);
+
+	printf("Pseudo-random number generation latencies:\n");
+
+	test_rand_perf_type(rand_type_64);
+
+	return 0;
+}
+
+REGISTER_TEST_COMMAND(rand_perf_autotest, test_rand_perf);
-- 
2.17.1



More information about the dev mailing list