From owner-dev-commits-src-all@freebsd.org Sun Jun 20 11:31:15 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 02B0F64D4F6; Sun, 20 Jun 2021 11:31:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G79TZ6Rcgz4rGg; Sun, 20 Jun 2021 11:31:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8EC7DDCC; Sun, 20 Jun 2021 11:31:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15KBVEQA099152; Sun, 20 Jun 2021 11:31:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15KBVECL099151; Sun, 20 Jun 2021 11:31:14 GMT (envelope-from git) Date: Sun, 20 Jun 2021 11:31:14 GMT Message-Id: <202106201131.15KBVECL099151@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marko Zec Subject: git: 09274116f4d9 - stable/13 - tests: Revise FIB lookups per second benchmarking routines MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zec X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 09274116f4d90f5c25cfad3bd7d13b48b2d494da Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jun 2021 11:31:15 -0000 The branch stable/13 has been updated by zec: URL: https://cgit.FreeBSD.org/src/commit/?id=09274116f4d90f5c25cfad3bd7d13b48b2d494da commit 09274116f4d90f5c25cfad3bd7d13b48b2d494da Author: Marko Zec AuthorDate: 2021-06-17 06:49:09 +0000 Commit: Marko Zec CommitDate: 2021-06-20 11:27:17 +0000 tests: Revise FIB lookups per second benchmarking routines Fix a bug in the LPM SEQ benchmark (missing break inside a switch block) by restructuring the test loop, while introducing additional two synthetic test options: ANN: scan only the address space announced in current RIB REP: repeat lookups over several keys in a sliding window scheme The total of eight combinations of test options are now available through dedicated sysctl hooks. Differential Revision: Reviewed by: melifaro MFC after: 3 days (cherry picked from commit b6f8436b094daf7b1c429ce74997a4daf6994fcb) --- sys/tests/fib_lookup/fib_lookup.c | 140 ++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 21 deletions(-) diff --git a/sys/tests/fib_lookup/fib_lookup.c b/sys/tests/fib_lookup/fib_lookup.c index 4093ff9dd487..927664166fdd 100644 --- a/sys/tests/fib_lookup/fib_lookup.c +++ b/sys/tests/fib_lookup/fib_lookup.c @@ -505,16 +505,46 @@ 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"); +#define LPS_SEQ 0x1 +#define LPS_ANN 0x2 +#define LPS_REP 0x4 + +struct lps_walk_state { + uint32_t *keys; + int pos; + int lim; +}; + +static int +reduce_keys(struct rtentry *rt, void *_data) +{ + struct lps_walk_state *wa = (struct lps_walk_state *) _data; + struct in_addr addr; + uint32_t scopeid; + int plen; + + rt_get_inet_prefix_plen(rt, &addr, &plen, &scopeid); + wa->keys[wa->pos] = ntohl(addr.s_addr) | + (wa->keys[wa->pos] & ~(0xffffffffU << (32 - plen))); + + wa->pos++; + return (wa->pos == wa->lim); +} + static int rnd_lps(SYSCTL_HANDLER_ARGS) { struct epoch_tracker et; struct in_addr key; + struct lps_walk_state wa; struct timespec ts_pre, ts_post; + struct nhop_object *nh_fib; uint64_t total_diff, lps; uint32_t *keys; + uint32_t t, p; uintptr_t acc = 0; - int count = 0; + int i, pos, count = 0; + int seq = 0, rep = 0; int error; error = sysctl_handle_int(oidp, &count, 0, req); @@ -526,25 +556,62 @@ rnd_lps(SYSCTL_HANDLER_ARGS) keys = malloc(sizeof(*keys) * count, M_TEMP, M_NOWAIT); if (keys == NULL) return (ENOMEM); - printf("Preparing %d random keys...\n", count); arc4random_buf(keys, sizeof(*keys) * count); - printf("Starting LPS test...\n"); + if (arg2 & LPS_ANN) { + wa.keys = keys; + wa.pos = 0; + wa.lim = count; + printf("Reducing keys to announced address space...\n"); + do { + rib_walk(RT_DEFAULT_FIB, AF_INET, false, reduce_keys, + &wa); + } while (wa.pos < wa.lim); + printf("Reshuffling keys...\n"); + for (int i = 0; i < count; i++) { + p = random() % count; + t = keys[p]; + keys[p] = keys[i]; + keys[i] = t; + } + } + + if (arg2 & LPS_REP) { + rep = 1; + printf("REP "); + } + if (arg2 & LPS_SEQ) { + seq = 1; + printf("SEQ"); + } else if (arg2 & LPS_ANN) + printf("ANN"); + else + printf("RND"); + printf(" LPS test starting...\n"); NET_EPOCH_ENTER(et); nanouptime(&ts_pre); - switch (arg2) { - case 0: - for (int i = 0; i < count; i++) { - key.s_addr = keys[i] + acc; - acc += (uintptr_t) fib4_lookup(RT_DEFAULT_FIB, key, 0, - NHR_NONE, 0); + for (i = 0, pos = 0; i < count; i++) { + key.s_addr = keys[pos++] ^ ((acc >> 10) & 0xff); + nh_fib = fib4_lookup(RT_DEFAULT_FIB, key, 0, NHR_NONE, 0); + if (seq) { + if (nh_fib != NULL) { + acc += (uintptr_t) nh_fib + 123; + if (acc & 0x1000) + acc += (uintptr_t) nh_fib->nh_ifp; + else + acc -= (uintptr_t) nh_fib->nh_ifp; + } else + acc ^= (acc >> 3) + (acc << 2) + i; + if (acc & 0x800) + pos++; + if (pos >= count) + pos = 0; } - case 1: - for (int i = 0; i < count; i++) { - key.s_addr = keys[i]; - acc += (uintptr_t) fib4_lookup(RT_DEFAULT_FIB, key, 0, - NHR_NONE, 0); + if (rep && ((i & 0xf) == 0xf)) { + pos -= 0xf; + if (pos < 0) + pos += 0xf; } } nanouptime(&ts_post); @@ -553,22 +620,53 @@ rnd_lps(SYSCTL_HANDLER_ARGS) free(keys, M_TEMP); total_diff = (ts_post.tv_sec - ts_pre.tv_sec) * 1000000000 + - (ts_post.tv_nsec - ts_pre.tv_nsec) + (acc & 1); + (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); + printf("%d lookups in %zu.%06zu milliseconds, %lu.%06lu MLPS\n", + count, total_diff / 1000000, total_diff % 1000000, + lps / 1000000, lps % 1000000); return (0); } -SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_seq, +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_rnd, CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0, rnd_lps, "I", + "Measure lookups per second, uniformly random keys, independent lookups"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_rnd_ann, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_ANN, rnd_lps, "I", + "Measure lookups per second, random keys from announced address space, " + "independent lookups"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_seq, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_SEQ, rnd_lps, "I", "Measure lookups per second, uniformly random keys, " "artificial dependencies between lookups"); -SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_rnd, +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_seq_ann, CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, - 0, 1, rnd_lps, "I", - "Measure lookups per second, uniformly random keys, independent lookups"); + 0, LPS_SEQ | LPS_ANN, rnd_lps, "I", + "Measure lookups per second, random keys from announced address space, " + "artificial dependencies between lookups"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_rnd_rep, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_REP, rnd_lps, "I", + "Measure lookups per second, uniformly random keys, independent lookups, " + "repeated keys"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_rnd_ann_rep, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_ANN | LPS_REP, rnd_lps, "I", + "Measure lookups per second, random keys from announced address space, " + "independent lookups, repeated keys"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_seq_rep, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_SEQ | LPS_REP, rnd_lps, "I", + "Measure lookups per second, uniformly random keys, " + "artificial dependencies between lookups, repeated keys"); +SYSCTL_PROC(_net_route_test, OID_AUTO, run_lps_seq_ann_rep, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + 0, LPS_SEQ | LPS_ANN | LPS_REP, rnd_lps, "I", + "Measure lookups per second, random keys from announced address space, " + "artificial dependencies between lookups, repeated keys"); static int test_fib_lookup_modevent(module_t mod, int type, void *unused)