From nobody Wed May 22 17:34:55 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vkz2m1H45z5M63Y; Wed, 22 May 2024 17:34:56 +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 4Vkz2l5L5Kz4kGH; Wed, 22 May 2024 17:34:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716399295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MVSVOJURmilM7lC8s2kCcXY8KkVJlYDe901a3iKtWOw=; b=kGLVvOzKBqyk56F+D7ogbmxGK5vD92i3saPuOsl5DzuPUEADNGtmqdQMUQY0K3xHYVNS+p GWuOF3qRl6GmyjurBURaELBzbz2Ye6/94jVEbgXNsPcHGh1GeCvxUOU6igNTFIDviCXC6c WAbx+Y2YpjHfYvJiG0rbTCui2fkpu7fFmXjO/ppvltiKTf6bU/MKZimEzRmTQUcUC8uYcA ulKIkhL50A631tFsncu55tDzbpKPog0qjyramQHY1VXgSU+0O86NM8bj2x9rR5Wco1oIDu f0g+VdJrpYs9IbdlqztYJG9HqCFJjyAeVvYk9DGAlSyA6F592BOq1YqTcaGghg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716399295; a=rsa-sha256; cv=none; b=a9YHsB473p/fBJ4gAsdKKNV8Aj0Yr+ept5ZSxkAyWkN4QVhS9Ir+jCQfbgjLhI0YKaiovi f7YLftDDufl2fvv/pX+oIRHDrTTc9AIOY50Wo9ngAfR3yg471x6e0CmAR/rVj8NA4o4Obe xi8msMw1UIUHg9TXI5c7kcWLvfbXWf4qKgfqbNhsUQm1ZnyKo+DLW+rgQ9IVnSAY28PrZY wh64jDI0Un7Db4dAoxpp7P+LNUJ8u9iIOS7zUAqIvzbmGL+TAu3vbGPKwFQCgw31mOx8x6 vKQb2yLIKofurEShCR3h94crw8gthfQa9q4b0ccipgx+Hmcos7BGs4puHQZ8qw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716399295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MVSVOJURmilM7lC8s2kCcXY8KkVJlYDe901a3iKtWOw=; b=nbiZgKb9gL0J0z3hJUjGQVAHO/O5O92YDCuhpHmWD7o+rEYHhJ2lfU84bZwPwkW0mF629N ktEicXf9OA77uaA0UA7ZYYz+AFgJZkRN3fgVSsa1HBWok1JEgv+6Nd+q/6OLQz/DllA/49 ShlrZJpD/FRfWjmsD7pKCJwcNtfQJx+Vq2O+aKi2bPXvmjGHTwkJi1nrv0cfF/+4j3SDEw UHcxbifRwWqGIB57iIiUQeGKse85u/Z+rwTwntUDJSk2SPB8U/do/86BMez+Vs72qt0kwL GJQZAC4/TT3xlHs06FsLTqLcSlhIzwIstYjlqGQafaobi/zZ7IPxPGej7xh6jQ== 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 4Vkz2l4yGbzFmZ; Wed, 22 May 2024 17:34:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44MHYtuY026632; Wed, 22 May 2024 17:34:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44MHYtTC026629; Wed, 22 May 2024 17:34:55 GMT (envelope-from git) Date: Wed, 22 May 2024 17:34:55 GMT Message-Id: <202405221734.44MHYtTC026629@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: 1266d894c50c - stable/14 - fib_dxr: code hygiene, prune old code, no functional changes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org 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/14 X-Git-Reftype: branch X-Git-Commit: 1266d894c50c54d7282c5cf13a1ac889e87ca0df Auto-Submitted: auto-generated The branch stable/14 has been updated by zec: URL: https://cgit.FreeBSD.org/src/commit/?id=1266d894c50c54d7282c5cf13a1ac889e87ca0df commit 1266d894c50c54d7282c5cf13a1ac889e87ca0df Author: Marko Zec AuthorDate: 2024-05-17 16:57:25 +0000 Commit: Marko Zec CommitDate: 2024-05-22 17:34:40 +0000 fib_dxr: code hygiene, prune old code, no functional changes The !DXR2 code corresponds to the original DXR encoding proposal from 2012 with a single direct-lookup stage, which is inferior to the more recent (DXR2) variant with two-stage trie both in terms of memory footprint of the lookup structures, and in terms of overall lookup througput. I'm axing the old code chunks to (hopefully) somewhat improve readability, as well as to simplify future maintenance and updates. MFC after: 1 week (cherry picked from commit 42b3c16e3051fdc04acc6276dd5d97dbe80ae7eb) --- sys/netinet/in_fib_dxr.c | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/sys/netinet/in_fib_dxr.c b/sys/netinet/in_fib_dxr.c index 326710cc4c45..b889131b544b 100644 --- a/sys/netinet/in_fib_dxr.c +++ b/sys/netinet/in_fib_dxr.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2012-2022 Marko Zec + * Copyright (c) 2012-2024 Marko Zec * Copyright (c) 2005, 2018 University of Zagreb * Copyright (c) 2005 International Computer Science Institute * @@ -68,9 +68,6 @@ CTASSERT(DXR_TRIE_BITS >= 16 && DXR_TRIE_BITS <= 24); -/* DXR2: two-stage primary trie, instead of a single direct lookup table */ -#define DXR2 - #if DXR_TRIE_BITS > 16 #define DXR_D 16 #else @@ -317,7 +314,6 @@ range_lookup(struct range_entry_long *rt, struct direct_entry de, uint32_t dst) ntohl(key.addr4.s_addr))]); \ } -#ifdef DXR2 #if DXR_TRIE_BITS > 16 DXR_LOOKUP_DEFINE(16) #endif @@ -328,23 +324,16 @@ DXR_LOOKUP_DEFINE(12) DXR_LOOKUP_DEFINE(11) DXR_LOOKUP_DEFINE(10) DXR_LOOKUP_DEFINE(9) -#endif /* DXR2 */ static int inline dxr_lookup(struct dxr *dxr, uint32_t dst) { struct direct_entry de; -#ifdef DXR2 uint16_t *dt = dxr->d; struct direct_entry *xt = dxr->x; de = xt[(dt[dst >> dxr->d_shift] << dxr->x_shift) + ((dst >> DXR_RANGE_SHIFT) & dxr->x_mask)]; -#else /* !DXR2 */ - struct direct_entry *dt = dxr->d; - - de = dt[dst >> DXR_RANGE_SHIFT]; -#endif /* !DXR2 */ if (__predict_true(de.fragments == FRAGS_MARK_HIT)) return (de.base); return (range_lookup(dxr->r, de, dst)); @@ -571,7 +560,6 @@ chunk_unref(struct dxr_aux *da, uint32_t chunk) LIST_INSERT_HEAD(&da->unused_chunks[i], cdp, cd_hash_le); } -#ifdef DXR2 static uint32_t trie_hash(struct dxr_aux *da, uint32_t dxr_x, uint32_t index) { @@ -670,7 +658,6 @@ trie_unref(struct dxr_aux *da, uint32_t index) } } while (tp != NULL); } -#endif static void heap_inject(struct dxr_aux *da, uint32_t start, uint32_t end, uint32_t preflen, @@ -864,12 +851,10 @@ dxr_build(struct dxr *dxr) uint32_t r_size, dxr_tot_size; uint32_t i, m, range_rebuild = 0; uint32_t range_frag; -#ifdef DXR2 struct trie_desc *tp; uint32_t d_tbl_size, dxr_x, d_size, x_size; uint32_t ti, trie_rebuild = 0, prev_size = 0; uint32_t trie_frag; -#endif MPASS(dxr->d == NULL); @@ -907,7 +892,6 @@ dxr_build(struct dxr *dxr) } range_rebuild = 1; } -#ifdef DXR2 if (da->x_tbl == NULL) { da->x_tbl = malloc(sizeof(*da->x_tbl) * da->xtbl_size, M_DXRAUX, M_NOWAIT); @@ -918,7 +902,6 @@ dxr_build(struct dxr *dxr) } trie_rebuild = 1; } -#endif microuptime(&t0); @@ -970,7 +953,6 @@ range_build: r_size = sizeof(*da->range_tbl) * da->rtbl_top; microuptime(&t1); -#ifdef DXR2 if (range_rebuild || abs(fls(da->prefixes) - fls(da->trie_rebuilt_prefixes)) > 1) trie_rebuild = 1; @@ -1044,10 +1026,6 @@ dxr2_try_squeeze: goto dxr2_try_squeeze; } microuptime(&t2); -#else /* !DXR2 */ - dxr_tot_size = sizeof(da->direct_tbl) + r_size; - t2 = t1; -#endif dxr->d = malloc(dxr_tot_size, M_DXRLPM, M_NOWAIT); if (dxr->d == NULL) { @@ -1055,7 +1033,6 @@ dxr2_try_squeeze: "Unable to allocate DXR lookup table"); return; } -#ifdef DXR2 memcpy(dxr->d, da->d_tbl, d_size); dxr->x = ((char *) dxr->d) + d_size; memcpy(dxr->x, da->x_tbl, x_size); @@ -1063,10 +1040,6 @@ dxr2_try_squeeze: dxr->d_shift = 32 - da->d_bits; dxr->x_shift = dxr_x; dxr->x_mask = 0xffffffffU >> (32 - dxr_x); -#else /* !DXR2 */ - memcpy(dxr->d, da->direct_tbl, sizeof(da->direct_tbl)); - dxr->r = ((char *) dxr->d) + sizeof(da->direct_tbl); -#endif memcpy(dxr->r, da->range_tbl, r_size); if (da->updates_low <= da->updates_high) @@ -1076,36 +1049,24 @@ dxr2_try_squeeze: da->updates_high = 0; microuptime(&t3); -#ifdef DXR2 FIB_PRINTF(LOG_INFO, da->fd, "D%dX%dR, %d prefixes, %d nhops (max)", da->d_bits, dxr_x, rinfo.num_prefixes, rinfo.num_nhops); -#else - FIB_PRINTF(LOG_INFO, da->fd, "D%dR, %d prefixes, %d nhops (max)", - DXR_D, rinfo.num_prefixes, rinfo.num_nhops); -#endif i = dxr_tot_size * 100; if (rinfo.num_prefixes) i /= rinfo.num_prefixes; FIB_PRINTF(LOG_INFO, da->fd, "%d.%02d KBytes, %d.%02d Bytes/prefix", dxr_tot_size / 1024, dxr_tot_size * 100 / 1024 % 100, i / 100, i % 100); -#ifdef DXR2 FIB_PRINTF(LOG_INFO, da->fd, "%d.%02d%% trie, %d.%02d%% range fragmentation", trie_frag / 100, trie_frag % 100, range_frag / 100, range_frag % 100); -#else - FIB_PRINTF(LOG_INFO, da->fd, "%d.%01d%% range fragmentation", - range_frag / 100, range_frag % 100); -#endif i = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec; FIB_PRINTF(LOG_INFO, da->fd, "range table %s in %u.%03u ms", range_rebuild ? "rebuilt" : "updated", i / 1000, i % 1000); -#ifdef DXR2 i = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec; FIB_PRINTF(LOG_INFO, da->fd, "trie %s in %u.%03u ms", trie_rebuild ? "rebuilt" : "updated", i / 1000, i % 1000); -#endif i = (t3.tv_sec - t2.tv_sec) * 1000000 + t3.tv_usec - t2.tv_usec; FIB_PRINTF(LOG_INFO, da->fd, "snapshot forked in %u.%03u ms", i / 1000, i % 1000); @@ -1194,7 +1155,6 @@ static void * choose_lookup_fn(struct dxr_aux *da) { -#ifdef DXR2 switch (da->d_bits) { #if DXR_TRIE_BITS > 16 case 16: @@ -1215,7 +1175,6 @@ choose_lookup_fn(struct dxr_aux *da) case 9: return (dxr_fib_lookup_9); } -#endif /* DXR2 */ return (dxr_fib_lookup); }