diff options
author | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2021-03-30 12:43:55 +0000 |
---|---|---|
committer | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2021-03-30 13:32:28 +0000 |
commit | b8598e2ff65ab82da0cf6861ee12f078b40bc252 (patch) | |
tree | de2a4a6872b1fd5f88ffdc707e657f0abcf11716 | |
parent | 75e67b4920f2d70b98bd1383966d17d541b7c46c (diff) | |
download | src-b8598e2ff65ab82da0cf6861ee12f078b40bc252.tar.gz src-b8598e2ff65ab82da0cf6861ee12f078b40bc252.zip |
-rw-r--r-- | sys/tests/fib_lookup/fib_lookup.c | 52 |
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) |