From nobody Wed Apr 30 17:12:35 2025 X-Original-To: dev-commits-src-main@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 4ZnkJg5HdNz5thKS; Wed, 30 Apr 2025 17:12:35 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZnkJg2xg7z3HwJ; Wed, 30 Apr 2025 17:12:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746033155; 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=kxzSKz98iYKXEzERuiRG7Zlf5pu52BxizRC9KgjT4wk=; b=mZQYJKc1f3VZX/ad548JX/i51y5zxa0DqN6emvJvXZKXEUD/QTq6G0ziIT5PMScOoq28Il zA41P7qSHcw8AtZPtonSzBNm4av+tr1MkV+JijBnxEbL83BlWHsgDff/I4VlMYBFuj2tLv lMB7mSIsVdcvrRpJhDEKrE8gA03r7ZcnACv98vYZkaqcCAXnB7VTINfO3HBTs0XC1gFMjg UlNWhsOsZsnOepm2F2eLZhdk7QpaE1YAOnMpXRAIFMk6O1KilLjQnvasPqnkwcsFvNQzeh qLp0/O2VJ+CCfjvyRv4AUYkJfc5oMn1dh1uuYse335g7UqktKDJDaieMti6gYw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746033155; a=rsa-sha256; cv=none; b=QBVB5qmuyDEDYKdust7b0rBDmI0bKn5p6jiN5KOG1IpQy7FoMP9ru6I830onNo8/QrNp3b VE5wxwbD00tge5xtVutbWonhIOWUiEmL+WoRs6mxcwfrype6KpFuB0uJTOKo2Rdfa8weyH dNXfKotlj4sfQifxqTm+9gGD6h3VUMn83OEpLeZhwPF0FOZJEPyUU61VhE4Zn+BSkrsafV SmMaCV9/obrj8oXvjo5sECGC7gFWN1SdfJlhi86wd7Eoo5vF3cIof47G8VCxqCM+HAzI7m 4IsERTJrH3TC10BuRQ32oV8FWPg6bP/+5SdTI8El8KKvnVuEc8sy7SXyATsZFA== 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=1746033155; 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=kxzSKz98iYKXEzERuiRG7Zlf5pu52BxizRC9KgjT4wk=; b=jFFBncRL45uxyv4JdOpFV2qIJcHykW+heth7SYiMJSZ+VYPnlOL5KfOrKBYurM2U1LRYNu XRd17pshzNhNn00VG6WJoOHHJ3wtytGS3juix6ibcStGYljFi5x9zwNrYvUiCOoGz9T7U1 2Of75vQoYBhp4RsHaGgp19FsR2hthA+lC4wRVADNpuO4InGeulZEyTOdPCcu2oRgZR9bwj 0rStKJRFcLsiRMofAoV7ar0Y/60uRJ/EF76I6TLpzADrsAHRqFx/NdgUDujejFLCpF+v6p 2OPchCAVh5UoQ+UeJw+sfwH8uVsC8x6sV5na+evgO0g4xViCv8x6Wws7WjFGJw== 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 4ZnkJg2W3szR4; Wed, 30 Apr 2025 17:12:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53UHCZNU077391; Wed, 30 Apr 2025 17:12:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53UHCZZK077388; Wed, 30 Apr 2025 17:12:35 GMT (envelope-from git) Date: Wed, 30 Apr 2025 17:12:35 GMT Message-Id: <202504301712.53UHCZZK077388@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: 014a45493865 - main - pctrie: add a locked pctrie_lookup_range List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 014a45493865f217c3c0ddd240c2260913ba7f76 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=014a45493865f217c3c0ddd240c2260913ba7f76 commit 014a45493865f217c3c0ddd240c2260913ba7f76 Author: Doug Moore AuthorDate: 2025-04-30 17:11:34 +0000 Commit: Doug Moore CommitDate: 2025-04-30 17:11:34 +0000 pctrie: add a locked pctrie_lookup_range Add a locked version of pctrie_lookup_range_unlocked. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50088 --- sys/kern/subr_pctrie.c | 48 ++++++++++++++++++++++++++++++++++++++---------- sys/sys/pctrie.h | 14 ++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c index feb29cf82330..be1d57b4931f 100644 --- a/sys/kern/subr_pctrie.c +++ b/sys/kern/subr_pctrie.c @@ -609,22 +609,19 @@ pctrie_iter_prev(struct pctrie_iter *it) /* * Returns the number of contiguous, non-NULL entries read into the value[] - * array, without requiring an external lock. These entries *may* never have - * been in the pctrie all at one time, but for a series of times t0, t1, t2, - * ..., with ti <= t(i+1), value[i] was in the trie at time ti. + * array, starting at index. */ -int -pctrie_lookup_range_unlocked(struct pctrie *ptree, uint64_t index, - uint64_t *value[], int count, smr_t smr) +static __always_inline int +_pctrie_lookup_range(struct pctrie *ptree, uint64_t index, uint64_t *value[], + int count, smr_t smr, enum pctrie_access access) { struct pctrie_node *parent, *node; int base, end, i; parent = NULL; - smr_enter(smr); for (i = 0; i < count;) { node = _pctrie_lookup_node(ptree, parent, index + i, &parent, - smr, PCTRIE_SMR); + smr, access); value[i] = pctrie_match_value(node, index + i); if (value[i] == NULL) break; @@ -635,7 +632,7 @@ pctrie_lookup_range_unlocked(struct pctrie *ptree, uint64_t index, end = MIN(count, i + PCTRIE_COUNT - base); while (i < end) { node = pctrie_node_load(&parent->pn_child[base++], - smr, PCTRIE_SMR); + smr, access); value[i] = pctrie_toval(node); if (value[i] == NULL) break; @@ -644,10 +641,41 @@ pctrie_lookup_range_unlocked(struct pctrie *ptree, uint64_t index, if (i < end) break; } - smr_exit(smr); return (i); } +/* + * Returns the number of contiguous, non-NULL entries read into the value[] + * array, starting at index, assuming access is externally synchronized by a + * lock. + */ +int +pctrie_lookup_range(struct pctrie *ptree, uint64_t index, + uint64_t *value[], int count) +{ + return (_pctrie_lookup_range(ptree, index, value, count, NULL, + PCTRIE_LOCKED)); +} + +/* + * Returns the number of contiguous, non-NULL entries read into the value[] + * array, starting at index, without requiring an external lock. These entries + * *may* never have been in the pctrie all at one time, but for a series of + * times t0, t1, t2, ..., with ti <= t(i+1), value[i] was in the trie at time + * ti. + */ +int +pctrie_lookup_range_unlocked(struct pctrie *ptree, uint64_t index, + uint64_t *value[], int count, smr_t smr) +{ + int res; + + smr_enter(smr); + res = _pctrie_lookup_range(ptree, index, value, count, smr, PCTRIE_SMR); + smr_exit(smr); + return (res); +} + /* * Find first leaf >= index, and fill iter with the path to the parent of that * leaf. Return NULL if there is no such leaf less than limit. diff --git a/sys/sys/pctrie.h b/sys/sys/pctrie.h index 01d9f34f11b9..0ccd4ec1e42e 100644 --- a/sys/sys/pctrie.h +++ b/sys/sys/pctrie.h @@ -215,6 +215,18 @@ name##_PCTRIE_LOOKUP(struct pctrie *ptree, uint64_t key) \ return name##_PCTRIE_VAL2PTR(pctrie_lookup(ptree, key)); \ } \ \ +static __inline __unused int \ +name##_PCTRIE_LOOKUP_RANGE(struct pctrie *ptree, uint64_t key, \ + struct type *value[], int count) \ +{ \ + uint64_t **data = (uint64_t **)value; \ + \ + count = pctrie_lookup_range(ptree, key, data, count); \ + for (int i = 0; i < count; i++) \ + value[i] = name##_PCTRIE_NZVAL2PTR(data[i]); \ + return (count); \ +} \ + \ static __inline __unused struct type * \ name##_PCTRIE_LOOKUP_LE(struct pctrie *ptree, uint64_t key) \ { \ @@ -383,6 +395,8 @@ void pctrie_insert_node(uint64_t *val, struct pctrie_node *parent, uint64_t *pctrie_lookup(struct pctrie *ptree, uint64_t key); uint64_t *pctrie_lookup_unlocked(struct pctrie *ptree, uint64_t key, smr_t smr); +int pctrie_lookup_range(struct pctrie *ptree, + uint64_t index, uint64_t *value[], int count); int pctrie_lookup_range_unlocked(struct pctrie *ptree, uint64_t index, uint64_t *value[], int count, smr_t smr); uint64_t *pctrie_iter_lookup(struct pctrie_iter *it, uint64_t index);