powerpc: Enable dynamic preemption
Shrikanth Hegde
reviewerv2 cover powerpc: Enable dynamic preemption
Now that preempt=lazy patches[1] are in powerpc-next tree, sending out the patch to support dynamic preemption based on DYNAMIC_KEY. I am not sure when it was to be sent out exactly. So here it is.
Depends on [1] to be applied first, if not in the tree yet.
Once the arch supports static inline calls, it would be needed to evaluate to see if that gives better performance.
v1->v2:
- Instead of copying asm-generic preempt.h content include it in arch/asm preempt.h. (Christophe Leroy)
- Merge the patches into one patch (Christophe Leroy)
v1: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/
Shrikanth Hegde (1):
powerpc: Enable dynamic preemption
arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/preempt.h | 11 +++++++++++ arch/powerpc/kernel/interrupt.c | 6 +++++- arch/powerpc/kernel/traps.c | 6 +++++- arch/powerpc/lib/vmx-helper.c | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/preempt.h
Signature · 1 line
2.39.3
Shrikanth Hegde
reviewerPATCH v2 1/1 powerpc: Enable dynamic preemption
Once the lazy preemption is supported, it would be desirable to change the preemption models at runtime. So add support for dynamic preemption using DYNAMIC_KEY.
In irq-exit to kernel path, use preempt_model_preemptible for decision. Other way would be using static key based decision. Keeping it simpler since key based change didn't show performance improvement.
Also print the right preemption model in __die.
::Tested lightly on Power10 LPAR
Performance numbers indicate that, preempt=none(no dynamic) and preempt=none(dynamic) are similar.
cat /sys/kernel/debug/sched/preempt
(none) voluntary full lazy
perf stat -e probe:__cond_resched -a sleep 1
Performance counter stats for 'system wide':
1,253 probe:__cond_resched
echo full > /sys/kernel/debug/sched/preempt
cat /sys/kernel/debug/sched/preempt
none voluntary (full) lazy
perf stat -e probe:__cond_resched -a sleep 1
Performance counter stats for 'system wide':
0 probe:__cond_resched
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/preempt.h | 11 +++++++++++ arch/powerpc/kernel/interrupt.c | 6 +++++- arch/powerpc/kernel/traps.c | 6 +++++- arch/powerpc/lib/vmx-helper.c | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/preempt.h
arch/powerpc/Kconfig +1 -0
@@ -272,6 +272,7 @@ config PPC select HAVE_PERF_EVENTS_NMI if PPC64 select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP + select HAVE_PREEMPT_DYNAMIC_KEY select HAVE_RETHOOK if KPROBES select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE
arch/powerpc/include/asm/preempt.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_POWERPC_PREEMPT_H +#define __ASM_POWERPC_PREEMPT_H + +#include <asm-generic/preempt.h> + +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#endif + +#endif /* __ASM_POWERPC_PREEMPT_H */
arch/powerpc/kernel/interrupt.c +5 -1
@@ -25,6 +25,10 @@unsigned long global_dbcr0[NR_CPUS ];#endif +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#endif +#ifdef CONFIG_PPC_BOOK3S_64 DEFINE_STATIC_KEY_FALSE (interrupt_exit_not_reentrant);static inline bool exit_must_hard_disable (void )
@@ -396,7 +400,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)/* Returning to a kernel context with local irqs enabled. */ WARN_ON_ONCE (!(regs->msr &MSR_EE )); again: -if (IS_ENABLED (CONFIG_PREEMPTION )) { +if (preempt_model_preemptible ()) {/* Return to preemptible kernel context */ if (unlikely (read_thread_flags () & _TIF_NEED_RESCHED)) {if (preempt_count () ==0 )
arch/powerpc/kernel/traps.c +5 -1
@@ -266,7 +266,11 @@ static int __die(const char *str, struct pt_regs *regs, long err) printk("%s PAGE_SIZE=%luK%s%s%s%s%s%s %s\n", IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN) ? "LE" : "BE", PAGE_SIZE / 1024, get_mmu_str(), - IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "", + preempt_model_none() ? "none" : + preempt_model_voluntary() ? "voluntary" : + preempt_model_full() ? "full" : + preempt_model_lazy() ? "lazy" : + "", IS_ENABLED(CONFIG_SMP) ? " SMP" : "", IS_ENABLED(CONFIG_SMP) ? (" NR_CPUS=" __stringify(NR_CPUS)) : "", debug_pagealloc_enabled() ? " DEBUG_PAGEALLOC" : "",
arch/powerpc/lib/vmx-helper.c +1 -1
@@ -45,7 +45,7 @@ int exit_vmx_usercopy(void)* set and we are preemptible. The hack here is to schedule a * decrementer to fire here and reschedule for us if necessary. */ -if (IS_ENABLED (CONFIG_PREEMPTION ) &&need_resched ()) +if (preempt_model_preemptible () &&need_resched ())set_dec (1 );return 0 ; }
Signature · 1 line
2.39.3
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Shrikanth,
kernel test robot noticed the following build errors:
[auto build test ERROR on powerpc/next]
[cannot apply to powerpc/fixes linus/master v6.13-rc5 next-20241220] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shrikanth-Hegde/powerpc-Enable-dynamic-preemption/20250103-032131 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20250102191856.499424-2-sshegde%40linux.ibm.com patch subject: [PATCH v2 1/1] powerpc: Enable dynamic preemption config: powerpc-randconfig-r072-20250104 (https://download.01.org/0day-ci/archive/20250104/[email protected]/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 096551537b2a747a3387726ca618ceeb3950e9bc) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:14:
In file included from include/linux/sem.h:5:
In file included from include/uapi/linux/sem.h:5:
In file included from include/linux/ipc.h:7:
In file included from include/linux/rhashtable-types.h:12:
In file included from include/linux/alloc_tag.h:11:
In file included from include/linux/preempt.h:79:
>> arch/powerpc/include/asm/preempt.h:8:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
8 | DECLARE_STATIC_KEY_TRUE(sk_dynamic_irqentry_exit_cond_resched);
| ^
| int
>> arch/powerpc/include/asm/preempt.h:8:25: error: a parameter list without types is only allowed in a function definition
8 | DECLARE_STATIC_KEY_TRUE(sk_dynamic_irqentry_exit_cond_resched);
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
98 | return (set->sig[3] | set->sig[2] |
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:98:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
98 | return (set->sig[3] | set->sig[2] |
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:114:11: warning: array index 3 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
114 | return (set1->sig[3] == set2->sig[3]) &&
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:114:27: warning: array index 3 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
114 | return (set1->sig[3] == set2->sig[3]) &&
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:115:5: warning: array index 2 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
115 | (set1->sig[2] == set2->sig[2]) &&
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:115:21: warning: array index 2 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
115 | (set1->sig[2] == set2->sig[2]) &&
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:157:1: warning: array index 3 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
157 | _SIG_SET_BINOP(sigorsets, _sig_or)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/signal.h:138:8: note: expanded from macro '_SIG_SET_BINOP'
138 | a3 = a->sig[3]; a2 = a->sig[2]; \
| ^ ~
arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
18 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/powerpc/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:17:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:157:1: warning: array index 2 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds]
157 | _SIG_SET_BINOP(sigorsets, _sig_or)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/signal.h:138:24: note: expanded from macro '_SIG_SET_BINOP'
138 | a3 = a->sig[3]; a2 = a->sig[2]; \vim +/int +8 arch/powerpc/include/asm/preempt.h
6
7 #if defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)
> 8 DECLARE_STATIC_KEY_TRUE(sk_dynamic_irqentry_exit_cond_resched);
9 #endif
10 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki