mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Rework pick_task_fair() control flow
@ 2026-09-09 18:17 Yury Norov
  2026-09-21 16:14 ` Yury Norov
  0 siblings, 1 reply; 2+ messages in thread
From: Yury Norov @ 2026-09-09 18:17 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel
  Cc: Yury Norov, Yury Norov

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched/fair: Rework pick_task_fair() control flow
  2026-09-09 18:17 [PATCH] sched/fair: Rework pick_task_fair() control flow Yury Norov
@ 2026-09-21 16:14 ` Yury Norov
  0 siblings, 0 replies; 2+ messages in thread
From: Yury Norov @ 2026-09-21 16:14 UTC (permalink / raw)
  To: Yury Norov
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

Ping?

On Wed, Sep 09, 2026 at 02:17:12PM -0400, Yury Norov wrote:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-21 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 18:17 [PATCH] sched/fair: Rework pick_task_fair() control flow Yury Norov
2026-09-21 16:14 ` Yury Norov

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®