preempt: PREEMPT vs PREEMPT_DYNAMIC configs fixup
v3 cover preempt: PREEMPT vs PREEMPT_DYNAMIC configs fixup
Hi folks,
This v3 is mostly about the naming problem - get your paintbrushes ready!
Patches
=======
o Patch 1 is the meat of the topic - note that it's now in tip/sched/urgent
o Patch 2 introduces helpers for the dynamic preempt state
o Patches 3-4 make use of said accessors where relevant.
Testing
=======
Briefly tested the dynamic part on an x86 kernel + QEMU. Compile-tested the kcsan test thingie as a module.
Revisions
=========
v1: http://lore.kernel.org/r/[email protected]
v1.5: http://lore.kernel.org/r/[email protected]
v2 -> v3
++++++++
o Turned is_preempt_*() into preempt_model_*() (Frederic)
It breaks my rule of "booleans must answer a yes/no question" but is the best I could come with using a "preempt_" prefix
o Added preempt_model_preemptible() (Marco)
Now used in kcsan_test.c
o Dropped powerpc changes
Cheers,
Valentin
Valentin Schneider (4):
preempt: Restore preemption model selection configs preempt/dynamic: Introduce preemption model accessors
kcsan: Use preemption model accessors
ftrace: Use preemption model accessors for trace header printout
include/linux/kernel.h | 2 +- include/linux/sched.h | 41 ++++++++++++++++++++++++++++++++++++++ include/linux/vermagic.h | 2 +- init/Makefile | 2 +- kernel/Kconfig.preempt | 42 +++++++++++++++++++-------------------- kernel/kcsan/kcsan_test.c | 5 +++-- kernel/sched/core.c | 18 ++++++++++++++--- kernel/trace/trace.c | 14 ++++--------- 8 files changed, 87 insertions(+), 39 deletions(-)
--
2.25.1
PATCH v3 1/4 preempt: Restore preemption model selection configs
Commit c597bfddc9e9 ("sched: Provide Kconfig support for default dynamic preempt mode") changed the selectable config names for the preemption model. This means a config file must now select
CONFIG_PREEMPT_BEHAVIOUR=y
rather than
CONFIG_PREEMPT=y
to get a preemptible kernel. This means all arch config files would need to be updated - right now they'll all end up with the default CONFIG_PREEMPT_NONE_BEHAVIOUR.
Rather than touch a good hundred of config files, restore usage of CONFIG_PREEMPT{_NONE, _VOLUNTARY}. Make them configure:
o The build-time preemption model when !PREEMPT_DYNAMIC
o The default boot-time preemption model when PREEMPT_DYNAMIC
Add siblings of those configs with the _BUILD suffix to unconditionally designate the build-time preemption model (PREEMPT_DYNAMIC is built with the "highest" preemption model it supports, aka PREEMPT). Downstream configs should by now all be depending / selected by CONFIG_PREEMPTION rather than CONFIG_PREEMPT, so only a few sites need patching up.
--- include/linux/kernel.h | 2 +- include/linux/vermagic.h | 2 +- init/Makefile | 2 +- kernel/Kconfig.preempt | 42 ++++++++++++++++++++-------------------- kernel/sched/core.c | 6 +++--- 5 files changed, 27 insertions(+), 27 deletions(-)
include/linux/kernel.h +1 -1
@@ -88,7 +88,7 @@struct completion ;struct user ; -#ifdef CONFIG_PREEMPT_VOLUNTARY +#ifdef CONFIG_PREEMPT_VOLUNTARY_BUILD extern int __cond_resched (void );# define might_resched () __cond_resched()
include/linux/vermagic.h +1 -1
@@ -15,7 +15,7 @@#else #define MODULE_VERMAGIC_SMP ""#endif -#ifdef CONFIG_PREEMPT +#ifdef CONFIG_PREEMPT_BUILD #define MODULE_VERMAGIC_PREEMPT "preempt "#elif defined(CONFIG_PREEMPT_RT )#define MODULE_VERMAGIC_PREEMPT "preempt_rt "
init/Makefile +1 -1
@@ -30,7 +30,7 @@ $(obj)/version.o: include/generated/compile.h quiet_cmd_compile.h = CHK $@ cmd_compile.h = \ $(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ - "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" \ + "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT_BUILD)" \ "$(CONFIG_PREEMPT_RT)" $(CONFIG_CC_VERSION_TEXT) "$(LD)" include/generated/compile.h: FORCE
kernel/Kconfig.preempt +21 -21
85 lines not on this page · raw message
kernel/sched/core.c +3 -3
@@ -6625,13 +6625,13 @@ __setup("preempt=", setup_preempt_mode);static void __init preempt_dynamic_init (void ) {if (preempt_dynamic_mode == preempt_dynamic_undefined) { -if (IS_ENABLED (CONFIG_PREEMPT_NONE_BEHAVIOUR )) { +if (IS_ENABLED (CONFIG_PREEMPT_NONE )) {sched_dynamic_update (preempt_dynamic_none); - }else if (IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY_BEHAVIOUR )) { + }else if (IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY )) {sched_dynamic_update (preempt_dynamic_voluntary); }else {/* Default static call setting, nothing to do */ -WARN_ON_ONCE (!IS_ENABLED (CONFIG_PREEMPT_BEHAVIOUR )); +WARN_ON_ONCE (!IS_ENABLED (CONFIG_PREEMPT )); preempt_dynamic_mode = preempt_dynamic_full;pr_info ("Dynamic Preempt: full\n" ); }
Signature · 1 line
2.25.1
PATCH v3 2/4 preempt/dynamic: Introduce preemption model accessors
In reply to Valentin SchneiderCONFIG_PREEMPT{_NONE, _VOLUNTARY} designate either:
o The build-time preemption model when !PREEMPT_DYNAMIC
o The default boot-time preemption model when PREEMPT_DYNAMIC
IOW, using those on PREEMPT_DYNAMIC kernels is meaningless - the actual model could have been set to something else by the "preempt=foo" cmdline parameter. Same problem applies to CONFIG_PREEMPTION.
Introduce a set of helpers to determine the actual preemption model used by the live kernel.
--- include/linux/sched.h | 41 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/core.c | 12 ++++++++++++ 2 files changed, 53 insertions(+)
include/linux/sched.h +41 -0
@@ -2073,6 +2073,47 @@ static inline void cond_resched_rcu(void)#endif } +#ifdef CONFIG_PREEMPT_DYNAMIC + +extern bool preempt_model_none (void ); +extern bool preempt_model_voluntary (void ); +extern bool preempt_model_full (void ); + +#else + +static inline bool preempt_model_none (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_NONE ); +} +static inline bool preempt_model_voluntary (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY ); +} +static inline bool preempt_model_full (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT ); +} + +#endif + +static inline bool preempt_model_rt (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_RT ); +} + +/* +* Does the preemption model allow non-cooperative preemption? +* +* For !CONFIG_PREEMPT_DYNAMIC kernels this is an exact match with +* CONFIG_PREEMPTION; for CONFIG_PREEMPT_DYNAMIC this doesn't work as the +* kernel is *built* with CONFIG_PREEMPTION=y but may run with e.g. the +* PREEMPT_NONE model. +*/ +static inline bool preempt_model_preemptible (void ) +{ +return preempt_model_full () ||preempt_model_rt (); +} +/* * Does a critical section need to be broken due to another * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
kernel/sched/core.c +12 -0
@@ -6638,6 +6638,18 @@ static void __init preempt_dynamic_init(void) } } +#define PREEMPT_MODEL_ACCESSOR (mode) \ + bool preempt_model_##mode(void) \ + { \ + WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \ + return preempt_dynamic_mode == preempt_dynamic_##mode; \ + } \ + EXPORT_SYMBOL_GPL(preempt_model_##mode) + +PREEMPT_MODEL_ACCESSOR (none); +PREEMPT_MODEL_ACCESSOR (voluntary); +PREEMPT_MODEL_ACCESSOR (full); +#else /* !CONFIG_PREEMPT_DYNAMIC */ static inline void preempt_dynamic_init (void ) { }
Signature · 1 line
2.25.1
Re: [PATCH v3 2/4] preempt/dynamic: Introduce preemption model accessors
Quoted 9 lines · Valentin Schneider
CONFIG_PREEMPT{_NONE,
_VOLUNTARY} designate either:
o The build-time preemption model when !PREEMPT_DYNAMIC
o The default boot-time preemption model whenPREEMPT_DYNAMICIOW, using those on
PREEMPT_DYNAMICkernels is meaningless - the actual model could have been set to something else by the "preempt=foo" cmdline parameter. Same problem applies toCONFIG_PREEMPTION.
Quoted 5 lines
Introduce a set of helpers to determine the actual preemption model used by the live kernel.
Suggested-by Marco Elver <[email protected]>Signed-off-by Valentin Schneider <[email protected]>
Looks sane.
Quoted 83 lines
--- include/linux/sched.h | 41 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/core.c | 12 ++++++++++++ 2 files changed, 53 insertions(+)include/linux/sched.h +41
-0@@ -2073,6 +2073,47 @@ static inline void cond_resched_rcu(void)#endif } +#ifdef CONFIG_PREEMPT_DYNAMIC + +extern bool preempt_model_none (void ); +extern bool preempt_model_voluntary (void ); +extern bool preempt_model_full (void ); + +#else + +static inline bool preempt_model_none (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_NONE ); +} +static inline bool preempt_model_voluntary (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY ); +} +static inline bool preempt_model_full (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT ); +} + +#endif + +static inline bool preempt_model_rt (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_RT ); +} + +/* +* Does the preemption model allow non-cooperative preemption? +* +* For !CONFIG_PREEMPT_DYNAMIC kernels this is an exact match with +* CONFIG_PREEMPTION; for CONFIG_PREEMPT_DYNAMIC this doesn't work as the +* kernel is *built* with CONFIG_PREEMPTION=y but may run with e.g. the +* PREEMPT_NONE model. +*/ +static inline bool preempt_model_preemptible (void ) +{ +return preempt_model_full () ||preempt_model_rt (); +} +/* * Does a critical section need to be broken due to another * task waiting?: (technically does not depend on CONFIG_PREEMPTION, kernel/sched/core.c +12
-1@@ -6638,6 +6638,18 @@ static void __init preempt_dynamic_init(void) } } +#define PREEMPT_MODEL_ACCESSOR (mode) \ + bool preempt_model_##mode(void) \ + { \ + WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \ + return preempt_dynamic_mode == preempt_dynamic_##mode; \ + } \ + EXPORT_SYMBOL_GPL(preempt_model_##mode) + +PREEMPT_MODEL_ACCESSOR (none); +PREEMPT_MODEL_ACCESSOR (voluntary); +PREEMPT_MODEL_ACCESSOR (full); +#else /* !CONFIG_PREEMPT_DYNAMIC */ static inline void preempt_dynamic_init (void ) { } --2.25.1
[tip: sched/core] preempt/dynamic: Introduce preemption model accessors
In reply to Valentin SchneiderThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: cfe43f478b79ba45573ca22d52d0d8823be068fa Gitweb: https://git.kernel.org/tip/cfe43f478b79ba45573ca22d52d0d8823be068fa Author: Valentin Schneider <[email protected]> AuthorDate: Fri, 12 Nov 2021 18:52:01 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 05 Apr 2022 10:24:42 +02:00
preempt/dynamic: Introduce preemption model accessors
CONFIG_PREEMPT{_NONE, _VOLUNTARY} designate either:
o The build-time preemption model when !PREEMPT_DYNAMIC
o The default boot-time preemption model when PREEMPT_DYNAMIC
IOW, using those on PREEMPT_DYNAMIC kernels is meaningless - the actual model could have been set to something else by the "preempt=foo" cmdline parameter. Same problem applies to CONFIG_PREEMPTION.
Introduce a set of helpers to determine the actual preemption model used by the live kernel.
--- include/linux/sched.h | 41 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/core.c | 12 ++++++++++++ 2 files changed, 53 insertions(+)
include/linux/sched.h +41 -0
@@ -2117,6 +2117,47 @@ static inline void cond_resched_rcu(void)#endif } +#ifdef CONFIG_PREEMPT_DYNAMIC + +extern bool preempt_model_none (void ); +extern bool preempt_model_voluntary (void ); +extern bool preempt_model_full (void ); + +#else + +static inline bool preempt_model_none (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_NONE ); +} +static inline bool preempt_model_voluntary (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY ); +} +static inline bool preempt_model_full (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT ); +} + +#endif + +static inline bool preempt_model_rt (void ) +{ +return IS_ENABLED (CONFIG_PREEMPT_RT ); +} + +/* +* Does the preemption model allow non-cooperative preemption? +* +* For !CONFIG_PREEMPT_DYNAMIC kernels this is an exact match with +* CONFIG_PREEMPTION; for CONFIG_PREEMPT_DYNAMIC this doesn't work as the +* kernel is *built* with CONFIG_PREEMPTION=y but may run with e.g. the +* PREEMPT_NONE model. +*/ +static inline bool preempt_model_preemptible (void ) +{ +return preempt_model_full () ||preempt_model_rt (); +} +/* * Does a critical section need to be broken due to another * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
kernel/sched/core.c +12 -0
@@ -8409,6 +8409,18 @@ static void __init preempt_dynamic_init(void) } } +#define PREEMPT_MODEL_ACCESSOR (mode) \ + bool preempt_model_##mode(void) \ + { \ + WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \ + return preempt_dynamic_mode == preempt_dynamic_##mode; \ + } \ + EXPORT_SYMBOL_GPL(preempt_model_##mode) + +PREEMPT_MODEL_ACCESSOR (none); +PREEMPT_MODEL_ACCESSOR (voluntary); +PREEMPT_MODEL_ACCESSOR (full); +#else /* !CONFIG_PREEMPT_DYNAMIC */ static inline void preempt_dynamic_init (void ) { }
PATCH v3 3/4 kcsan: Use preemption model accessors
In reply to Valentin SchneiderPer PREEMPT_DYNAMIC, checking CONFIG_PREEMPT doesn't tell you the actual preemption model of the live kernel. Use the newly-introduced accessors instead.
--- kernel/kcsan/kcsan_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kcsan/kcsan_test.c +3 -2
@@ -1005,13 +1005,14 @@ static const void *nthreads_gen_params(const void *prev, char *desc)else nthreads *=2 ; -if (!IS_ENABLED (CONFIG_PREEMPT ) || !IS_ENABLED (CONFIG_KCSAN_INTERRUPT_WATCHER )) { +if (!preempt_model_preemptible () || + !IS_ENABLED (CONFIG_KCSAN_INTERRUPT_WATCHER )) {/* * Without any preemption, keep 2 CPUs free for other tasks, one * of which is the main test case function checking for * completion or failure. */ -const long min_unused_cpus =IS_ENABLED (CONFIG_PREEMPT_NONE ) ?2 :0 ; +const long min_unused_cpus =preempt_model_none () ?2 :0 ;const long min_required_cpus =2 + min_unused_cpus;if (num_online_cpus () < min_required_cpus) {
Signature · 1 line
2.25.1
[tip: sched/core] kcsan: Use preemption model accessors
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 5693fa74f98afed5421ac0165e9e9291bde7d9e1 Gitweb: https://git.kernel.org/tip/5693fa74f98afed5421ac0165e9e9291bde7d9e1 Author: Valentin Schneider <[email protected]> AuthorDate: Fri, 12 Nov 2021 18:52:02 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 05 Apr 2022 10:24:42 +02:00
kcsan: Use preemption model accessors
Per PREEMPT_DYNAMIC, checking CONFIG_PREEMPT doesn't tell you the actual preemption model of the live kernel. Use the newly-introduced accessors instead.
--- kernel/kcsan/kcsan_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kcsan/kcsan_test.c +3 -2
@@ -1380,13 +1380,14 @@ static const void *nthreads_gen_params(const void *prev, char *desc)else nthreads *=2 ; -if (!IS_ENABLED (CONFIG_PREEMPT ) || !IS_ENABLED (CONFIG_KCSAN_INTERRUPT_WATCHER )) { +if (!preempt_model_preemptible () || + !IS_ENABLED (CONFIG_KCSAN_INTERRUPT_WATCHER )) {/* * Without any preemption, keep 2 CPUs free for other tasks, one * of which is the main test case function checking for * completion or failure. */ -const long min_unused_cpus =IS_ENABLED (CONFIG_PREEMPT_NONE ) ?2 :0 ; +const long min_unused_cpus =preempt_model_none () ?2 :0 ;const long min_required_cpus =2 + min_unused_cpus;if (num_online_cpus () < min_required_cpus) {
PATCH v3 4/4 ftrace: Use preemption model accessors for trace header printout
In reply to Valentin SchneiderPer PREEMPT_DYNAMIC, checking CONFIG_PREEMPT doesn't tell you the actual preemption model of the live kernel. Use the newly-introduced accessors instead.
--- kernel/trace/trace.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/trace/trace.c +4 -10
@@ -4271,17 +4271,11 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) entries, total, buf->cpu, -#if defined(CONFIG_PREEMPT_NONE) - "server", -#elif defined(CONFIG_PREEMPT_VOLUNTARY) - "desktop", -#elif defined(CONFIG_PREEMPT) - "preempt", -#elif defined(CONFIG_PREEMPT_RT) -"preempt_rt" , -#else +preempt_model_none () ?"server" : +preempt_model_voluntary () ?"desktop" : +preempt_model_full () ?"preempt" : +preempt_model_rt () ?"preempt_rt" :"unknown" , -#endif/* These are reserved for later use */ 0, 0, 0, 0);#ifdef CONFIG_SMP
Signature · 1 line
2.25.1
[tip: sched/core] ftrace: Use preemption model accessors for trace header printout
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 089c02ae2771a14af2928c59c56abfb9b885a8d7 Gitweb: https://git.kernel.org/tip/089c02ae2771a14af2928c59c56abfb9b885a8d7 Author: Valentin Schneider <[email protected]> AuthorDate: Fri, 12 Nov 2021 18:52:03 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 05 Apr 2022 10:24:42 +02:00
ftrace: Use preemption model accessors for trace header printout
Per PREEMPT_DYNAMIC, checking CONFIG_PREEMPT doesn't tell you the actual preemption model of the live kernel. Use the newly-introduced accessors instead.
--- kernel/trace/trace.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/trace/trace.c +4 -10
@@ -4289,17 +4289,11 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) entries, total, buf->cpu, -#if defined(CONFIG_PREEMPT_NONE) - "server", -#elif defined(CONFIG_PREEMPT_VOLUNTARY) - "desktop", -#elif defined(CONFIG_PREEMPT) - "preempt", -#elif defined(CONFIG_PREEMPT_RT) -"preempt_rt" , -#else +preempt_model_none () ?"server" : +preempt_model_voluntary () ?"desktop" : +preempt_model_full () ?"preempt" : +preempt_model_rt () ?"preempt_rt" :"unknown" , -#endif/* These are reserved for later use */ 0, 0, 0, 0);#ifdef CONFIG_SMP
Quoted 33 lines · Valentin Schneider
Hi folks,
This v3 is mostly about the naming problem - get your paintbrushes ready!
Patches
=======o Patch 1 is the meat of the topic - note that it's now in tip/sched/urgent
o Patch 2 introduces helpers for the dynamic preempt state
o Patches 3-4 make use of said accessors where relevant.Testing
=======Briefly tested the dynamic part on an x86 kernel + QEMU. Compile-tested the kcsan test thingie as a module.
Revisions
=========v1: http://lore.kernel.org/r/[email protected]
v1.5: http://lore.kernel.org/r/[email protected]v2 -> v3
++++++++o Turned is_preempt_*() into preempt_model_*() (Frederic)
It breaks my rule of "booleans must answer a yes/no question" but is the best I could come with using a "preempt_" prefixo Added
preempt_model_preemptible()(Marco)
Now used inkcsan_test.c
Quoted 8 lines
o Dropped powerpc changes
Cheers,
ValentinValentin Schneider (4):
preempt: Restore preemption model selection configs
Seems like this one has been applied from the previous series.
Quoted 3 lines
preempt/dynamic: Introduce preemption model accessors
kcsan: Use preemption model accessors
ftrace: Use preemption model accessors for trace header printout
So for the rest:
Thanks!