aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2021-03-30 12:43:55 +0000
committerMarko Zec <zec@FreeBSD.org>2021-06-20 11:25:58 +0000
commit402ddb85eed2332c6e876e68e0d319e07bb8223d (patch)
tree389b508fa57ce901b07227746af5016e5aa6adbd
parente5d8c43e170b1c45f13c030aff99ac25dba1593e (diff)
downloadsrc-402ddb85eed2332c6e876e68e0d319e07bb8223d.tar.gz
src-402ddb85eed2332c6e876e68e0d319e07bb8223d.zip
Add IPv4 fib lookup performance tests with uniform keys.
Submitted by: zec MFC after: 1 week (cherry picked from commit b8598e2ff65ab82da0cf6861ee12f078b40bc252)
-rw-r--r--sys/tests/fib_lookup/fib_lookup.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/sys/tests/fib_lookup/fib_lookup.c b/sys/tests/fib_lookup/fib_lookup.c
index 3dd1bb8d5a50..ea07e3d697c6 100644
--- a/sys/tests/fib_lookup/fib_lookup.c
+++ b/sys/tests/fib_lookup/fib_lookup.c
@@ -505,6 +505,58 @@ SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet_scan,
CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
0, 0, run_test_inet_scan, "I", "Execute fib4_lookup scan tests");
+static int
+rnd_lps(SYSCTL_HANDLER_ARGS)
+{
+ struct epoch_tracker et;
+ struct in_addr *keys;
+ struct nhop_object **nhops;
+
+ struct timespec ts_pre, ts_post;
+ uint64_t total_diff, lps;
+ int error;
+ int count = 0;
+
+ error = sysctl_handle_int(oidp, &count, 0, req);
+ if (error != 0)
+ return (error);
+ if (count <= 0)
+ return (0);
+
+ keys = malloc(sizeof(*keys) * count, M_TEMP, M_NOWAIT);
+ nhops = malloc(sizeof(*nhops) * count, M_TEMP, M_NOWAIT);
+ if (keys == NULL || nhops == NULL) {
+ free(keys, M_TEMP);
+ free(nhops, M_TEMP);
+ return (ENOMEM);
+ }
+
+ printf("Preparing %d random keys...\n", count);
+ arc4random_buf(keys, sizeof(*keys) * count);
+ printf("Starting LPS test...\n");
+
+ NET_EPOCH_ENTER(et);
+ nanouptime(&ts_pre);
+ for (int i = 0; i < count; i++)
+ nhops[i] = fib4_lookup(RT_DEFAULT_FIB, keys[i], 0, NHR_NONE, 0);
+ nanouptime(&ts_post);
+ NET_EPOCH_EXIT(et);
+
+ free(keys, M_TEMP);
+ free(nhops, M_TEMP);
+
+ total_diff = (ts_post.tv_sec - ts_pre.tv_sec) * 1000000000 +
+ (ts_post.tv_nsec - ts_pre.tv_nsec);
+ lps = 1000000000ULL * count / total_diff;
+ printf("%d lookups in %zu nanoseconds, %lu.%06lu MLPS\n",
+ count, total_diff, lps / 1000000, lps % 1000000);
+
+ return (0);
+}
+SYSCTL_PROC(_net_route_test, OID_AUTO, rnd_lps,
+ CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+ 0, 0, rnd_lps, "I",
+ "Measure lookups per second using uniformly random keys");
static int
test_fib_lookup_modevent(module_t mod, int type, void *unused)