powerpc, arm64: move preempt dynamic key into kernel/sched
Subsystems (4)
Shrikanth Hegde
reviewerv2 cover powerpc, arm64: move preempt dynamic key into kernel/sched
Current usage of preempt dynamic key is not specific to architecture and can be moved into sched/core instead. Most of the code around it looks similar. (same code for powerpc, arm64).
Since preemption is more associated with scheduler rather than entry/exit, it is probably better it should be moved.
This is tested on powerVM PREEMPT_DYNAMIC=y/n and on arm64 by Mark
v1->v2:
- Rebase to 6.16-rc6
- Collected the tags
Ingo, Peter,
Can this go via tip sched tree?
Both arm64, powerpc have acked the changes and been tested.
Shrikanth Hegde (1):
sched: preempt: Move dynamic keys into kernel/sched
arch/arm64/include/asm/preempt.h | 1 - arch/arm64/kernel/entry-common.c | 8 -------- arch/powerpc/include/asm/preempt.h | 16 ---------------- arch/powerpc/kernel/interrupt.c | 4 ---- include/linux/irq-entry-common.h | 1 - include/linux/sched.h | 8 ++++++++ kernel/entry/common.c | 1 - kernel/sched/core.c | 4 ++++ 8 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 arch/powerpc/include/asm/preempt.h
Signature · 1 line
2.43.0
Shrikanth Hegde
reviewerPATCH v2 1/1 sched: preempt: Move dynamic keys into kernel/sched
Dynamic preemption can be static key or static call based. Static key is used to check kernel preemption depending on the current preemption model. i.e enable for lazy, full.
Code is currently spread across entry/common.c, arm64 and latest being powerpc. There is little arch specific to it. arm64, powerpc have the same code. It is better to move it into kernel/sched since preemption is more closely associated with scheduler.
Plus, Any new arch that wants dynamic preemption enabled need to have only HAVE_PREEMPT_DYNAMIC_KEY.
--- arch/arm64/include/asm/preempt.h | 1 - arch/arm64/kernel/entry-common.c | 8 -------- arch/powerpc/include/asm/preempt.h | 16 ---------------- arch/powerpc/kernel/interrupt.c | 4 ---- include/linux/irq-entry-common.h | 1 - include/linux/sched.h | 8 ++++++++ kernel/entry/common.c | 1 - kernel/sched/core.c | 4 ++++ 8 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 arch/powerpc/include/asm/preempt.h
arch/arm64/include/asm/preempt.h +0 -1
@@ -87,7 +87,6 @@ void preempt_schedule_notrace(void);#ifdef CONFIG_PREEMPT_DYNAMIC -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_preempt_schedule (void );#define __preempt_schedule () dynamic_preempt_schedule()void dynamic_preempt_schedule_notrace (void );
arch/arm64/kernel/entry-common.c +0 -8
@@ -259,14 +259,6 @@ static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)lockdep_hardirqs_on (CALLER_ADDR0 ); } -#ifdef CONFIG_PREEMPT_DYNAMIC -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#define need_irq_preemption () \ - (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) -#else -#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) -#endif - static void __sched arm64_preempt_schedule_irq(void) {if (!need_irq_preemption ())
arch/powerpc/include/asm/preempt.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* 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 ) -#include <linux/jump_label.h> -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#define need_irq_preemption () \ - (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) -#else -#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) -#endif - -#endif /* __ASM_POWERPC_PREEMPT_H */
arch/powerpc/kernel/interrupt.c +0 -4
@@ -25,10 +25,6 @@unsigned long global_dbcr0[NR_CPUS ];#endif -#if defined(CONFIG_PREEMPT_DYNAMIC ) -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 )
include/linux/irq-entry-common.h +0 -1
@@ -343,7 +343,6 @@ void raw_irqentry_exit_cond_resched(void);DECLARE_STATIC_CALL (irqentry_exit_cond_resched, raw_irqentry_exit_cond_resched);#define irqentry_exit_cond_resched () static_call(irqentry_exit_cond_resched)()#elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_irqentry_exit_cond_resched (void );#define irqentry_exit_cond_resched () dynamic_irqentry_exit_cond_resched()#endif
include/linux/sched.h +8 -0
@@ -2076,6 +2076,14 @@ static inline int _cond_resched(void)#endif /* !CONFIG_PREEMPTION || CONFIG_PREEMPT_DYNAMIC */ +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#define need_irq_preemption () \ + (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) +#else +#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) +#endif +#define cond_resched () ({ \ __might_resched(__FILE__, __LINE__, 0); \ _cond_resched(); \
kernel/entry/common.c +0 -1
@@ -157,7 +157,6 @@ void raw_irqentry_exit_cond_resched(void)#if defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL )DEFINE_STATIC_CALL (irqentry_exit_cond_resched, raw_irqentry_exit_cond_resched);#elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_irqentry_exit_cond_resched (void ) {if (!static_branch_unlikely (&sk_dynamic_irqentry_exit_cond_resched))
kernel/sched/core.c +4 -0
@@ -6999,6 +6999,10 @@ EXPORT_SYMBOL(dynamic_preempt_schedule_notrace);#endif /* CONFIG_PREEMPTION */ +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#endif +/* * This is the entry point to schedule() from kernel preemption * off of IRQ context.
Signature · 1 line
2.43.0
Re: [PATCH v2 1/1] sched: preempt: Move dynamic keys into kernel/sched
Quoted 162 lines · Shrikanth Hegde
Dynamic preemption can be static key or static call based. Static key is used to check kernel preemption depending on the current preemption model. i.e enable for lazy, full.
Code is currently spread across
entry/common.c, arm64 and latest being powerpc. There is little arch specific to it. arm64, powerpc have the same code. It is better to move it into kernel/sched since preemption is more closely associated with scheduler.Plus, Any new arch that wants dynamic preemption enabled need to have only
HAVE_PREEMPT_DYNAMIC_KEY.Suggested-by Sebastian Andrzej Siewior <[email protected]>Signed-off-by Shrikanth Hegde <[email protected]>Acked-by Mark Rutland <[email protected]>Acked-by Will Deacon <[email protected]>---
arch/arm64/include/asm/preempt.h | 1 - arch/arm64/kernel/entry-common.c | 8 -------- arch/powerpc/include/asm/preempt.h | 16 ---------------- arch/powerpc/kernel/interrupt.c | 4 ---- include/linux/irq-entry-common.h | 1 - include/linux/sched.h | 8 ++++++++ kernel/entry/common.c | 1 - kernel/sched/core.c | 4 ++++ 8 files changed, 12 insertions(+), 31 deletions(-)delete mode 100644
arch/powerpc/include/asm/preempt.harch/arm64/include/asm/preempt.h +0
-1@@ -87,7 +87,6 @@ void preempt_schedule_notrace(void);#ifdef CONFIG_PREEMPT_DYNAMIC -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_preempt_schedule (void );#define __preempt_schedule () dynamic_preempt_schedule()void dynamic_preempt_schedule_notrace (void );arch/arm64/kernel/entry-common.c +0
-8@@ -259,14 +259,6 @@ static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)lockdep_hardirqs_on (CALLER_ADDR0 ); } -#ifdef CONFIG_PREEMPT_DYNAMIC -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#define need_irq_preemption () \ - (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) -#else -#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) -#endif - static void __sched arm64_preempt_schedule_irq(void) {if (!need_irq_preemption ())arch/powerpc/include/asm/preempt.h deleted +0
-16@@ -1,16 +0,0 @@ -/* 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 ) -#include <linux/jump_label.h> -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); -#define need_irq_preemption () \ - (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) -#else -#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) -#endif - -#endif /* __ASM_POWERPC_PREEMPT_H */ arch/powerpc/kernel/interrupt.c +0
-4@@ -25,10 +25,6 @@unsigned long global_dbcr0[NR_CPUS ];#endif -#if defined(CONFIG_PREEMPT_DYNAMIC ) -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 )include/linux/irq-entry-common.h +0
-1@@ -343,7 +343,6 @@ void raw_irqentry_exit_cond_resched(void);DECLARE_STATIC_CALL (irqentry_exit_cond_resched, raw_irqentry_exit_cond_resched);#define irqentry_exit_cond_resched () static_call(irqentry_exit_cond_resched)()#elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) -DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_irqentry_exit_cond_resched (void );#define irqentry_exit_cond_resched () dynamic_irqentry_exit_cond_resched()#endif include/linux/sched.h +8
-0@@ -2076,6 +2076,14 @@ static inline int _cond_resched(void)#endif /* !CONFIG_PREEMPTION || CONFIG_PREEMPT_DYNAMIC */ +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DECLARE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#define need_irq_preemption () \ + (static_branch_unlikely(&sk_dynamic_irqentry_exit_cond_resched)) +#else +#define need_irq_preemption () (IS_ENABLED(CONFIG_PREEMPTION)) +#endif +#define cond_resched () ({ \ __might_resched(__FILE__, __LINE__, 0); \ _cond_resched(); \kernel/entry/common.c +0
-1@@ -157,7 +157,6 @@ void raw_irqentry_exit_cond_resched(void)#if defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL )DEFINE_STATIC_CALL (irqentry_exit_cond_resched, raw_irqentry_exit_cond_resched);#elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) -DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched);void dynamic_irqentry_exit_cond_resched (void ) {if (!static_branch_unlikely (&sk_dynamic_irqentry_exit_cond_resched))kernel/sched/core.c +4
-0@@ -6999,6 +6999,10 @@ EXPORT_SYMBOL(dynamic_preempt_schedule_notrace);#endif /* CONFIG_PREEMPTION */ +#if defined(CONFIG_PREEMPT_DYNAMIC ) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY ) +DEFINE_STATIC_KEY_TRUE (sk_dynamic_irqentry_exit_cond_resched); +#endif +/* * This is the entry point to schedule() from kernel preemption * off of IRQ context. Signature · 1 line
2.43.0
<Resending to the right thread>
Tested this patch, by applying on top of mainline kernel.
Dynamically changed the preemption modes, and its working as expected. Hence,
Regards,
Venkat.
Shrikanth Hegde
reviewerRe: [PATCH v2 1/1] sched: preempt: Move dynamic keys into kernel/sched
In reply to Shrikanth HegdeQuoted 27 lines · Shrikanth Hegde
Dynamic preemption can be static key or static call based. Static key is used to check kernel preemption depending on the current preemption model. i.e enable for lazy, full.
Code is currently spread across
entry/common.c, arm64 and latest being powerpc. There is little arch specific to it. arm64, powerpc have the same code. It is better to move it into kernel/sched since preemption is more closely associated with scheduler.Plus, Any new arch that wants dynamic preemption enabled need to have only
HAVE_PREEMPT_DYNAMIC_KEY.Suggested-by Sebastian Andrzej Siewior <[email protected]>Signed-off-by Shrikanth Hegde <[email protected]>Acked-by Mark Rutland <[email protected]>Acked-by Will Deacon <[email protected]>--- arch/arm64/include/asm/preempt.h | 1 - arch/arm64/kernel/entry-common.c | 8 -------- arch/powerpc/include/asm/preempt.h | 16 ---------------- arch/powerpc/kernel/interrupt.c | 4 ---- include/linux/irq-entry-common.h | 1 - include/linux/sched.h | 8 ++++++++ kernel/entry/common.c | 1 - kernel/sched/core.c | 4 ++++ 8 files changed, 12 insertions(+), 31 deletions(-)
Quoted 2 lines
delete mode 100644
arch/powerpc/include/asm/preempt.h
Hi Ingo, Peter.
Does this change makes sense? Are there any further concerns that you see? Also can it go via tip tree?
Patch applies on 6.17-rc1 (at commit ca76508b9352e8c770b58213cc6c4700e459b7c2)