From nobody Sun Aug 28 05:46:12 2022 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 4MFjH92RQKz4ZrdX; Sun, 28 Aug 2022 05:46:13 +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 4MFjH91F4xz3ddR; Sun, 28 Aug 2022 05:46:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661665573; 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=B3EKNE8pYQyY7Vcq1yUxgSmu+ObAmznpxfeQRPY8brM=; b=AbAdrrF19reRF1YrNmmKtsjzIEP5Zc4a8JOQnVWdSFJBwydEpEZpMSZurodFoAOKIUIxrq pqkQnuM6H3FUDdHH/ao2sDJ1lVxPDOFP0C/etF+CKuimC8r73IL/dxtTscJvioXOrR95e7 xzNyGBYcBENiagMFBkFzs6zLICDLHp65a8KYZAlK7iWv01GtbWCXMiq1W2jGeyo+0vdNO7 pWwOjXDKv3XtAmDi563Hx7Fw0HBO9k2WR4tr3I4hxUCkBh4iVVqy/63RFKbMtwXoE2AsDU gFAj+f+9PZwVv2qm2F/5w+Nr43RaTkpS49Gya9Br3vB0HdMOpbDw4oSAPba0Zw== 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 4MFjH90GFwz10FR; Sun, 28 Aug 2022 05:46:13 +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 27S5kC6j082176; Sun, 28 Aug 2022 05:46:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27S5kCIx082175; Sun, 28 Aug 2022 05:46:12 GMT (envelope-from git) Date: Sun, 28 Aug 2022 05:46:12 GMT Message-Id: <202208280546.27S5kCIx082175@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: 5886089ecfc3 - main - rb_tree: fine-tune RB_REMOVE 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: 5886089ecfc3a7c77bbdf9e95cbf14112f592c50 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661665573; 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=B3EKNE8pYQyY7Vcq1yUxgSmu+ObAmznpxfeQRPY8brM=; b=UdbdHs+FkXkApEFfnoLvunB9pOLe8uXD9zLyr67qp5ypJ8c8KjivLfOCu6U0or+bdjEA/c goaY3R5OHmCsNxodwA7zlodyJYO/r68lVHOMGWl3TuI6aXjWSB/CKg3bMk/4tDUNqYBJme ybcq+9OIZXM0ptvDBC5/cXTBX9eqdwP23bFqgbOzYjevGnXxsssRecKhXz7k6Lcx7B7qkI RfnarP+gZZ+866rmEI7/Z4Tc/3glV1jpcF03RCU8CAnYkXEBnX+d08EO0QFgv/5D9cIDOi fScaEpa0vvDNc1bilcx2d8/bPhhgZpjb0WpsgzbxuCMgixcI36N3JvvjdsRGnw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661665573; a=rsa-sha256; cv=none; b=Hzkx2ycg1M/PkL/c+8UjUzsPW/7FGmu9emTtoi4qC2m34ikLAaKtiSWG0dmf098IQ/6l2O OWM7SojjnoAqGJGzcPg/5c2ViDFJ/L4eAoF6Jp6NYi1TAWbU/wdfjNe8CYoiRr8CzeeYqO jEtACWc6Fw4yFnyZLpgZxOeCstPLGaUa1JFPuqmjCoa0Yvzhx9FcokyeSAZXvCryKu3tLi dYCAI7si2ZeE+zg1Rb0SvoQwwNCVpltr/kIkPQ1yMsOWOTwI3wiGbO8f/QQRARYhEt1T0Q w45VH8vgoPTdf9e7cZmu8SvMyk1dEXmlD4F+ceT0/nzlw25KaGJJBBVmyCiNiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=5886089ecfc3a7c77bbdf9e95cbf14112f592c50 commit 5886089ecfc3a7c77bbdf9e95cbf14112f592c50 Author: Doug Moore AuthorDate: 2022-08-28 05:43:49 +0000 Commit: Doug Moore CommitDate: 2022-08-28 05:43:49 +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 --- 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 35c6b28be868..bd804c1a64db 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) \