From nobody Sun Dec 14 06:19:06 2025 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8981F4D8D0 for ; Sat, 27 Jul 2024 11:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722078147; cv=none; b=I3oDlFNoG72fMrJKp5nVq2p7QLNoP4mKdnvJYxQEbw+nd6lEFlsZwumT7PWNq9P29JwGqLk0/RgQbV+BLKKEB+ZHYNtioi4OoRPTaUJyf0MLis1dLJF/TQEu9P+wTykUDRmN887AbVC7Z0WUpBMagUEQvDPo0+wcLg9RtbcXr88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722078147; c=relaxed/simple; bh=kSvxvy4/yoYnf9FCBRWdJWzSutKP9ReoOQkAiZZfpWw=; h=Message-Id:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ZHh218cU9Xily+djpQdQF/41ovVFuEiSkHzYIsdrp/Ayu+zfq4CjDjc6e5wRnlGPUEFerQ1webBr7TJGzsDGqHjej21XAwjtgwvLpE6JXsdWGNx1iifuOeCfqUh+lEkIpXu48MGwcP93WGnIe8JCM7+rrdsfFo44AMGfECAHBhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=IESUCHlN; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IESUCHlN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=FG3IvHQufE/O/s5O2v8p/EyTrS09xA8nLYQquzdpLRU=; b=IESUCHlNFsxTWaa4o9gPJ5NwmH o7+Yi/bI0FmoCGH58MzXqHLcfHsLekutner9ktx5A7iUJ1Q/ccv2SgIyUgxBiA3Ju61uTDDudPDTf 78YNwWLz5+7P+Y9iw0f2KlbXLDth5DSt8KiYWMrOqJne+gulS1kBn6YyH97NcEgy2KXCzf2tfFmwx PaEk6+NSEg/gj/7PpLI455FY9tEPev01HxGkFgVcP4eKQp4Fm2h1oXHLZN3vydle+rNFQ03OqTYEH TOCJ5q1d/ILn60ksKvwgGrGeCvjotECmQ1kqC1ZDOGIbhPhxrE2Z572RNjeiiqYFFkXi5wOIBJ6/7 ZcswPJCQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXfBg-00000004QMd-0fFo; Sat, 27 Jul 2024 11:02:09 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id A069A3011E4; Sat, 27 Jul 2024 13:02:06 +0200 (CEST) Message-Id: <20240727105028.725062368@infradead.org> User-Agent: quilt/0.65 Date: Sat, 27 Jul 2024 12:27:37 +0200 From: Peter Zijlstra 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, vschneid@redhat.com, linux-kernel@vger.kernel.org Cc: kprateek.nayak@amd.com, wuyun.abel@bytedance.com, youssefesmat@chromium.org, tglx@linutronix.de, efault@gmx.de Subject: [PATCH 05/24] sched/fair: Unify pick_{,next_}_task_fair() References: <20240727102732.960974693@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement pick_next_task_fair() in terms of pick_task_fair() to de-duplicate the pick loop. More importantly, this makes all the pick loops use the state-invariant form, which is useful to introduce further re-try conditions in later patches. Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/fair.c | 60 ++++++-----------------------------------------= ----- 1 file changed, 8 insertions(+), 52 deletions(-) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8415,7 +8415,6 @@ static void check_preempt_wakeup_fair(st resched_curr(rq); } =20 -#ifdef CONFIG_SMP static struct task_struct *pick_task_fair(struct rq *rq) { struct sched_entity *se; @@ -8427,7 +8426,7 @@ static struct task_struct *pick_task_fai return NULL; =20 do { - /* When we pick for a remote RQ, we'll not have done put_prev_entity() */ + /* Might not have done put_prev_entity() */ if (cfs_rq->curr && cfs_rq->curr->on_rq) update_curr(cfs_rq); =20 @@ -8440,19 +8439,19 @@ static struct task_struct *pick_task_fai =20 return task_of(se); } -#endif =20 struct task_struct * pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_fla= gs *rf) { - struct cfs_rq *cfs_rq =3D &rq->cfs; struct sched_entity *se; struct task_struct *p; int new_tasks; =20 again: - if (!sched_fair_runnable(rq)) + p =3D pick_task_fair(rq); + if (!p) goto idle; + se =3D &p->se; =20 #ifdef CONFIG_FAIR_GROUP_SCHED if (!prev || prev->sched_class !=3D &fair_sched_class) @@ -8464,52 +8463,14 @@ pick_next_task_fair(struct rq *rq, struc * * Therefore attempt to avoid putting and setting the entire cgroup * hierarchy, only change the part that actually changes. - */ - - do { - struct sched_entity *curr =3D cfs_rq->curr; - - /* - * Since we got here without doing put_prev_entity() we also - * have to consider cfs_rq->curr. If it is still a runnable - * entity, update_curr() will update its vruntime, otherwise - * forget we've ever seen it. - */ - if (curr) { - if (curr->on_rq) - update_curr(cfs_rq); - else - curr =3D NULL; - - /* - * This call to check_cfs_rq_runtime() will do the - * throttle and dequeue its entity in the parent(s). - * Therefore the nr_running test will indeed - * be correct. - */ - if (unlikely(check_cfs_rq_runtime(cfs_rq))) { - cfs_rq =3D &rq->cfs; - - if (!cfs_rq->nr_running) - goto idle; - - goto simple; - } - } - - se =3D pick_next_entity(cfs_rq); - cfs_rq =3D group_cfs_rq(se); - } while (cfs_rq); - - p =3D task_of(se); - - /* + * * Since we haven't yet done put_prev_entity and if the selected task * is a different task than we started out with, try and touch the * least amount of cfs_rqs. */ if (prev !=3D p) { struct sched_entity *pse =3D &prev->se; + struct cfs_rq *cfs_rq; =20 while (!(cfs_rq =3D is_same_group(se, pse))) { int se_depth =3D se->depth; @@ -8535,13 +8496,8 @@ pick_next_task_fair(struct rq *rq, struc if (prev) put_prev_task(rq, prev); =20 - do { - se =3D pick_next_entity(cfs_rq); - set_next_entity(cfs_rq, se); - cfs_rq =3D group_cfs_rq(se); - } while (cfs_rq); - - p =3D task_of(se); + for_each_sched_entity(se) + set_next_entity(cfs_rq_of(se), se); =20 done: __maybe_unused; #ifdef CONFIG_SMP