From owner-dev-commits-src-main@freebsd.org Tue Mar 30 21:39:01 2021 Return-Path: Delivered-To: dev-commits-src-main@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 C72475AE863; Tue, 30 Mar 2021 21:39:01 +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 4F92rj5DQyz3P2M; Tue, 30 Mar 2021 21:39:01 +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 A21045F12; Tue, 30 Mar 2021 21:39:01 +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 12ULd1xF034647; Tue, 30 Mar 2021 21:39:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12ULd1ap034646; Tue, 30 Mar 2021 21:39:01 GMT (envelope-from git) Date: Tue, 30 Mar 2021 21:39:01 GMT Message-Id: <202103302139.12ULd1ap034646@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: b8598e2ff65a - main - Add IPv4 fib lookup performance tests with uniform keys. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b8598e2ff65ab82da0cf6861ee12f078b40bc252 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Mar 2021 21:39:01 -0000 The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=b8598e2ff65ab82da0cf6861ee12f078b40bc252 commit b8598e2ff65ab82da0cf6861ee12f078b40bc252 Author: Alexander V. Chernikov AuthorDate: 2021-03-30 12:43:55 +0000 Commit: Alexander V. Chernikov CommitDate: 2021-03-30 13:32:28 +0000 Add IPv4 fib lookup performance tests with uniform keys. Submitted by: zec MFC after: 1 week --- sys/tests/fib_lookup/fib_lookup.c | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) 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)