mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP
@ 2026-11-29 19:19 Mehmet Fide
  2026-11-29 19:25 ` Christian Loehle
  0 siblings, 1 reply; 4+ messages in thread
From: Mehmet Fide @ 2026-11-29 19:19 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

Since commit cac5cefbade9 ("sched/smp: Make SMP unconditional") a
CONFIG_SMP=n kernel runs the PELT updates of the fair class. Before it,
!SMP had stubs for update_load_avg(), which only called
cfs_rq_util_change(), for {attach,detach,remove}_entity_load_avg() and
for util_est_{enqueue,dequeue}().

On a single CPU nothing needs these averages: there is nothing to
balance, and schedutil, and with it UCLAMP_TASK, depends on SMP. The
group shares read them, but on one CPU a runnable group gets tg->shares
in every cgroup_mode with or without them, but for "tasks", which
scales tg->shares by the runnable average.

Return early from these functions again on !CONFIG_SMP, with the
IS_ENABLED(CONFIG_SMP) toggles the cover letter of the series suggested
for the UP overhead. detach_entity_cfs_rq() again tests
se->avg.last_update_time, which stays 0 without the updates, only on
SMP.

Round trips between two tasks on a Toradex Colibri VF50 (NXP Vybrid
VF500, a single Cortex-A5, CONFIG_SMP=n, PREEMPT_VOLUNTARY, HZ=100,
FAIR_GROUP_SCHED), in us, the mean of three boots, and of two boots for
a build with -falign-functions=32:

                      default build      -falign-functions=32
                      before   after     before   after
  pipe                   224     178        189     148
  futex                  272     221        248     213
  unix stream            397     367        372     322
  sched_yield, 2 calls    35      40         43      28

In both builds the instructions per round trip go from 11800-11840 to
10170 for the pipe and from 4805 to 4020 for sched_yield. sched_yield
depends on the code layout: its L1 I-cache misses per round trip go
from 66 to 98 in the default build, and from 98 to 45 in the other.

Link: https://lore.kernel.org/all/20250528080924.2273858-1-mingo@kernel.org/
Signed-off-by: Mehmet Fide <mehmet.fide@gmail.com>
---

Notes:
    RFC because I do not know whether the PELT updates on UP are wanted
    for something I missed, and whether the RT, DL, IRQ and HW pressure
    averages should get the same treatment: they were !SMP stubs before
    cac5cefbade9 too and still run, as I measured only the fair class.
    
    With the patch, /proc/<pid>/sched and the sched debugfs files show the
    initial averages, and cgroup_mode "tasks" uses one task per group.
    
    Tested on the VF50 before and after: cgroup v2 cpu.weight 100:300 gives
    a 1:3 split, cpu.max of 20 % gives 2010 of 10000 ms, cgroup moves,
    policy and nice changes, fork and exec; the same on a PROVE_LOCKING and
    DEBUG_ATOMIC_SLEEP kernel without a report. kernel/sched builds with W=1
    without new warnings for ARM multi_v7_defconfig, x86_64 defconfig,
    x86_64 with SMP=n, FAIR_GROUP_SCHED and CFS_BANDWIDTH, and tinyconfig.
    systemd reported the boot 0.18 s (0.6 %) faster, the median of ten each.

 kernel/sched/fair.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2d9d3d68626..159b3eb53c2 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5908,11 +5908,16 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
  */
 static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
+	u32 divider;
+
+	if (!IS_ENABLED(CONFIG_SMP))
+		return;
+
 	/*
 	 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se.
 	 * See ___update_load_avg() for details.
 	 */
-	u32 divider = get_pelt_divider(&cfs_rq->avg);
+	divider = get_pelt_divider(&cfs_rq->avg);
 
 	/*
 	 * When we attach the @se to the @cfs_rq, we must align the decay
@@ -5963,6 +5968,9 @@ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
  */
 static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
+	if (!IS_ENABLED(CONFIG_SMP))
+		return;
+
 	dequeue_load_avg(cfs_rq, se);
 	__update_sa(&cfs_rq->avg, util, -se->avg.util_avg, -se->avg.util_sum);
 	__update_sa(&cfs_rq->avg, runnable, -se->avg.runnable_avg, -se->avg.runnable_sum);
@@ -6058,9 +6066,17 @@ static inline void util_est_update(struct sched_entity *se)
 /* Update task and its cfs_rq load average */
 static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
 {
-	u64 now = cfs_rq_clock_pelt(cfs_rq);
+	u64 now;
 	int decayed;
 
+	/* Load balancing and schedutil, the users of PELT, need SMP */
+	if (!IS_ENABLED(CONFIG_SMP)) {
+		cfs_rq_util_change(cfs_rq, 0);
+		return;
+	}
+
+	now = cfs_rq_clock_pelt(cfs_rq);
+
 	/*
 	 * Track task load average for carrying it to new CPU after migrated, and
 	 * track group sched_entity load average for task_h_load calculation in migration
@@ -6123,6 +6139,9 @@ static void remove_entity_load_avg(struct sched_entity *se)
 	struct cfs_rq *cfs_rq = cfs_rq_of(se);
 	unsigned long flags;
 
+	if (!IS_ENABLED(CONFIG_SMP))
+		return;
+
 	/*
 	 * tasks cannot exit without having gone through wake_up_new_task() ->
 	 * enqueue_task_fair() which will have added things to the cfs_rq,
@@ -6172,7 +6191,7 @@ static inline void util_est_enqueue(struct cfs_rq *cfs_rq,
 {
 	unsigned int enqueued;
 
-	if (!sched_feat(UTIL_EST))
+	if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST))
 		return;
 
 	/* Update root cfs_rq's estimated utilization */
@@ -6188,7 +6207,7 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
 {
 	unsigned int enqueued;
 
-	if (!sched_feat(UTIL_EST))
+	if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST))
 		return;
 
 	/* Update root cfs_rq's estimated utilization */
@@ -15495,7 +15514,7 @@ static void detach_entity_cfs_rq(struct sched_entity *se)
 	 * - A task which has been woken up by try_to_wake_up() but is
 	 *   waiting for actually being woken up by sched_ttwu_pending().
 	 */
-	if (!se->avg.last_update_time)
+	if (IS_ENABLED(CONFIG_SMP) && !se->avg.last_update_time)
 		return;
 
 	/* Catch up with the cfs_rq and remove our load when we leave */
-- 
2.56.0


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

* Re: [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP
  2026-11-29 19:19 [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP Mehmet Fide
@ 2026-11-29 19:25 ` Christian Loehle
  2026-11-29 19:32   ` Mehmet Fide
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Loehle @ 2026-11-29 19:25 UTC (permalink / raw)
  To: Mehmet Fide, Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

On 11/29/26 19:19, Mehmet Fide wrote:
> Since commit cac5cefbade9 ("sched/smp: Make SMP unconditional") a
> CONFIG_SMP=n kernel runs the PELT updates of the fair class. Before it,
> !SMP had stubs for update_load_avg(), which only called
> cfs_rq_util_change(), for {attach,detach,remove}_entity_load_avg() and
> for util_est_{enqueue,dequeue}().
> 
> On a single CPU nothing needs these averages: there is nothing to
> balance, and schedutil, and with it UCLAMP_TASK, depends on SMP. The
> group shares read them, but on one CPU a runnable group gets tg->shares
> in every cgroup_mode with or without them, but for "tasks", which
> scales tg->shares by the runnable average.
> 
> Return early from these functions again on !CONFIG_SMP, with the
> IS_ENABLED(CONFIG_SMP) toggles the cover letter of the series suggested
> for the UP overhead. detach_entity_cfs_rq() again tests
> se->avg.last_update_time, which stays 0 without the updates, only on
> SMP.
> 
> Round trips between two tasks on a Toradex Colibri VF50 (NXP Vybrid
> VF500, a single Cortex-A5, CONFIG_SMP=n, PREEMPT_VOLUNTARY, HZ=100,
> FAIR_GROUP_SCHED), in us, the mean of three boots, and of two boots for
> a build with -falign-functions=32:
> 
>                       default build      -falign-functions=32
>                       before   after     before   after
>   pipe                   224     178        189     148
>   futex                  272     221        248     213
>   unix stream            397     367        372     322
>   sched_yield, 2 calls    35      40         43      28
> 
> In both builds the instructions per round trip go from 11800-11840 to
> 10170 for the pipe and from 4805 to 4020 for sched_yield. sched_yield
> depends on the code layout: its L1 I-cache misses per round trip go
> from 66 to 98 in the default build, and from 98 to 45 in the other.
> 
> Link: https://lore.kernel.org/all/20250528080924.2273858-1-mingo@kernel.org/
> Signed-off-by: Mehmet Fide <mehmet.fide@gmail.com>
> ---
> 
> Notes:
>     RFC because I do not know whether the PELT updates on UP are wanted
>     for something I missed, and whether the RT, DL, IRQ and HW pressure
>     averages should get the same treatment: they were !SMP stubs before
>     cac5cefbade9 too and still run, as I measured only the fair class.

We can still use them for DVFS, i.e. schedutil, can't we?
Besides, the entire point of the commit was to get rid of the SMP ifdeffery
and this is introducing them in a worse way.

>     
>     With the patch, /proc/<pid>/sched and the sched debugfs files show the
>     initial averages, and cgroup_mode "tasks" uses one task per group.
>     
>     Tested on the VF50 before and after: cgroup v2 cpu.weight 100:300 gives
>     a 1:3 split, cpu.max of 20 % gives 2010 of 10000 ms, cgroup moves,
>     policy and nice changes, fork and exec; the same on a PROVE_LOCKING and
>     DEBUG_ATOMIC_SLEEP kernel without a report. kernel/sched builds with W=1
>     without new warnings for ARM multi_v7_defconfig, x86_64 defconfig,
>     x86_64 with SMP=n, FAIR_GROUP_SCHED and CFS_BANDWIDTH, and tinyconfig.
>     systemd reported the boot 0.18 s (0.6 %) faster, the median of ten each.
> 
>  kernel/sched/fair.c | 29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 2d9d3d68626..159b3eb53c2 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5908,11 +5908,16 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
>   */
>  static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  {
> +	u32 divider;
> +
> +	if (!IS_ENABLED(CONFIG_SMP))
> +		return;
> +
>  	/*
>  	 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se.
>  	 * See ___update_load_avg() for details.
>  	 */
> -	u32 divider = get_pelt_divider(&cfs_rq->avg);
> +	divider = get_pelt_divider(&cfs_rq->avg);
>  
>  	/*
>  	 * When we attach the @se to the @cfs_rq, we must align the decay
> @@ -5963,6 +5968,9 @@ static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
>   */
>  static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  {
> +	if (!IS_ENABLED(CONFIG_SMP))
> +		return;
> +
>  	dequeue_load_avg(cfs_rq, se);
>  	__update_sa(&cfs_rq->avg, util, -se->avg.util_avg, -se->avg.util_sum);
>  	__update_sa(&cfs_rq->avg, runnable, -se->avg.runnable_avg, -se->avg.runnable_sum);
> @@ -6058,9 +6066,17 @@ static inline void util_est_update(struct sched_entity *se)
>  /* Update task and its cfs_rq load average */
>  static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>  {
> -	u64 now = cfs_rq_clock_pelt(cfs_rq);
> +	u64 now;
>  	int decayed;
>  
> +	/* Load balancing and schedutil, the users of PELT, need SMP */
> +	if (!IS_ENABLED(CONFIG_SMP)) {
> +		cfs_rq_util_change(cfs_rq, 0);
> +		return;
> +	}
> +
> +	now = cfs_rq_clock_pelt(cfs_rq);
> +
>  	/*
>  	 * Track task load average for carrying it to new CPU after migrated, and
>  	 * track group sched_entity load average for task_h_load calculation in migration
> @@ -6123,6 +6139,9 @@ static void remove_entity_load_avg(struct sched_entity *se)
>  	struct cfs_rq *cfs_rq = cfs_rq_of(se);
>  	unsigned long flags;
>  
> +	if (!IS_ENABLED(CONFIG_SMP))
> +		return;
> +
>  	/*
>  	 * tasks cannot exit without having gone through wake_up_new_task() ->
>  	 * enqueue_task_fair() which will have added things to the cfs_rq,
> @@ -6172,7 +6191,7 @@ static inline void util_est_enqueue(struct cfs_rq *cfs_rq,
>  {
>  	unsigned int enqueued;
>  
> -	if (!sched_feat(UTIL_EST))
> +	if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST))
>  		return;
>  
>  	/* Update root cfs_rq's estimated utilization */
> @@ -6188,7 +6207,7 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
>  {
>  	unsigned int enqueued;
>  
> -	if (!sched_feat(UTIL_EST))
> +	if (!IS_ENABLED(CONFIG_SMP) || !sched_feat(UTIL_EST))
>  		return;
>  
>  	/* Update root cfs_rq's estimated utilization */
> @@ -15495,7 +15514,7 @@ static void detach_entity_cfs_rq(struct sched_entity *se)
>  	 * - A task which has been woken up by try_to_wake_up() but is
>  	 *   waiting for actually being woken up by sched_ttwu_pending().
>  	 */
> -	if (!se->avg.last_update_time)
> +	if (IS_ENABLED(CONFIG_SMP) && !se->avg.last_update_time)
>  		return;
>  
>  	/* Catch up with the cfs_rq and remove our load when we leave */


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

* Re: [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP
  2026-11-29 19:25 ` Christian Loehle
@ 2026-11-29 19:32   ` Mehmet Fide
  2026-11-29 19:53     ` Christian Loehle
  0 siblings, 1 reply; 4+ messages in thread
From: Mehmet Fide @ 2026-11-29 19:32 UTC (permalink / raw)
  To: Christian Loehle
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

Hi Christian,

> We can still use them for DVFS, i.e. schedutil, can't we?

Not with CONFIG_SMP=n: CPU_FREQ_GOV_SCHEDUTIL still depends on SMP, so
such a kernel has no schedutil. If that dependency is dropped, the
skip would have to follow schedutil instead of SMP.

> Besides, the entire point of the commit was to get rid of the SMP ifdeffery
> and this is introducing them in a worse way.

I went by the cover letter of the series, which asked for UP
improvements through "well-placed IS_ENABLED(CONFIG_SMP) kind of
toggles". If seven of them in fair.c are too many for 7-22 % on the
round trips of a UP board, is there a form you would accept?

Mehmet

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

* Re: [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP
  2026-11-29 19:32   ` Mehmet Fide
@ 2026-11-29 19:53     ` Christian Loehle
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Loehle @ 2026-11-29 19:53 UTC (permalink / raw)
  To: Mehmet Fide
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

On 11/29/26 19:32, Mehmet Fide wrote:
> Hi Christian,
> 
>> We can still use them for DVFS, i.e. schedutil, can't we?
> 
> Not with CONFIG_SMP=n: CPU_FREQ_GOV_SCHEDUTIL still depends on SMP, so
> such a kernel has no schedutil. If that dependency is dropped, the
> skip would have to follow schedutil instead of SMP.

Ah you're right of course. That being said that was because PELT didn't
support UP back then while now it's probably just a matter of removing
that Kconfig dependency AFAICT, if anything this probably should've been
done with cac5cefbade9 ("sched/smp: Make SMP unconditional")


Not that it actually achieves what you aim to do, rather the opposite.

> 
>> Besides, the entire point of the commit was to get rid of the SMP ifdeffery
>> and this is introducing them in a worse way.
> 
> I went by the cover letter of the series, which asked for UP
> improvements through "well-placed IS_ENABLED(CONFIG_SMP) kind of
> toggles". If seven of them in fair.c are too many for 7-22 % on the
> round trips of a UP board, is there a form you would accept?
> 

You'll be glad to hear that I don't call the shots here ;)
The feeling I get is that scheduler folks dream of dropping support
for CONFIG_SMP=n altogether if there was a way that they could...

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

end of thread, other threads:[~2026-11-29 19:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 19:19 [RFC PATCH] sched/fair: Skip PELT on !CONFIG_SMP Mehmet Fide
2026-11-29 19:25 ` Christian Loehle
2026-11-29 19:32   ` Mehmet Fide
2026-11-29 19:53     ` Christian Loehle

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®