From nobody Tue Jun 20 16:32:47 2023 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 4Qlscb3RQwz4gMfr; Tue, 20 Jun 2023 16:32:47 +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 4Qlscb2t21z3FsB; Tue, 20 Jun 2023 16:32:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687278767; 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=EBwB8rTRxM2yL7RoY7xxweuxiMTLeaavSRY7aO0b7a8=; b=PcbiwJBRi5JBkYAxAEM2haPJW04mqIvPnPvRSXPgLzHsmPzMqQdu+Z0NwHaVNRiroJSRx/ k09fkbxxzO7UVQewa9XdITstmCeO8vDMDKy/l2p4ckp14TZik21QjViTQHg7rrMQ7v/AHn H5f5gh3CBQIVqst4sVT+TikxvSkXZhNlLh3y+ueO9kEuelDvKLFz0R0GC9n8J6GJ64sNcx VCfKhu1F3ZWB1gZQPSX0xgu5Il6WL10KgAk9fwGa3LNh0v2JKpS1goT8gPnv/8Jnrc7/qq 1QW5Q2/vIiykFocCJNVUf1K2Ce2D5gFFGEd7UOWx2o/qYZhaRscUzVMGdbrkTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687278767; 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=EBwB8rTRxM2yL7RoY7xxweuxiMTLeaavSRY7aO0b7a8=; b=oUYNNo9xIJ3Yco4ZjXrIx0ioH1BDCLZ2NpNdQtrFra3UopecDS+j04+snnPZqvGJ3XMTqU affT/BFZpY8rxZC+o2VtpfZpW58xNNefEcfpWR7Kv9VubD3TRSfsqdLtDwvfvuX5E+ZNEV ei2jLyj2Ap8Aie1oiE+izBIXM1rV7mrnO8LHfJskJLeWkuCzR2skFE6DQmandKnhW25kG8 jbQm2XPtNEomCIwX0UPbPaHbp0b7z89Z3GB+RVioLLVlcn/EsEx+13B5TIjLipbvwSlJuH Jgz7y922BCBjvEHPjakP6SjDN8FobKCcANFClu1NUS2bcDBQedH0kGl8SY2L1w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687278767; a=rsa-sha256; cv=none; b=JfyKda2ZmqKANt7+T2s8Cl27ScNgsfVKFOyhYX30FUxH0bEOo7AlIKUEGLjbvj+kNr0hfl PKpsRsSaGeWur7Ff7KABYuMvu22CSyUE+jT7/ThrRZ+XvI26a0zxEFHaRdlVx/OT3rhHze Syo2PlkS0foQu+Zf8Wc7wAohYrI9QAiFOCS1tkSfY6OOjNKDhzC1R7OrDUWvlPSmChRClx aNdplQVF2eVlNi6qbrzRaFe+OYwtjXkkoyEnagKLBU2A6Oh2d4LjvR6Yb+XcKPA9UrgA5S bBAUFLaQiUuaZYdrGcWQQ8pEhkw7lavfGwxIkAtgSu4YO4ki+MIHv4NvYiNgoQ== 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 4Qlscb1gQ2z16GH; Tue, 20 Jun 2023 16:32:47 +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 35KGWlDG061007; Tue, 20 Jun 2023 16:32:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35KGWl69061006; Tue, 20 Jun 2023 16:32:47 GMT (envelope-from git) Date: Tue, 20 Jun 2023 16:32:47 GMT Message-Id: <202306201632.35KGWl69061006@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: 05963ea4d130 - main - radix_trie: eliminate iteration in keydiff 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 05963ea4d130c39b332ae8b69414e8a894ca81e0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=05963ea4d130c39b332ae8b69414e8a894ca81e0 commit 05963ea4d130c39b332ae8b69414e8a894ca81e0 Author: Doug Moore AuthorDate: 2023-06-20 16:30:29 +0000 Commit: Doug Moore CommitDate: 2023-06-20 16:30:29 +0000 radix_trie: eliminate iteration in keydiff Use flsll(), instead of a loop, to find where two keys differ, and then arithmetic to transform that to a trie level. Approved by: alc, markj Differential Revision: https://reviews.freebsd.org/D40585 --- sys/kern/subr_pctrie.c | 14 ++++++++------ sys/vm/vm_radix.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c index 9db7dd2b68c6..d4262e32be51 100644 --- a/sys/kern/subr_pctrie.c +++ b/sys/kern/subr_pctrie.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include /* smr.h depends on struct thread. */ #include @@ -259,21 +260,22 @@ pctrie_addval(struct pctrie_node *node, uint64_t index, uint16_t clev, } /* - * Returns the slot where two keys differ. + * Returns the level where two keys differ. * It cannot accept 2 equal keys. */ static __inline uint16_t pctrie_keydiff(uint64_t index1, uint64_t index2) { - uint16_t clev; KASSERT(index1 != index2, ("%s: passing the same key value %jx", __func__, (uintmax_t)index1)); + CTASSERT(sizeof(long long) >= sizeof(uint64_t)); - index1 ^= index2; - for (clev = PCTRIE_LIMIT;; clev--) - if (pctrie_slot(index1, clev) != 0) - return (clev); + /* + * From the highest-order bit where the indexes differ, + * compute the highest level in the trie where they differ. + */ + return ((flsll(index1 ^ index2) - 1) / PCTRIE_WIDTH); } /* diff --git a/sys/vm/vm_radix.c b/sys/vm/vm_radix.c index 908bc4ec0bd1..836c3652c2c1 100644 --- a/sys/vm/vm_radix.c +++ b/sys/vm/vm_radix.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -285,21 +286,22 @@ vm_radix_addpage(struct vm_radix_node *rnode, vm_pindex_t index, uint16_t clev, } /* - * Returns the slot where two keys differ. + * Returns the level where two keys differ. * It cannot accept 2 equal keys. */ static __inline uint16_t vm_radix_keydiff(vm_pindex_t index1, vm_pindex_t index2) { - uint16_t clev; KASSERT(index1 != index2, ("%s: passing the same key value %jx", __func__, (uintmax_t)index1)); + CTASSERT(sizeof(long long) >= sizeof(vm_pindex_t)); - index1 ^= index2; - for (clev = VM_RADIX_LIMIT;; clev--) - if (vm_radix_slot(index1, clev) != 0) - return (clev); + /* + * From the highest-order bit where the indexes differ, + * compute the highest level in the trie where they differ. + */ + return ((flsll(index1 ^ index2) - 1) / VM_RADIX_WIDTH); } /*