From patchwork Mon Mar 6 13:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 64748 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1886547wrd; Mon, 6 Mar 2023 06:59:41 -0800 (PST) X-Google-Smtp-Source: AK7set+/btfoyk8e7mjBJJIPyK/t3yesNqzx+UMinqZ69mmG/sxF2rbGzrKPxbgtoTXhqsys26SP X-Received: by 2002:a17:90b:3812:b0:23a:4875:6e1a with SMTP id mq18-20020a17090b381200b0023a48756e1amr12155851pjb.25.1678114781469; Mon, 06 Mar 2023 06:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678114781; cv=none; d=google.com; s=arc-20160816; b=ZzUIsKojsJ+MBAurXbhBt4eYCmt7ORJVMDGTQpgvQ+aUx1yFTm2mM7by+CBH+ALQws WuAShHmxMfZ2bI2ryU/p5LxZsRM0IPwzvTiZXxbisP09+5ov2hN4nItBrvMnYMb0gPno ulT0J5ERqUxxgzuBrEwLEx0WtRMglQkZlh94tZlPo1cz5XbXm6319gTtLh4n6CE8Ewpt 6vDJ0ncJGRUKU5IA7eTkvkAw2WpMWT7QUrN8zPQzzS0W9FEjSVymYnd29MnwxJgQcWhJ EDsDnCBVM84GB1hU3KLXQI/WNvuD183xRRPXIACZ1F5bLxqMTSpJE4bHDTi0GAI/NJ+f 9Riw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=2nCdUjbTqHSXIpP/as6UIFPlbvoMHockVe8OM3H17xE=; b=HQ7kajWxZ9ZsP7iLm56jvJLuE8np1HowK+PYRjCXG+RotaZutcHkfRjrn6g3JuBuXm 5Ym+ZJ5DFhVlUxpfDzzAcyefi+Zp7lF8XM5dY5aysfGBT3V8VNwwPl7PeqPTisNTADXK qgorjTVw9ujmNqqdU69tvRbO9uX10y4hMw+aBL0l1F/e1g1eKghDvQ0dTT16ExVvwzTm RlTaSDxJPPmd4bz7tWyiXaqh3n/zepbvQvJpPCyfBAtfaPHieK/1RVklqVbA2fFfm3+g FoBDqCDMiUcXL/pSxqgLlDettC2MGh/8NlZwbWNI2HHs9a5hUwaKoz1RWcfJbfMQUJ0D EoAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Mod0KOPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a17090ae58400b00234b3d276afsi8818618pjz.91.2023.03.06.06.59.29; Mon, 06 Mar 2023 06:59:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Mod0KOPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231162AbjCFOVI (ORCPT + 99 others); Mon, 6 Mar 2023 09:21:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbjCFOUV (ORCPT ); Mon, 6 Mar 2023 09:20:21 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C72E28862 for ; Mon, 6 Mar 2023 06:19:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=2nCdUjbTqHSXIpP/as6UIFPlbvoMHockVe8OM3H17xE=; b=Mod0KOPpiSabgUHOLTx1sle+s2 anx6IYYxBch+n485hQS8W7QsAh3wiEDutIbB1MmycwrsXES4TkHFXVNYRq2M9wDwN09aC020vrFlU lW7pv5pEZhnV7cxx+FJFWUXYP/VXMWB6k/o8zGFRkTNAsInxGRKzKJ/PGma5pjzyE7ieMmW1EQ6hv kiRINAsgZMgUqLhEtmzYJdfKHmvFog2n8oUJ6ojkUeJRb4ONUyLKGOanBZ5QuPVfqI9K93Ol4dGdR Ln3uKdLOA4vM25GKxYtrxmBUaSrvON2J1xvyBIKnIQRqe/6+0WWVLPiFHr41pBqIM2k77WyjlC+GV f3YXMk6Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZBe6-005P2a-8B; Mon, 06 Mar 2023 14:16:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 89030300328; Mon, 6 Mar 2023 15:16:56 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 18D5C23BC8E2F; Mon, 6 Mar 2023 15:16:55 +0100 (CET) Message-ID: <20230306141502.750918974@infradead.org> User-Agent: quilt/0.66 Date: Mon, 06 Mar 2023 14:25:30 +0100 From: Peter Zijlstra To: mingo@kernel.org, vincent.guittot@linaro.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, corbet@lwn.net, qyousef@layalina.io, chris.hyser@oracle.com, patrick.bellasi@matbug.net, pjt@google.com, pavel@ucw.cz, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, timj@gnu.org, kprateek.nayak@amd.com, yu.c.chen@intel.com, youssefesmat@chromium.org, joel@joelfernandes.org Subject: [PATCH 09/10] rbtree: Add rb_add_augmented_cached() helper References: <20230306132521.968182689@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759630885270083254?= X-GMAIL-MSGID: =?utf-8?q?1759630885270083254?= While slightly sub-optimal, updating the augmented data while going down the tree during lookup would be faster -- alas the augment interface does not currently allow for that, provide a generic helper to add a node to an augmented cached tree. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/rbtree_augmented.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) --- a/include/linux/rbtree_augmented.h +++ b/include/linux/rbtree_augmented.h @@ -60,6 +60,32 @@ rb_insert_augmented_cached(struct rb_nod rb_insert_augmented(node, &root->rb_root, augment); } +static __always_inline struct rb_node * +rb_add_augmented_cached(struct rb_node *node, struct rb_root_cached *tree, + bool (*less)(struct rb_node *, const struct rb_node *), + const struct rb_augment_callbacks *augment) +{ + struct rb_node **link = &tree->rb_root.rb_node; + struct rb_node *parent = NULL; + bool leftmost = true; + + while (*link) { + parent = *link; + if (less(node, parent)) { + link = &parent->rb_left; + } else { + link = &parent->rb_right; + leftmost = false; + } + } + + rb_link_node(node, parent, link); + augment->propagate(parent, NULL); /* suboptimal */ + rb_insert_augmented_cached(node, tree, leftmost, augment); + + return leftmost ? node : NULL; +} + /* * Template for declaring augmented rbtree callbacks (generic case) *