kernel: allow to configure PREEMPT_NONE, PREEMPT_VOLUNTARY on kernel command line
Subsystems (10)
RFC PATCH 1/1 kernel: allow to configure PREEMPT_NONE, PREEMPT_VOLUNTARY on kernel command line
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing PREEMPT_NONE for typical server deployments and PREEMPT_VOLUNTARY for desktop users.
Having two different kernel binaries differing only by the preemption mode seems rather wasteful and inflexible. Especially when the difference between PREEMPT_NONE and PREEMPT_VOLUNTARY is really minimal. Both only allow explicit scheduling points while running in the kernel and it is only might_sleep which adds additional preemption points for PREEMPT_VOLUNTARY.
Add a kernel command line parameter preempt_mode=[none, voluntary] which allows to override the default compile time preemption mode (CONFIG_PREEMPT_NONE resp. CONFIG_PREEMPT_VOLUTARY). Voluntary preempt mode is guarded by a jump label to prevent any potential runtime overhead.
---
Hi all,
this is sent as an RFC because it still needs some work. E.g. move jump label changes into their own patch. They are needed mostly to get rid of header files dependencies (seen for CONFIG_JUMP_LABEL=n via atomic.h -> bug.h).
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
Thoughts?
.../admin-guide/kernel-parameters.txt | 5 ++ include/linux/gpio/consumer.h | 1 + include/linux/jump_label.h | 44 +---------------- include/linux/jump_label_type.h | 49 +++++++++++++++++++ include/linux/kernel.h | 12 +++-- kernel/sched/core.c | 30 ++++++++++++ 6 files changed, 95 insertions(+), 46 deletions(-) create mode 100644 include/linux/jump_label_type.h
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -3873,6 +3873,11 @@ Format: {"off"} Disable Hardware Transactional Memory + preempt_mode={none,voluntary} + Set the preemption mode. + none - equivalent to CONFIG_PREEMPT_NONE + voluntary - equivalent to CONFIG_PREEMPT_VOLUNTARY + print-fatal-signals= [KNL] debug: print fatal signals
include/linux/gpio/consumer.h +1 -0
@@ -3,6 +3,7 @@#define __LINUX_GPIO_CONSUMER_H#include <linux/bits.h> +#include <linux/jump_label.h> #include <linux/bug.h> #include <linux/compiler_types.h> #include <linux/err.h>
include/linux/jump_label.h +1 -43
74 lines not on this page · raw message
include/linux/jump_label_type.h new file +49 -0
49 lines not on this page · raw message
include/linux/kernel.h +9 -3
@@ -14,6 +14,7 @@#include <linux/typecheck.h> #include <linux/printk.h> #include <linux/build_bug.h> +#include <linux/jump_label_type.h> #include <asm/byteorder.h> #include <asm/div64.h> #include <uapi/linux/kernel.h>
@@ -192,11 +193,16 @@ struct completion;struct pt_regs ;struct user ; +#ifndef CONFIG_PREEMPTION #ifdef CONFIG_PREEMPT_VOLUNTARY -extern int _cond_resched (void ); -# define might_resched () _cond_resched() +DECLARE_STATIC_KEY_TRUE (preempt_voluntary_key);#else -# define might_resched () do { } while (0) +DECLARE_STATIC_KEY_FALSE (preempt_voluntary_key); +#endif + +extern int _cond_resched (void ); +# define might_resched () \ + do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0)#endif #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
kernel/sched/core.c +30 -0
@@ -43,6 +43,14 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); +#ifdef CONFIG_PREEMPT_VOLUNTARY +DEFINE_STATIC_KEY_TRUE (preempt_voluntary_key); +#else +/* PREEMPT_NONE vs PREEMPT_VOLUNTARY */ +DEFINE_STATIC_KEY_FALSE (preempt_voluntary_key); +#endif +EXPORT_SYMBOL (preempt_voluntary_key); +#if defined(CONFIG_SCHED_DEBUG ) && defined(CONFIG_JUMP_LABEL )/* * Debugging: various feature bits
@@ -8482,3 +8490,25 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count) {trace_sched_update_nr_running_tp (rq, count); } + +#ifndef CONFIG_PREEMPTION +static int __init setup_non_preempt_mode (char *str) +{ +if (!strcmp (str,"none" )) { +if (IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY )) { +static_branch_disable (&preempt_voluntary_key); +pr_info ("Switching to PREEMPT_NONE mode." ); + } + }else if (!strcmp (str,"voluntary" )) { +if (!IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY )) { +static_branch_enable (&preempt_voluntary_key); +pr_info ("Switching to PREEMPT_VOLUNTARY mode." ); + } + }else { +pr_warn ("Unsupported preempt mode %s\n" , str); +return 1 ; + } +return 0 ; +} +__setup ("preempt_mode=" , setup_non_preempt_mode); +#endif
Signature · 1 line
2.28.0
Peter Zijlstra
maintainerQuoted 6 lines · Michal Hocko
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing
PREEMPT_NONEfor typical server deployments andPREEMPT_VOLUNTARYfor desktop users.
Is there actually a benefit to NONE? We were recently talking about removing it.
The much more interesting (runtime) switch (IMO) would be between VOLUNTARY and PREEMPT.
Peter Zijlstra
maintainerQuoted 4 lines · Michal Hocko
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
The sanest way there is to static_call() __preempt_schedule() I think. Alternatively you could use alternatives but that makes the whole thing arch specific again.
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Michal Hocko
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing
PREEMPT_NONEfor typical server deployments andPREEMPT_VOLUNTARYfor desktop users.Is there actually a benefit to NONE? We were recently talking about removing it.
I believe Mel can provide much better insight. We have been historically using PREEMPT_NONE for our enterprise customers mostly for nice throughput numbers. Many users are really targeting throughput much more than latencies. My understanding is that even though VOLUNTARY preemption model doesn't add too many preemption points on top of NONE it is still something that is observable (IIRC 2-3% on hackbench).
Quoted 2 lines
The much more interesting (runtime) switch (IMO) would be between VOLUNTARY and PREEMPT.
Absolutely and as said we are looking into that. This is meant to be a first baby step in that direction. Still very useful in our current situation when we want to provide both NONE and VOLUNTARY.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Michal Hocko
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
The sanest way there is to
static_call()__preempt_schedule()I think.
Yes, I have checked the code and identified few other places like irqentry_exit_cond_resched. We also need unconditional CONFIG_PREEMPT_COUNT IIUC and there are quite some places guarded by CONFIG_PREEMPTION that would need to be examined. Some of them are likely pretending to be more clever than they really are/should be - e.g. mm/slub.c. So there is likely a lot of leg work.
Signature · 2 lines
Michal Hocko SUSE Labs
Mel Gorman
reviewerQuoted 12 lines · Michal Hocko
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Michal Hocko
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing
PREEMPT_NONEfor typical server deployments andPREEMPT_VOLUNTARYfor desktop users.Is there actually a benefit to NONE? We were recently talking about removing it.
Quoted 7 lines
I believe Mel can provide much better insight. We have been historically using
PREEMPT_NONEfor our enterprise customers mostly for nice throughput numbers. Many users are really targeting throughput much more than latencies. My understanding is that even though VOLUNTARY preemption model doesn't add too many preemption points on top of NONE it is still something that is observable (IIRC 2-3% on hackbench).
It's marginal from the tests I ran but that was based on 5.3. At worst, it looked like roughly a hit but a lot of loads simply didn't notice. However, it might vary between architectures that I cannot cover or workloads that I didn't consider. As the impact of PREEMPT_VOLUNTARY depends on where cond_resched and might_sleep is used, it's also something that can vary over time. The intent was that by having the command-line switch, a user could test the switch if there was a suspicion that a regression was related to PREEMPT_VOLUNTARY as opposed to telling them "tough, that's the reality now".
Signature · 2 lines
Mel Gorman SUSE Labs
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Michal,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on gpio/for-next]
[also build test ERROR on tip/sched/core linus/master v5.9-rc8 next-20201007] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Michal-Hocko/kernel-allow-to-configure-PREEMPT_NONE-PREEMPT_VOLUNTARY-on-kernel-command-line/20201007-200554 base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next config: x86_64-randconfig-a002-20201007 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4d1d8ae7100ec3c7e1709addb7b3ec6f9ad0b44f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/d4c95538fb41de2d4ad28f5605da76e857266355
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Michal-Hocko/kernel-allow-to-configure-PREEMPT_NONE-PREEMPT_VOLUNTARY-on-kernel-command-line/20201007-200554 git checkout d4c95538fb41de2d4ad28f5605da76e857266355
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
>> include/linux/wait_bit.h:73:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:98:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:125:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:153:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:181:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:205:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:6:
include/linux/wait_bit.h:232:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:33:
>> include/linux/percpu-rwsem.h:49:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:13:
In file included from include/linux/pagemap.h:11:
>> include/linux/highmem.h:139:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:13:
>> include/linux/pagemap.h:546:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:13:
include/linux/pagemap.h:558:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:13:
include/linux/pagemap.h:590:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:22:
>> include/linux/writeback.h:205:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:10:
>> include/linux/freezer.h:57:2: error: implicit declaration of function 'might_resched' [-Werror,-Wimplicit-function-declaration]
might_sleep();
^
include/linux/kernel.h:226:45: note: expanded from macro 'might_sleep'
do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
^ 14 errors generated.
make[2]: *** [scripts/Makefile.build:117: arch/x86/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1198: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/might_resched +73 include/linux/wait_bit.h
5dd43ce2f69d42a Ingo Molnar 2017-06-20 53
5dd43ce2f69d42a Ingo Molnar 2017-06-20 54 /**
5dd43ce2f69d42a Ingo Molnar 2017-06-20 55 * wait_on_bit - wait for a bit to be cleared
5dd43ce2f69d42a Ingo Molnar 2017-06-20 56 * @word: the word being waited on, a kernel virtual address
5dd43ce2f69d42a Ingo Molnar 2017-06-20 57 * @bit: the bit of the word being waited on
5dd43ce2f69d42a Ingo Molnar 2017-06-20 58 * @mode: the task state to sleep in
5dd43ce2f69d42a Ingo Molnar 2017-06-20 59 *
5dd43ce2f69d42a Ingo Molnar 2017-06-20 60 * There is a standard hashed waitqueue table for generic use. This
5dd43ce2f69d42a Ingo Molnar 2017-06-20 61 * is the part of the hashtable's accessor API that waits on a bit.
5dd43ce2f69d42a Ingo Molnar 2017-06-20 62 * For instance, if one were to have waiters on a bitflag, one would
5dd43ce2f69d42a Ingo Molnar 2017-06-20 63 * call wait_on_bit() in threads waiting for the bit to clear.
5dd43ce2f69d42a Ingo Molnar 2017-06-20 64 * One uses wait_on_bit() where one is waiting for the bit to clear,
5dd43ce2f69d42a Ingo Molnar 2017-06-20 65 * but has no intention of setting it.
5dd43ce2f69d42a Ingo Molnar 2017-06-20 66 * Returned value will be zero if the bit was cleared, or non-zero
5dd43ce2f69d42a Ingo Molnar 2017-06-20 67 * if the process received a signal and the mode permitted wakeup
5dd43ce2f69d42a Ingo Molnar 2017-06-20 68 * on that signal.
5dd43ce2f69d42a Ingo Molnar 2017-06-20 69 */
5dd43ce2f69d42a Ingo Molnar 2017-06-20 70 static inline int
5dd43ce2f69d42a Ingo Molnar 2017-06-20 71 wait_on_bit(unsigned long *word, int bit, unsigned mode)
5dd43ce2f69d42a Ingo Molnar 2017-06-20 72 {
5dd43ce2f69d42a Ingo Molnar 2017-06-20 @73 might_sleep();
5dd43ce2f69d42a Ingo Molnar 2017-06-20 74 if (!test_bit(bit, word))
5dd43ce2f69d42a Ingo Molnar 2017-06-20 75 return 0;
5dd43ce2f69d42a Ingo Molnar 2017-06-20 76 return out_of_line_wait_on_bit(word, bit,
5dd43ce2f69d42a Ingo Molnar 2017-06-20 77 bit_wait,
5dd43ce2f69d42a Ingo Molnar 2017-06-20 78 mode);
5dd43ce2f69d42a Ingo Molnar 2017-06-20 79 }5dd43ce2f69d42a Ingo Molnar 2017-06-20 80
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 9 lines · kernel test robot
Hi Michal,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on gpio/for-next]
[also build test ERROR on tip/sched/core linus/master v5.9-rc8 next-20201007] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
Thanks for the report. So this is CONFIG_PREEMPT=y and I haven't tested with that option for this RFC TBH. But the fix should be trivial.
include/linux/kernel.h +3 -0
@@ -203,6 +203,9 @@ DECLARE_STATIC_KEY_FALSE(preempt_voluntary_key);extern int _cond_resched (void );# define might_resched () \ do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0) +#else +# define might_resched () \ + do { } while (0)#endif #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 28 lines · Michal Hocko
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing
PREEMPT_NONEfor typical server deployments andPREEMPT_VOLUNTARYfor desktop users.Having two different kernel binaries differing only by the preemption mode seems rather wasteful and inflexible. Especially when the difference between
PREEMPT_NONEandPREEMPT_VOLUNTARYis really minimal. Both only allow explicit scheduling points while running in the kernel and it is onlymight_sleepwhich adds additional preemption points forPREEMPT_VOLUNTARY.Add a kernel command line parameter preempt_mode=[none, voluntary] which allows to override the default compile time preemption mode (
CONFIG_PREEMPT_NONEresp.CONFIG_PREEMPT_VOLUTARY). Voluntary preempt mode is guarded by a jump label to prevent any potential runtime overhead.Signed-off-by Michal Hocko <[email protected]>---
Hi all,
this is sent as an RFC because it still needs some work. E.g. move jump label changes into their own patch. They are needed mostly to get rid of header files dependencies (seen forCONFIG_JUMP_LABEL=nviaatomic.h->bug.h).
Quoted 6 lines
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
Thoughts?
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Signature · 2 lines
Michal Hocko SUSE Labs
Peter Zijlstra
maintainerQuoted 2 lines · Michal Hocko
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Maybe remove PREEMPT_NONE after that? Since that's then equivalent to building with VOLUNTARY and booting with preempt=none.
Peter Zijlstra
maintainerQuoted 7 lines · Michal Hocko
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Michal Hocko
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
Quoted 8 lines
Quoted 1 line
The sanest way there is to
static_call()__preempt_schedule()I think.Yes, I have checked the code and identified few other places like
irqentry_exit_cond_resched. We also need unconditionalCONFIG_PREEMPT_COUNTIIUC and there are quite some places guarded byCONFIG_PREEMPTIONthat would need to be examined. Some of them are likely pretending to be more clever than they really are/should be - e.g.mm/slub.c. So there is likely a lot of leg work.
The easiest way might be to introduce PREEMPT_DYNAMIC that depends/selects PREEMPT. That way you're basically running a PREEMPT=y kernel.
Then have PREEMPT_DYNAMIC allow disabling the __preempt_schedule / preempt_schedule_irq() callsites using static_call/static_branch respectively.
That is, work backwards (from PREEMPT back to VOLUNTARY) instead of the other way around.
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Michal Hocko
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Maybe remove
PREEMPT_NONEafter that? Since that's then equivalent to building with VOLUNTARY and booting with preempt=none.
So do you mean that I should post an additional patch which does this on top? With a justification that there is one option less to chose from?
kernel/Kconfig.preempt +1 -14
@@ -2,20 +2,7 @@ choice prompt "Preemption Model" - default PREEMPT_NONE - -config PREEMPT_NONE - bool "No Forced Preemption (Server)" - help - This is the traditional Linux preemption model, geared towards - throughput. It will still provide good latencies most of the - time, but there are no guarantees and occasional longer delays - are possible. - - Select this option if you are building a kernel for a server or - scientific/computation system, or if you want to maximize the - raw processing power of the kernel, irrespective of scheduling - latencies. + default PREEMPT_VOLUNTARY config PREEMPT_VOLUNTARY bool "Voluntary Kernel Preemption (Desktop)"
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 21 lines · Peter Zijlstra
Quoted 7 lines · Michal Hocko
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Michal Hocko
I wanted to make sure that the idea is sound for maintainers first. The next step would be extending the command line to support full preemption as well but there is much more work in that area. Frederic has promissed to look into that.
Quoted 8 lines
Quoted 1 line
The sanest way there is to
static_call()__preempt_schedule()I think.Yes, I have checked the code and identified few other places like
irqentry_exit_cond_resched. We also need unconditionalCONFIG_PREEMPT_COUNTIIUC and there are quite some places guarded byCONFIG_PREEMPTIONthat would need to be examined. Some of them are likely pretending to be more clever than they really are/should be - e.g.mm/slub.c. So there is likely a lot of leg work.The easiest way might be to introduce
PREEMPT_DYNAMICthat depends/selects PREEMPT. That way you're basically running a PREEMPT=y kernel.
Quoted 6 lines
Then have
PREEMPT_DYNAMICallow disabling the__preempt_schedule/preempt_schedule_irq()callsites using static_call/static_branch respectively.That is, work backwards (from PREEMPT back to VOLUNTARY) instead of the other way around.
My original idea was that the config would only define the default preemption mode. preempt_none parameter would then just act as an override. That would mean that CONFIG_PREEMPTION would be effectively gone from the kernel. The reason being that any code outside of the scheduler shouldn't really care about the preemption mode. I suspect this will prevent from dubious hacks and provide a more robust code in the end.
Does that sound reasonable?
Signature · 2 lines
Michal Hocko SUSE Labs
Peter Zijlstra
maintainerQuoted 10 lines · Michal Hocko
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Michal Hocko
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Maybe remove
PREEMPT_NONEafter that? Since that's then equivalent to building with VOLUNTARY and booting with preempt=none.So do you mean that I should post an additional patch which does this on top? With a justification that there is one option less to chose from?
Exactly!
Peter Zijlstra
maintainerQuoted 5 lines · Michal Hocko
Quoted 2 lines · Peter Zijlstra
That is, work backwards (from PREEMPT back to VOLUNTARY) instead of the other way around.
Quoted 7 lines
My original idea was that the config would only define the default preemption mode.
preempt_noneparameter would then just act as an override. That would mean thatCONFIG_PREEMPTIONwould be effectively gone from the kernel. The reason being that any code outside of the scheduler shouldn't really care about the preemption mode. I suspect this will prevent from dubious hacks and provide a more robust code in the end.
Sure; but the way of arriving at that destination might be easier if you work backwards from PREEMPT=y, because while there _should_ not be dependencies outside of the scheduler, we both know there are.
This also makes your patches independent of the series that makes CONFIG_PREEMPTION unconditional.
It also gives Kconfig space to limit the dynamic thing to archs that have sufficient support (we'll be relying on static_call/static_branch, and not everybody has that implemented in a way that makes it the dynamic change worth-while).
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Michal Hocko
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Maybe remove
PREEMPT_NONEafter that? Since that's then equivalent to building with VOLUNTARY and booting with preempt=none.So do you mean that I should post an additional patch which does this on top? With a justification that there is one option less to chose from?
Exactly!
It seems we have to get rid of CONFIG_NO_PREEMPT first
$ git grep ARCH_NO_PREEMPT arch/Kconfig:config ARCH_NO_PREEMPT arch/alpha/Kconfig: select ARCH_NO_PREEMPT arch/hexagon/Kconfig: select ARCH_NO_PREEMPT arch/m68k/Kconfig: select ARCH_NO_PREEMPT if !COLDFIRE arch/um/Kconfig: select ARCH_NO_PREEMPT kernel/Kconfig.preempt: depends on !ARCH_NO_PREEMPT kernel/Kconfig.preempt: depends on !ARCH_NO_PREEMPT lib/Kconfig.debug: select PREEMPT_COUNT if !ARCH_NO_PREEMPT lib/Kconfig.debug: depends on !ARCH_NO_PREEMPT
Is there anybody working on that. Is this even possible? I can see it has been added by 87a4c375995e ("kconfig: include kernel/Kconfig.preempt from init/Kconfig") but this looks more like a mechanical change and it has defined ARCH_NO_PREEMPT all arches which haven't included Kconfig.preempt. But is there any reason why those cannot support preemption for some reason? Cc respective maintainer (the email thread starts http://lkml.kernel.org/r/[email protected]
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 14 lines · Peter Zijlstra
Quoted 5 lines · Michal Hocko
Quoted 2 lines · Peter Zijlstra
That is, work backwards (from PREEMPT back to VOLUNTARY) instead of the other way around.
Quoted 7 lines
My original idea was that the config would only define the default preemption mode.
preempt_noneparameter would then just act as an override. That would mean thatCONFIG_PREEMPTIONwould be effectively gone from the kernel. The reason being that any code outside of the scheduler shouldn't really care about the preemption mode. I suspect this will prevent from dubious hacks and provide a more robust code in the end.
Quoted 3 lines
Sure; but the way of arriving at that destination might be easier if you work backwards from PREEMPT=y, because while there _should_ not be dependencies outside of the scheduler, we both know there are.
Wouldn't we need to examine each of the CONFIG_PREEMPTION code anyway? And wouldn't that be even more tricky? The boot time option would result in a more restrictive preemption mode while the code is actually assuming a less restrictive one.
Quoted 7 lines
This also makes your patches independent of the series that makes
CONFIG_PREEMPTIONunconditional.It also gives
Kconfigspace to limit the dynamic thing to archs that have sufficient support (we'll be relying on static_call/static_branch, and not everybody has that implemented in a way that makes it the dynamic change worth-while).
Hmm, this is actually a good argument. I can imagine that kernels without CONFIG_JUMP_LABEL might increase a runtime overhead for something that users of that kernel might be not really interested in. This would make CONFIG_PREEMPT_DYNAMIC be selected by CONFIG_JUMP_LABEL.
I will add the CONFIG_PREEMPT_DYNAMIC in the next version. I just have to think whether flipping the direction is really safe and easier in the end. For our particular usecase we are more interested in NONE<->VOLUNTARY at this moment and having full preemption in the mix later is just fine. If you insist on the other direction then we can work on that.
Thanks!
Signature · 2 lines
Michal Hocko SUSE Labs
On Fri 09-10-20 12:48:09, Michal Hocko wrote:
[...]
Quoted 6 lines
I will add the
CONFIG_PREEMPT_DYNAMICin the next version. I just have to think whether flipping the direction is really safe and easier in the end. For our particular usecase we are more interested in NONE<->VOLUNTARY at this moment and having full preemption in the mix later is just fine. If you insist on the other direction then we can work on that.
This is a quick implementation of PREEMPT_DYNAMIC (still with the original approach to start from non preemptive kernels). It is a bit hairy but I suspect that starting with CONFIG_PREEMPTION wouldn't make it very much easier but I haven't tried that yet. Advantage of this approach is that it is clear that it is safe as NONE/VOLUNTARY are trivial to examine.
include/linux/kernel.h +18 -2
@@ -193,20 +193,36 @@ struct completion;struct pt_regs ;struct user ; +/* +* cond_resched() and cond_resched_lock(): latency reduction via +* explicit rescheduling in places that are safe. The return +* value indicates whether a reschedule was done in fact. +* cond_resched_lock() will drop the spinlock before scheduling, +*/ #ifndef CONFIG_PREEMPTION +extern int _cond_resched (void ); +#else +static inline int _cond_resched (void ) {return 0 ; } +#endif + +#ifdef CONFIG_PREEMPT_DYNAMIC #ifdef CONFIG_PREEMPT_VOLUNTARY DECLARE_STATIC_KEY_TRUE (preempt_voluntary_key);#else DECLARE_STATIC_KEY_FALSE (preempt_voluntary_key);#endif -extern int _cond_resched (void );# define might_resched () \ do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0)#else + +#ifdef CONFIG_PREEMPT_VOLUNTARY # define might_resched () \ - do { } while (0) + do { _cond_resched(); } while (0) +#else +# define might_resched () do { } while (0)#endif +#endif /* CONFIG_PREEMPT_DYNAMIC */ #ifdef CONFIG_DEBUG_ATOMIC_SLEEP extern void ___might_sleep (const char *file,int line,int preempt_offset);
include/linux/sched.h +0 -12
@@ -1812,18 +1812,6 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)return unlikely (test_tsk_thread_flag (tsk,TIF_NEED_RESCHED )); } -/* -* cond_resched() and cond_resched_lock(): latency reduction via -* explicit rescheduling in places that are safe. The return -* value indicates whether a reschedule was done in fact. -* cond_resched_lock() will drop the spinlock before scheduling, -*/ -#ifndef CONFIG_PREEMPTION -extern int _cond_resched (void ); -#else -static inline int _cond_resched (void ) {return 0 ; } -#endif -#define cond_resched () ({ \ ___might_sleep(__FILE__, __LINE__, 0); \ _cond_resched(); \
kernel/Kconfig.preempt +19 -0
@@ -74,6 +74,25 @@ config PREEMPT_RT endchoice +config PREEMPT_DYNAMIC + bool "Allow boot time preemption model selection" + depends on PREEMPT_NONE || PREEMPT_VOLUNTARY + help + This option allows to define the preemption model on the kernel + command line parameter and thus override the default preemption + model defined during compile time. + + The feature is primarily interesting for Linux distributions which + provide a pre-built kernel binary to reduce the number of kernel + flavors they offer while still offering different usecases. + + The runtime overhead is negligible with JUMP_LABELS enabled but if + runtime patching is not available for the specific architecture then + the potential overhead should be considered. + + Select if you the same pre-built kernel should be used for both Server + and Desktop workloads. + config PREEMPT_COUNT bool
kernel/sched/core.c +5 -1
@@ -43,6 +43,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); +#ifdef CONFIG_PREEMPT_DYNAMIC +#ifdef CONFIG_PREEMPT_VOLUNTARY DEFINE_STATIC_KEY_TRUE (preempt_voluntary_key);#else
@@ -51,6 +53,8 @@ DEFINE_STATIC_KEY_FALSE(preempt_voluntary_key);#endif EXPORT_SYMBOL (preempt_voluntary_key); +#endif +#if defined(CONFIG_SCHED_DEBUG ) && defined(CONFIG_JUMP_LABEL )/* * Debugging: various feature bits
@@ -8491,7 +8495,7 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count)trace_sched_update_nr_running_tp (rq, count); } -#ifndef CONFIG_PREEMPTION +#ifdef CONFIG_PREEMPT_DYNAMIC static int __init setup_non_preempt_mode (char *str) {if (!strcmp (str,"none" )) {
Signature · 2 lines
Michal Hocko SUSE Labs
On Fri 09-10-20 13:17:04, Michal Hocko wrote:
[...]
kernel/Kconfig.preempt config PREEMPT_RT · line 78
Quoted 2 lines
kernel/Kconfig.preempt +2
-0+config PREEMPT_DYNAMIC + bool "Allow boot time preemption model selection"
depends on !ARCH_NO_PREEMPT
Quoted 19 lines
kernel/Kconfig.preempt +17
-0+ depends on PREEMPT_NONE || PREEMPT_VOLUNTARY + help + This option allows to define the preemption model on the kernel + command line parameter and thus override the default preemption + model defined during compile time. + + The feature is primarily interesting for Linux distributions which + provide a pre-built kernel binary to reduce the number of kernel + flavors they offer while still offering different usecases. + + The runtime overhead is negligible with JUMP_LABELS enabled but if + runtime patching is not available for the specific architecture then + the potential overhead should be considered. + + Select if you the same pre-built kernel should be used for both Server + and Desktop workloads. + config PREEMPT_COUNT bool
Signature · 2 lines
Michal Hocko SUSE Labs
Peter Zijlstra
maintainerQuoted 15 lines · Michal Hocko
Quoted 14 lines · Peter Zijlstra
Quoted 12 lines · Michal Hocko
Quoted 2 lines · Peter Zijlstra
That is, work backwards (from PREEMPT back to VOLUNTARY) instead of the other way around.
My original idea was that the config would only define the default preemption mode.
preempt_noneparameter would then just act as an override. That would mean thatCONFIG_PREEMPTIONwould be effectively gone from the kernel. The reason being that any code outside of the scheduler shouldn't really care about the preemption mode. I suspect this will prevent from dubious hacks and provide a more robust code in the end.
Quoted 8 lines
Quoted 3 lines
Sure; but the way of arriving at that destination might be easier if you work backwards from PREEMPT=y, because while there _should_ not be dependencies outside of the scheduler, we both know there are.
Wouldn't we need to examine each of the
CONFIG_PREEMPTIONcode anyway? And wouldn't that be even more tricky? The boot time option would result in a more restrictive preemption mode while the code is actually assuming a less restrictive one.
Sure, in the end we'll have to look at all of that.
Quoted 13 lines
Quoted 7 lines
This also makes your patches independent of the series that makes
CONFIG_PREEMPTIONunconditional.It also gives
Kconfigspace to limit the dynamic thing to archs that have sufficient support (we'll be relying on static_call/static_branch, and not everybody has that implemented in a way that makes it the dynamic change worth-while).Hmm, this is actually a good argument. I can imagine that kernels without
CONFIG_JUMP_LABELmight increase a runtime overhead for something that users of that kernel might be not really interested in. This would makeCONFIG_PREEMPT_DYNAMICbe selected byCONFIG_JUMP_LABEL.
Quoted 6 lines
I will add the
CONFIG_PREEMPT_DYNAMICin the next version. I just have to think whether flipping the direction is really safe and easier in the end. For our particular usecase we are more interested in NONE<->VOLUNTARY at this moment and having full preemption in the mix later is just fine. If you insist on the other direction then we can work on that.
Ah, I was purely thinking of the FULL preempt case. For the NONE/VOLATILE case you can probably keep it simpler.
Peter Zijlstra
maintainerQuoted 27 lines · Michal Hocko
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Michal Hocko
Is there any additional feedback? Should I split up the patch and repost for inclusion?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Maybe remove
PREEMPT_NONEafter that? Since that's then equivalent to building with VOLUNTARY and booting with preempt=none.So do you mean that I should post an additional patch which does this on top? With a justification that there is one option less to chose from?
Exactly!
It seems we have to get rid of
CONFIG_NO_PREEMPTfirst$ git grep ARCH_NO_PREEMPT arch/Kconfig:config ARCH_NO_PREEMPT arch/alpha/Kconfig: select ARCH_NO_PREEMPT arch/hexagon/Kconfig: select ARCH_NO_PREEMPT arch/m68k/Kconfig: select ARCH_NO_PREEMPT if !COLDFIRE arch/um/Kconfig: select ARCH_NO_PREEMPT kernel/Kconfig.preempt: depends on !ARCH_NO_PREEMPT kernel/Kconfig.preempt: depends on !ARCH_NO_PREEMPT lib/Kconfig.debug: select PREEMPT_COUNT if !ARCH_NO_PREEMPT lib/Kconfig.debug: depends on !ARCH_NO_PREEMPT
Quoted 7 lines
Is there anybody working on that. Is this even possible? I can see it has been added by
87a4c375995e("kconfig: includekernel/Kconfig.preemptfrom init/Kconfig") but this looks more like a mechanical change and it has definedARCH_NO_PREEMPTall arches which haven't includedKconfig.preempt. But is there any reason why those cannot support preemption for some reason? Cc respective maintainer (the email thread starts http://lkml.kernel.org/r/[email protected]
I suspect we can drop ARCH_NO_PREEMPT from VOLUNTARY, IIRC there's no arch dependency there. PREEMPT itself obviously needs arch help.
RFC PATCH v2 1/5 jump_label: split out declaration parts into its own headers
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
Follow up patch would like to add a static key into kernel.h and that requires a declaration of the key in the same file. Including jump_label.h into kernel.h is not possible due to headers dependencies.
Separate parts needed for declaration into its own header which doesn't depend on any other header file. kernel.h can include jump_abel_type.h.
--- include/linux/jump_label.h | 44 +---------------------------- include/linux/jump_label_type.h | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 include/linux/jump_label_type.h
include/linux/jump_label.h +1 -43
@@ -75,6 +75,7 @@#include <linux/types.h> #include <linux/compiler.h> +#include <linux/jump_label_type.h> extern bool static_key_initialized;
@@ -82,35 +83,6 @@ extern bool static_key_initialized; "%s(): static key '%pS' used before call to jump_label_init()", \ __func__, (key)) -#ifdef CONFIG_JUMP_LABEL - -struct static_key { -atomic_t enabled; -/* -* Note: -* To make anonymous unions work with old compilers, the static -* initialization of them requires brackets. This creates a dependency -* on the order of the struct with the initializers. If any fields -* are added, STATIC_KEY_INIT_TRUE and STATIC_KEY_INIT_FALSE may need -* to be modified. -* -* bit 0 => 1 if key is initially true -* 0 if initially false -* bit 1 => 1 if points to struct static_key_mod -* 0 if points to struct jump_entry -*/ -union { -unsigned long type; -struct jump_entry *entries; -struct static_key_mod *next; - }; -}; - -#else -struct static_key { -atomic_t enabled; -}; -#endif /* CONFIG_JUMP_LABEL */ #endif /* __ASSEMBLY__ */ #ifdef CONFIG_JUMP_LABEL
@@ -343,14 +315,6 @@ static inline void static_key_disable(struct static_key *key)* All the below code is macros in order to play type games. */ -struct static_key_true { -struct static_key key; -}; - -struct static_key_false { -struct static_key key; -}; -#define STATIC_KEY_TRUE_INIT (struct static_key_true) { .key = STATIC_KEY_INIT_TRUE, }#define STATIC_KEY_FALSE_INIT (struct static_key_false){ .key = STATIC_KEY_INIT_FALSE, }
@@ -360,18 +324,12 @@ struct static_key_false {#define DEFINE_STATIC_KEY_TRUE_RO (name) \ struct static_key_true name __ro_after_init = STATIC_KEY_TRUE_INIT -#define DECLARE_STATIC_KEY_TRUE (name) \ - extern struct static_key_true name -#define DEFINE_STATIC_KEY_FALSE (name) \ struct static_key_false name = STATIC_KEY_FALSE_INIT#define DEFINE_STATIC_KEY_FALSE_RO (name) \ struct static_key_false name __ro_after_init = STATIC_KEY_FALSE_INIT -#define DECLARE_STATIC_KEY_FALSE (name) \ - extern struct static_key_false name -#define DEFINE_STATIC_KEY_ARRAY_TRUE (name, count) \ struct static_key_true name[count] = { \ [0 ... (count) - 1] = STATIC_KEY_TRUE_INIT, \
include/linux/jump_label_type.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.28.0
RFC PATCH v2 5/5 kernel: drop PREEMPT_NONE compile time option
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
Now that preempt_mode command line parameter supports both preempt_none and preempt_voluntary we do not necessarily need a config option for this preemption mode and we can reduce the overall config space a bit.
--- kernel/Kconfig.preempt | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
kernel/Kconfig.preempt +4 -17
@@ -2,23 +2,10 @@ choice prompt "Preemption Model" - default PREEMPT_NONE - -config PREEMPT_NONE - bool "No Forced Preemption (Server)" - help - This is the traditional Linux preemption model, geared towards - throughput. It will still provide good latencies most of the - time, but there are no guarantees and occasional longer delays - are possible. - - Select this option if you are building a kernel for a server or - scientific/computation system, or if you want to maximize the - raw processing power of the kernel, irrespective of scheduling - latencies. + default PREEMPT_VOLUNTARY config PREEMPT_VOLUNTARY - bool "Voluntary Kernel Preemption (Desktop)" + bool "Voluntary Kernel Preemption (Throughput oriented workloads)" help This option reduces the latency of the kernel by adding more "explicit preemption points" to the kernel code. These new
@@ -35,7 +22,7 @@ config PREEMPT_VOLUNTARY Select this if you are building a kernel for a desktop system. config PREEMPT - bool "Preemptible Kernel (Low-Latency Desktop)" + bool "Preemptible Kernel (Low-Latency oriented workloads)" depends on !ARCH_NO_PREEMPT select PREEMPTION select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
@@ -75,7 +62,7 @@ endchoice config PREEMPT_DYNAMIC bool "Allow boot time preemption model selection" - depends on PREEMPT_NONE || PREEMPT_VOLUNTARY + depends on PREEMPT_VOLUNTARY help This option allows to define the preemption model on the kernel command line parameter and thus override the default preemption
Signature · 1 line
2.28.0
RFC PATCH v2 4/5 kernel: introduce CONFIG_PREEMPT_DYNAMIC
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
Boot time preemption mode selection is currently hardcoded for !CONFIG_PREEMPTION. Peter has suggested to introduce a dedicated option for the functionality because not each archiveture implements implements static branches (jump labels) effectively and therefore an additional overhead might be prohibitive or undesirable.
Introduce CONFIG_PREEMPT_DYNAMIC that allows boot time preemption mode override. The functionality is currently implemented for PREEMPT_NONE and PREEMPT_VOLUNTARY preemption modes.
--- include/linux/kernel.h | 20 ++++++++++++++++++-- include/linux/sched.h | 12 ------------ kernel/Kconfig.preempt | 19 +++++++++++++++++++ kernel/sched/core.c | 6 +++++- 4 files changed, 42 insertions(+), 15 deletions(-)
include/linux/kernel.h +18 -2
@@ -193,20 +193,36 @@ struct completion;struct pt_regs ;struct user ; +/* +* cond_resched() and cond_resched_lock(): latency reduction via +* explicit rescheduling in places that are safe. The return +* value indicates whether a reschedule was done in fact. +* cond_resched_lock() will drop the spinlock before scheduling, +*/ #ifndef CONFIG_PREEMPTION +extern int _cond_resched (void ); +#else +static inline int _cond_resched (void ) {return 0 ; } +#endif + +#ifdef CONFIG_PREEMPT_DYNAMIC #ifdef CONFIG_PREEMPT_VOLUNTARY DECLARE_STATIC_KEY_TRUE (preempt_voluntary_key);#else DECLARE_STATIC_KEY_FALSE (preempt_voluntary_key);#endif -extern int _cond_resched (void );# define might_resched () \ do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0)#else + +#ifdef CONFIG_PREEMPT_VOLUNTARY # define might_resched () \ - do { } while (0) + do { _cond_resched(); } while (0) +#else +# define might_resched () do { } while (0)#endif +#endif /* CONFIG_PREEMPT_DYNAMIC */ #ifdef CONFIG_DEBUG_ATOMIC_SLEEP extern void ___might_sleep (const char *file,int line,int preempt_offset);
include/linux/sched.h +0 -12
@@ -1812,18 +1812,6 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)return unlikely (test_tsk_thread_flag (tsk,TIF_NEED_RESCHED )); } -/* -* cond_resched() and cond_resched_lock(): latency reduction via -* explicit rescheduling in places that are safe. The return -* value indicates whether a reschedule was done in fact. -* cond_resched_lock() will drop the spinlock before scheduling, -*/ -#ifndef CONFIG_PREEMPTION -extern int _cond_resched (void ); -#else -static inline int _cond_resched (void ) {return 0 ; } -#endif -#define cond_resched () ({ \ ___might_sleep(__FILE__, __LINE__, 0); \ _cond_resched(); \
kernel/Kconfig.preempt +19 -0
@@ -73,6 +73,25 @@ config PREEMPT_RT endchoice +config PREEMPT_DYNAMIC + bool "Allow boot time preemption model selection" + depends on PREEMPT_NONE || PREEMPT_VOLUNTARY + help + This option allows to define the preemption model on the kernel + command line parameter and thus override the default preemption + model defined during compile time. + + The feature is primarily interesting for Linux distributions which + provide a pre-built kernel binary to reduce the number of kernel + flavors they offer while still offering different usecases. + + The runtime overhead is negligible with JUMP_LABELS enabled but if + runtime patching is not available for the specific architecture then + the potential overhead should be considered. + + Select if you the same pre-built kernel should be used for both Server + and Desktop workloads. + config PREEMPT_COUNT bool
kernel/sched/core.c +5 -1
@@ -43,6 +43,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); +#ifdef CONFIG_PREEMPT_DYNAMIC +#ifdef CONFIG_PREEMPT_VOLUNTARY DEFINE_STATIC_KEY_TRUE (preempt_voluntary_key);#else
@@ -51,6 +53,8 @@ DEFINE_STATIC_KEY_FALSE(preempt_voluntary_key);#endif EXPORT_SYMBOL (preempt_voluntary_key); +#endif +#if defined(CONFIG_SCHED_DEBUG ) && defined(CONFIG_JUMP_LABEL )/* * Debugging: various feature bits
@@ -8491,7 +8495,7 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count)trace_sched_update_nr_running_tp (rq, count); } -#ifndef CONFIG_PREEMPTION +#ifdef CONFIG_PREEMPT_DYNAMIC static int __init setup_non_preempt_mode (char *str) {if (!strcmp (str,"none" )) {
Signature · 1 line
2.28.0
v2 cover allow overriding default preempt mode from command line
In reply to Michal HockoHi,
let me repost the pile that has grown from the initial patch based on the review feedback I have collected from Peter. I do realize that he also suggested to go from the other direction and implement this for the full preemption mode first. As I've said I believe this would require to examine all CONFIG_PREEMPTION code paths and preempt_mode=[none,voluntary] is already quite useful for distributions which are targeting high throuhput and desktop environments. Adding full preemption on top is definitely desirable and something we will be looking into. This is the first step in that direction.
If maintainers really believe that starting from the full preemption mode first then we are willing to explore that path of course.
I am stil posting that as an RFC because I didn't get to push this through a complete compile time testing and rely on 0-day bot in that aspect.
Thanks and I am looking forward for a further feedback.
RFC PATCH v2 2/5 kernel: allow to configure PREEMPT_NONE, PREEMPT_VOLUNTARY on kernel command line
From: Michal Hocko <[email protected]>
Many people are still relying on pre built distribution kernels and so distributions have to provide mutliple kernel flavors to offer different preemption models. Most of them are providing PREEMPT_NONE for typical server deployments and PREEMPT_VOLUNTARY for desktop users.
Having two different kernel binaries differing only by the preemption mode seems rather wasteful and inflexible. Especially when the difference between PREEMPT_NONE and PREEMPT_VOLUNTARY is really minimal. Both only allow explicit scheduling points while running in the kernel and it is only might_sleep which adds additional preemption points for PREEMPT_VOLUNTARY.
Add a kernel command line parameter preempt_mode=[none, voluntary] which allows to override the default compile time preemption mode (CONFIG_PREEMPT_NONE resp. CONFIG_PREEMPT_VOLUTARY). Voluntary preempt mode is guarded by a jump label to prevent any potential runtime overhead.
Add an explicit include of jump_label to gpio/consumer.h to make sure all its consumers will get static_branch_likely) as kernel.h cannot include it directly.
--- .../admin-guide/kernel-parameters.txt | 5 ++++ include/linux/gpio/consumer.h | 1 + include/linux/kernel.h | 13 ++++++-- kernel/sched/core.c | 30 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -3873,6 +3873,11 @@ Format: {"off"} Disable Hardware Transactional Memory + preempt_mode={none,voluntary} + Set the preemption mode. + none - equivalent to CONFIG_PREEMPT_NONE + voluntary - equivalent to CONFIG_PREEMPT_VOLUNTARY + print-fatal-signals= [KNL] debug: print fatal signals
include/linux/gpio/consumer.h +1 -0
@@ -3,6 +3,7 @@#define __LINUX_GPIO_CONSUMER_H#include <linux/bits.h> +#include <linux/jump_label.h> #include <linux/bug.h> #include <linux/compiler_types.h> #include <linux/err.h>
include/linux/kernel.h +11 -2
@@ -14,6 +14,7 @@#include <linux/typecheck.h> #include <linux/printk.h> #include <linux/build_bug.h> +#include <linux/jump_label_type.h> #include <asm/byteorder.h> #include <asm/div64.h> #include <uapi/linux/kernel.h>
@@ -192,11 +193,19 @@ struct completion;struct pt_regs ;struct user ; +#ifndef CONFIG_PREEMPTION #ifdef CONFIG_PREEMPT_VOLUNTARY +DECLARE_STATIC_KEY_TRUE (preempt_voluntary_key); +#else +DECLARE_STATIC_KEY_FALSE (preempt_voluntary_key); +#endif +extern int _cond_resched (void ); -# define might_resched () _cond_resched() +# define might_resched () \ + do { if (static_branch_likely(&preempt_voluntary_key)) _cond_resched(); } while (0)#else -# define might_resched () do { } while (0) +# define might_resched () \ + do { } while (0)#endif #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
kernel/sched/core.c +30 -0
@@ -43,6 +43,14 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(sched_update_nr_running_tp); DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); +#ifdef CONFIG_PREEMPT_VOLUNTARY +DEFINE_STATIC_KEY_TRUE (preempt_voluntary_key); +#else +/* PREEMPT_NONE vs PREEMPT_VOLUNTARY */ +DEFINE_STATIC_KEY_FALSE (preempt_voluntary_key); +#endif +EXPORT_SYMBOL (preempt_voluntary_key); +#if defined(CONFIG_SCHED_DEBUG ) && defined(CONFIG_JUMP_LABEL )/* * Debugging: various feature bits
@@ -8482,3 +8490,25 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count) {trace_sched_update_nr_running_tp (rq, count); } + +#ifndef CONFIG_PREEMPTION +static int __init setup_non_preempt_mode (char *str) +{ +if (!strcmp (str,"none" )) { +if (IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY )) { +static_branch_disable (&preempt_voluntary_key); +pr_info ("Switching to PREEMPT_NONE mode." ); + } + }else if (!strcmp (str,"voluntary" )) { +if (!IS_ENABLED (CONFIG_PREEMPT_VOLUNTARY )) { +static_branch_enable (&preempt_voluntary_key); +pr_info ("Switching to PREEMPT_VOLUNTARY mode." ); + } + }else { +pr_warn ("Unsupported preempt mode %s\n" , str); +return 1 ; + } +return 0 ; +} +__setup ("preempt_mode=" , setup_non_preempt_mode); +#endif
Signature · 1 line
2.28.0
RFC PATCH v2 3/5 kernel: ARCH_NO_PREEMPT shouldn't exclude PREEMPT_VOLUNTARY
In reply to Michal HockoFrom: Michal Hocko <[email protected]>
PREEMPT_VOLUNTARY is fully arch agnostic so there shouldn't be any reason to restrict this preemption mode by ARCH_NO_PREEMPT.
--- kernel/Kconfig.preempt | 1 - 1 file changed, 1 deletion(-)
kernel/Kconfig.preempt +0 -1
@@ -19,7 +19,6 @@ config PREEMPT_NONE config PREEMPT_VOLUNTARY bool "Voluntary Kernel Preemption (Desktop)" - depends on !ARCH_NO_PREEMPT help This option reduces the latency of the kernel by adding more "explicit preemption points" to the kernel code. These new
Signature · 1 line
2.28.0
Peter Zijlstra
maintainerRe: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
In reply to Michal HockoCan you please not thread the new series onto the old one? That's some seriously annoying behaviour that I see more and more... It makes me loose whole patch-sets.
Re: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
Quoted 4 lines · Peter Zijlstra
Can you please not thread the new series onto the old one? That's some seriously annoying behaviour that I see more and more... It makes me loose whole patch-sets.
Sure, no problem. This is not really unusual in mm and I personally prefer to have discussion in a single thread rather than separated in two or more. But I definitely do not insist of course. It is surprising that you are losing the whole patchset as the threading seems to be done properly. Mutt doesn't seem to have problems with that.
Anyway, let me know if I should repost.
Signature · 2 lines
Michal Hocko SUSE Labs
Peter Zijlstra
maintainerRe: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
Quoted 11 lines · Michal Hocko
Quoted 4 lines · Peter Zijlstra
Can you please not thread the new series onto the old one? That's some seriously annoying behaviour that I see more and more... It makes me loose whole patch-sets.
Sure, no problem. This is not really unusual in mm and I personally prefer to have discussion in a single thread rather than separated in two or more. But I definitely do not insist of course. It is surprising that you are losing the whole patchset as the threading seems to be done properly. Mutt doesn't seem to have problems with that.
I often sort by thread and date and look at the recent most threads. Mutt sorts threads by first post, not most recent post, hence the thread is 'lost'.
Quoted 1 line
Anyway, let me know if I should repost.
I've already broken the thread (#), no need to repost.
Peter Zijlstra
maintainerRe: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
In reply to Michal HockoQuoted 10 lines · Michal Hocko
Hi,
let me repost the pile that has grown from the initial patch based on the review feedback I have collected from Peter. I do realize that he also suggested to go from the other direction and implement this for the full preemption mode first. As I've said I believe this would require to examine allCONFIG_PREEMPTIONcode paths and preempt_mode=[none,voluntary] is already quite useful for distributions which are targeting high throuhput and desktop environments. Adding full preemption on top is definitely desirable and something we will be looking into. This is the first step in that direction.
Just for giggles, configure a x86_64-PREEMPT kernel and apply the below. It builds and boots here, except for "preempt=zero", which hangs somewhere early.
It should be able to switch preemption mode at runtime too, but I've not bothered to wire that up.
Also, some of it is utterly yuck ;-)
---
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -3894,6 +3894,11 @@ Format: {"off"} Disable Hardware Transactional Memory + preempt={none,voluntary} + Set the preemption mode. + none - equivalent to CONFIG_PREEMPT_NONE + voluntary - equivalent to CONFIG_PREEMPT_VOLUNTARY + print-fatal-signals= [KNL] debug: print fatal signals
arch/x86/include/asm/preempt.h +20 -8
@@ -5,6 +5,7 @@#include <asm/rmwcc.h> #include <asm/percpu.h> #include <linux/thread_info.h> +#include <linux/static_call_types.h> DECLARE_PER_CPU (int, __preempt_count);
@@ -103,16 +104,27 @@ static __always_inline bool should_resched(int preempt_offset) }#ifdef CONFIG_PREEMPTION - extern asmlinkage void preempt_schedule_thunk(void); -# define __preempt_schedule () \ - asm volatile ("call preempt_schedule_thunk" : ASM_CALL_CONSTRAINT) - extern asmlinkage void preempt_schedule(void); - extern asmlinkage void preempt_schedule_notrace_thunk(void); -# define __preempt_schedule_notrace () \ - asm volatile ("call preempt_schedule_notrace_thunk" : ASM_CALL_CONSTRAINT) +extern asmlinkage void preempt_schedule(void); +extern asmlinkage void preempt_schedule_thunk(void); +DECLARE_STATIC_CALL (preempt_schedule, preempt_schedule_thunk); + +#define __preempt_schedule () \ +do { \ + __ADDRESSABLE(STATIC_CALL_KEY(preempt_schedule)); \ + asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule) : ASM_CALL_CONSTRAINT); \ +} while (0) + +extern asmlinkage void preempt_schedule_notrace(void); +extern asmlinkage void preempt_schedule_notrace_thunk(void); +DECLARE_STATIC_CALL (preempt_schedule_notrace, preempt_schedule_notrace_thunk); + +#define __preempt_schedule_notrace () \ +do { \ + __ADDRESSABLE(STATIC_CALL_KEY(preempt_schedule_notrace)); \ + asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule_notrace) : ASM_CALL_CONSTRAINT); \ +} while (0) - extern asmlinkage void preempt_schedule_notrace(void);#endif #endif /* __ASM_PREEMPT_H */
arch/x86/kernel/static_call.c +6 -1
@@ -16,7 +16,12 @@ static void __ref __static_call_transform(void *insn, enum insn_type type, voidint size =CALL_INSN_SIZE ;const void *code; -switch (type) { +if (type <2 && func == &__static_call_return0) { + +static const u8 ret0[5 ] = {0x66 ,0x66 ,0x48 ,0x31 ,0xc0 }; + code = ret0; + + }else switch (type) {case CALL : code =text_gen_insn (CALL_INSN_OPCODE , insn, func);break ;
include/linux/kernel.h +16 -6
@@ -14,6 +14,7 @@#include <linux/typecheck.h> #include <linux/printk.h> #include <linux/build_bug.h> +#include <linux/static_call_types.h> #include <asm/byteorder.h> #include <asm/div64.h> #include <uapi/linux/kernel.h>
@@ -192,12 +193,21 @@ struct completion;struct pt_regs ;struct user ; -#ifdef CONFIG_PREEMPT_VOLUNTARY -extern int _cond_resched (void ); -# define might_resched () _cond_resched() -#else -# define might_resched () do { } while (0) -#endif +extern int __cond_resched (void ); +DECLARE_STATIC_CALL (cond_resched, __cond_resched); + +static __always_inline int _cond_resched(void) +{ +return static_call (cond_resched)(); +} + +extern void __might_resched (void ); +DECLARE_STATIC_CALL (might_resched, __might_resched); + +static __always_inline void might_resched(void) +{ +static_call (might_resched)(); +}#ifdef CONFIG_DEBUG_ATOMIC_SLEEP extern void ___might_sleep (const char *file,int line,int preempt_offset);
include/linux/rcutree.h +0 -2
@@ -64,9 +64,7 @@ extern int rcu_scheduler_active __read_mostly;void rcu_end_inkernel_boot (void );bool rcu_inkernel_boot_has_ended (void );bool rcu_is_watching (void ); -#ifndef CONFIG_PREEMPTION void rcu_all_qs (void ); -#endif /* RCUtree hotplug events */ int rcutree_prepare_cpu (unsigned int cpu);
include/linux/sched.h +0 -5
@@ -1820,11 +1820,6 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)* value indicates whether a reschedule was done in fact. * cond_resched_lock() will drop the spinlock before scheduling, */ -#ifndef CONFIG_PREEMPTION -extern int _cond_resched (void ); -#else -static inline int _cond_resched (void ) {return 0 ; } -#endif #define cond_resched () ({ \ ___might_sleep(__FILE__, __LINE__, 0); \
include/linux/static_call.h +6 -20
@@ -107,26 +107,11 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool#define STATIC_CALL_TRAMP_ADDR (name) &STATIC_CALL_TRAMP(name) -/* -* __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from -* the symbol table so that objtool can reference it when it generates the -* .static_call_sites section. -*/ -#define __static_call (name) \ -({ \ - __ADDRESSABLE(STATIC_CALL_KEY(name)); \ - &STATIC_CALL_TRAMP(name); \ -}) -#else #define STATIC_CALL_TRAMP_ADDR (name) NULL#endif -#define DECLARE_STATIC_CALL (name, func) \ - extern struct static_call_key STATIC_CALL_KEY(name); \ - extern typeof(func) STATIC_CALL_TRAMP(name); -#define static_call_update (name, func) \ ({ \ BUILD_BUG_ON(!__same_type(*(func), STATIC_CALL_TRAMP(name))); \
@@ -136,6 +121,8 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool#ifdef CONFIG_HAVE_STATIC_CALL_INLINE +extern int __static_call_return0 (void ); +extern int __init static_call_init (void ); struct static_call_mod {
@@ -174,7 +161,6 @@ extern int static_call_text_reserved(void *start, void *end); }; \ ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) -#define static_call (name) __static_call(name)#define static_call_cond (name) (void)__static_call(name)#define EXPORT_STATIC_CALL (name) \
@@ -187,6 +173,8 @@ extern int static_call_text_reserved(void *start, void *end);#elif defined(CONFIG_HAVE_STATIC_CALL ) +static inline int __static_call_return0 (void ) {return 0 ; } +static inline int static_call_init (void ) {return 0 ; } struct static_call_key {
@@ -207,7 +195,6 @@ struct static_call_key { }; \ ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) -#define static_call (name) __static_call(name)#define static_call_cond (name) (void)__static_call(name) static inline
@@ -234,6 +221,8 @@ static inline int static_call_text_reserved(void *start, void *end)#else /* Generic implementation */ +static inline int __static_call_return0 (void ) {return 0 ; } +static inline int static_call_init (void ) {return 0 ; } struct static_call_key {
@@ -252,9 +241,6 @@ struct static_call_key { .func = NULL, \ } -#define static_call (name) \ - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) -static inline void __static_call_nop (void ) { }/*
include/linux/static_call_types.h +27 -0
@@ -4,6 +4,7 @@#include <linux/types.h> #include <linux/stringify.h> +#include <linux/compiler.h> #define STATIC_CALL_KEY_PREFIX __SCK__#define STATIC_CALL_KEY_PREFIX_STR __stringify(STATIC_CALL_KEY_PREFIX)
@@ -32,4 +33,30 @@ struct static_call_site { s32 key; }; +#define DECLARE_STATIC_CALL (name, func) \ + extern struct static_call_key STATIC_CALL_KEY(name); \ + extern typeof(func) STATIC_CALL_TRAMP(name); + +#ifdef CONFIG_HAVE_STATIC_CALL + +/* +* __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from +* the symbol table so that objtool can reference it when it generates the +* .static_call_sites section. +*/ +#define __static_call (name) \ +({ \ + __ADDRESSABLE(STATIC_CALL_KEY(name)); \ + &STATIC_CALL_TRAMP(name); \ +}) + +#define static_call (name) __static_call(name) + +#else + +#define static_call (name) \ + ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) + +#endif /* CONFIG_HAVE_STATIC_CALL */ +#endif /* _STATIC_CALL_TYPES_H */
kernel/entry/common.c +3 -1
@@ -359,6 +359,8 @@ void irqentry_exit_cond_resched(void) } } +DECLARE_STATIC_KEY_TRUE (irq_preemption_key); + noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state) {lockdep_assert_irqs_disabled ();
@@ -384,7 +386,7 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state) }instrumentation_begin (); -if (IS_ENABLED (CONFIG_PREEMPTION )) +if (static_branch_likely (&irq_preemption_key))irqentry_exit_cond_resched ();/* Covers both tracing and lockdep */ trace_hardirqs_on ();
kernel/sched/core.c +104 -4
137 lines not on this page · raw message
kernel/static_call.c +5 -0
@@ -438,6 +438,11 @@ int __init static_call_init(void) }early_initcall (static_call_init); +int __static_call_return0 (void ) +{ +return 0 ; +} +#ifdef CONFIG_STATIC_CALL_SELFTEST static int func_a (int x)
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Michal,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on tip/sched/core]
[also build test ERROR on gpio/for-next linus/master v5.9] [cannot apply to linux/master next-20201015]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Michal-Hocko/allow-overriding-default-preempt-mode-from-command-line/20201009-203052 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git feff2e65efd8d84cf831668e182b2ce73c604bbb config: parisc-randconfig-r031-20201014 (attached as .config) compiler: hppa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/643d7718ce08c98533500e214350e74125056b98
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Michal-Hocko/allow-overriding-default-preempt-mode-from-command-line/20201009-203052 git checkout 643d7718ce08c98533500e214350e74125056b98
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/compiler_types.h:74,
from <command-line>:
arch/parisc/include/asm/jump_label.h: In function 'arch_static_branch':
>> arch/parisc/include/asm/jump_label.h:18:4: error: expected ':' before '__stringify'
18 | __stringify(ASM_ULONG_INSN) " %c0 - .\n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:115:47: note: in definition of macro 'asm_volatile_goto'
115 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:89,
from include/linux/gpio/consumer.h:6,
from drivers/iio/proximity/srf04.c:38:
arch/parisc/include/asm/jump_label.h:23:1: warning: label 'l_yes' defined but not used [-Wunused-label]
23 | l_yes:
| ^~~~~
In file included from include/linux/compiler_types.h:74,
from <command-line>:
arch/parisc/include/asm/jump_label.h: In function 'arch_static_branch_jump':
arch/parisc/include/asm/jump_label.h:33:4: error: expected ':' before '__stringify'
33 | __stringify(ASM_ULONG_INSN) " %c0 - .\n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:115:47: note: in definition of macro 'asm_volatile_goto'
115 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:89,
from include/linux/gpio/consumer.h:6,
from drivers/iio/proximity/srf04.c:38:
arch/parisc/include/asm/jump_label.h:38:1: warning: label 'l_yes' defined but not used [-Wunused-label]
38 | l_yes:
| ^~~~~--
In file included from include/linux/compiler_types.h:74,
from <command-line>:
arch/parisc/include/asm/jump_label.h: In function 'arch_static_branch':
>> arch/parisc/include/asm/jump_label.h:18:4: error: expected ':' before '__stringify'
18 | __stringify(ASM_ULONG_INSN) " %c0 - .\n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:115:47: note: in definition of macro 'asm_volatile_goto'
115 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:89,
from include/linux/gpio/consumer.h:6,
from sound/soc/codecs/es7241.c:6:
arch/parisc/include/asm/jump_label.h:23:1: warning: label 'l_yes' defined but not used [-Wunused-label]
23 | l_yes:
| ^~~~~
In file included from include/linux/compiler_types.h:74,
from <command-line>:
arch/parisc/include/asm/jump_label.h: In function 'arch_static_branch_jump':
arch/parisc/include/asm/jump_label.h:33:4: error: expected ':' before '__stringify'
33 | __stringify(ASM_ULONG_INSN) " %c0 - .\n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:115:47: note: in definition of macro 'asm_volatile_goto'
115 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:89,
from include/linux/gpio/consumer.h:6,
from sound/soc/codecs/es7241.c:6:
arch/parisc/include/asm/jump_label.h:38:1: warning: label 'l_yes' defined but not used [-Wunused-label]
38 | l_yes:
| ^~~~~
At top level:
sound/soc/codecs/es7241.c:206:33: warning: 'es7241_chip' defined but not used [-Wunused-const-variable=]
206 | static const struct es7241_chip es7241_chip = {
| ^~~~~~~~~~~vim +18 arch/parisc/include/asm/jump_label.h
62217beb394e654 Helge Deller 2019-05-03 11
62217beb394e654 Helge Deller 2019-05-03 12 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
62217beb394e654 Helge Deller 2019-05-03 13 {
62217beb394e654 Helge Deller 2019-05-03 14 asm_volatile_goto("1:\n\t"
62217beb394e654 Helge Deller 2019-05-03 15 "nop\n\t"
62217beb394e654 Helge Deller 2019-05-03 16 ".pushsection __jump_table, \"aw\"\n\t"
62217beb394e654 Helge Deller 2019-05-03 17 ".word 1b - ., %l[l_yes] - .\n\t"
62217beb394e654 Helge Deller 2019-05-03 @18 __stringify(ASM_ULONG_INSN) " %c0 - .\n\t"
62217beb394e654 Helge Deller 2019-05-03 19 ".popsection\n\t"
62217beb394e654 Helge Deller 2019-05-03 20 : : "i" (&((char *)key)[branch]) : : l_yes);
62217beb394e654 Helge Deller 2019-05-03 21
62217beb394e654 Helge Deller 2019-05-03 22 return false;
62217beb394e654 Helge Deller 2019-05-03 23 l_yes:
62217beb394e654 Helge Deller 2019-05-03 24 return true;
62217beb394e654 Helge Deller 2019-05-03 25 }
62217beb394e654 Helge Deller 2019-05-03 26 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Frederic Weisbecker
maintainerRe: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
In reply to Peter ZijlstraQuoted 28 lines · Peter Zijlstra
kernel/sched/core.c +28
-0+DEFINE_STATIC_KEY_TRUE (irq_preemption_key); + +/* +* SC:cond_resched +* SC:might_resched +* SC:preempt_schedule +* SC:preempt_schedule_notrace +* SB:irq_preemption_key +* +* +* ZERO +* cond_resched <- RET0 +* might_resched <- NOP +* preempt_schedule <- NOP +* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* NONE: +* cond_resched <- __cond_resched +* might_resched <- NOP +* preempt_schedule <- NOP +* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* VOLUNTARY: +* cond_resched <- __cond_resched +* might_resched <- __might_resched +* preempt_schedule <- NOP
kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 8539
Quoted 10 lines
kernel/sched/core.c +10
-0+* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* FULL: +* cond_resched <- RET0 +* might_resched <- NOP +* preempt_schedule <- preempt_schedule +* preempt_schedule_notrace <- preempt_schedule_notrace +* irq_preemption_key <- true +*/
That's cute! I'll try to end up to that result.
Quoted 20 lines
kernel/sched/core.c +20
-0+static int __init setup_preempt_mode (char *str) +{ +if (!strcmp (str,"zero" )) { +static_call_update (cond_resched, __static_call_return0); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, (void (*)(void ))NULL ); +static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"none" )) { +static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, (void (*)(void ))NULL ); +static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"voluntary" )) { +static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, __might_resched); +static_call_update (preempt_schedule, (void (*)(void ))NULL );
kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 8569
Quoted 10 lines
kernel/sched/core.c +10
-0+static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"ponies" )) { +static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, preempt_schedule_thunk); +static_call_update (preempt_schedule_notrace, preempt_schedule_notrace_thunk); +static_branch_enable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str);
Why would we need that ponies version?
Thanks!
Peter Zijlstra
maintainerRe: [RFC PATCH v2 0/5] allow overriding default preempt mode from command line
Quoted 33 lines · Frederic Weisbecker
Quoted 32 lines · Peter Zijlstra
kernel/sched/core.c +32
-0+DEFINE_STATIC_KEY_TRUE (irq_preemption_key); + +/* +* SC:cond_resched +* SC:might_resched +* SC:preempt_schedule +* SC:preempt_schedule_notrace +* SB:irq_preemption_key +* +* +* ZERO +* cond_resched <- RET0 +* might_resched <- NOP +* preempt_schedule <- NOP +* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* NONE: +* cond_resched <- __cond_resched +* might_resched <- NOP +* preempt_schedule <- NOP +* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* VOLUNTARY: +* cond_resched <- __cond_resched +* might_resched <- __might_resched +* preempt_schedule <- NOP +* preempt_schedule_notrace <- NOP +* irq_preemption_key <- false +* +* FULL:
Quoted 8 lines
Quoted 6 lines
+ * cond_resched <- RET0 + * might_resched <- NOP + * preempt_schedule <- preempt_schedule + * preempt_schedule_notrace <- preempt_schedule_notrace + * irq_preemption_key <- true+ */
That's cute! I'll try to end up to that result.
Beware, ZERO is 'broken', I included it because I was curious what, if anything, would happen :-)
Quoted 24 lines
Quoted 24 lines
kernel/sched/core.c +24
-0+static int __init setup_preempt_mode (char *str) +{ +if (!strcmp (str,"zero" )) { +static_call_update (cond_resched, __static_call_return0); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, (void (*)(void ))NULL ); +static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"none" )) { +static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, (void (*)(void ))NULL ); +static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"voluntary" )) { +static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, __might_resched); +static_call_update (preempt_schedule, (void (*)(void ))NULL ); +static_call_update (preempt_schedule_notrace, (void (*)(void ))NULL ); +static_branch_disable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str); + }else if (!strcmp (str,"ponies" )) {
Quoted 8 lines
kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 8569
Quoted 6 lines
kernel/sched/core.c +6
-0+static_call_update (cond_resched, __cond_resched); +static_call_update (might_resched, (void (*)(void ))NULL ); +static_call_update (preempt_schedule, preempt_schedule_thunk); +static_call_update (preempt_schedule_notrace, preempt_schedule_notrace_thunk); +static_branch_enable (&irq_preemption_key); +printk ("XXX PREEMPT: %s\n" , str);Why would we need that ponies version?
We don't, but it was a missing combination (like ZERO), and I wanted to test it worked (as expected, it does).
We'll only encounter it as an intermediate state when flipping states at runtime, but unlike zero, it should work just fine.