From nobody Sat Feb 7 22:01:53 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64906EB64DD for ; Wed, 2 Aug 2023 02:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231719AbjHBCYe (ORCPT ); Tue, 1 Aug 2023 22:24:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjHBCYc (ORCPT ); Tue, 1 Aug 2023 22:24:32 -0400 Received: from out-120.mta1.migadu.com (out-120.mta1.migadu.com [95.215.58.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC77E213F for ; Tue, 1 Aug 2023 19:24:30 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690943067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fwE+Rq9mSoCZ0Nln+HHt8N0bG1PTqQvHzIw9QHmw6bs=; b=dLfBcyCus8YC/ybHlmyFMKLW7KJXaxqnWgSK17lfGcbv8Qqhh3EDBOb2nA/Ly8fxSwm/wh 7KemxI6RQAVD4qd87aWAj4xT9KxxshCvpG1jy6BhBlNaUSnx8wxz2yk1/yw1X8wka+Li1h OqAts/cjjBpXHDHXQYnSoPOWxSaGB5Q= From: Yajun Deng To: mingo@redhat.com, peterz@infradead.org, 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 Cc: linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v2] sched/rt: move back to RT_GROUP_SCHED and rename it child Date: Wed, 2 Aug 2023 10:24:08 +0800 Message-Id: <20230802022408.529208-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The member back in struct sched_rt_entity only related to RT_GROUP_SCHED, it should not place out of RT_GROUP_SCHED, move back to RT_GROUP_SCHED and rename it child. Init child in init_tg_rt_entry(). Also, add WARN_ON_ONCE if parent is NULL, because parent is only NULL when rt_se is NULL. Introduce for_each_sched_rt_entity_reverse() to iterate rt_entity from top to down. Signed-off-by: Yajun Deng --- V1 -> V2: Add WARN_ON_ONCE in init_tg_rt_entry(). --- include/linux/sched.h | 2 +- kernel/sched/rt.c | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 177b3f3676ef..5635655d6c35 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -594,8 +594,8 @@ struct sched_rt_entity { unsigned short on_rq; unsigned short on_list; =20 - struct sched_rt_entity *back; #ifdef CONFIG_RT_GROUP_SCHED + struct sched_rt_entity *child; struct sched_rt_entity *parent; /* rq on which this entity is (to be) queued: */ struct rt_rq *rt_rq; diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 00e0e5074115..8e577c7b9257 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -228,13 +228,13 @@ void init_tg_rt_entry(struct task_group *tg, struct r= t_rq *rt_rq, if (!rt_se) return; =20 - if (!parent) - rt_se->rt_rq =3D &rq->rt; - else - rt_se->rt_rq =3D parent->my_q; + if (WARN_ON_ONCE(!parent)) + return; =20 + rt_se->rt_rq =3D parent->my_q; rt_se->my_q =3D rt_rq; rt_se->parent =3D parent; + parent->child =3D rt_se; INIT_LIST_HEAD(&rt_se->run_list); } =20 @@ -564,6 +564,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 =3D rt_se->parent) =20 +#define for_each_sched_rt_entity_reverse(rt_se) \ + for (; rt_se; rt_se =3D rt_se->child) + static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) { return rt_se->my_q; @@ -669,6 +672,9 @@ typedef struct rt_rq *rt_rq_iter_t; #define for_each_sched_rt_entity(rt_se) \ for (; rt_se; rt_se =3D NULL) =20 +#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 +1487,21 @@ static void __dequeue_rt_entity(struct sched_rt_ent= ity *rt_se, unsigned int flag */ static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int f= lags) { - struct sched_rt_entity *back =3D NULL; + struct sched_rt_entity *root; unsigned int rt_nr_running; =20 - for_each_sched_rt_entity(rt_se) { - rt_se->back =3D back; - back =3D rt_se; - } + for_each_sched_rt_entity(rt_se) + root =3D rt_se; =20 - rt_nr_running =3D rt_rq_of_se(back)->rt_nr_running; + rt_nr_running =3D rt_rq_of_se(root)->rt_nr_running; =20 - for (rt_se =3D back; rt_se; rt_se =3D rt_se->back) { + rt_se =3D root; + for_each_sched_rt_entity_reverse(rt_se) { if (on_rt_rq(rt_se)) __dequeue_rt_entity(rt_se, flags); } =20 - dequeue_top_rt_rq(rt_rq_of_se(back), rt_nr_running); + dequeue_top_rt_rq(rt_rq_of_se(root), rt_nr_running); } =20 static void enqueue_rt_entity(struct sched_rt_entity *rt_se, unsigned int = flags) --=20 2.25.1