From nobody Sun Sep 18 18:15:52 2022 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 4MVwwT188Bz4d5bs; Sun, 18 Sep 2022 18:15:53 +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 4MVwwT0cktz3kpk; Sun, 18 Sep 2022 18:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663524953; 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=RA42aGuStNpIxQm9lb3ysNcuaMNB6zExniobvp6n3s0=; b=W6R+RwdSy5gueBa5YU0+Tmtfg+9NgO4ELc+dUHdvIjSKFiZKjOyphoBR90hAOB+fvVvcoY 6PzZDzfu25Zx+XTZZxfbrk3RHTYviG9IgZTqM3Mlkgnz/lugCh8F9tZIaQPu6b0CO01WFI +qeDjjWLpq7eloaEpKCt6Ap0IJRCnAHMsXOLAgp6oY9IbHcrftGrsdjijEwZh7zVX43r/C YiSr20v+nsrP0/dmbjQ60R3ej6K5hjKHA0c10vKzTAPDkcidPK5LpDco2r0/lGT1vYJ5kW Km6LDyGwgeKtGvBxjJw5SMAR08XQhN/8ZZHf1Gb5FNok3BCNZvCd2fnZVohftg== 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 4MVwwS6nFtz16h9; Sun, 18 Sep 2022 18:15:52 +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 28IIFqNe050930; Sun, 18 Sep 2022 18:15:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28IIFq2n050929; Sun, 18 Sep 2022 18:15:52 GMT (envelope-from git) Date: Sun, 18 Sep 2022 18:15:52 GMT Message-Id: <202209181815.28IIFq2n050929@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Moore Subject: git: b63021e001dc - stable/13 - rb_tree: fine-tune RB_REMOVE 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/stable/13 X-Git-Reftype: branch X-Git-Commit: b63021e001dc0de62bd63a2b185f8e1fc82492c3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663524953; 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=RA42aGuStNpIxQm9lb3ysNcuaMNB6zExniobvp6n3s0=; b=dBTZ/zQc1MBGeMO+vhIVfgkC0Rb3Hrg0neos/eTM52K7HNJVwRajHaFYs4UZ5RBP97J57w +rrIuagpjXt5AdknUl9gYP8QOlL7BD66Ug4q9qeecBTe24KtbnSdc33KyC/G9CdC1XEYBg A84RdX4/ZOLuM/xdr/Ymyewu9jSLrQaiWnuhXnugvBdQzkzAGGr7MSJsCAM1N3bz1g14W3 OoSZu3RM+WCR8n99C3LZSdLoAkWnl0mw72F920cehFrYBg+caWLFoA3LkOoSY4Q4A+vfIn JyxNkGfBUkFJ6r1swSaAtP9tLoJiJKWDKGOinsEwT4/mgyL9Fqr2xoeZ7wQfnQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663524953; a=rsa-sha256; cv=none; b=GLopNONmpx8wbaS+kA63+Zf39z66GUjlexiQryrIepxz8WKuzTjAdz1Ch3V4ley6pN75jR HxkzjBF2IaC9mkt3Iq/61V94SycwHRj70gtLjPh1BN2RDaz6vxUJVrakEm7cAX3ODqNUiu /xSZERBvD3JRZnNDHhoLlSLJ83rM97Za4O9xVTJ0KQng0/0MJw7KswvAk1LychFyKKt/+D yS/3Wf0fti+d3CsC44erg/JoblDgkEEf4d0ePiXD14ZiA+e2lARB8mGdLMjlbTeoVpsUXc 7Z+yG7oRcopwd6LsOdZ3N/vOAVBuuHSnvWC7j2mfnwZH5qdNmjHvToV0LEGdRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=b63021e001dc0de62bd63a2b185f8e1fc82492c3 commit b63021e001dc0de62bd63a2b185f8e1fc82492c3 Author: Doug Moore AuthorDate: 2022-08-28 05:43:49 +0000 Commit: Doug Moore CommitDate: 2022-09-18 18:15:29 +0000 rb_tree: fine-tune RB_REMOVE Improve RB_REMOVE by reading the fields of the removed node only once, and by not writing to the removed node. Reviewed by: kib Discussed with: markj MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D36288 (cherry picked from commit 5886089ecfc3a7c77bbdf9e95cbf14112f592c50) --- sys/sys/tree.h | 59 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/sys/sys/tree.h b/sys/sys/tree.h index 88d15bda4177..38c82c4e4a52 100644 --- a/sys/sys/tree.h +++ b/sys/sys/tree.h @@ -343,8 +343,9 @@ struct { \ #define RB_FLIP_ALL(elm, field) (RB_BITS(elm, field) ^= RB_RED_MASK) #define RB_RED_LEFT(elm, field) ((RB_BITS(elm, field) & RB_RED_L) != 0) #define RB_RED_RIGHT(elm, field) ((RB_BITS(elm, field) & RB_RED_R) != 0) -#define RB_PARENT(elm, field) ((__typeof(RB_UP(elm, field))) \ - (RB_BITS(elm, field) & ~RB_RED_MASK)) +#define _RB_PARENT_ONLY(elm) (__typeof(elm)) \ + ((__uintptr_t)elm & ~RB_RED_MASK) +#define RB_PARENT(elm, field) _RB_PARENT_ONLY(RB_UP(elm, field)) #define RB_ROOT(head) (head)->rbh_root #define RB_EMPTY(head) (RB_ROOT(head) == NULL) @@ -397,7 +398,7 @@ struct { \ * relationship between elm and its former parent is not changed; * where this macro once updated those fields, that is now left to the * caller of RB_ROTATE to clean up, so that a pair of rotations does - * not twice update the came pair of pointer fields with distinct + * not twice update the same pair of pointer fields with distinct * values. */ #define RB_ROTATE_LEFT(elm, tmp, field) do { \ @@ -682,44 +683,42 @@ name##_RB_REMOVE_COLOR(struct name *head, \ #define RB_GENERATE_REMOVE(name, type, field, attr) \ attr struct type * \ -name##_RB_REMOVE(struct name *head, struct type *elm) \ +name##_RB_REMOVE(struct name *head, struct type *out) \ { \ - struct type *child, *gpar, *old, *parent, *right; \ + struct type *child, *in, *opar, *parent; \ \ - old = elm; \ - gpar = parent = RB_PARENT(elm, field); \ - right = RB_RIGHT(elm, field); \ - if (RB_LEFT(elm, field) == NULL) \ - elm = child = right; \ - else if (right == NULL) \ - elm = child = RB_LEFT(elm, field); \ - else { \ - if ((child = RB_LEFT(right, field)) == NULL) { \ - child = RB_RIGHT(right, field); \ - RB_RIGHT(old, field) = child; \ - parent = elm = right; \ - } else { \ - do \ - elm = child; \ - while ((child = RB_LEFT(elm, field)) != NULL); \ - child = RB_RIGHT(elm, field); \ - parent = RB_PARENT(elm, field); \ + child = RB_LEFT(out, field); \ + in = RB_RIGHT(out, field); \ + opar = RB_UP(out, field); \ + if (in == NULL || child == NULL) { \ + in = child = in == NULL ? child : in; \ + parent = opar = _RB_PARENT_ONLY(opar); \ + } else { \ + parent = in; \ + while (RB_LEFT(in, field)) \ + in = RB_LEFT(in, field); \ + RB_SET_PARENT(child, in, field); \ + RB_LEFT(in, field) = child; \ + child = RB_RIGHT(in, field); \ + if (parent != in) { \ + RB_SET_PARENT(parent, in, field); \ + RB_RIGHT(in, field) = parent; \ + parent = RB_PARENT(in, field); \ RB_LEFT(parent, field) = child; \ - RB_SET_PARENT(RB_RIGHT(old, field), elm, field);\ } \ - RB_SET_PARENT(RB_LEFT(old, field), elm, field); \ - elm->field = old->field; \ + RB_UP(in, field) = opar; \ + opar = _RB_PARENT_ONLY(opar); \ } \ - RB_SWAP_CHILD(head, gpar, old, elm, field); \ + RB_SWAP_CHILD(head, opar, out, in, field); \ if (child != NULL) \ - RB_SET_PARENT(child, parent, field); \ + RB_UP(child, field) = parent; \ if (parent != NULL) { \ name##_RB_REMOVE_COLOR(head, parent, child); \ - if (parent == elm && RB_LEFT(parent, field) == NULL) \ + if (parent == in && RB_LEFT(parent, field) == NULL) \ parent = RB_PARENT(parent, field); \ RB_UPDATE_AUGMENT(parent, field); \ } \ - return (old); \ + return (out); \ } #define RB_GENERATE_INSERT(name, type, field, cmp, attr) \