linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/43] sched: Use the SMP scheduler on UP too
@ 2025-05-28  8:08 Ingo Molnar
  2025-05-28  8:08 ` [PATCH 01/43] sched: Clean up and standardize #if/#else/#endif markers in sched/autogroup.[ch] Ingo Molnar
                   ` (44 more replies)
  0 siblings, 45 replies; 95+ messages in thread
From: Ingo Molnar @ 2025-05-28  8:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dietmar Eggemann, Linus Torvalds, Peter Zijlstra, Shrikanth Hegde,
	Thomas Gleixner, Valentin Schneider, Steven Rostedt, Mel Gorman,
	Vincent Guittot, Sebastian Andrzej Siewior, Ingo Molnar

This series implements an idea Peter Zijlstra has mentioned
before: standardize the Linux scheduler on the SMP variant to
drastically reduce the number of CONFIG_SMP blocks of code
and related complexity in the scheduler.

Today the Linux scheduler has an obscene amount of CONFIG_SMP
preprocessor blocks of code, where UP code diverges from SMP code:

	$ git grep CONFIG_SMP kernel/sched/ | grep -v endif | wc -l
	175

Which is substantial complexity that regularly results in build
failures and the occasional boot failure when people develop on
CONFIG_SMP and (naturally) don't immediately test on !CONFIG_SMP.

These build and boot failures are in fact under-reported in the
upstream kernel Git history, because they tend to be triggered
on developer systems: but they are still there and they are still
an ongoing development and maintenance cost. It's rare to see
a larger scheduler patch series that doesn't have some sort of
build complication on !SMP.

Another problem is that these literally 175 separate blocks of
preprocessor code make the scheduler code harder to review and
harder to understand.

All the while most modern hardware platforms - even embedded ones -
tend to have two or more CPUs and use SMP kernels these days.

So there's an ongoing and largely hidden burden of maintenance
and cost of complexity on scheduler developers.

This series gets rid of much of that CONFIG_SMP complexity by building
the UP scheduler from the SMP scheduler:

	$ git grep CONFIG_SMP kernel/sched/ | grep -v endif | wc -l
	28

The plain code reduction is nice too:

	33 files changed, 237 insertions(+), 999 deletions(-)

... or, when measured from after the cleanup series:

	24 files changed, 26 insertions(+), 789 deletions(-)

Note that even after this series the UP kernel can still be
improved too, as long as it is done via sensible patches
that use well-placed IS_ENABLED(CONFIG_SMP) kind of toggles,
without these almost 200 insane #ifdef blocks.

Note that the approach I chose is pretty blunt and straightforward,
to make sure this conversion is as bug-free as possible. I'd rather
bloat the UP scheduler a bit than to break it.

The first part of the series cleans up #if/#else/#endif markers to
be consistent, this made the removal patches much easier to
review, because instead of a random, context-free #endif removal:

	@@ -658,6 +657,7 @@ int __sched_setscheduler(struct task_struct *p,
					goto unlock;
				}
			}
	-#endif
		}

We now modify properly marked-up #endif blocks:

	@@ -658,6 +657,7 @@ int __sched_setscheduler(struct task_struct *p,
					goto unlock;
				}
			}
	-#endif /* CONFIG_SMP */
		}

Which can more easily be verified for intent and correctness.

The second part of the series converts the UP scheduler to the SMP
scheduler. The biggest patch:

	sched/smp: Make SMP unconditional

Ended up being rather large and monolithic, and there's no easy way I can
see to increase granularity there without breaking the scheduler in the
interim step: because there's no clear separation of various aspects of the
UP/SMP scheduler, other than a humunguous amount of #ifdef CONFIG_SMP blocks
we grew over ~25 years...

Once that first large step was done, it was easier to do the rest more
gradually.

Note that much of the extra SMP code is unused code that will never
be triggered on a UP kernel - such as load-balancing, but there's some
extra context switching overhead on UP kernels:

  $ perf stat --null --sync --repeat 5 perf bench sched pipe

  # Before: 2.55022 +- 0.00308 seconds time elapsed  ( +-  0.12% )
  # After:  2.68700 +- 0.01600 seconds time elapsed  ( +-  0.59% )

Kernel size impact (on x86-defconfig+!CONFIG_SMP):

      text       data        bss         dec        hex    filename
  28816070    7720174    1837328    38373572    24988c4    vmlinux.defconfig.nosmp.before
  28904324    7735982    1817876    38458182    24ad346    vmlinux.defconfig.nosmp.after

+0.3% text, +0.2% data.

But at this point I think the burden of proof and the burden of
work needs to be reversed: and anyone who cares about UP performance
or size should present sensible patches to improve performance/size.

The series is lightly tested at the moment, but I've tested the UP
scheduler on every bisection point to make sure it boots & works, and
to make sure any problems can be bisected back as far as possible.

The latest version of this series can be found at:

	git://git.kernel.org/pub/scm/linux/kernel/git/mingo/tip.git WIP.sched/core

Thanks,

	Ingo

================>
Ingo Molnar (43):
  sched: Clean up and standardize #if/#else/#endif markers in sched/autogroup.[ch]
  sched: Clean up and standardize #if/#else/#endif markers in sched/clock.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/core.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/cpufreq_schedutil.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/cpupri.h
  sched: Clean up and standardize #if/#else/#endif markers in sched/cputime.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/deadline.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/debug.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/fair.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/idle.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/loadavg.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/pelt.[ch]
  sched: Clean up and standardize #if/#else/#endif markers in sched/psi.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/rt.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/sched.h
  sched: Clean up and standardize #if/#else/#endif markers in sched/stats.[ch]
  sched: Clean up and standardize #if/#else/#endif markers in sched/syscalls.c
  sched: Clean up and standardize #if/#else/#endif markers in sched/topology.c
  sched/smp: Always define sched_domains_mutex_lock()/unlock(), def_root_domain and sched_domains_mutex
  sched/smp: Make SMP unconditional
  sched/smp: Always define is_percpu_thread() and scheduler_ipi()
  sched/smp: Always define rq->hrtick_csd
  sched/smp: Use the SMP version of try_to_wake_up()
  sched/smp: Use the SMP version of __task_needs_rq_lock()
  sched/smp: Use the SMP version of wake_up_new_task()
  sched/smp: Use the SMP version of sched_exec()
  sched/smp: Use the SMP version of idle_thread_set_boot_cpu()
  sched/smp: Use the SMP version of the RT scheduling class
  sched/smp: Use the SMP version of the deadline scheduling class
  sched/smp: Use the SMP version of scheduler debugging data
  sched/smp: Use the SMP version of schedstats
  sched/smp: Use the SMP version of the scheduler syscalls
  sched/smp: Use the SMP version of sched_update_asym_prefer_cpu()
  sched/smp: Use the SMP version of the idle scheduling class
  sched/smp: Use the SMP version of the stop-CPU scheduling class
  sched/smp: Use the SMP version of cpu_of()
  sched/smp: Use the SMP version of is_migration_disabled()
  sched/smp: Use the SMP version of rq_pin_lock()
  sched/smp: Use the SMP version of task_on_cpu()
  sched/smp: Use the SMP version of WF_ and SD_ flag sanity checks
  sched/smp: Use the SMP version of ENQUEUE_MIGRATED
  sched/smp: Use the SMP version of add_nr_running()
  sched/smp: Use the SMP version of double_rq_clock_clear_update()

 include/linux/preempt.h          |   9 --
 include/linux/sched.h            |  55 --------
 include/linux/sched/deadline.h   |   4 -
 include/linux/sched/idle.h       |   4 -
 include/linux/sched/nohz.h       |   4 +-
 include/linux/sched/task.h       |   4 -
 include/linux/sched/topology.h   |  32 -----
 kernel/sched/autogroup.c         |   6 +-
 kernel/sched/autogroup.h         |   4 +-
 kernel/sched/build_policy.c      |   6 +-
 kernel/sched/build_utility.c     |   9 +-
 kernel/sched/clock.c             |   4 +-
 kernel/sched/core.c              | 281 ++++++++++++---------------------------
 kernel/sched/cpudeadline.h       |   2 -
 kernel/sched/cpufreq_schedutil.c |   4 +-
 kernel/sched/cpupri.h            |   2 -
 kernel/sched/cputime.c           |  14 +-
 kernel/sched/deadline.c          | 115 +---------------
 kernel/sched/debug.c             |  44 ++----
 kernel/sched/fair.c              | 194 ++++++---------------------
 kernel/sched/idle.c              |  10 +-
 kernel/sched/loadavg.c           |   4 +-
 kernel/sched/pelt.c              |   4 +-
 kernel/sched/pelt.h              |  62 +--------
 kernel/sched/psi.c               |   4 +-
 kernel/sched/rt.c                |  98 +++-----------
 kernel/sched/sched.h             | 206 +++++-----------------------
 kernel/sched/stats.c             |   4 -
 kernel/sched/stats.h             |  10 +-
 kernel/sched/stop_task.c         |   4 -
 kernel/sched/syscalls.c          |  15 +--
 kernel/sched/topology.c          |  14 +-
 kernel/smpboot.c                 |   4 -
 33 files changed, 237 insertions(+), 999 deletions(-)

-- 
2.45.2


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

end of thread, other threads:[~2025-06-13  7:37 UTC | newest]

Thread overview: 95+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28  8:08 [PATCH 00/43] sched: Use the SMP scheduler on UP too Ingo Molnar
2025-05-28  8:08 ` [PATCH 01/43] sched: Clean up and standardize #if/#else/#endif markers in sched/autogroup.[ch] Ingo Molnar
2025-05-30  2:29   ` Sohil Mehta
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 02/43] sched: Clean up and standardize #if/#else/#endif markers in sched/clock.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 03/43] sched: Clean up and standardize #if/#else/#endif markers in sched/core.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 04/43] sched: Clean up and standardize #if/#else/#endif markers in sched/cpufreq_schedutil.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 05/43] sched: Clean up and standardize #if/#else/#endif markers in sched/cpupri.h Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 06/43] sched: Clean up and standardize #if/#else/#endif markers in sched/cputime.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 07/43] sched: Clean up and standardize #if/#else/#endif markers in sched/deadline.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 08/43] sched: Clean up and standardize #if/#else/#endif markers in sched/debug.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 09/43] sched: Clean up and standardize #if/#else/#endif markers in sched/fair.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 10/43] sched: Clean up and standardize #if/#else/#endif markers in sched/idle.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 11/43] sched: Clean up and standardize #if/#else/#endif markers in sched/loadavg.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 12/43] sched: Clean up and standardize #if/#else/#endif markers in sched/pelt.[ch] Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 13/43] sched: Clean up and standardize #if/#else/#endif markers in sched/psi.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 14/43] sched: Clean up and standardize #if/#else/#endif markers in sched/rt.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 15/43] sched: Clean up and standardize #if/#else/#endif markers in sched/sched.h Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 16/43] sched: Clean up and standardize #if/#else/#endif markers in sched/stats.[ch] Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 17/43] sched: Clean up and standardize #if/#else/#endif markers in sched/syscalls.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:08 ` [PATCH 18/43] sched: Clean up and standardize #if/#else/#endif markers in sched/topology.c Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 19/43] sched/smp: Always define sched_domains_mutex_lock()/unlock(), def_root_domain and sched_domains_mutex Ingo Molnar
2025-05-28  8:14   ` [PATCH 20/43] sched/smp: Make SMP unconditional Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] sched/smp: Always define sched_domains_mutex_lock()/unlock(), def_root_domain and sched_domains_mutex tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 20/43] sched/smp: Make SMP unconditional Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 21/43] sched/smp: Always define is_percpu_thread() and scheduler_ipi() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 22/43] sched/smp: Always define rq->hrtick_csd Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 23/43] sched/smp: Use the SMP version of try_to_wake_up() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 24/43] sched/smp: Use the SMP version of __task_needs_rq_lock() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 25/43] sched/smp: Use the SMP version of wake_up_new_task() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 26/43] sched/smp: Use the SMP version of sched_exec() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 27/43] sched/smp: Use the SMP version of idle_thread_set_boot_cpu() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 28/43] sched/smp: Use the SMP version of the RT scheduling class Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 29/43] sched/smp: Use the SMP version of the deadline " Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 30/43] sched/smp: Use the SMP version of scheduler debugging data Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 31/43] sched/smp: Use the SMP version of schedstats Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 32/43] sched/smp: Use the SMP version of the scheduler syscalls Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 33/43] sched/smp: Use the SMP version of sched_update_asym_prefer_cpu() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 34/43] sched/smp: Use the SMP version of the idle scheduling class Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 35/43] sched/smp: Use the SMP version of the stop-CPU " Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 36/43] sched/smp: Use the SMP version of cpu_of() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 37/43] sched/smp: Use the SMP version of is_migration_disabled() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 38/43] sched/smp: Use the SMP version of rq_pin_lock() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 39/43] sched/smp: Use the SMP version of task_on_cpu() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 40/43] sched/smp: Use the SMP version of WF_ and SD_ flag sanity checks Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 41/43] sched/smp: Use the SMP version of ENQUEUE_MIGRATED Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 42/43] sched/smp: Use the SMP version of add_nr_running() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:09 ` [PATCH 43/43] sched/smp: Use the SMP version of double_rq_clock_clear_update() Ingo Molnar
2025-06-13  7:37   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-05-28  8:58 ` [PATCH 00/43] sched: Use the SMP scheduler on UP too Peter Zijlstra
2025-05-28 14:00   ` Steven Rostedt
2025-05-28 16:10     ` Peter Zijlstra
2025-05-28 16:21       ` Steven Rostedt
2025-05-29  6:42   ` Ingo Molnar
2025-05-30  9:34 ` [PATCH] sched: Break dependency loop between sched.h and preempt.h Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).