powerpc: Enable dynamic preemption
Shrikanth Hegde
reviewerv4 cover powerpc: Enable dynamic preemption
Now that preempt=lazy patches are merged upstream, sending out the patch to support dynamic preemption based on DYNAMIC_KEY.
Once the arch supports static inline calls, it would be needed to evaluate to see if that gives better performance.
This makes the same code for arm64 and powerpc. Will be sending an RFC patch to move this static key into sched/core.
v3->v4:
- Use static key instead of using preempt_model_preemptible (Sebastian Andrzej Siewior and Christophe Leroy)
- Dropped printing the preemption model, since it is addressed in a patchset from Sebastian Andrzej Siewior
v2->v3:
- fixed a build error reported by linux test robot by including jump label header.
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)
v3: https://lore.kernel.org/all/[email protected]/
Shrikanth Hegde (1):
powerpc: enable dynamic preemption
arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/preempt.h | 16 ++++++++++++++++ arch/powerpc/kernel/interrupt.c | 6 +++++- arch/powerpc/lib/vmx-helper.c | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/asm/preempt.h
Signature · 1 line
2.39.3
Shrikanth Hegde
reviewerPATCH v4 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.
::Tested lightly on Power10 LPAR
Performance numbers indicate that, preempt=none(no dynamic) and preempt=none(dynamic) are close.
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 | 16 ++++++++++++++++ arch/powerpc/kernel/interrupt.c | 6 +++++- arch/powerpc/lib/vmx-helper.c | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/asm/preempt.h
arch/powerpc/Kconfig +1 -0
@@ -275,6 +275,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 +16 -0
@@ -0,0 +1,16 @@ +/* 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 +5 -1
@@ -25,6 +25,10 @@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 )
@@ -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 (need_irq_preemption ()) {/* Return to preemptible kernel context */ if (unlikely (read_thread_flags () & _TIF_NEED_RESCHED)) {if (preempt_count () ==0 )
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 (need_irq_preemption () &&need_resched ())set_dec (1 );return 0 ; }
Signature · 1 line
2.39.3
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Shrikanth, Christophe,
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by CONFIG_PREEMPT_RCU becoming active once HAVE_PREEMPT_DYNAMIC_KEY is selected.
Benchmark: stress-ng kill stressor (tight kill() syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).
Bisected across Fedora ELN kernel builds on ppc64le:
kernel CONFIG_PREEMPT_RCU kill bogo-ops/sec
--- 6.15-rc6 (eln148) no 103,207
6.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)
For comparison, x86_64 (AMD EPYC 9355P) with the same config change shows only a 2.8% regression:
6.12 x86_64 37,436
7.2 x86_64 36,392 (-2.8%)
perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (check_kill_permission -> security_task_kill -> selinux_task_kill -> avc_has_perm -> avc_lookup):
Function 6.15 (no PREEMPT_RCU) 6.16 (PREEMPT_RCU)
--- avc_lookup 15.23% 24.79%
__rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%
On x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.
This aligns with Christophe's earlier review comment that HAVE_PREEMPT_DYNAMIC_CALL should be more performant. Would implementing static calls for ppc64 be feasible to close this gap?
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)
Happy to run additional tests if needed.
Quoted 106 lines · Shrikanth Hegde
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.::Tested lightly on Power10 LPAR
Performance numbers indicate that, preempt=none(no dynamic) and preempt=none(dynamic) are close.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_reschedecho 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_reschedSigned-off-by Shrikanth Hegde <[email protected]>--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/preempt.h | 16 ++++++++++++++++ arch/powerpc/kernel/interrupt.c | 6 +++++- arch/powerpc/lib/vmx-helper.c | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/asm/preempt.harch/powerpc/Kconfig +1
-0@@ -275,6 +275,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_STACKTRACEarch/powerpc/include/asm/preempt.h new file +16
-0@@ -0,0 +1,16 @@ +/* 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 +5
-1@@ -25,6 +25,10 @@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 )@@ -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 (need_irq_preemption ()) {/* Return to preemptible kernel context */ if (unlikely (read_thread_flags () & _TIF_NEED_RESCHED)) {if (preempt_count () ==0 )arch/powerpc/lib/vmx-helper.c +1
-2@@ -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 (need_irq_preemption () &&need_resched ())set_dec (1 );return 0 ; } --2.39.3
Signature · 1 line
-Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 4 lines
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by
CONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.
This is true only if user selected PREEMPT_DYNAMIC option i think.
config PREEMPT_RCU
bool
default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC)
select TREE_RCUQuoted 10 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le:
kernel
CONFIG_PREEMPT_RCUkill bogo-ops/sec
--- 6.15-rc6 (eln148) no 103,2076.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)
Does your preemption mode remain the same in two cases?
Quoted 17 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436 7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (
check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no
PREEMPT_RCU) 6.16 (PREEMPT_RCU)
---avc_lookup15.23% 24.79%__rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%
Quoted 5 lines
On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.
Weak memory model would need barriers irrespective of HAVE_PREEMPT_DYNAMIC_CALL or HAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much about PREEMPT_RCU. So might take a while.
Quoted 5 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?
Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Shrikanth,
Thanks for the quick response and for looping in Paul.
Quoted 1 line
This is true only if user selected
PREEMPT_DYNAMICoption i think.
Yes, exactly. The issue is that CONFIG_PREEMPT_DYNAMIC=y has been in the Fedora/RHEL kernel config since kernel 5.16 (2021). It was silently ignored on ppc64le until your 6.16 patch added HAVE_PREEMPT_DYNAMIC_KEY, so this is the first time PREEMPT_RCU actually takes effect for all Fedora/RHEL ppc64le users.
Quoted 1 line
Does your preemption mode remain the same in two cases?
Verified. On 6.15-rc6 (before PREEMPT_DYNAMIC takes effect):
CONFIG_PREEMPT_VOLUNTARY=y
(no CONFIG_PREEMPT_DYNAMIC, no /sys/kernel/debug/sched/preempt)
On both 7.1 and 7.2-rc4 (with PREEMPT_DYNAMIC active):
CONFIG_PREEMPT_LAZY=y CONFIG_PREEMPT_DYNAMIC=y CONFIG_PREEMPT_RCU=y
cat /sys/kernel/debug/sched/preempt: "full (lazy)"
So the runtime preemption mode is the same on 7.1 and 7.2. The difference between 6.15 and 7.1+ is that the preemption model changed from voluntary (static) to full/lazy (dynamic), which is what pulls in PREEMPT_RCU.
Quoted 3 lines
Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. Static key too is expected to minimal cost.
You're right, I should clarify -- the overhead is not in the static key mechanism itself. The cost comes from __rcu_read_lock() and __rcu_read_unlock() which are called when CONFIG_PREEMPT_RCU=y. These need real memory barriers (lwsync/isync) on ppc64le regardless of whether the dynamic mechanism uses keys or calls.
The real question is: why does enabling PREEMPT_RCU cost ~33% on ppc64le but only ~3% on x86_64? The answer is that x86_64's TSO memory model makes the barriers in __rcu_read_lock/__rcu_read_unlock essentially free, while ppc64le's weak ordering requires explicit lwsync/isync instructions, which are expensive when called thousands of times per second in the SELinux AVC hot path.
I also have new data from SELinux isolation testing that helps quantify this. On kernel 7.1 (which already has PREEMPT_RCU=y):
SELinux mode kill bogo-ops/sec vs enforcing ------------ ----------------- ------------ Enforcing 69,107 baseline Permissive 70,248 +1.6% Disabled 93,566 +35.4%
Permissive ~ enforcing confirms the overhead is not in SELinux policy evaluation. Disabling SELinux removes the rcu_read_lock/unlock call sites in the AVC path and recovers most of the performance -- but still leaves a ~13% gap vs 6.12 (no PREEMPT_RCU), which is the base cost of PREEMPT_RCU in the non-SELinux parts of the kill() path.
So the core issue is: on ppc64le, CONFIG_PREEMPT_RCU makes rcu_read_lock/unlock significantly more expensive, and the kill() syscall path hits them very heavily through SELinux AVC lookups.
Thanks,
Jirka
Quoted 80 lines · Shrikanth Hegde
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 4 lines
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by
CONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.This is true only if user selected
PREEMPT_DYNAMICoption i think.config
PREEMPT_RCUbool default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) select TREE_RCUQuoted 10 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le:
kernel
CONFIG_PREEMPT_RCUkill bogo-ops/sec
--- 6.15-rc6 (eln148) no 103,2076.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)Does your preemption mode remain the same in two cases?
Quoted 17 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436 7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (
check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no
PREEMPT_RCU) 6.16 (PREEMPT_RCU)
---avc_lookup15.23% 24.79%__rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%Quoted 5 lines
On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much aboutPREEMPT_RCU. So might take a while.Quoted 5 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Signature · 1 line
-Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Jirka,
Please avoid top-posting.
Quoted 26 lines · Jirka Hladky
Hi Shrikanth,
Thanks for the quick response and for looping in Paul.
Quoted 1 line
This is true only if user selected
PREEMPT_DYNAMICoption i think.Yes, exactly. The issue is that
CONFIG_PREEMPT_DYNAMIC=yhas been in the Fedora/RHEL kernel config since kernel 5.16 (2021). It was silently ignored on ppc64le until your 6.16 patch addedHAVE_PREEMPT_DYNAMIC_KEY, so this is the first timePREEMPT_RCUactually takes effect for all Fedora/RHEL ppc64le users.Quoted 1 line
Does your preemption mode remain the same in two cases?
Verified. On 6.15-rc6 (before
PREEMPT_DYNAMICtakes effect):
CONFIG_PREEMPT_VOLUNTARY=y
(noCONFIG_PREEMPT_DYNAMIC, no/sys/kernel/debug/sched/preempt)On both 7.1 and 7.2-rc4 (with
PREEMPT_DYNAMICactive):
CONFIG_PREEMPT_LAZY=yCONFIG_PREEMPT_DYNAMIC=yCONFIG_PREEMPT_RCU=y
cat/sys/kernel/debug/sched/preempt: "full (lazy)"
Quoted 4 lines
So the runtime preemption mode is the same on 7.1 and 7.2. The difference between 6.15 and 7.1+ is that the preemption model changed from voluntary (static) to full/lazy (dynamic), which is what pulls in
PREEMPT_RCU.
That means comparison is between preempt=voluntary vs preempt=lazy.
If you make it full preemption in 6.15 you will likely see similar data as 7.1+. Only on 7.0/7.1 there is force switch to lazy/full. Can you give that a try?
If it shows same data, that implies the regression is mainly due to change of preemption modes, rather than the static key stuff.
Quoted 11 lines
Quoted 4 lines
Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. Static key too is expected to minimal cost.You're right, I should clarify -- the overhead is not in the static key mechanism itself. The cost comes from
__rcu_read_lock()and__rcu_read_unlock()which are called whenCONFIG_PREEMPT_RCU=y. These need real memory barriers (lwsync/isync) on ppc64le regardless of whether the dynamic mechanism uses keys or calls.
Quoted 6 lines
The real question is: why does enabling
PREEMPT_RCUcost ~33% on ppc64le but only ~3% onx86_64? The answer is that x86_64's TSO memory model makes the barriers in __rcu_read_lock/__rcu_read_unlock essentially free, while ppc64le's weak ordering requires explicit lwsync/isync instructions, which are expensive when called thousands of times per second in the SELinux AVC hot path.
Plus, it may call schedule in lazy/pull preemption.
Quoted 10 lines
I also have new data from SELinux isolation testing that helps quantify this. On kernel 7.1 (which already has PREEMPT_RCU=y):
SELinux mode kill bogo-ops/sec vs enforcing ------------ ----------------- ------------ Enforcing 69,107 baseline Permissive 70,248 +1.6% Disabled 93,566 +35.4%
Quoted 6 lines
Permissive ~ enforcing confirms the overhead is not in SELinux policy evaluation. Disabling SELinux removes the rcu_read_lock/unlock call sites in the AVC path and recovers most of the performance -- but still leaves a ~13% gap vs 6.12 (no
PREEMPT_RCU), which is the base cost ofPREEMPT_RCUin the non-SELinux parts of thekill()path.
This seems strange. How come rcu lock/unlock depends on SELinux policy? One should call rcu lock/unlock if they are working with rcu updated fields.
Does the policy change itself protected with rcu lock/unlock? I will check it up.
Quoted 90 lines
So the core issue is: on ppc64le,
CONFIG_PREEMPT_RCUmakes rcu_read_lock/unlock significantly more expensive, and thekill()syscall path hits them very heavily through SELinux AVC lookups.Thanks,
JirkaQuoted 80 lines · Shrikanth Hegde
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 4 lines
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by
CONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.This is true only if user selected
PREEMPT_DYNAMICoption i think.config
PREEMPT_RCUbool default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) select TREE_RCUQuoted 10 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le: kernel CONFIG_PREEMPT_RCU kill bogo-ops/sec --- 6.15-rc6 (eln148) no 103,207 6.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)Does your preemption mode remain the same in two cases?
Quoted 17 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436 7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (
check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no
PREEMPT_RCU) 6.16 (PREEMPT_RCU)
---avc_lookup15.23% 24.79%__rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%Quoted 5 lines
On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much aboutPREEMPT_RCU. So might take a while.Quoted 5 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Shrikanth,
Le 27/07/2026 à 12:28, Shrikanth Hegde a écrit :
Quoted 30 lines
Hi Jirka,
Please avoid top-posting.Quoted 26 lines · Jirka Hladky
Hi Shrikanth,
Thanks for the quick response and for looping in Paul.
Quoted 1 line
This is true only if user selected
PREEMPT_DYNAMICoption i think.Yes, exactly. The issue is that
CONFIG_PREEMPT_DYNAMIC=yhas been in the Fedora/RHEL kernel config since kernel 5.16 (2021). It was silently ignored on ppc64le until your 6.16 patch addedHAVE_PREEMPT_DYNAMIC_KEY, so this is the first timePREEMPT_RCUactually takes effect for all Fedora/RHEL ppc64le users.Quoted 1 line
Does your preemption mode remain the same in two cases?
Verified. On 6.15-rc6 (before
PREEMPT_DYNAMICtakes effect):
CONFIG_PREEMPT_VOLUNTARY=y
(noCONFIG_PREEMPT_DYNAMIC, no/sys/kernel/debug/sched/preempt)On both 7.1 and 7.2-rc4 (with
PREEMPT_DYNAMICactive):
CONFIG_PREEMPT_LAZY=yCONFIG_PREEMPT_DYNAMIC=yCONFIG_PREEMPT_RCU=y
cat/sys/kernel/debug/sched/preempt: "full (lazy)"
Quoted 6 lines
Quoted 4 lines
So the runtime preemption mode is the same on 7.1 and 7.2. The difference between 6.15 and 7.1+ is that the preemption model changed from voluntary (static) to full/lazy (dynamic), which is what pulls in
PREEMPT_RCU.That means comparison is between preempt=voluntary vs preempt=lazy.
As far as I can see CONFIG_PREEMPT_LAZY doesn't pull CONFIG_PREEMPT_RCU. CONFIG_PREEMPT_DYNAMIC does:
config PREEMPT_RCU
bool
default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) select TREE_RCU
help
This option selects the RCU implementation that is designed for very large SMP systems with hundreds or thousands of CPUs, but for which real-time response is also required. It also scales down nicely to smaller systems.
Select this option if you are unsure.
Christophe
Quoted 141 lines
If you make it full preemption in 6.15 you will likely see similar data as 7.1+. Only on 7.0/7.1 there is force switch to lazy/full. Can you give that a try?
If it shows same data, that implies the regression is mainly due to change of preemption modes, rather than the static key stuff.
Quoted 11 lines
Quoted 4 lines
Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. Static key too is expected to minimal cost.You're right, I should clarify -- the overhead is not in the static key mechanism itself. The cost comes from
__rcu_read_lock()and__rcu_read_unlock()which are called whenCONFIG_PREEMPT_RCU=y. These need real memory barriers (lwsync/isync) on ppc64le regardless of whether the dynamic mechanism uses keys or calls.Quoted 6 lines
The real question is: why does enabling
PREEMPT_RCUcost ~33% on ppc64le but only ~3% onx86_64? The answer is that x86_64's TSO memory model makes the barriers in __rcu_read_lock/__rcu_read_unlock essentially free, while ppc64le's weak ordering requires explicit lwsync/isync instructions, which are expensive when called thousands of times per second in the SELinux AVC hot path.Plus, it may call schedule in lazy/pull preemption.
Quoted 10 lines
I also have new data from SELinux isolation testing that helps quantify this. On kernel 7.1 (which already has PREEMPT_RCU=y):
SELinux mode kill bogo-ops/sec vs enforcing
------------ ----------------- ------------
Enforcing 69,107 baseline
Permissive 70,248 +1.6%
Disabled 93,566 +35.4%Quoted 6 lines
Permissive ~ enforcing confirms the overhead is not in SELinux policy evaluation. Disabling SELinux removes the rcu_read_lock/unlock call sites in the AVC path and recovers most of the performance -- but still leaves a ~13% gap vs 6.12 (no
PREEMPT_RCU), which is the base cost ofPREEMPT_RCUin the non-SELinux parts of thekill()path.This seems strange. How come rcu lock/unlock depends on SELinux policy? One should call rcu lock/unlock if they are working with rcu updated fields.
Does the policy change itself protected with rcu lock/unlock? I will check it up.
Quoted 90 lines
So the core issue is: on ppc64le,
CONFIG_PREEMPT_RCUmakes rcu_read_lock/unlock significantly more expensive, and thekill()syscall path hits them very heavily through SELinux AVC lookups.Thanks,
JirkaQuoted 80 lines · Shrikanth Hegde
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 4 lines
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by
CONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.This is true only if user selected
PREEMPT_DYNAMICoption i think.config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCUQuoted 10 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le:
kernel CONFIG_PREEMPT_RCU kill bogo-ops/sec --- 6.15-rc6 (eln148) no 103,207 6.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)
Does your preemption mode remain the same in two cases?
Quoted 17 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436
7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (
check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no PREEMPT_RCU) 6.16 (
PREEMPT_RCU) --- avc_lookup 15.23% 24.79% __rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%Quoted 5 lines
On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much aboutPREEMPT_RCU. So might take a while.Quoted 5 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 38 lines · Christophe Leroy (CS GROUP)
Hi Shrikanth,
Le 27/07/2026 à 12:28, Shrikanth Hegde a écrit :
Quoted 35 lines
Hi Jirka,
Please avoid top-posting.Quoted 30 lines · Jirka Hladky
Hi Shrikanth,
Thanks for the quick response and for looping in Paul.
Quoted 1 line
This is true only if user selected
PREEMPT_DYNAMICoption i think.Yes, exactly. The issue is that
CONFIG_PREEMPT_DYNAMIC=yhas been in the Fedora/RHEL kernel config since kernel 5.16 (2021). It was silently ignored on ppc64le until your 6.16 patch addedHAVE_PREEMPT_DYNAMIC_KEY, so this is the first timePREEMPT_RCUactually takes effect for all Fedora/RHEL ppc64le users.Quoted 1 line
Does your preemption mode remain the same in two cases?
Verified. On 6.15-rc6 (before
PREEMPT_DYNAMICtakes effect):
CONFIG_PREEMPT_VOLUNTARY=y
(noCONFIG_PREEMPT_DYNAMIC, no/sys/kernel/debug/sched/preempt)On both 7.1 and 7.2-rc4 (with
PREEMPT_DYNAMICactive):
CONFIG_PREEMPT_LAZY=yCONFIG_PREEMPT_DYNAMIC=yCONFIG_PREEMPT_RCU=y
cat/sys/kernel/debug/sched/preempt: "full (lazy)"So the runtime preemption mode is the same on 7.1 and 7.2. The difference between 6.15 and 7.1+ is that the preemption model changed from voluntary (static) to full/lazy (dynamic), which is what pulls in
PREEMPT_RCU.
Quoted 4 lines
Quoted 1 line
That means comparison is between preempt=voluntary vs preempt=lazy.
As far as I can see
CONFIG_PREEMPT_LAZYdoesn't pullCONFIG_PREEMPT_RCU.CONFIG_PREEMPT_DYNAMICdoes:
That is correct.
Now, PREEMPT_LAZY does add preempt_disable() to rcu_read_lock() and preempt_enable() to rcu_read_unlock(), compared to PREEMPT_NONE. So there might be some performance impact. But hopefully not quite as much as an isync or lwsync instruction.
OK, OK, PREEMPT_NONE also has preempt_disable() in rcu_read_lock() and preempt_enable() in rcu_read_unlock(). The real difference is that in PREEMPT_NONE, both preempt_disable() and preempt_enable() are no-ops. In contrast, in PREEMPT_LAZY these two execute real code.
Thanx, Paul
Quoted 166 lines
config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCU
help
This option selects the RCU implementation that is designed for very large SMP systems with hundreds or thousands of CPUs, but for which real-time response is also required. It also scales down nicely to smaller systems.Select this option if you are unsure.
Christophe
Quoted 149 lines
If you make it full preemption in 6.15 you will likely see similar data as 7.1+.
Only on 7.0/7.1 there is force switch to lazy/full. Can you give that a try?If it shows same data, that implies the regression is mainly due to change of preemption modes, rather than the static key stuff.
Quoted 11 lines
Quoted 4 lines
Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. Static key too is expected to minimal cost.You're right, I should clarify -- the overhead is not in the static key mechanism itself. The cost comes from
__rcu_read_lock()and__rcu_read_unlock()which are called whenCONFIG_PREEMPT_RCU=y. These need real memory barriers (lwsync/isync) on ppc64le regardless of whether the dynamic mechanism uses keys or calls.Quoted 6 lines
The real question is: why does enabling
PREEMPT_RCUcost ~33% on ppc64le but only ~3% onx86_64? The answer is that x86_64's TSO memory model makes the barriers in __rcu_read_lock/__rcu_read_unlock essentially free, while ppc64le's weak ordering requires explicit lwsync/isync instructions, which are expensive when called thousands of times per second in the SELinux AVC hot path.Plus, it may call schedule in lazy/pull preemption.
Quoted 10 lines
I also have new data from SELinux isolation testing that helps quantify this. On kernel 7.1 (which already has PREEMPT_RCU=y):
SELinux mode kill bogo-ops/sec vs enforcing
------------ ----------------- ------------
Enforcing 69,107 baseline
Permissive 70,248 +1.6%
Disabled 93,566 +35.4%Quoted 6 lines
Permissive ~ enforcing confirms the overhead is not in SELinux policy evaluation. Disabling SELinux removes the rcu_read_lock/unlock call sites in the AVC path and recovers most of the performance -- but still leaves a ~13% gap vs 6.12 (no
PREEMPT_RCU), which is the base cost ofPREEMPT_RCUin the non-SELinux parts of thekill()path.This seems strange. How come rcu lock/unlock depends on SELinux policy? One should call rcu lock/unlock if they are working with rcu updated fields.
Does the policy change itself protected with rcu lock/unlock? I will check it up.
Quoted 95 lines
So the core issue is: on ppc64le,
CONFIG_PREEMPT_RCUmakes rcu_read_lock/unlock significantly more expensive, and thekill()syscall path hits them very heavily through SELinux AVC lookups.Thanks,
JirkaQuoted 84 lines · Shrikanth Hegde
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 5 lines
I'm seeing a significant performance regression on ppc64le after this
patch landed in 6.16, caused byCONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.This is true only if user selected
PREEMPT_DYNAMICoption i think.config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCUQuoted 10 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le:
kernel CONFIG_PREEMPT_RCU kill bogo-ops/sec --- 6.15-rc6 (eln148) no 103,207 6.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)
Does your preemption mode remain the same in two cases?
Quoted 18 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436
7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the
SELinux AVC path (check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no PREEMPT_RCU) 6.16 (
PREEMPT_RCU) --- avc_lookup 15.23% 24.79% __rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17% selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%Quoted 5 lines
On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALL
orHAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much aboutPREEMPT_RCU. So might take a while.Quoted 5 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Shrikanth HegdeQuoted 8 lines · Shrikanth Hegde
That means comparison is between preempt=voluntary vs preempt=lazy.
If you make it full preemption in 6.15 you will likely see similar data as 7.1+. Only on 7.0/7.1 there is force switch to lazy/full. Can you give that a try?
If it shows same data, that implies the regression is mainly due to change of preemption modes, rather than the static key stuff.
Tested on 7.1 by switching the runtime mode via/sys/kernel/debug/sched/preempt:
Mode kill bogo-ops/sec ---- ----------------- full 57,476 lazy 56,892 Delta ~1% (noise)
The preemption mode (full vs lazy) makes no difference. The regression is from CONFIG_PREEMPT_RCU being enabled, not from the choice of preemption mode.
And as Christophe pointed out, it's CONFIG_PREEMPT_DYNAMIC that pulls in CONFIG_PREEMPT_RCU, not CONFIG_PREEMPT_LAZY:
config PREEMPT_RCU
default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC)So the chain is: your patch enables HAVE_PREEMPT_DYNAMIC_KEY -> CONFIG_PREEMPT_DYNAMIC takes effect -> CONFIG_PREEMPT_RCU=y -> expensive rcu_read_lock/unlock on ppc64le.
Quoted 1 line
Plus, it may call schedule in lazy/pull preemption.
The full vs lazy results above suggest extra scheduling is not a significant factor here.
Quoted 5 lines
This seems strange. How come rcu lock/unlock depends on SELinux policy? One should call rcu lock/unlock if they are working with rcu updated fields.
Does the policy change itself protected with rcu lock/unlock?
The rcu_read_lock/unlock calls don't depend on SELinux policy -- they are in the SELinux *code path* itself. SELinux uses RCU to protect its AVC (Access Vector Cache) lookups. Every call to avc_has_perm() takes rcu_read_lock() around the avc_lookup() hash table access.
When you boot with selinux=0, the SELinux LSM hooks are never called, so the AVC code path (and its rcu_read_lock/unlock pairs) is never reached. That's why disabling SELinux removes those call sites from the hot path.
The call chain is:
sys_kill -> check_kill_permission -> security_task_kill
-> selinux_task_kill -> avc_has_perm
-> rcu_read_lock()
-> avc_lookup() <-- hash table lookup under RCU protection
-> rcu_read_unlock()With selinux=0, security_task_kill() is essentially a no-op and none of the avc/rcu code runs.
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 10 lines · Jirka Hladky
Quoted 8 lines · Shrikanth Hegde
That means comparison is between preempt=voluntary vs preempt=lazy.
If you make it full preemption in 6.15 you will likely see similar data as 7.1+. Only on 7.0/7.1 there is force switch to lazy/full. Can you give that a try?
If it shows same data, that implies the regression is mainly due to change of preemption modes, rather than the static key stuff.
Quoted 9 lines
Tested on 7.1 by switching the runtime mode via
/sys/kernel/debug/sched/preempt:Mode kill bogo-ops/sec ---- ----------------- full 57,476 lazy 56,892 Delta ~1% (noise)
What I asked you was to do voluntary vs lazy comparison without CONFIG_PREEMPT_DYNAMIC.
Quoted 47 lines
The preemption mode (full vs lazy) makes no difference. The regression is from
CONFIG_PREEMPT_RCUbeing enabled, not from the choice of preemption mode.And as Christophe pointed out, it's
CONFIG_PREEMPT_DYNAMICthat pulls inCONFIG_PREEMPT_RCU, notCONFIG_PREEMPT_LAZY:config PREEMPT_RCU default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC)So the chain is: your patch enables
HAVE_PREEMPT_DYNAMIC_KEY->CONFIG_PREEMPT_DYNAMICtakes effect ->CONFIG_PREEMPT_RCU=y-> expensive rcu_read_lock/unlock on ppc64le.Quoted 1 line
Plus, it may call schedule in lazy/pull preemption.
The full vs lazy results above suggest extra scheduling is not a significant factor here.
Quoted 5 lines
This seems strange. How come rcu lock/unlock depends on SELinux policy? One should call rcu lock/unlock if they are working with rcu updated fields.
Does the policy change itself protected with rcu lock/unlock?
The rcu_read_lock/unlock calls don't depend on SELinux policy -- they are in the SELinux *code path* itself. SELinux uses RCU to protect its AVC (Access Vector Cache) lookups. Every call to
avc_has_perm()takesrcu_read_lock()around theavc_lookup()hash table access.When you boot with selinux=0, the SELinux LSM hooks are never called, so the AVC code path (and its rcu_read_lock/unlock pairs) is never reached. That's why disabling SELinux removes those call sites from the hot path.
The call chain is:
sys_kill -> check_kill_permission -> security_task_kill -> selinux_task_kill -> avc_has_perm -> rcu_read_lock() -> avc_lookup() <-- hash table lookup under RCU protection -> rcu_read_unlock()With selinux=0,
security_task_kill()is essentially a no-op and none of the avc/rcu code runs.Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Jirka HladkyQuoted 2 lines · Jirka Hladky
Hi Shrikanth,
[...]
Quoted 8 lines
The real question is: why does enabling
PREEMPT_RCUcost ~33% on ppc64le but only ~3% onx86_64? The answer is that x86_64's TSO memory model makes the barriers in __rcu_read_lock/__rcu_read_unlock essentially free, while ppc64le's weak ordering requires explicit lwsync/isync instructions, which are expensive when called thousands of times per second in the SELinux AVC hot path.
Ensure when comparing the preemption modes are same or not. x86 has dynamic preemption since long time. It might be possible in your testing when you compared for x86, preemption modes were same, whereas in case of powerpc you are comparing between voluntary vs lazy.
If it is voluntary vs lazy, this would simplify where to concentrate. (You can easily do this with CONFIG_PREEMPT_DYNAMIC=n on a kernel before 7.0)
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Shrikanth HegdeQuoted 12 lines · Shrikanth Hegde
+cc paul for any further/RCU insights.
Quoted 2 lines · Jirka Hladky
Hi Shrikanth, Christophe,
Hi Jirka, thanks for the report.
Quoted 3 lines
I'm seeing a significant performance regression on ppc64le after this patch landed in 6.16, caused by
CONFIG_PREEMPT_RCUbecoming active onceHAVE_PREEMPT_DYNAMIC_KEYis selected.
Quoted 6 lines
This is true only if user selected
PREEMPT_DYNAMICoption i think.config
PREEMPT_RCUbool default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) select TREE_RCU
Yes, if you select PREEMPT_DYNAMIC, RCU doesn't have much choice but to choose PREEMPT_RCU. Something about not having the guts to implement an RCU that dynamically switches between its preemptible and non-preemptible variants. Cowardly of me, I know!
So if you want non-preemptible RCU, you need to turn off PREEMPT_DYNAMIC.
Quoted 5 lines
Quoted 5 lines
Benchmark: stress-ng kill stressor (tight
kill()syscall loop), single thread, POWER10 LPAR (8 vCPUs, 1 core SMT-8).Bisected across Fedora ELN kernel builds on ppc64le:
Quoted 22 lines
Quoted 5 lines
kernel
CONFIG_PREEMPT_RCUkill bogo-ops/sec
--- 6.15-rc6 (eln148) no 103,2076.16 (eln150) yes 70,281 (-32%) 6.18 (eln154) yes 72,552 (-30%)Does your preemption mode remain the same in two cases?
Quoted 14 lines
For comparison,
x86_64(AMD EPYC 9355P) with the same config change shows only a 2.8% regression:6.12 x86_64 37,436 7.2 x86_64 36,392 (-2.8%)perf report shows the overhead comes from rcu_read_lock/unlock in the SELinux AVC path (
check_kill_permission->security_task_kill->selinux_task_kill->avc_has_perm->avc_lookup):Function 6.15 (no
PREEMPT_RCU) 6.16 (PREEMPT_RCU)
---avc_lookup15.23% 24.79%__rcu_read_lock ~0% 4.52% __rcu_read_unlock ~0% 4.17%
Yes, non-preemptible RCU's __rcu_read_{,un}lock() are (almost) no-ops, but preemptible RCU must actually execute real code. But I would not expect *this* much overhead.
Quoted 9 lines
Quoted 8 lines
selinux_task_kill 6.23% 7.35% audit_signal_info* 0.94% 3.59%On
x86_64, rcu_read_lock/unlock are cheap thanks to static calls (HAVE_PREEMPT_DYNAMIC_CALL). On ppc64le with the KEY-based implementation, the weak memory model requires real barriers (lwsync/isync) making each RCU read-side critical section significantly more expensive.
Quoted 3 lines
Weak memory model would need barriers irrespective of
HAVE_PREEMPT_DYNAMIC_CALLorHAVE_PREEMPT_DYNAMIC_KEY. That's my assumption. I will look more into it. Also i don't know much aboutPREEMPT_RCU. So might take a while.
OK, if you are executing an isync or an lwsync instruction in each call to __rcu_read_{,un}lock(), that would explain the overhead.
CONFIG_PREEMPT_DYNAMIC=n for the win?
Thanx, Paul
Quoted 16 lines
Quoted 4 lines
This aligns with Christophe's earlier review comment that
HAVE_PREEMPT_DYNAMIC_CALLshould be more performant. Would implementing static calls for ppc64 be feasible to close this gap?Static key too is expected to minimal cost. There maybe more into this.
Quoted 9 lines
Test details:
- Machine: IBM POWER10 (pvr 0080 0200), pHyp virtualization
- stress-ng 0.21.03, gcc 14.3.1, glibc 2.39
- Tuned profile: virtual-guest
- SELinux: enforcing (permissive recovers only ~7%)Happy to run additional tests if needed.
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 3 lines · Paul E. McKenney
Yes, non-preemptible RCU's __rcu_read_{,un}lock() are (almost) no-ops, but preemptible RCU must actually execute real code. But I would not expect *this* much overhead.
I've now isolated the PREEMPT_RCU cost with a controlled experiment. Built two kernels from the same 6.15-rc6 upstream source on the same POWER10 machine, no CONFIG_PREEMPT_DYNAMIC in either case:
Config A: CONFIG_PREEMPT_VOLUNTARY=y (no PREEMPT_RCU)
Config B: CONFIG_PREEMPT=y (PREEMPT_RCU=y)
Results (stress-ng --kill 1 -t 23, SELinux enforcing):
Kernel PREEMPT_RCU kill bogo-ops/sec --------------------------- ----------- ----------------- 6.15-rc6-voluntary-test no 105,014 6.15-rc6-preempt-test yes 73,317
Delta -30.2%
PREEMPT_RCU alone accounts for ~30% on this workload. The kill() path hits rcu_read_lock/unlock very heavily through the SELinux AVC (avc_has_perm -> avc_lookup wraps every hash table lookup in an RCU read-side critical section).
This also answers Shrikanth's question about whether the regression is from the preemption mode change (voluntary -> lazy) or from PREEMPT_RCU. Since no PREEMPT_DYNAMIC is involved in either build, the preemption mode is not a factor. Additionally, switching between full and lazy at runtime on 7.1 showed only ~1% difference (57,476 vs 56,892), further confirming the mode doesn't matter.
Quoted 2 lines
OK, if you are executing an isync or an lwsync instruction in each call to __rcu_read_{,un}lock(), that would explain the overhead.
Yes, that's what perf shows. __rcu_read_lock and __rcu_read_unlock together consume ~9% of total cycles on ppc64le with PREEMPT_RCU, vs essentially 0% without.
Quoted 1 line
CONFIG_PREEMPT_DYNAMIC=nfor the win?
That's the simplest distro workaround for ppc64le. But since commit 7dadeaa6e851 ("sched: Further restrict the preemption modes") removed PREEMPT_VOLUNTARY as an option for architectures with ARCH_HAS_PREEMPT_LAZY (which includes powerpc), distros that want voluntary preemption on ppc64le would need to disable PREEMPT_DYNAMIC anyway.
Is there any path to reducing the barrier cost in __rcu_read_lock/__rcu_read_unlock on weakly-ordered architectures? Or is the current implementation fundamentally constrained by the memory model?
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Jirka.
Quoted 5 lines · Jirka Hladky
Quoted 3 lines · Paul E. McKenney
Yes, non-preemptible RCU's __rcu_read_{,un}lock() are (almost) no-ops, but preemptible RCU must actually execute real code. But I would not expect *this* much overhead.
Thanks for doing these experiment.
Quoted 6 lines
I've now isolated the
PREEMPT_RCUcost with a controlled experiment. Built two kernels from the same 6.15-rc6 upstream source on the same POWER10 machine, noCONFIG_PREEMPT_DYNAMICin either case:Config A:
CONFIG_PREEMPT_VOLUNTARY=y(noPREEMPT_RCU)
Config B:CONFIG_PREEMPT=y(PREEMPT_RCU=y)
That's full preemption mode.
Quoted 9 lines
Results (stress-ng --kill 1 -t 23, SELinux enforcing):
Kernel PREEMPT_RCU kill bogo-ops/sec --------------------------- ----------- ----------------- 6.15-rc6-voluntary-test no 105,014 6.15-rc6-preempt-test yes 73,317Delta -30.2%
That is voluntary -> full preemption change.
When preemption mode changes preempt_enable/disable which were just a barrier earlier now become real preemption points. If the code path repeatedly does the exact same thing, it might pop up.
But, can we say is that number expected? it is difficult to put a number to it.
What I was asking is below. (You can do this only with below 7.0)
Config A: CONFIG_PREEMPT_VOLUNTARY=y (CONFIG_PREEMPT_DYNAMIC=n i.e no PREEMPT_RCU) Config B: CONFIG_PREEMPT_VOLUNTARY=y (CONFIG_PREEMPT_DYNAMIC=y i.e PREEMPT_RCU)
That should keep in voluntary preemption.
You can confirm with dynamic preemption using /sys/kerenl/debug/sched/preempt.
In Config B, though there is rcu_read_lock/unlock it should be just a barrier.
Quoted 11 lines
PREEMPT_RCUalone accounts for ~30% on this workload. Thekill()path hits rcu_read_lock/unlock very heavily through the SELinux AVC (avc_has_perm->avc_lookupwraps every hash table lookup in an RCU read-side critical section).This also answers Shrikanth's question about whether the regression is from the preemption mode change (voluntary -> lazy) or from
PREEMPT_RCU. Since noPREEMPT_DYNAMICis involved in either build, the preemption mode is not a factor. Additionally, switching between full and lazy at runtime on 7.1 showed only ~1% difference (57,476 vs 56,892), further confirming the mode doesn't matter.
Lazy/full switch is same. There will not be any additional overhead. The real concern is none/voluntary vs lazy/full.
Quoted 17 lines
Quoted 3 lines
OK, if you are executing an isync or an lwsync instruction in each call to __rcu_read_{,un}lock(), that would explain the overhead.
Yes, that's what perf shows.
__rcu_read_lockand__rcu_read_unlocktogether consume ~9% of total cycles on ppc64le withPREEMPT_RCU, vs essentially 0% without.Quoted 1 line
CONFIG_PREEMPT_DYNAMIC=nfor the win?That's the simplest distro workaround for ppc64le. But since commit
7dadeaa6e851("sched: Further restrict the preemption modes") removedPREEMPT_VOLUNTARYas an option for architectures withARCH_HAS_PREEMPT_LAZY(which includes powerpc), distros that want voluntary preemption on ppc64le would need to disablePREEMPT_DYNAMICanyway.
Quoted 5 lines
Is there any path to reducing the barrier cost in __rcu_read_lock/__rcu_read_unlock on weakly-ordered architectures? Or is the current implementation fundamentally constrained by the memory model?
Are you saying you see regression with voluntary with CONFIG_PREEMPT_DYNAMIC=y?
Quoted 2 lines
Jirka
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Shrikanth,
Le 27/07/2026 à 19:10, Shrikanth Hegde a écrit :
Quoted 60 lines
Hi Jirka.
Quoted 5 lines · Jirka Hladky
Quoted 3 lines · Paul E. McKenney
Yes, non-preemptible RCU's __rcu_read_{,un}lock() are (almost) no-ops, but preemptible RCU must actually execute real code. But I would not expect *this* much overhead.
Thanks for doing these experiment.
Quoted 6 lines
I've now isolated the
PREEMPT_RCUcost with a controlled experiment. Built two kernels from the same 6.15-rc6 upstream source on the same POWER10 machine, noCONFIG_PREEMPT_DYNAMICin either case:Config A:
CONFIG_PREEMPT_VOLUNTARY=y(noPREEMPT_RCU) Config B:CONFIG_PREEMPT=y(PREEMPT_RCU=y)That's full preemption mode.
Quoted 9 lines
Results (stress-ng --kill 1 -t 23, SELinux enforcing):
Kernel PREEMPT_RCU kill bogo-ops/sec --------------------------- ----------- ----------------- 6.15-rc6-voluntary-test no 105,014 6.15-rc6-preempt-test yes 73,317 Delta -30.2%
That is voluntary -> full preemption change.
When preemption mode changes preempt_enable/disable which were just a barrier earlier now become real preemption points. If the code path repeatedly does the exact same thing, it might pop up.
But, can we say is that number expected? it is difficult to put a number to it.What I was asking is below. (You can do this only with below 7.0)
Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=ni.e noPREEMPT_RCU) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=yi.ePREEMPT_RCU)That should keep in voluntary preemption.
You can confirm with dynamic preemption using/sys/kerenl/debug/sched/preempt.In Config B, though there is rcu_read_lock/unlock it should be just a barrier.
Quoted 11 lines
PREEMPT_RCUalone accounts for ~30% on this workload. Thekill()path hits rcu_read_lock/unlock very heavily through the SELinux AVC (avc_has_perm->avc_lookupwraps every hash table lookup in an RCU read-side critical section).This also answers Shrikanth's question about whether the regression is from the preemption mode change (voluntary -> lazy) or from
PREEMPT_RCU. Since noPREEMPT_DYNAMICis involved in either build, the preemption mode is not a factor. Additionally, switching between full and lazy at runtime on 7.1 showed only ~1% difference (57,476 vs 56,892), further confirming the mode doesn't matter.
Quoted 2 lines
Lazy/full switch is same. There will not be any additional overhead. The real concern is none/voluntary vs lazy/full.
That's right with CONFIG_PREEMPT_DYNAMIC=y
With CONFIG_PREEMT_DYNAMIC=n:
- CONFIG_PREEMPT (full) implies CONFIG_PREEMPT_RCU
- CONFIG_PREEMPT_LAZY (lazy) doesn't imply CONFIG_PREEMPT_RCU
because of kernel/rcu/Kconfig,
config PREEMPT_RCU
bool default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) select TREE_RCU
Christophe
Quoted 29 lines
Quoted 18 lines
Quoted 4 lines
OK, if you are executing an isync or an lwsync instruction in each call to __rcu_read_{,un}lock(), that would explain the overhead.
Yes, that's what perf shows.
__rcu_read_lockand__rcu_read_unlocktogether consume ~9% of total cycles on ppc64le withPREEMPT_RCU, vs essentially 0% without.Quoted 1 line
CONFIG_PREEMPT_DYNAMIC=nfor the win?That's the simplest distro workaround for ppc64le. But since commit
7dadeaa6e851("sched: Further restrict the preemption modes") removedPREEMPT_VOLUNTARYas an option for architectures withARCH_HAS_PREEMPT_LAZY(which includes powerpc), distros that want voluntary preemption on ppc64le would need to disablePREEMPT_DYNAMICanyway.Quoted 5 lines
Is there any path to reducing the barrier cost in __rcu_read_lock/__rcu_read_unlock on weakly-ordered architectures? Or is the current implementation fundamentally constrained by the memory model?
Are you saying you see regression with voluntary with
CONFIG_PREEMPT_DYNAMIC=y?Quoted 2 lines
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Paul, Christophe,
Quoted 10 lines · Christophe Leroy (CS GROUP)
Hi Shrikanth,
That's right with
CONFIG_PREEMPT_DYNAMIC=yWith
CONFIG_PREEMT_DYNAMIC=n:
-CONFIG_PREEMPT(full) impliesCONFIG_PREEMPT_RCU
-CONFIG_PREEMPT_LAZY(lazy) doesn't implyCONFIG_PREEMPT_RCU
Quoted 10 lines
because of
kernel/rcu/Kconfig,config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCUChristophe
Right.
Looks like __rcu_read_unlock can set need_resched bit if it find irq were disabled and rcu_read_unlock_special.s is set. I don't have much clue about it. So, after seeing __rcu_read_unlock for PREEMPT_RCU I have these concerns now.
In current upstream, lazy is a preemption mode with preempt_enable being a preemptible point,
1. If PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n, then PREEMPT_RCU=n. That seems wrong. It is supposed to do the preemption checks, since preempt_count is actual count with lazy preemption.
2. PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n and PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y are supposed to be similar w.r.t to performance. Promise of PREEMPT_DYNAMIC was the ability to switch at runtime based on the user workload and his/her preference.
But with PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y, there is additional cost due to PREEMPT_RCU. lazy being the middle ground w.r.t for decent performance, either PREEMPT_RCU should either kick in for both cases or bail out for both.
Before 7.0
3. the same concerns would be true to PREEMPT_VOLUNTARY and PREEMPT_NONE with PREEMPT_DYNAMIC=y. Those model never wanted a preemption, but PREEMPT_RCU could have forced a need_resched to be set. Which is also likely wrong. No?
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 24 lines · Shrikanth Hegde
Hi Paul, Christophe,
Quoted 10 lines · Christophe Leroy (CS GROUP)
Hi Shrikanth,
That's right with
CONFIG_PREEMPT_DYNAMIC=yWith
CONFIG_PREEMT_DYNAMIC=n:
-CONFIG_PREEMPT(full) impliesCONFIG_PREEMPT_RCU
-CONFIG_PREEMPT_LAZY(lazy) doesn't implyCONFIG_PREEMPT_RCUQuoted 10 lines
because of
kernel/rcu/Kconfig,config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCUChristophe
Quoted 5 lines
Right.
Looks like
__rcu_read_unlockcan setneed_reschedbit if it find irq were disabled and rcu_read_unlock_special.s is set. I don't have much clue about it. So, after seeing__rcu_read_unlockforPREEMPT_RCUI have these concerns now.
This is because irq-disabled regions of code act as RCU readers. For non-preemptible RCU (even in CONFIG_PREEMPT_LAZY=y kernels), this comes for free. In contrast, preemptible RCU must explicitly (and, as you noticed, rather painfully) handle the irq-disabled case:
rcu_read_lock(); do_something(); local_irq_disable(); do_something_else(); rcu_read_unlock(); do_yet_another_thing(); local_irq_enable();
Here, the RCU reader extends all the way from the rcu_read_lock() to the final local_irq_enable(). And this is why RCU checks for IRQs being disabled in __rcu_read_unlock().
Quoted 4 lines
In current upstream, lazy is a preemption mode with
preempt_enablebeing a preemptible point,1. If PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n, then PREEMPT_RCU=n. That seems wrong. It is supposed to do the preemption checks, since
preempt_countis actual count with lazy preemption.
Sorry, but no, not wrong at all. This is the way that it is supposed to be. In this configuration, RCU readers explicitly disable preemption. This gets us minimal RCU overhead on architectures such as x86 and arm64 that have prohibited CONFIG_PREEMPT_NONE and CONFIG_PREEMPT_VOLUNTARY. Not zero overhead, but minimal overhead given the constraints imposed by CONFIG_PREEMPT_LAZY. This also prevents preemption of RCU readers, which is extremely important on datacenter servers that have good and sufficient quantities of memory, but which are not well-endowed with memory.
Quoted 2 lines
2. PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n and PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y are supposed to be similar w.r.t to performance.
RCU never made that promise. ;-)
With PREMPT_DYNAMIC=y, RCU has no choice but to be preemptible, at least unless and until someone decides to make RCU's preemptibility be changeable at runtime (which I do not recommend). And we really do need non-preemptible RCU for server workloads.
So it is not just that RCU never made that promise, it is that RCU cannot reasonably make that promise.
Quoted 5 lines
Promise of
PREEMPT_DYNAMICwas the ability to
switch at runtime based on the user workload and his/her preference.
But with PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y, there is additional cost due toPREEMPT_RCU. lazy being the middle ground w.r.t for decent performance, eitherPREEMPT_RCUshould either kick in for both cases or bail out for both.
Absolutely not!!! Please see above.
Quoted 4 lines
Before 7.0
3. the same concerns would be true toPREEMPT_VOLUNTARYandPREEMPT_NONEwith PREEMPT_DYNAMIC=y. Those model never wanted a preemption, butPREEMPT_RCUcould have forced aneed_reschedto be set. Which is also likely wrong. No?
You lost me on this one. Please give me an explicit sequence of events that would cause things to go wrong in this case.
Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 53 lines · Paul E. McKenney
Quoted 24 lines · Shrikanth Hegde
Hi Paul, Christophe,
Quoted 10 lines · Christophe Leroy (CS GROUP)
Hi Shrikanth,
That's right with
CONFIG_PREEMPT_DYNAMIC=yWith
CONFIG_PREEMT_DYNAMIC=n:
-CONFIG_PREEMPT(full) impliesCONFIG_PREEMPT_RCU
-CONFIG_PREEMPT_LAZY(lazy) doesn't implyCONFIG_PREEMPT_RCUQuoted 10 lines
because of
kernel/rcu/Kconfig,config
PREEMPT_RCU
bool
default y if (PREEMPT ||PREEMPT_RT||PREEMPT_DYNAMIC) selectTREE_RCUChristophe
Quoted 5 lines
Right.
Looks like
__rcu_read_unlockcan setneed_reschedbit if it find irq were disabled and rcu_read_unlock_special.s is set. I don't have much clue about it. So, after seeing__rcu_read_unlockforPREEMPT_RCUI have these concerns now.This is because irq-disabled regions of code act as RCU readers. For non-preemptible RCU (even in
CONFIG_PREEMPT_LAZY=ykernels), this comes for free. In contrast, preemptible RCU must explicitly (and, as you noticed, rather painfully) handle the irq-disabled case:rcu_read_lock(); do_something(); local_irq_disable(); do_something_else(); rcu_read_unlock(); do_yet_another_thing(); local_irq_enable();Here, the RCU reader extends all the way from the
rcu_read_lock()to the finallocal_irq_enable(). And this is why RCU checks for IRQs being disabled in__rcu_read_unlock().Quoted 4 lines
In current upstream, lazy is a preemption mode with
preempt_enablebeing a preemptible point,1. If PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n, then PREEMPT_RCU=n. That seems wrong. It is supposed to do the preemption checks, since
preempt_countis actual count with lazy preemption.
Quoted 8 lines
Sorry, but no, not wrong at all. This is the way that it is supposed to be. In this configuration, RCU readers explicitly disable preemption. This gets us minimal RCU overhead on architectures such as x86 and arm64 that have prohibited
CONFIG_PREEMPT_NONEandCONFIG_PREEMPT_VOLUNTARY. Not zero overhead, but minimal overhead given the constraints imposed byCONFIG_PREEMPT_LAZY. This also prevents preemption of RCU readers, which is extremely important on datacenter servers that have good and sufficient quantities of memory, but which are not well-endowed with memory.
Now, if you would like to be able to manually choose between non-preemptible and preemptible RCU when when PREEMPT_LAZY=y, *that* we could discuss.
But it looks like you are looking for low overhead, and thus wanting to avoid preemptible RCU.
Thanx, Paul
Quoted 30 lines
Quoted 2 lines
2. PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n and PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y are supposed to be similar w.r.t to performance.
RCU never made that promise. ;-)
With PREMPT_DYNAMIC=y, RCU has no choice but to be preemptible, at least unless and until someone decides to make RCU's preemptibility be changeable at runtime (which I do not recommend). And we really do need non-preemptible RCU for server workloads.
So it is not just that RCU never made that promise, it is that RCU cannot reasonably make that promise.
Quoted 5 lines
Promise of
PREEMPT_DYNAMICwas the ability to
switch at runtime based on the user workload and his/her preference.
But with PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y, there is additional cost due toPREEMPT_RCU. lazy being the middle ground w.r.t for decent performance, eitherPREEMPT_RCUshould either kick in for both cases or bail out for both.Absolutely not!!! Please see above.
Quoted 4 lines
Before 7.0
3. the same concerns would be true toPREEMPT_VOLUNTARYandPREEMPT_NONEwith PREEMPT_DYNAMIC=y. Those model never wanted a preemption, butPREEMPT_RCUcould have forced aneed_reschedto be set. Which is also likely wrong. No?You lost me on this one. Please give me an explicit sequence of events that would cause things to go wrong in this case.
Thanx, Paul
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Paul E. McKenneyHi Paul. Thanks for taking time looking into this.
Quoted 9 lines
Quoted 4 lines
In current upstream, lazy is a preemption mode with
preempt_enablebeing a preemptible point,1. If PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n, then PREEMPT_RCU=n. That seems wrong. It is supposed to do the preemption checks, since
preempt_countis actual count with lazy preemption.Sorry, but no, not wrong at all. This is the way that it is supposed to be. In this configuration, RCU readers explicitly disable preemption. This gets us minimal RCU overhead on architectures such as x86 and arm64 that have prohibited
CONFIG_PREEMPT_NONEandCONFIG_PREEMPT_VOLUNTARY.
This is after 7.0 only right? Before that one could choose even on x86 and arm64 IIUC. After 7.0, even on powerpc, one cannot choose them anymore.
Quoted 8 lines
Not zero overhead, but minimal overhead given the constraints imposed by
CONFIG_PREEMPT_LAZY. This also prevents preemption of RCU readers, which is extremely important on datacenter servers that have good and sufficient quantities of memory, but which are not well-endowed with memory.Quoted 2 lines
2. PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n and PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y are supposed to be similar w.r.t to performance.
Quoted 6 lines
RCU never made that promise. ;-)
With PREMPT_DYNAMIC=y, RCU has no choice but to be preemptible, at least unless and until someone decides to make RCU's preemptibility be changeable at runtime (which I do not recommend). And we really do need non-preemptible RCU for server workloads.
most of the distros i see set PREMPT_DYNAMIC=y.
I checked in SLES, RHEL. (I could be wrong here)
Quoted 12 lines
So it is not just that RCU never made that promise, it is that RCU cannot reasonably make that promise.
Quoted 5 lines
Promise of
PREEMPT_DYNAMICwas the ability to
switch at runtime based on the user workload and his/her preference.
But with PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y, there is additional cost due toPREEMPT_RCU. lazy being the middle ground w.r.t for decent performance, eitherPREEMPT_RCUshould either kick in for both cases or bail out for both.Absolutely not!!! Please see above.
Quoted 7 lines
Quoted 4 lines
Before 7.0
3. the same concerns would be true toPREEMPT_VOLUNTARYandPREEMPT_NONEwith PREEMPT_DYNAMIC=y. Those model never wanted a preemption, butPREEMPT_RCUcould have forced aneed_reschedto be set. Which is also likely wrong. No?You lost me on this one. Please give me an explicit sequence of events that would cause things to go wrong in this case.
You are right. PREEMPT_RCU may set need_resched. But even then on none/voluntary schedule will not be called since static keys it cannot.
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 7 lines · Shrikanth Hegde
Hi Paul. Thanks for taking time looking into this.
Quoted 5 lines
Quoted 4 lines
In current upstream, lazy is a preemption mode with
preempt_enablebeing a preemptible point,1. If PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n, then PREEMPT_RCU=n. That seems wrong. It is supposed to do the preemption checks, since
preempt_countis actual count with lazy preemption.
Quoted 7 lines
Quoted 4 lines
Sorry, but no, not wrong at all. This is the way that it is supposed to be. In this configuration, RCU readers explicitly disable preemption. This gets us minimal RCU overhead on architectures such as x86 and arm64 that have prohibited
CONFIG_PREEMPT_NONEandCONFIG_PREEMPT_VOLUNTARY.This is after 7.0 only right? Before that one could choose even on x86 and arm64 IIUC. After 7.0, even on powerpc, one cannot choose them anymore.
Yes, until quite recently, you could select CONFIG_PREEMPT_NONE and CONFIG_PREEMPT_VOLUNTARY. Now you can do so only for architectures that don't support preemption, if I recall correctly.
Quoted 10 lines
Quoted 10 lines
Not zero overhead, but minimal overhead given the constraints imposed by
CONFIG_PREEMPT_LAZY. This also prevents preemption of RCU readers, which is extremely important on datacenter servers that have good and sufficient quantities of memory, but which are not well-endowed with memory.Quoted 2 lines
2. PREEMPT_LAZY=y and PREEMPT_DYNAMIC=n and PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y are supposed to be similar w.r.t to performance.
RCU never made that promise. ;-)
Quoted 7 lines
Quoted 4 lines
With PREMPT_DYNAMIC=y, RCU has no choice but to be preemptible, at least unless and until someone decides to make RCU's preemptibility be changeable at runtime (which I do not recommend). And we really do need non-preemptible RCU for server workloads.
most of the distros i see set PREMPT_DYNAMIC=y.
I checked in SLES, RHEL. (I could be wrong here)
I believe that to be the case. But there are those of us who build our own kernels and deploy them through large numbers of large datacenters.
Quoted 16 lines
Quoted 16 lines
So it is not just that RCU never made that promise, it is that RCU cannot reasonably make that promise.
Quoted 5 lines
Promise of
PREEMPT_DYNAMICwas the ability to
switch at runtime based on the user workload and his/her preference.
But with PREEMPT_LAZY=y and PREEMPT_DYNAMIC=y, there is additional cost due toPREEMPT_RCU. lazy being the middle ground w.r.t for decent performance, eitherPREEMPT_RCUshould either kick in for both cases or bail out for both.Absolutely not!!! Please see above.
Quoted 4 lines
Before 7.0
3. the same concerns would be true toPREEMPT_VOLUNTARYandPREEMPT_NONEwith PREEMPT_DYNAMIC=y. Those model never wanted a preemption, butPREEMPT_RCUcould have forced aneed_reschedto be set. Which is also likely wrong. No?
Quoted 5 lines
Quoted 2 lines
You lost me on this one. Please give me an explicit sequence of events that would cause things to go wrong in this case.
You are right.
PREEMPT_RCUmay setneed_resched. But even then on none/voluntary schedule will not be called since static keys it cannot.
Whew!!! ;-)
Thanx, Paul
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Shrikanth HegdeQuoted 7 lines · Shrikanth Hegde
That's full preemption mode.
When preemption mode changes preempt_enable/disable which were just a barrier earlier now become real preemption points. If the code path repeatedly does the exact same thing, it might pop up. But, can we say is that number expected? it is difficult to put a number to it.
You were right -- my previous test conflated two variables. I've now built a third kernel to separate them. All three are from the same 6.15-rc6 source, same machine (POWER10 lp11), no PREEMPT_DYNAMIC:
Config Mode PREEMPT_RCU
kill bogo-ops/sec
------------------------------------ ---------- -----------
-----------------
PREEMPT_VOLUNTARY=y voluntary no 105,014
PREEMPT_LAZY=y lazy no 86,878
PREEMPT=y full yes 73,317
voluntary -> lazy -17.3%
lazy -> full+PREEMPT_RCU -15.6%
voluntary -> full+PREEMPT_RCU -30.2%
The regression splits roughly 55/45 between the preemption mode change and PREEMPT_RCU:
1) voluntary -> lazy (-17.3%): preempt_disable/enable becoming real preemption points, as you predicted. On ppc64le this is expensive because the kill() syscall path is very tight and hits these points heavily.
2) lazy -> full+PREEMPT_RCU (-15.6%): __rcu_read_lock/__rcu_read_unlock requiring lwsync/isync barriers on ppc64le.
Quoted 4 lines
What I was asking is below. (You can do this only with below 7.0)
Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=n) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=y)
I couldn't do this exact test because 6.15-rc6 doesn't have HAVE_PREEMPT_DYNAMIC_KEY for powerpc (that's your 6.16 patch), so CONFIG_PREEMPT_DYNAMIC=y would be silently ignored. I would need a 6.16-6.19 kernel for this, which is before 7dadeaa6e851 removed voluntary as an option.
But the PREEMPT_LAZY test above achieves the same goal: it isolates the preemption mode cost without PREEMPT_RCU.
Quoted 2 lines
Are you saying you see regression with voluntary with
CONFIG_PREEMPT_DYNAMIC=y?
Yes. On the ELN kernels with CONFIG_PREEMPT_DYNAMIC=y, the regression appears at 6.16 when HAVE_PREEMPT_DYNAMIC_KEY is added, because:
1) PREEMPT_DYNAMIC forces the runtime mode to lazy/full (voluntary is no longer available on architectures with ARCH_HAS_PREEMPT_LAZY)
2) PREEMPT_DYNAMIC pulls in PREEMPT_RCU
Both contribute to the ~30% total regression.
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Jirka,
Thanks for these experiments.
Quoted 25 lines · Jirka Hladky
Quoted 7 lines · Shrikanth Hegde
That's full preemption mode.
When preemption mode changes preempt_enable/disable which were just a barrier earlier now become real preemption points. If the code path repeatedly does the exact same thing, it might pop up. But, can we say is that number expected? it is difficult to put a number to it.
You were right -- my previous test conflated two variables. I've now built a third kernel to separate them. All three are from the same 6.15-rc6 source, same machine (POWER10 lp11), no
PREEMPT_DYNAMIC:Config Mode
PREEMPT_RCU
kill bogo-ops/sec
------------------------------------ ---------- -----------
-----------------
PREEMPT_VOLUNTARY=y voluntary no 105,014
PREEMPT_LAZY=y lazy no 86,878
PREEMPT=y full yes 73,317voluntary -> lazy -17.3%
lazy -> full+PREEMPT_RCU -15.6%
voluntary -> full+PREEMPT_RCU -30.2%
Quoted 7 lines
The regression splits roughly 55/45 between the preemption mode change and
PREEMPT_RCU:1) voluntary -> lazy (-17.3%): preempt_disable/enable becoming real preemption points, as you predicted. On ppc64le this is expensive because the
kill()syscall path is very tight and hits these points heavily.
That's true for all archs. Please check your preemption mode in your x86 experiment. If it remained same, then that small difference could PREEMPT_RCU cost.
even preempt_enable/disable has barriers.
Quoted 4 lines
2) lazy -> full+PREEMPT_RCU (-15.6%): __rcu_read_lock/__rcu_read_unlock requiring lwsync/isync barriers on ppc64le.
Full is more aggressive in setting in the need_resched bit and PREEMPT_RCU doing more than just barriers specially __rcu_read_unlock.
Quoted 5 lines
Quoted 4 lines
What I was asking is below. (You can do this only with below 7.0)
Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=n) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=y)
Quoted 9 lines
I couldn't do this exact test because 6.15-rc6 doesn't have
HAVE_PREEMPT_DYNAMIC_KEYfor powerpc (that's your 6.16 patch), soCONFIG_PREEMPT_DYNAMIC=ywould be silently ignored. I would need a 6.16-6.19 kernel for this, which is before7dadeaa6e851removed voluntary as an option.But the
PREEMPT_LAZYtest above achieves the same goal: it isolates the preemption mode cost withoutPREEMPT_RCU.
No. It doesn't confirm. I would recommend you do that case to find out the cost of PREEMPT_RCU alone.
The reason being, lazy is a real preemption mode. All the callsites of preempt_enable could force a context switch.
Whereas,
Quoted 2 lines
Quoted 2 lines
Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=n) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=y)
Both are expected to same/similar w.r.t preempt_enable. But as we have discovered PREEMPT_DYNAMIC in additions enables PREEMPT_RCU. If we get the above data, then we can quantify the cost due to PREEMPT_RCU alone.
Preemption mode cost is one thing, i.e preempt enable/disable cost, additional cost is call to schedule itself if need resched is set, that will likely over weigh the preemption cost.
That is observed in your experiments too.
full is more aggressive in setting the need_resched bit. Plus additional cost of PREEMPT_RCU which too can set need_resched bits.
Quoted 7 lines
Quoted 2 lines
Are you saying you see regression with voluntary with
CONFIG_PREEMPT_DYNAMIC=y?Yes. On the ELN kernels with
CONFIG_PREEMPT_DYNAMIC=y, the regression appears at 6.16 whenHAVE_PREEMPT_DYNAMIC_KEYis added, because:
1)PREEMPT_DYNAMICforces the runtime mode to lazy/full (voluntary is no longer available on architectures withARCH_HAS_PREEMPT_LAZY)
1. Is not true. PREEMPT_DYNAMIC doesn't force the preemption mode switch. You can still choose voluntary even with PREEMPT_DYNAMIC on 6.16 to 6.19 kernel.
Forced mode switch to lazy/full due to ARCH_HAS_PREEMPT_LAZY has happened in 7.0.
Quoted 2 lines
2)
PREEMPT_DYNAMICpulls inPREEMPT_RCU
This looks it can set need_resched bit aggressive to force a quiescent state? Concerns i see with this config, I have put it in other thread.
Quoted 4 lines
Both contribute to the ~30% total regression.
Jirka
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 5 lines · Shrikanth Hegde
No. It doesn't confirm. I would recommend you do that case to find out the cost of
PREEMPT_RCUalone.Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=n) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=y)
Done. Built two kernels from 6.18 upstream source on the same POWER10 machine. Both are voluntary preemption, differing only in PREEMPT_DYNAMIC (and thus PREEMPT_RCU):
Config A: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=n (no PREEMPT_RCU) Config B: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=y (PREEMPT_RCU=y)
Config B runtime mode confirmed as voluntary:
cat /sys/kernel/debug/sched/preempt: "none (voluntary) full lazy"
Results (stress-ng --kill 1 -t 23, SELinux enforcing, mean of 3 runs):
Kernel PREEMPT_RCU kill bogo-ops/sec stddev ---------------------- ----------- ----------------- ------ 6.18.0-vol-nodynamic no 108,836 19 6.18.0-vol-dynamic yes 68,197 1,146
Delta -37.3%
PREEMPT_RCU alone costs 37.3% on ppc64le with zero preemption mode change. Both kernels run voluntary preemption.
Quoted 2 lines
That's true for all archs. Please check your preemption mode in your x86 experiment.
Checked. On x86_64 (AMD EPYC 7313):
Kernel PREEMPT_RCU Runtime mode kill bogo-ops/sec ------------------- ----------- ------------------ ----------------- 6.12.0-211 (el10) yes none (voluntary) 37,436 7.2.0-rc4 (eln158) yes full (lazy) 36,392 (-2.8%)
Both x86 kernels already had PREEMPT_RCU=y, so the x86 comparison only shows the voluntary->lazy mode change cost (~3%), not the PREEMPT_RCU enablement cost.
Quoted 3 lines
1. Is not true.
PREEMPT_DYNAMICdoesn't force the preemption mode switch. You can still choose voluntary even withPREEMPT_DYNAMICon 6.16 to 6.19 kernel.
You are correct, I apologize for the error. The forced switch to lazy/full happened only in 7.0 with commit 7dadeaa6e851. On 6.16-6.19, voluntary is still available with PREEMPT_DYNAMIC, as confirmed by Config B above:
$ cat /sys/kernel/debug/sched/preempt none (voluntary) full lazy
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Jirka, Paul,
Quoted 19 lines · Jirka Hladky
Quoted 5 lines · Shrikanth Hegde
No. It doesn't confirm. I would recommend you do that case to find out the cost of
PREEMPT_RCUalone.Config A:
CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=n) Config B:CONFIG_PREEMPT_VOLUNTARY=y(CONFIG_PREEMPT_DYNAMIC=y)Done. Built two kernels from 6.18 upstream source on the same POWER10 machine. Both are voluntary preemption, differing only in
PREEMPT_DYNAMIC(and thusPREEMPT_RCU):Config A: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=n (no
PREEMPT_RCU) Config B: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=y (PREEMPT_RCU=y)Config B runtime mode confirmed as voluntary:
cat/sys/kernel/debug/sched/preempt: "none (voluntary) full lazy"Results (stress-ng --kill 1 -t 23, SELinux enforcing, mean of 3 runs):
Quoted 9 lines
Kernel PREEMPT_RCU kill bogo-ops/sec stddev ---------------------- ----------- ----------------- ------ 6.18.0-vol-nodynamic no 108,836 19 6.18.0-vol-dynamic yes 68,197 1,146Delta -37.3%
PREEMPT_RCUalone costs 37.3% on ppc64le with zero preemption mode change. Both kernels run voluntary preemption.
I tried to repro using "taskset -c 0-7 stress-ng --kill 1 -t 23 --metrics" since system had more than 1 core.
I did observe close to 25% regression with Config B
Config A: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=n
Config B: PREEMPT_VOLUNTARY=y, PREEMPT_DYNAMIC=y
I spent some more time debugging it as it was bugging me for few reasons.
1. There is barrier even when CONFIG_PREEMPTION=n. See include/linux/preempt.h.
#define preempt_disable() barrier()
#define preempt_enable() barrier()
So i was doubting all the cost is due to that.
2. Seeing the stress-ng --kill 1 -t 23, it spawns 3 threads IIUC. two will be long running. Given there are 8 CPUs in the test, preemption should be minimal. (This is only a guess)
3. Though rcu_lock/unlock shows up only in one case, it could be just that they are inline in PREEMPT_DYNAMIC=n. They still do barriers.
A did below hacks to see where the cost is coming from.
===================================
First thing i did was to remove PREEMPT_RCU for PREEMPT_DYNAMIC=y.
kernel/rcu/Kconfig +1 -1
@@ -18,7 +18,7 @@ config TREE_RCU config PREEMPT_RCU bool - default y if (PREEMPT || PREEMPT_RT || PREEMPT_DYNAMIC) + default y if (PREEMPT || PREEMPT_RT) select TREE_RCU help This option selects the RCU implementation that is
This improves it by 5%. But doesn't cover the whole regression.
============================================================================
So PREEMPT_RCU is not the main reason. Now what else PREEMPT_DYNAMIC adds,
1. PREEMPT_DYNAMIC select CONFIG_PREEMPTION and that selects PREEMPT_COUNT. That turns every preempt_enable/disable to dec/inc the preempt count. Even though it isn't finally used for voluntary preemption. This can have overhead on any RISC architecture if all the workload does is hitting that path, without doing any meaningful work.
2. Static key overheads.
++++++++++++++++++++++++++++++++++++++
For 1, first thought came to my mind was is it due to preempt_count being part of thread_info. Tried to move it PACA as it is more efficient(atleast for 64 bit). Even with that numbers didn;t improve much. Then i thought, is it purely due to preempt count itself. So did below,
kernel/Kconfig.preempt +2 -2
@@ -117,11 +117,11 @@ config PREEMPT_RT_NEEDS_BH_LOCK the old synchronized behaviour. config PREEMPTION - bool - select PREEMPT_COUNT + bool + select PREEMPT_COUNT if !PREEMPT_VOLUNTARY
That is able to recover all the regression. You can give it a try if you want. But that's not a solution as dynamic preemption just won't work.
++++++++++++++++++++++++
For 2, Sadly, i lost the system to try any hacks for static key overheads. But given above, i don't expect it to be a major one.
==============================================================================
From the above, it is quite evident that main cost is cost of preempt_disable/preempt_enable due to inc/dec of preempt count itself. This is due to nature of this workload which probably hits just lock/unlock likely, and no other work outside of it.
The cost of preempt_count is likely un-avoidable with DYNAMIC_PREEMPTION for all RISC architecture. I think CISC cost is minimal since it can update memory and folding of need_resched bit into the preempt count. Both are not doable in RISC.
Also given that after 7.0, all major archs including powerpc, can have only full/lazy preemption. None/voluntary are no longer possible. So making any sort of optimization for preempt count is not useful since it has to be there for full/lazy.
Also, evaluate it with any real life workloads, IIRC i have run hackbench, schbench, daytrader(db2 workload) this cost wasn't visible.
Quoted 14 lines
Quoted 2 lines
That's true for all archs. Please check your preemption mode in your x86 experiment.
Checked. On
x86_64(AMD EPYC 7313):Kernel PREEMPT_RCU Runtime mode kill bogo-ops/sec ------------------- ----------- ------------------ ----------------- 6.12.0-211 (el10) yes none (voluntary) 37,436 7.2.0-rc4 (eln158) yes full (lazy) 36,392 (-2.8%)Both x86 kernels already had PREEMPT_RCU=y, so the x86 comparison only shows the
voluntary->lazymode change cost (~3%), not thePREEMPT_RCUenablement cost.
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 3 lines · Shrikanth Hegde
From the above, it is quite evident that main cost is cost of preempt_disable/preempt_enable due to inc/dec of preempt count itself.
Thanks for the deep debugging, Shrikanth. This changes the picture significantly.
So the chain is:
PREEMPT_DYNAMIC -> PREEMPTION -> PREEMPT_COUNT
-> every preempt_disable/enable becomes load-modify-store with barriers
And the __rcu_read_lock/__rcu_read_unlock overhead I measured was actually the preempt_disable/preempt_enable inside them, not the RCU logic itself. That explains why removing PREEMPT_RCU only recovered ~5% -- the remaining preempt_count operations throughout the syscall path are the dominant cost.
Quoted 2 lines
The cost of
preempt_countis likely un-avoidable withDYNAMIC_PREEMPTIONfor all RISC architecture.
Agreed. On CISC (x86), the preempt_count update is a single memory inc/dec instruction. On RISC, it requires load-modify-store plus barriers for the atomic update, which is fundamentally more expensive per operation.
Quoted 4 lines
Also given that after 7.0, all major archs including powerpc, can have only full/lazy preemption. None/voluntary are no longer possible. So making any sort of optimization for preempt count is not useful since it has to be there for full/lazy.
Right. With full/lazy, PREEMPT_COUNT is required regardless of PREEMPT_DYNAMIC.
Quoted 2 lines
Also, evaluate it with any real life workloads, IIRC i have run hackbench, schbench, daytrader(db2 workload) this cost wasn't visible.
Good to know. I reviewed our full CI results across all benchmark suites on ppc64le and I don't see regressions outside of stress-ng. The stress-ng kill stressor is a worst case -- a tight syscall loop that hits preempt_disable/enable many times per call through the SELinux AVC path. Real workloads that do actual work between syscalls amortize this cost.
I'll update our internal tracking with the corrected root cause.
Thanks again for your persistence on isolating this. Good to have the real root cause understood, even if it's a fundamental RISC cost we have to accept.
Jirka
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 44 lines · Jirka Hladky
Quoted 3 lines · Shrikanth Hegde
From the above, it is quite evident that main cost is cost of preempt_disable/preempt_enable due to inc/dec of preempt count itself.
Thanks for the deep debugging, Shrikanth. This changes the picture significantly.
So the chain is:
PREEMPT_DYNAMIC-> PREEMPTION ->PREEMPT_COUNT
-> every preempt_disable/enable becomes load-modify-store with barriersAnd the __rcu_read_lock/__rcu_read_unlock overhead I measured was actually the preempt_disable/preempt_enable inside them, not the RCU logic itself. That explains why removing
PREEMPT_RCUonly recovered ~5% -- the remainingpreempt_countoperations throughout the syscall path are the dominant cost.Quoted 2 lines
The cost of
preempt_countis likely un-avoidable withDYNAMIC_PREEMPTIONfor all RISC architecture.Agreed. On CISC (x86), the
preempt_countupdate is a single memory inc/dec instruction. On RISC, it requires load-modify-store plus barriers for the atomic update, which is fundamentally more expensive per operation.Quoted 4 lines
Also given that after 7.0, all major archs including powerpc, can have only full/lazy preemption. None/voluntary are no longer possible. So making any sort of optimization for preempt count is not useful since it has to be there for full/lazy.
Right. With full/lazy,
PREEMPT_COUNTis required regardless ofPREEMPT_DYNAMIC.Quoted 2 lines
Also, evaluate it with any real life workloads, IIRC i have run hackbench, schbench, daytrader(db2 workload) this cost wasn't visible.
Good to know. I reviewed our full CI results across all benchmark suites on ppc64le and I don't see regressions outside of stress-ng. The stress-ng kill stressor is a worst case -- a tight syscall loop that hits preempt_disable/enable many times per call through the SELinux AVC path. Real workloads that do actual work between syscalls amortize this cost.
Quoted 5 lines
I'll update our internal tracking with the corrected root cause.
Thanks again for your persistence on isolating this. Good to have the real root cause understood, even if it's a fundamental RISC cost we have to accept.
Good on all of you!
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
In particular, I can see why the preempt_count() operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around the preempt_count() operations?
What am I missing here?
Thanx, Paul
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in PREEMPT_DYNAMIC:
Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Quoted 7 lines
In particular, I can see why the
preempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around thepreempt_count()operations?What am I missing here?
That's a good question -- I don't know enough about the powerpc preempt_count implementation to answer this. Shrikanth, could you comment on whether removing the barriers or using software interrupt disabling around preempt_count is feasible?
Thank you
Jirka
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 15 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%
Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
That is more like I would expect. Yes, there is added overhead, but it should not be excessively expensive. Though I suspect that arm64 could also do better. Easy for me to say, I know! ;-)
Thanx, Paul
Quoted 16 lines
Quoted 7 lines
In particular, I can see why the
preempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around thepreempt_count()operations?What am I missing here?
That's a good question -- I don't know enough about the powerpc
preempt_countimplementation to answer this. Shrikanth, could you comment on whether removing the barriers or using software interrupt disabling aroundpreempt_countis feasible?Thank you
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Jirka HladkyHi Jirka, Paul,
+cc will
Quoted 15 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%
Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Ouch!. But that's good to know.
Quoted 6 lines
Quoted 6 lines
In particular, I can see why the
preempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around thepreempt_count()operations?
Barrier are in core implementation, not in arch specific.
#ifdef CONFIG_PREEMPT_COUNT
#define preempt_disable() \
do { \
preempt_count_inc(); \
barrier(); \
} while (0)#ifdef CONFIG_PREEMPTION
#define preempt_enable() \
do { \
barrier(); \
if (unlikely(preempt_count_dec_and_test())) \
__preempt_schedule(); \
} while (0)Quoted 11 lines
Quoted 2 lines
What am I missing here?
That's a good question -- I don't know enough about the powerpc
preempt_countimplementation to answer this. Shrikanth, could you comment on whether removing the barriers or using software interrupt disabling aroundpreempt_countis feasible?Thank you
Jirka
PowerPC currently uses asm-generic implementation which is probably sub-optimal w.r.t to check of need_resched.
When i see ARM's implementation, i see there is trick of splitting it into two.
union {
u64 preempt_count; /* 0 => preemptible, <0 => bug */
struct {
#ifdef CONFIG_CPU_BIG_ENDIAN
u32 need_resched;
u32 count;
#else
u32 count;
u32 need_resched;
#endif
} preempt;
};Seeing Will's changelog is on similar direction.
396244692232 arm64: preempt: Provide our own implementation of asm/preempt.h "The asm-generic/preempt.h implementation doesn't make use of the PREEMPT_NEED_RESCHED flag, since this can interact badly with load/store architectures which rely on the preempt_count word being unchanged across an interrupt.
However, since we're a 64-bit architecture and the preempt count is only 32 bits wide, we can simply pack it next to the resched flag and load the whole thing in one go, so that a dec-and-test operation doesn't need to load twice. "
I am speculating this might help solve for ppc64 too. But i don't have a system to try this right now, will get back once i do
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 43 lines · Shrikanth Hegde
Hi Jirka, Paul,
+cc will
Quoted 15 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Ouch!. But that's good to know.
Quoted 6 lines
Quoted 6 lines
In particular, I can see why the
preempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around thepreempt_count()operations?Barrier are in core implementation, not in arch specific.
#ifdef
CONFIG_PREEMPT_COUNT
#definepreempt_disable()\do { \ preempt_count_inc(); \ barrier(); \ } while (0)
Quoted 7 lines
#ifdef
CONFIG_PREEMPTION
#definepreempt_enable()\do { \ barrier(); \ if (unlikely(preempt_count_dec_and_test())) \ __preempt_schedule(); \ } while (0)
But barrier() is just "__asm__ __volatile__("": : :"memory")", which does not emit any instructions. Or is this doing more machine-register flushing/restoring than one might expect?
Quoted 38 lines
Quoted 10 lines
Quoted 1 line
What am I missing here?
That's a good question -- I don't know enough about the powerpc
preempt_countimplementation to answer this. Shrikanth, could you comment on whether removing the barriers or using software interrupt disabling aroundpreempt_countis feasible?Thank you
JirkaPowerPC currently uses asm-generic implementation which is probably sub-optimal w.r.t to check of
need_resched.When i see ARM's implementation, i see there is trick of splitting it into two.
union { u64 preempt_count; /* 0 => preemptible, <0 => bug */ struct { #ifdef CONFIG_CPU_BIG_ENDIAN u32 need_resched; u32 count; #else u32 count; u32 need_resched; #endif } preempt; };Seeing Will's changelog is on similar direction.
396244692232 arm64: preempt: Provide our own implementation of
asm/preempt.h"Theasm-generic/preempt.himplementation doesn't make use of thePREEMPT_NEED_RESCHEDflag, since this can interact badly with load/store architectures which rely on thepreempt_countword being unchanged across an interrupt.
Quoted 7 lines
However, since we're a 64-bit architecture and the preempt count is only 32 bits wide, we can simply pack it next to the resched flag and load the whole thing in one go, so that a dec-and-test operation doesn't need to load twice. "
I am speculating this might help solve for ppc64 too. But i don't have a system to try this right now, will get back once i do
Looking forward to seeing what you come up with!
Thanx, Paul
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Shrikanth Hegde
Barrier are in core implementation, not in arch specific.
"Compiler barrier"s are not actually a thing, it is not a barrier for anything. It's just telling the compiler that at the point of the "barrier" all the registers should hold the values that they conceptually do also *actually*.
(In theory the compiler can sometimes prove it can do things that do not even guarantee that, but in practice this holds).
Quoted 3 lines
But
barrier()is just "__asm____volatile__("": : :"memory")", which does not emit any instructions. Or is this doing more machine-register flushing/restoring than one might expect?
(__volatile__ is redundant, any asm without outputs is always counted as volatile. If this wasn't true, GCC could always delete any such asm, since it has no side effects at all!
People often think "volatile" asm is some magic that prohibits the compiler from optimising stuff, but it is not, it has very contrained and very specific meaning).
Nope. The "memory" clobber says that all memory can be read and written in that asm, so any value that conceptually resides in memory there should have a stable value there. This can trigger some save/restore stuff, sure, but on all Power ABIs we have actual registers for pretty much everything, so nothing at all is done here.
Segher
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Le 30/07/2026 à 20:40, Segher Boessenkool a écrit :
Quoted 12 lines · Paul E. McKenney
Quoted 2 lines · Shrikanth Hegde
Quoted 1 line
Barrier are in core implementation, not in arch specific.
"Compiler barrier"s are not actually a thing, it is not a barrier for anything. It's just telling the compiler that at the point of the "barrier" all the registers should hold the values that they conceptually do also *actually*.
(In theory the compiler can sometimes prove it can do things that do not even guarantee that, but in practice this holds).
Quoted 7 lines
Quoted 3 lines
But
barrier()is just "__asm____volatile__("": : :"memory")", which does not emit any instructions. Or is this doing more machine-register flushing/restoring than one might expect?(
__volatile__is redundant, any asm without outputs is always counted as volatile. If this wasn't true, GCC could always delete any such asm, since it has no side effects at all!
There is a comment for the volatile:
/* Optimization barrier */
#ifndef barrier
/* The "volatile" is due to gcc bugs */
# define barrier() __asm__ __volatile__("": : :"memory")
#endifQuoted 13 lines
People often think "volatile" asm is some magic that prohibits the compiler from optimising stuff, but it is not, it has very contrained and very specific meaning).
Nope. The "memory" clobber says that all memory can be read and written in that asm, so any value that conceptually resides in memory there should have a stable value there. This can trigger some save/restore stuff, sure, but on all Power ABIs we have actual registers for pretty much everything, so nothing at all is done here.
Segher
Christophe Leroy (CS GROUP)
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
In reply to Shrikanth HegdeLe 30/07/2026 à 19:10, Shrikanth Hegde a écrit :
Quoted 21 lines
Hi Jirka, Paul,
+cc will
Quoted 15 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836
ppc64le on 68,197 -37.3% aarch64 off 5,538
aarch64 on 5,082 -8.2%
Quoted 4 lines
Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Ouch!. But that's good to know.
Might be a stupid question, but what is your .config ? Are you sure it doesn't contain CONFIG_DEBUG_PREEMPT ?
Quoted 75 lines
Quoted 7 lines
Quoted 7 lines
In particular, I can see why the
preempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers. And doesn't powerpc still use software interrupt disabling? If so, why not use that to simply software-disable interrupts around thepreempt_count()operations?Barrier are in core implementation, not in arch specific.
#ifdef
CONFIG_PREEMPT_COUNT
#definepreempt_disable()\
do { \
preempt_count_inc(); \
barrier(); \
} while (0)#ifdef
CONFIG_PREEMPTION
#definepreempt_enable()\
do { \
barrier(); \
if (unlikely(preempt_count_dec_and_test())) \
__preempt_schedule(); \
} while (0)Quoted 11 lines
Quoted 2 lines
What am I missing here?
That's a good question -- I don't know enough about the powerpc
preempt_countimplementation to answer this. Shrikanth, could you comment on whether removing the barriers or using software interrupt disabling aroundpreempt_countis feasible?Thank you
JirkaPowerPC currently uses asm-generic implementation which is probably sub- optimal w.r.t to check of
need_resched.When i see ARM's implementation, i see there is trick of splitting it into two.
union {
u64 preempt_count; /* 0 => preemptible, <0
=> bug */
struct {
#ifdefCONFIG_CPU_BIG_ENDIAN
u32need_resched;
u32 count;
#else
u32 count;
u32need_resched;
#endif
} preempt;
};Seeing Will's changelog is on similar direction.
396244692232 arm64: preempt: Provide our own implementation of asm/
preempt.h"Theasm-generic/preempt.himplementation doesn't make use of thePREEMPT_NEED_RESCHEDflag, since this can interact badly with load/store architectures which rely on thepreempt_countword being unchanged across an interrupt.However, since we're a 64-bit architecture and the preempt count is only 32 bits wide, we can simply pack it next to the resched flag and load the whole thing in one go, so that a dec-and-test operation doesn't need to load twice. "
I am speculating this might help solve for ppc64 too. But i don't have a system to try this right now, will get back once i do
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 26 lines · Christophe Leroy (CS GROUP)
Quoted 22 lines · Shrikanth Hegde
Hi Jirka, Paul,
+cc will
Quoted 16 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Ouch!. But that's good to know.
Might be a stupid question, but what is your .config ? Are you sure it doesn't contain
CONFIG_DEBUG_PREEMPT?
I have double-checked that and it's not set:
# CONFIG_DEBUG_PREEMPT is not set
Thanks
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi.
Quoted 33 lines · Jirka Hladky
Quoted 31 lines · Christophe Leroy (CS GROUP)
Quoted 26 lines · Shrikanth Hegde
Hi Jirka, Paul,
+cc will
Quoted 16 lines · Jirka Hladky
Quoted 2 lines · Paul E. McKenney
But is this really a fundamental RISC cost? For example, does arm64 see the same performance issues?
We tested arm64 (Ampere Altra Max) with the same controlled experiment -- two 6.18 kernels, both voluntary, differing only in
PREEMPT_DYNAMIC:Arch PREEMPT_DYNAMIC kill bogo-ops/sec Delta ------- --------------- ----------------- ----- ppc64le off 108,836 ppc64le on 68,197 -37.3% aarch64 off 5,538 aarch64 on 5,082 -8.2%Quoted 2 lines
arm64 sees -8.2% vs ppc64le's -37.3%. So arm64 is affected but much less severely.
Ouch!. But that's good to know.
Quoted 9 lines
Quoted 2 lines
Might be a stupid question, but what is your .config ? Are you sure it doesn't contain
CONFIG_DEBUG_PREEMPT?I have double-checked that and it's not set:
#CONFIG_DEBUG_PREEMPTis not setThanks
Jirka
Coming into numbers, I did notice later, arm64 numbers are almost 20x less. I believe you are having similar core count or benchmark is same.
But if we compare the time taken for each operations, it tells a different story.
PREEMPT_DYNAMIC
ppc64le off 108836 ops/s = 9.19 us/op
ppc64le on 68197 ops/s = 14.66 us/op
delta +5.47 us/op
aarch64 off 5538 ops/s = 180.57 us/op
aarch64 on 5082 ops/s = 196.77 us/op
delta +16.20 us/op
PS: I tried porting some of those changes in arm64 to powerpc to split preempt count into two. but i don;t see much improvement there. If i see get better numbers i will reply with that.
Re: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 3 lines · Shrikanth Hegde
Coming into numbers, I did notice later, arm64 numbers are almost 20x less. But if we compare the time taken for each operations, it tells a different story.
Good catch. I investigated why the arm64 baseline is so much slower. The 20x gap is due to cross-process signal delivery cost on the 128-core Ampere Altra Max, not preempt_count.
Self-kill (same process) vs cross-process kill on arm64:
self-kill (kill to self): 1.16 us/op (863k ops/sec)
cross-process kill: 54.06 us/op (18.5k ops/sec)
The stress-ng kill stressor sends signals between parent and child processes, so it's dominated by the cross-process path (IPI, wakeup, context switch). On the 128-core Ampere, this is expensive.
In contrast, the ppc64le test ran on 8 vCPUs sharing 1 physical core (SMT-8 LPAR), where cross-thread signaling is much cheaper.
For reference, basic syscall latency (getppid) is only 1.6x different:
ppc64le POWER10: 0.106 us/op
aarch64 Ampere: 0.171 us/op
So the architectures are comparable for simple syscalls. The kill stressor gap is about signal delivery topology, not CPU speed.
I also reran the arm64 tests with "taskset -c 0-7" to match the ppc64le vCPU count. Results barely changed (kill uses only 2-3 threads), confirming this is not a core count issue but a cross-core signaling cost:
With taskset -c 0-7 on arm64 (Ampere Altra Max, 6.18):
Kernel PREEMPT_RCU kill ops/sec us/op ---------------------- ----------- ------------ ------ 6.18.0-vol-nodynamic no 6,171 162.0 6.18.0-vol-dynamic yes 5,477 182.6 Delta -11.2% +20.6 us/op
Updated per-operation comparison:
PREEMPT_DYNAMIC
ppc64le off 9.19 us/op
ppc64le on 14.66 us/op
delta +5.47 us/op
aarch64 off 162.0 us/op aarch64 on 182.6 us/op delta +20.6 us/op
The absolute delta is larger on arm64 (+20.6 us vs +5.47 us), but as a percentage of total cost, ppc64le is hit harder (-37% vs -11%) because its baseline is dominated by the syscall/security path where preempt_count operations concentrate, whereas arm64's baseline is dominated by signal delivery overhead that masks the preempt_count cost.
The bottom line: PREEMPT_DYNAMIC/preempt_count overhead is present on both RISC architectures but its visibility depends heavily on the workload profile and hardware topology.
Quoted 3 lines
PS: I tried porting some of those changes in arm64 to powerpc to split preempt count into two. but i don;t see much improvement there.
Thanks for trying. Paul questioned whether barriers are actually needed for preempt_count, or whether software interrupt disabling would suffice (his words: "I can see why the preempt_count() operations need to be interrupt-safe, but I don't see why you would need barriers"). Any thoughts on whether that's feasible for powerpc?
Jirka
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Jirka.
Quoted 13 lines · Jirka Hladky
Quoted 3 lines · Shrikanth Hegde
Coming into numbers, I did notice later, arm64 numbers are almost 20x less. But if we compare the time taken for each operations, it tells a different story.
The bottom line: PREEMPT_DYNAMIC/preempt_count overhead is present on both RISC architectures but its visibility depends heavily on the workload profile and hardware topology.
Quoted 3 lines
PS: I tried porting some of those changes in arm64 to powerpc to split preempt count into two. but i don;t see much improvement there.
I tried moving to PACA plus splitting 64 bit into need_resched and preempt count. But it doesn;t move the needle. But it maybe worth pursuing, since it could help preemption modes. It needs more work and needs numbers across benchmark.
Quoted 8 lines
Thanks for trying. Paul questioned whether barriers are actually needed for
preempt_count, or whether software interrupt disabling would suffice (his words: "I can see why thepreempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers"). Any thoughts on whether that's feasible for powerpc?
Barrier are likely not the concern as it is mostly nop.
Also, soft disabling interrupts needs to arch specific hooks to setup before preempt_disable and replay interrupts after preempt_enable. I don't think it would benefit since interrupt disabling during this likely shouldn't happen. Maybe I don't understand how that could work.
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 29 lines · Shrikanth Hegde
Hi Jirka.
Quoted 13 lines · Jirka Hladky
Quoted 3 lines · Shrikanth Hegde
Coming into numbers, I did notice later, arm64 numbers are almost 20x less. But if we compare the time taken for each operations, it tells a different story.
The bottom line: PREEMPT_DYNAMIC/preempt_count overhead is present on both RISC architectures but its visibility depends heavily on the workload profile and hardware topology.
Quoted 3 lines
PS: I tried porting some of those changes in arm64 to powerpc to split preempt count into two. but i don;t see much improvement there.
I tried moving to PACA plus splitting 64 bit into
need_reschedand preempt count. But it doesn;t move the needle. But it maybe worth pursuing, since it could help preemption modes. It needs more work and needs numbers across benchmark.Quoted 6 lines
Thanks for trying. Paul questioned whether barriers are actually needed for
preempt_count, or whether software interrupt disabling would suffice (his words: "I can see why thepreempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers"). Any thoughts on whether that's feasible for powerpc?
Quoted 5 lines
Barrier are likely not the concern as it is mostly nop.
Also, soft disabling interrupts needs to arch specific hooks to setup beforepreempt_disableand replay interrupts afterpreempt_enable. I don't think it would benefit since interrupt disabling during this likely shouldn't happen. Maybe I don't understand how that could work.
For some reason, I remembered powerpc software-disabling interrupts, but when I go look now, there is no such thing. Maybe powerpc used to but no longer does. Or maybe I am just hallucinating. ;-)
Thanx, Paul
Shrikanth Hegde
reviewerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Hi Paul,
Quoted 18 lines
Quoted 12 lines
I tried moving to PACA plus splitting 64 bit into
need_reschedand preempt count. But it doesn;t move the needle. But it maybe worth pursuing, since it could help preemption modes. It needs more work and needs numbers across benchmark.Quoted 6 lines
Thanks for trying. Paul questioned whether barriers are actually needed for
preempt_count, or whether software interrupt disabling would suffice (his words: "I can see why thepreempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers"). Any thoughts on whether that's feasible for powerpc?Quoted 5 lines
Barrier are likely not the concern as it is mostly nop.
Also, soft disabling interrupts needs to arch specific hooks to setup beforepreempt_disableand replay interrupts afterpreempt_enable. I don't think it would benefit since interrupt disabling during this likely shouldn't happen. Maybe I don't understand how that could work.
Quoted 5 lines
For some reason, I remembered powerpc software-disabling interrupts, but when I go look now, there is no such thing. Maybe powerpc used to but no longer does. Or maybe I am just hallucinating. ;-)
Thanx, Paul
It is there still,
static inline unsigned long arch_local_irq_save(void)
{
return irq_soft_mask_or_return(IRQS_DISABLED);
}Sets the softmask bit, and any interrupt that arrives,
gets added to a list and that will be replayed in arch_local_irq_restore.
That will protect against the race of irq vs preempt count in __preempt_count_dec_and_test. In the PACA based PoC i have i tried to use it, but it doesn't make a difference, since this particular test accounts mainly preempt count overhead itself, which cannot be escaped in dynamic preemption.
So, I think this is the tax we got to live with for dynamic preemption on RISC archs. But good thing is, its effect is limited to a very few microbenchmarks.
Paul E. McKenney
maintainerRe: [PATCH v4 1/1] powerpc: enable dynamic preemption
Quoted 36 lines · Shrikanth Hegde
Hi Paul,
Quoted 18 lines
Quoted 12 lines
I tried moving to PACA plus splitting 64 bit into
need_reschedand preempt count. But it doesn;t move the needle. But it maybe worth pursuing, since it could help preemption modes. It needs more work and needs numbers across benchmark.Quoted 6 lines
Thanks for trying. Paul questioned whether barriers are actually needed for
preempt_count, or whether software interrupt disabling would suffice (his words: "I can see why thepreempt_count()operations need to be interrupt-safe, but I don't see why you would need barriers"). Any thoughts on whether that's feasible for powerpc?Quoted 5 lines
Barrier are likely not the concern as it is mostly nop.
Also, soft disabling interrupts needs to arch specific hooks to setup beforepreempt_disableand replay interrupts afterpreempt_enable. I don't think it would benefit since interrupt disabling during this likely shouldn't happen. Maybe I don't understand how that could work.Quoted 5 lines
For some reason, I remembered powerpc software-disabling interrupts, but when I go look now, there is no such thing. Maybe powerpc used to but no longer does. Or maybe I am just hallucinating. ;-)
Thanx, Paul
It is there still,
static inline unsigned long
arch_local_irq_save(void){ return irq_soft_mask_or_return(IRQS_DISABLED); }Sets the softmask bit, and any interrupt that arrives,
gets added to a list and that will be replayed inarch_local_irq_restore.
Quoted 7 lines
That will protect against the race of irq vs preempt count in
__preempt_count_dec_and_test. In the PACA based PoC i have i tried to use it, but it doesn't make a difference, since this particular test accounts mainly preempt count overhead itself, which cannot be escaped in dynamic preemption.So, I think this is the tax we got to live with for dynamic preemption on RISC archs. But good thing is, its effect is limited to a very few microbenchmarks.
OK, I guess I just didn't look hard enough. ;-)
And glad that the blast radius is limited.
Thanx, Paul