From: Yury Norov <yury.norov@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>
Subject: [PATCH] sched/fair: Rework pick_task_fair() control flow
Date: Wed, 9 Sep 2026 14:17:12 -0400 [thread overview]
Message-ID: <20260909181712.1050224-1-ynorov@nvidia.com> (raw)
Split out the logic picking a task from rq to a separate helper,
and get rid of the gotos.
With GCC 15.2.0 and x86_64_defconfig, the new version saves 96 bytes,
and with defconfig + CONFIG_SCHED_CORE + CONFIG_CFS_BANDWIDTH it saves
124 bytes.
No functional changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
kernel/sched/fair.c | 51 ++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ade1eceb39b8..ad0c477e58a8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10043,39 +10043,42 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f
resched_curr_lazy(rq);
}
-struct task_struct *pick_task_fair(struct rq *rq, struct rq_flags *rf)
- __must_hold(__rq_lockp(rq))
+static struct task_struct *pick_task_fair_rq(struct rq *rq)
{
struct cfs_rq *cfs_rq = &rq->cfs;
struct sched_entity *se;
- struct task_struct *p;
- int new_tasks;
-again:
- if (!cfs_rq->h_nr_queued)
- goto idle;
+ while (cfs_rq->h_nr_queued) {
+ /* Might not have done put_prev_entity() */
+ if (cfs_rq->curr && cfs_rq->curr->on_rq)
+ update_curr_eevdf(cfs_rq);
- /* Might not have done put_prev_entity() */
- if (cfs_rq->curr && cfs_rq->curr->on_rq)
- update_curr_eevdf(cfs_rq);
+ se = pick_next_entity(rq, true);
+ if (se)
+ return task_of(se);
+ }
- se = pick_next_entity(rq, true);
- if (!se)
- goto again;
+ return NULL;
+}
- p = task_of(se);
- return p;
+struct task_struct *pick_task_fair(struct rq *rq, struct rq_flags *rf)
+ __must_hold(__rq_lockp(rq))
+{
+ struct task_struct *p;
+ int new_tasks;
-idle:
- if (sched_core_enabled(rq))
- return NULL;
+ do {
+ p = pick_task_fair_rq(rq);
+ if (p)
+ return p;
- new_tasks = sched_balance_newidle(rq, rf);
- if (new_tasks < 0)
- return RETRY_TASK;
- if (new_tasks > 0)
- goto again;
- return NULL;
+ if (sched_core_enabled(rq))
+ return NULL;
+
+ new_tasks = sched_balance_newidle(rq, rf);
+ } while (new_tasks > 0);
+
+ return new_tasks ? RETRY_TASK : NULL;
}
static struct task_struct *
--
2.53.0
reply other threads:[~2026-09-09 18:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260909181712.1050224-1-ynorov@nvidia.com \
--to=yury.norov@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=ynorov@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®