Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1864864rdb; Tue, 3 Oct 2023 03:37:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTmi35UPZKQaSnZcu5qEpt8W5LMOhE76t/wEkxMg+9H+SNUf3HZYjayEaDbWsd7TDHgXT1 X-Received: by 2002:a05:6e02:1523:b0:34f:7ff6:acfe with SMTP id i3-20020a056e02152300b0034f7ff6acfemr17273581ilu.9.1696329429963; Tue, 03 Oct 2023 03:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696329429; cv=none; d=google.com; s=arc-20160816; b=b8THbkgo2qkWkZ77CeSxZwGH0dynGSh6K9Mh2jriRwtq7ECxog0ZUicEakqzBD2yzv gQlu2qbmMvofsnEyW7kQZoVg71Q6lVLnUmyjtiNy4g3aadyookba6VaAJmSReTF6YOMm 9Zlg5ep/3HFki6XQbnxn4TT23e+uPrqdrWw7uIC/Iqo6EBwyvi4csy5IAkpE3LIESsFf hGvXSahC3UKgYwzmKM5xSWjyStk84qSrD+urciWcdoL2KavKZGzNw2ukIFe/RB4BhWWU zQenvwwLRyU7KMU0gG0GvP/ywuTJ2KytxMgqtXDDn0ur9HnMswDxcrogUVAvboZttdCF 74Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sYFV784QNfVsvR6OfaRbdZY0R9+sNWsxSwOAX+vHka8=; fh=dzFVMTMQp1p7TLk6JTtT18MlrHtxCIU51j1wEHJQqwU=; b=rp5UJsGrAHi46Zkc8EQ2454D1O7uorukmNU6zUd/Jn4EBa3XhveiMvyJyp2jhUI/6T O45XGCKRNHSw7ZZyg0MKvA6hZAvlaHuxqTh6hEcYMeBdgv5tIfwOxPXdR7kE1hThu9/l xfcxWOolNsrSClKVrTjUvQkWDEifYGsJjlXePoUcaB8FTle7BTJQqrvkRV3xGSAGpEZX Pkr2FuQ9L8zVCHEwfSIWBbVxxBGE6GwXJYqKGWrRWohr1z5poBMjbyo3dVn7xSdVvVDr p8fFvJPTyLMEog9IYIBdqM2I97IDxOJn2MbIai0ixUtwCOFXay/49Lx9DQ/Hotwxtyem 2PZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Lzyv0kqT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i131-20020a636d89000000b00585a45417acsi1124601pgc.454.2023.10.03.03.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 03:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Lzyv0kqT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F1229815A1D2; Tue, 3 Oct 2023 03:37:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231736AbjJCKhG (ORCPT + 99 others); Tue, 3 Oct 2023 06:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjJCKhF (ORCPT ); Tue, 3 Oct 2023 06:37:05 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF3CAC for ; Tue, 3 Oct 2023 03:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sYFV784QNfVsvR6OfaRbdZY0R9+sNWsxSwOAX+vHka8=; b=Lzyv0kqTljtDaZ9pNT6SbEsAdc Pu0My9FYykJIiQ0T4evWjXkmtINCQEWTnRLZ4g3zJtcQUkuN1RSht1vJhTs4wWKqq/uIn1m4lDdQ6 KfNOLcCGWVq944pMfLucy8bauWFXszNB/pIXN8hrDuNJpGH/n3OegC1oYsNks83392gSfcc7g3Ef1 fXwfe4dG8vFlokRkqQtx0ZwX+n8T+VcFH6a4kQrzmBlDgOwtPyFYnGDMMm99oViMcZllh0TJVgHQ0 oIABSlqqyGzgZmYOB02cnI2oGKv3gBHOuLWBOxKxH1OnhyGSt7Z/+YHRvTAy27kqBt27K7/OExLbC Kz5pi/DA==; 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 1qnclb-00EWuG-Te; Tue, 03 Oct 2023 10:36:39 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 630AE300348; Tue, 3 Oct 2023 12:36:39 +0200 (CEST) Date: Tue, 3 Oct 2023 12:36:39 +0200 From: Peter Zijlstra To: Yajun Deng Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH v4] sched/rt: move back to RT_GROUP_SCHED and rename it child Message-ID: <20231003103639.GD1539@noisy.programming.kicks-ass.net> References: <20230803050317.2240948-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230803050317.2240948-1-yajun.deng@linux.dev> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 03:37:08 -0700 (PDT) On Thu, Aug 03, 2023 at 01:03:17PM +0800, Yajun Deng wrote: > @@ -564,6 +566,9 @@ static inline struct task_group *next_task_group(struct task_group *tg) > #define for_each_sched_rt_entity(rt_se) \ > for (; rt_se; rt_se = rt_se->parent) > > +#define for_each_sched_rt_entity_reverse(rt_se) \ > + for (; rt_se; rt_se = rt_se->child) > + > static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) > { > return rt_se->my_q; > @@ -669,6 +674,9 @@ typedef struct rt_rq *rt_rq_iter_t; > #define for_each_sched_rt_entity(rt_se) \ > for (; rt_se; rt_se = NULL) > > +#define for_each_sched_rt_entity_reverse(rt_se) \ > + for_each_sched_rt_entity(rt_se) > + > static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) > { > return NULL; > @@ -1481,22 +1489,21 @@ static void __dequeue_rt_entity(struct sched_rt_entity *rt_se, unsigned int flag > */ > static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int flags) > { > - struct sched_rt_entity *back = NULL; > + struct sched_rt_entity *root; > unsigned int rt_nr_running; > > - for_each_sched_rt_entity(rt_se) { > - rt_se->back = back; > - back = rt_se; > - } > + for_each_sched_rt_entity(rt_se) > + root = rt_se; > > - rt_nr_running = rt_rq_of_se(back)->rt_nr_running; > + rt_nr_running = rt_rq_of_se(root)->rt_nr_running; > > - for (rt_se = back; rt_se; rt_se = rt_se->back) { > + rt_se = root; > + for_each_sched_rt_entity_reverse(rt_se) { > if (on_rt_rq(rt_se)) > __dequeue_rt_entity(rt_se, flags); > } > > - dequeue_top_rt_rq(rt_rq_of_se(back), rt_nr_running); > + dequeue_top_rt_rq(rt_rq_of_se(root), rt_nr_running); > } Urgh, please don't do this. The whole thing is super fragile. Creating these abstractions makes it appear like for_each_sched_rt_entity_reverse() is somehow a sane thing to do. Aside from the name being insanely long, the whole thing makes no sense what-so-ever unless you first went and did the normal iteration and set the back pointers. It's called back for a reason, it walks back the path it first walked. Normals and unambiguous iteration is up the tree, towards the root, walking back down is not.