rcu/context-tracking: Merge RCU eqs-dynticks counter to context tracking
Subsystems (22)
Frederic Weisbecker
maintainercover rcu/context-tracking: Merge RCU eqs-dynticks counter to context tracking
This mixes up the RCU dynticks counter and the context tracking state updates into a single atomic instruction. This may serve several purposes:
1) Improve CPU isolation with deferring some disturbances until sensitive userspace workload completes and goes to the kernel. This can take several forms, for example smp_call_function_housekeeping() or on_each_housekeeping_cpu() to enqueue and execute work on all housekeeping CPUs. Then an atomic operation on ct->state can defer the work on nohz_full CPUs until they run in kernel (or IPI them if they are in kernel mode), see this proposal by Peter:
https://lore.kernel.org/all/[email protected]/#r
2) Unearth sysidle (https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git/commit/?h=sysidle.2017.05.11a&id=fe5ac724d81a3c7803e60c2232718f212f3f38d4)
This feature allowed to shutdown the tick on the last housekeeping
CPU once the rest of the system is fully idle. We needed some proper
fully ordered context tracking for that.
Inspired by Peterz: https://lore.kernel.org/all/[email protected]
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
rcu/context-tracking
HEAD: e4eaff86ec91c1cbde9a113cf5232dac9f897337
Thanks,
Frederic
---
Frederic Weisbecker (19):
context_tracking: Rename __context_tracking_enter/exit() to __ct_user_enter/exit()
context_tracking: Rename context_tracking_user_enter/exit() to user_enter/exit_callable()
context_tracking: Rename context_tracking_enter/exit() to ct_user_enter/exit()
context_tracking: Rename context_tracking_cpu_set() to context_tracking_cpu_track_user()
context_tracking: Split user tracking Kconfig
context_tracking: Take idle eqs entrypoints over RCU
context_tracking: Take IRQ eqs entrypoints over RCU
context_tracking: Take NMI eqs entrypoints over RCU
rcu/context-tracking: Remove rcu_irq_enter/exit()
rcu/context_tracking: Move dynticks counter to context tracking rcu/context_tracking: Move dynticks_nesting to context tracking rcu/context_tracking: Move dynticks_nmi_nesting to context tracking rcu/context-tracking: Move deferred nocb resched to context tracking rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking rcu/context-tracking: Remove unused and/or unecessary middle functions
context_tracking: Convert state to atomic_t
rcu/context-tracking: Use accessor for dynticks counter value rcu/context_tracking: Merge dynticks counter and context tracking states
context_tracking: Exempt CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
.../RCU/Design/Requirements/Requirements.rst | 10 +- Documentation/RCU/stallwarn.rst | 6 +- .../time/context-tracking/arch-support.txt | 6 +- arch/Kconfig | 8 +- arch/arm/Kconfig | 2 +- arch/arm/kernel/entry-common.S | 4 +- arch/arm/kernel/entry-header.S | 12 +- arch/arm/mach-imx/cpuidle-imx6q.c | 5 +- arch/arm64/Kconfig | 2 +- arch/arm64/kernel/entry-common.c | 14 +- arch/csky/Kconfig | 2 +- arch/csky/kernel/entry.S | 8 +- arch/mips/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/context_tracking.h | 2 +- arch/riscv/Kconfig | 2 +- arch/riscv/kernel/entry.S | 12 +- arch/sparc/Kconfig | 2 +- arch/sparc/kernel/rtrap_64.S | 2 +- arch/x86/Kconfig | 4 +- arch/x86/mm/fault.c | 2 +- drivers/acpi/processor_idle.c | 5 +- drivers/cpuidle/cpuidle-psci.c | 8 +- drivers/cpuidle/cpuidle.c | 9 +- include/linux/context_tracking.h | 81 ++-- include/linux/context_tracking_irq.h | 21 + include/linux/context_tracking_state.h | 92 +++- include/linux/entry-common.h | 10 +- include/linux/hardirq.h | 12 +- include/linux/rcupdate.h | 7 +- include/linux/rcutiny.h | 6 - include/linux/rcutree.h | 15 +- include/linux/tracepoint.h | 4 +- init/Kconfig | 4 +- kernel/context_tracking.c | 526 +++++++++++++++++++-- kernel/cpu_pm.c | 8 +- kernel/entry/common.c | 16 +- kernel/extable.c | 4 +- kernel/locking/lockdep.c | 2 +- kernel/rcu/Kconfig | 2 + kernel/rcu/rcu.h | 4 - kernel/rcu/tree.c | 478 ++----------------- kernel/rcu/tree.h | 8 - kernel/rcu/tree_exp.h | 2 +- kernel/rcu/tree_plugin.h | 36 +- kernel/rcu/tree_stall.h | 7 +- kernel/rcu/update.c | 2 +- kernel/sched/core.c | 2 +- kernel/sched/idle.c | 11 +- kernel/softirq.c | 4 +- kernel/time/Kconfig | 22 +- kernel/time/tick-sched.c | 2 +- kernel/trace/trace.c | 8 +- 53 files changed, 793 insertions(+), 734 deletions(-)
Frederic Weisbecker
maintainerPATCH 1/19 context_tracking: Rename __context_tracking_enter/exit() to __ct_user_enter/exit()
The context tracking namespace is going to expand and some new functions will require even longer names. Start shrinking the context_tracking prefix to "ct" as is already the case for some existing macros, this will make the introduction of new functions easier.
--- include/linux/context_tracking.h | 12 ++++++------ kernel/context_tracking.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-)
include/linux/context_tracking.h +6 -6
@@ -14,8 +14,8 @@extern void context_tracking_cpu_set (int cpu);/* Called with interrupts disabled. */ -extern void __context_tracking_enter (enum ctx_state state); -extern void __context_tracking_exit (enum ctx_state state); +extern void __ct_user_enter (enum ctx_state state); +extern void __ct_user_exit (enum ctx_state state);extern void context_tracking_enter (enum ctx_state state);extern void context_tracking_exit (enum ctx_state state);
@@ -38,13 +38,13 @@ static inline void user_exit(void) static __always_inline void user_enter_irqoff(void) {if (context_tracking_enabled ()) -__context_tracking_enter (CONTEXT_USER ); +__ct_user_enter (CONTEXT_USER ); } static __always_inline void user_exit_irqoff(void) {if (context_tracking_enabled ()) -__context_tracking_exit (CONTEXT_USER ); +__ct_user_exit (CONTEXT_USER ); }static inline enum ctx_state exception_enter (void )
@@ -74,7 +74,7 @@ static inline void exception_exit(enum ctx_state prev_ctx) static __always_inline bool context_tracking_guest_enter(void) {if (context_tracking_enabled ()) -__context_tracking_enter (CONTEXT_GUEST ); +__ct_user_enter (CONTEXT_GUEST );return context_tracking_enabled_this_cpu (); }
@@ -82,7 +82,7 @@ static __always_inline bool context_tracking_guest_enter(void) static __always_inline void context_tracking_guest_exit(void) {if (context_tracking_enabled ()) -__context_tracking_exit (CONTEXT_GUEST ); +__ct_user_exit (CONTEXT_GUEST ); }/**
kernel/context_tracking.c +10 -10
@@ -51,15 +51,15 @@ static __always_inline void context_tracking_recursion_exit(void) }/** -* context_tracking_enter - Inform the context tracking that the CPU is going -* enter user or guest space mode. +* __ct_user_enter - Inform the context tracking that the CPU is going +* to enter user or guest space mode. * * This function must be called right before we switch from the kernel * to user or guest space, when it's guaranteed the remaining kernel * instructions to execute won't use any RCU read side critical section * because this function sets RCU in extended quiescent state. */ -void noinstr __context_tracking_enter(enum ctx_state state) +void noinstr __ct_user_enter(enum ctx_state state) {/* Kernel threads aren't supposed to go to userspace */ WARN_ON_ONCE (!current->mm);
@@ -101,7 +101,7 @@ void noinstr __context_tracking_enter(enum ctx_state state) }context_tracking_recursion_exit (); } -EXPORT_SYMBOL_GPL (__context_tracking_enter); +EXPORT_SYMBOL_GPL (__ct_user_enter);void context_tracking_enter (enum ctx_state state) {
@@ -119,7 +119,7 @@ void context_tracking_enter(enum ctx_state state)return ;local_irq_save (flags); -__context_tracking_enter (state); +__ct_user_enter (state);local_irq_restore (flags); }NOKPROBE_SYMBOL (context_tracking_enter);
@@ -132,8 +132,8 @@ void context_tracking_user_enter(void)NOKPROBE_SYMBOL (context_tracking_user_enter);/** -* context_tracking_exit - Inform the context tracking that the CPU is -* exiting user or guest mode and entering the kernel. +* __ct_user_exit - Inform the context tracking that the CPU is +* exiting user or guest mode and entering the kernel. * * This function must be called after we entered the kernel from user or * guest space before any use of RCU read side critical section. This
@@ -143,7 +143,7 @@ NOKPROBE_SYMBOL(context_tracking_user_enter);* This call supports re-entrancy. This way it can be called from any exception * handler without needing to know if we came from userspace or not. */ -void noinstr __context_tracking_exit(enum ctx_state state) +void noinstr __ct_user_exit(enum ctx_state state) {if (!context_tracking_recursion_enter ())return ;
@@ -166,7 +166,7 @@ void noinstr __context_tracking_exit(enum ctx_state state) }context_tracking_recursion_exit (); } -EXPORT_SYMBOL_GPL (__context_tracking_exit); +EXPORT_SYMBOL_GPL (__ct_user_exit);void context_tracking_exit (enum ctx_state state) {
@@ -176,7 +176,7 @@ void context_tracking_exit(enum ctx_state state)return ;local_irq_save (flags); -__context_tracking_exit (state); +__ct_user_exit (state);local_irq_restore (flags); }NOKPROBE_SYMBOL (context_tracking_exit);
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 2/19 context_tracking: Rename context_tracking_user_enter/exit() to user_enter/exit_callable()
In reply to Frederic Weisbeckercontext_tracking_user_enter() and context_tracking_user_exit() are ASM callable versions of user_enter() and user_exit() for architectures that didn't manage to check the context tracking static key from ASM. Change those function names to better reflect their purpose.
--- arch/arm/kernel/entry-header.S | 8 ++++---- arch/csky/kernel/entry.S | 4 ++-- arch/riscv/kernel/entry.S | 6 +++--- include/linux/context_tracking.h | 4 ++-- kernel/context_tracking.c | 18 ++++++++++++++---- 5 files changed, 25 insertions(+), 15 deletions(-)
arch/arm/kernel/entry-header.S +4 -4
@@ -364,10 +364,10 @@ #ifdef CONFIG_CONTEXT_TRACKING .if \save stmdb sp!, {r0-r3, ip, lr} - bl context_tracking_user_exit + bl user_exit_callable ldmia sp!, {r0-r3, ip, lr} .else - bl context_tracking_user_exit + bl user_exit_callable .endif #endif .endm
@@ -376,10 +376,10 @@ #ifdef CONFIG_CONTEXT_TRACKING .if \save stmdb sp!, {r0-r3, ip, lr} - bl context_tracking_user_enter + bl user_enter_callable ldmia sp!, {r0-r3, ip, lr} .else - bl context_tracking_user_enter + bl user_enter_callable .endif #endif .endm
arch/csky/kernel/entry.S +2 -2
@@ -23,7 +23,7 @@ mfcr a0, epsr btsti a0, 31 bt 1f - jbsr context_tracking_user_exit + jbsr user_exit_callable ldw a0, (sp, LSAVE_A0) ldw a1, (sp, LSAVE_A1) ldw a2, (sp, LSAVE_A2)
@@ -160,7 +160,7 @@ ret_from_exception: cmpnei r10, 0 bt exit_work #ifdef CONFIG_CONTEXT_TRACKING - jbsr context_tracking_user_enter + jbsr user_enter_callable #endif 1: #ifdef CONFIG_PREEMPTION
arch/riscv/kernel/entry.S +3 -3
@@ -112,11 +112,11 @@ _save_context: #endif #ifdef CONFIG_CONTEXT_TRACKING - /* If previous state is in user mode, call context_tracking_user_exit. */ + /* If previous state is in user mode, call user_exit_callable(). */ li a0, SR_PP and a0, s1, a0 bnez a0, skip_context_tracking - call context_tracking_user_exit + call user_exit_callable skip_context_tracking: #endif
@@ -252,7 +252,7 @@ resume_userspace: bnez s1, work_pending #ifdef CONFIG_CONTEXT_TRACKING - call context_tracking_user_enter + call user_enter_callable #endif /* Save unwound kernel stack pointer in thread_info */
include/linux/context_tracking.h +2 -2
@@ -19,8 +19,8 @@ extern void __ct_user_exit(enum ctx_state state);extern void context_tracking_enter (enum ctx_state state);extern void context_tracking_exit (enum ctx_state state); -extern void context_tracking_user_enter (void ); -extern void context_tracking_user_exit (void ); +extern void user_enter_callable (void ); +extern void user_exit_callable (void );static inline void user_enter (void ) {
kernel/context_tracking.c +14 -4
@@ -125,11 +125,16 @@ void context_tracking_enter(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_enter);EXPORT_SYMBOL_GPL (context_tracking_enter); -void context_tracking_user_enter (void ) +/** +* user_enter_callable() - Unfortunate ASM callable version of user_enter() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_enter_callable (void ) {user_enter (); } -NOKPROBE_SYMBOL (context_tracking_user_enter); +NOKPROBE_SYMBOL (user_enter_callable);/** * __ct_user_exit - Inform the context tracking that the CPU is
@@ -182,11 +187,16 @@ void context_tracking_exit(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_exit);EXPORT_SYMBOL_GPL (context_tracking_exit); -void context_tracking_user_exit (void ) +/** +* user_exit_callable() - Unfortunate ASM callable version of user_exit() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_exit_callable (void ) {user_exit (); } -NOKPROBE_SYMBOL (context_tracking_user_exit); +NOKPROBE_SYMBOL (user_exit_callable);void __init context_tracking_cpu_set (int cpu) {
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 3/19 context_tracking: Rename context_tracking_enter/exit() to ct_user_enter/exit()
In reply to Frederic Weisbeckercontext_tracking_enter() and context_tracking_exit() have confusing names that don't explain the fact they are referring to user/guest state.
Use more self-explanatory names and shrink to the new context tracking prefix instead.
--- include/linux/context_tracking.h | 13 +++++++------ kernel/context_tracking.c | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-)
include/linux/context_tracking.h +7 -6
@@ -17,21 +17,22 @@ extern void context_tracking_cpu_set(int cpu);extern void __ct_user_enter (enum ctx_state state);extern void __ct_user_exit (enum ctx_state state); -extern void context_tracking_enter (enum ctx_state state); -extern void context_tracking_exit (enum ctx_state state); +extern void ct_user_enter (enum ctx_state state); +extern void ct_user_exit (enum ctx_state state); +extern void user_enter_callable (void );extern void user_exit_callable (void );static inline void user_enter (void ) {if (context_tracking_enabled ()) -context_tracking_enter (CONTEXT_USER ); +ct_user_enter (CONTEXT_USER ); }static inline void user_exit (void ) {if (context_tracking_enabled ()) -context_tracking_exit (CONTEXT_USER ); +ct_user_exit (CONTEXT_USER ); }/* Called with interrupts disabled. */
@@ -57,7 +58,7 @@ static inline enum ctx_state exception_enter(void) prev_ctx =this_cpu_read (context_tracking.state);if (prev_ctx !=CONTEXT_KERNEL ) -context_tracking_exit (prev_ctx); +ct_user_exit (prev_ctx);return prev_ctx; }
@@ -67,7 +68,7 @@ static inline void exception_exit(enum ctx_state prev_ctx)if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) &&context_tracking_enabled ()) {if (prev_ctx !=CONTEXT_KERNEL ) -context_tracking_enter (prev_ctx); +ct_user_enter (prev_ctx); } }
kernel/context_tracking.c +6 -6
@@ -103,7 +103,7 @@ void noinstr __ct_user_enter(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_enter); -void context_tracking_enter (enum ctx_state state) +void ct_user_enter (enum ctx_state state) {unsigned long flags;
@@ -122,8 +122,8 @@ void context_tracking_enter(enum ctx_state state)__ct_user_enter (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_enter); -EXPORT_SYMBOL_GPL (context_tracking_enter); +NOKPROBE_SYMBOL (ct_user_enter); +EXPORT_SYMBOL_GPL (ct_user_enter);/** * user_enter_callable() - Unfortunate ASM callable version of user_enter() for
@@ -173,7 +173,7 @@ void noinstr __ct_user_exit(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_exit); -void context_tracking_exit (enum ctx_state state) +void ct_user_exit (enum ctx_state state) {unsigned long flags;
@@ -184,8 +184,8 @@ void context_tracking_exit(enum ctx_state state)__ct_user_exit (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_exit); -EXPORT_SYMBOL_GPL (context_tracking_exit); +NOKPROBE_SYMBOL (ct_user_exit); +EXPORT_SYMBOL_GPL (ct_user_exit);/** * user_exit_callable() - Unfortunate ASM callable version of user_exit() for
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 4/19 context_tracking: Rename context_tracking_cpu_set() to context_tracking_cpu_track_user()
In reply to Frederic Weisbeckercontext_tracking_cpu_set() is called in order to tell a CPU to track user/kernel transitions. Since context tracking is going to expand in to also track transitions from/to idle/IRQ/NMIs, the scope of this function name becomes too broad and needs to be made more specific.
--- include/linux/context_tracking.h | 2 +- kernel/context_tracking.c | 4 ++-- kernel/time/tick-sched.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/context_tracking.h +1 -1
@@ -11,7 +11,7 @@#ifdef CONFIG_CONTEXT_TRACKING -extern void context_tracking_cpu_set (int cpu); +extern void context_tracking_cpu_track_user (int cpu);/* Called with interrupts disabled. */ extern void __ct_user_enter (enum ctx_state state);
kernel/context_tracking.c +2 -2
@@ -198,7 +198,7 @@ void user_exit_callable(void) }NOKPROBE_SYMBOL (user_exit_callable); -void __init context_tracking_cpu_set (int cpu) +void __init context_tracking_cpu_track_user (int cpu) {static __initdata bool initialized = false;
@@ -228,6 +228,6 @@ void __init context_tracking_init(void)int cpu;for_each_possible_cpu (cpu) - context_tracking_cpu_set(cpu); + context_tracking_cpu_track_user(cpu); }#endif
kernel/time/tick-sched.c +1 -1
@@ -571,7 +571,7 @@ void __init tick_nohz_init(void) }for_each_cpu (cpu, tick_nohz_full_mask) -context_tracking_cpu_set (cpu); +context_tracking_cpu_track_user (cpu); ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "kernel/nohz:predown", NULL,
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 5/19 context_tracking: Split user tracking Kconfig
In reply to Frederic WeisbeckerContext tracking is going to be used not only to track user transitions but also idle/IRQs/NMIs. The user tracking part will then become a seperate feature. Prepare Kconfig for that.
--- .../time/context-tracking/arch-support.txt | 6 ++--- arch/Kconfig | 4 ++-- arch/arm/Kconfig | 2 +- arch/arm/kernel/entry-common.S | 4 ++-- arch/arm/kernel/entry-header.S | 4 ++-- arch/arm64/Kconfig | 2 +- arch/csky/Kconfig | 2 +- arch/csky/kernel/entry.S | 4 ++-- arch/mips/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/context_tracking.h | 2 +- arch/riscv/Kconfig | 2 +- arch/riscv/kernel/entry.S | 6 ++--- arch/sparc/Kconfig | 2 +- arch/sparc/kernel/rtrap_64.S | 2 +- arch/x86/Kconfig | 4 ++-- include/linux/context_tracking.h | 12 +++++----- include/linux/context_tracking_state.h | 4 ++-- init/Kconfig | 4 ++-- kernel/context_tracking.c | 6 ++++- kernel/sched/core.c | 2 +- kernel/time/Kconfig | 22 +++++++++++-------- 22 files changed, 54 insertions(+), 46 deletions(-)
Documentation/features/time/context-tracking/arch-support.txt +3 -3
@@ -1,7 +1,7 @@ # -# Feature name: context-tracking -# Kconfig: HAVE_CONTEXT_TRACKING -# description: arch supports context tracking for NO_HZ_FULL +# Feature name: user-context-tracking +# Kconfig: HAVE_CONTEXT_TRACKING_USER +# description: arch supports user context tracking for NO_HZ_FULL # ----------------------- | arch |status|
arch/Kconfig +2 -2
@@ -762,7 +762,7 @@ config HAVE_ARCH_WITHIN_STACK_FRAMES and similar) by implementing an inline arch_within_stack_frames(), which is used by CONFIG_HARDENED_USERCOPY. -config HAVE_CONTEXT_TRACKING +config HAVE_CONTEXT_TRACKING_USER bool help Provide kernel/user boundaries probes necessary for subsystems
@@ -773,7 +773,7 @@ config HAVE_CONTEXT_TRACKING protected inside rcu_irq_enter/rcu_irq_exit() but preemption or signal handling on irq exit still need to be protected. -config HAVE_CONTEXT_TRACKING_OFFSTACK +config HAVE_CONTEXT_TRACKING_USER_OFFSTACK bool help Architecture neither relies on exception_enter()/exception_exit()
arch/arm/Kconfig +1 -1
@@ -81,7 +81,7 @@ config ARM select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE select HAVE_ARM_SMCCC if CPU_V7 select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32 - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK if !XIP_KERNEL select HAVE_DMA_CONTIGUOUS if MMU
arch/arm/kernel/entry-common.S +2 -2
@@ -26,7 +26,7 @@ #include "entry-header.S" saved_psr .req r8 -#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING) +#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING_USER) saved_pc .req r9 #define TRACE(x...) x #else
@@ -36,7 +36,7 @@ saved_pc .req lr .section .entry.text,"ax",%progbits .align 5 -#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \ +#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING_USER) || \ IS_ENABLED(CONFIG_DEBUG_RSEQ)) /* * This is the fast syscall return path. We do as little as possible here,
arch/arm/kernel/entry-header.S +2 -2
@@ -361,7 +361,7 @@ * between user and kernel mode. */ .macro ct_user_exit, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER .if \save stmdb sp!, {r0-r3, ip, lr} bl user_exit_callable
@@ -373,7 +373,7 @@ .endm .macro ct_user_enter, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER .if \save stmdb sp!, {r0-r3, ip, lr} bl user_enter_callable
arch/arm64/Kconfig +1 -1
@@ -169,7 +169,7 @@ config ARM64 select HAVE_C_RECORDMCOUNT select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE
arch/csky/Kconfig +1 -1
@@ -42,7 +42,7 @@ config CSKY select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_SECCOMP_FILTER - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_VIRT_CPU_ACCOUNTING_GEN select HAVE_DEBUG_BUGVERBOSE select HAVE_DEBUG_KMEMLEAK
arch/csky/kernel/entry.S +2 -2
@@ -19,7 +19,7 @@ .endm .macro context_tracking -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER mfcr a0, epsr btsti a0, 31 bt 1f
@@ -159,7 +159,7 @@ ret_from_exception: and r10, r9 cmpnei r10, 0 bt exit_work -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER jbsr user_enter_callable #endif 1:
arch/mips/Kconfig +1 -1
@@ -55,7 +55,7 @@ config MIPS select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_TIF_NOHZ select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK
arch/powerpc/Kconfig +1 -1
@@ -192,7 +192,7 @@ config PPC select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING if PPC64 + select HAVE_CONTEXT_TRACKING_USER if PPC64 select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK select HAVE_DEBUG_STACKOVERFLOW
arch/powerpc/include/asm/context_tracking.h +1 -1
@@ -2,7 +2,7 @@#ifndef _ASM_POWERPC_CONTEXT_TRACKING_H#define _ASM_POWERPC_CONTEXT_TRACKING_H -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER #define SCHEDULE_USER bl schedule_user#else #define SCHEDULE_USER bl schedule
arch/riscv/Kconfig +1 -1
@@ -80,7 +80,7 @@ config RISCV select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_VMAP_STACK if MMU && 64BIT select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS if MMU select HAVE_EBPF_JIT if MMU
arch/riscv/kernel/entry.S +3 -3
@@ -111,7 +111,7 @@ _save_context: call trace_hardirqs_off #endif -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER /* If previous state is in user mode, call user_exit_callable(). */ li a0, SR_PP and a0, s1, a0
@@ -176,7 +176,7 @@ handle_syscall: */ csrs CSR_STATUS, SR_IE #endif -#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING) +#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING_USER) /* Recover a0 - a7 for system calls */ REG_L a0, PT_A0(sp) REG_L a1, PT_A1(sp)
@@ -251,7 +251,7 @@ resume_userspace: andi s1, s0, _TIF_WORK_MASK bnez s1, work_pending -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER call user_enter_callable #endif
arch/sparc/Kconfig +1 -1
@@ -71,7 +71,7 @@ config SPARC64 select HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD select HAVE_SYSCALL_TRACEPOINTS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_TIF_NOHZ select HAVE_DEBUG_KMEMLEAK select IOMMU_HELPER
arch/sparc/kernel/rtrap_64.S +1 -1
@@ -15,7 +15,7 @@ #include <asm/visasm.h> #include <asm/processor.h> -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER # define SCHEDULE_USER schedule_user #else # define SCHEDULE_USER schedule
arch/x86/Kconfig +2 -2
@@ -182,8 +182,8 @@ config X86 select HAVE_ASM_MODVERSIONS select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING if X86_64 - select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER if X86_64 + select HAVE_CONTEXT_TRACKING_USER_OFFSTACK if HAVE_CONTEXT_TRACKING_USER select HAVE_C_RECORDMCOUNT select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION select HAVE_DEBUG_KMEMLEAK
include/linux/context_tracking.h +6 -6
@@ -10,7 +10,7 @@#include <asm/ptrace.h> -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER extern void context_tracking_cpu_track_user (int cpu);/* Called with interrupts disabled. */
@@ -52,7 +52,7 @@ static inline enum ctx_state exception_enter(void) {enum ctx_state prev_ctx; -if (IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) || +if (IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) || !context_tracking_enabled ())return 0 ;
@@ -65,7 +65,7 @@ static inline enum ctx_state exception_enter(void)static inline void exception_exit (enum ctx_state prev_ctx) { -if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) && +if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) &&context_tracking_enabled ()) {if (prev_ctx !=CONTEXT_KERNEL )ct_user_enter (prev_ctx);
@@ -109,14 +109,14 @@ static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; } static __always_inline bool context_tracking_guest_enter(void) { return false; }static inline void context_tracking_guest_exit (void ) { } -#endif /* !CONFIG_CONTEXT_TRACKING */ +#endif /* !CONFIG_CONTEXT_TRACKING_USER */ #define CT_WARN_ON (cond) WARN_ON(context_tracking_enabled() && (cond)) -#ifdef CONFIG_CONTEXT_TRACKING_FORCE +#ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE extern void context_tracking_init (void );#else static inline void context_tracking_init (void ) { } -#endif /* CONFIG_CONTEXT_TRACKING_FORCE */ +#endif /* CONFIG_CONTEXT_TRACKING_USER_FORCE */ #endif
include/linux/context_tracking_state.h +2 -2
@@ -22,7 +22,7 @@ struct context_tracking { } state; }; -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER extern struct static_key_false context_tracking_key; DECLARE_PER_CPU(struct context_tracking, context_tracking);
@@ -50,6 +50,6 @@ static inline bool context_tracking_in_user(void) { return false; }static inline bool context_tracking_enabled (void ) {return false; }static inline bool context_tracking_enabled_cpu (int cpu) {return false; }static inline bool context_tracking_enabled_this_cpu (void ) {return false; } -#endif /* CONFIG_CONTEXT_TRACKING */ +#endif /* CONFIG_CONTEXT_TRACKING_USER */ #endif
init/Kconfig +2 -2
@@ -498,11 +498,11 @@ config VIRT_CPU_ACCOUNTING_NATIVE config VIRT_CPU_ACCOUNTING_GEN bool "Full dynticks CPU time accounting" - depends on HAVE_CONTEXT_TRACKING + depends on HAVE_CONTEXT_TRACKING_USER depends on HAVE_VIRT_CPU_ACCOUNTING_GEN depends on GENERIC_CLOCKEVENTS select VIRT_CPU_ACCOUNTING - select CONTEXT_TRACKING + select CONTEXT_TRACKING_USER help Select this option to enable task and CPU time accounting on full dynticks systems. This accounting is implemented by watching every
kernel/context_tracking.c +5 -1
@@ -22,6 +22,8 @@#include <linux/export.h> #include <linux/kprobes.h> +#ifdef CONFIG_CONTEXT_TRACKING_USER +#define CREATE_TRACE_POINTS #include <trace/events/context_tracking.h>
@@ -222,7 +224,7 @@ void __init context_tracking_cpu_track_user(int cpu) initialized = true; } -#ifdef CONFIG_CONTEXT_TRACKING_FORCE +#ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE void __init context_tracking_init (void ) {int cpu;
@@ -231,3 +233,5 @@ void __init context_tracking_init(void)context_tracking_cpu_track_user (cpu); }#endif + +#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */
kernel/sched/core.c +1 -1
@@ -6398,7 +6398,7 @@ void __sched schedule_idle(void) }while (need_resched ()); } -#if defined(CONFIG_CONTEXT_TRACKING ) && !defined(CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) +#if defined(CONFIG_CONTEXT_TRACKING_USER ) && !defined(CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) asmlinkage __visible void __sched schedule_user(void) {/*
kernel/time/Kconfig +13 -9
@@ -111,7 +111,7 @@ config NO_HZ_FULL # NO_HZ_COMMON dependency # We need at least one periodic CPU for timekeeping depends on SMP - depends on HAVE_CONTEXT_TRACKING + depends on HAVE_CONTEXT_TRACKING_USER # VIRT_CPU_ACCOUNTING_GEN dependency depends on HAVE_VIRT_CPU_ACCOUNTING_GEN select NO_HZ_COMMON
@@ -140,28 +140,32 @@ endchoice config CONTEXT_TRACKING bool -config CONTEXT_TRACKING_FORCE - bool "Force context tracking" - depends on CONTEXT_TRACKING +config CONTEXT_TRACKING_USER + select CONTEXT_TRACKING + bool + +config CONTEXT_TRACKING_USER_FORCE + bool "Force user context tracking" + depends on CONTEXT_TRACKING_USER default y if !NO_HZ_FULL help The major pre-requirement for full dynticks to work is to - support the context tracking subsystem. But there are also + support the user context tracking subsystem. But there are also other dependencies to provide in order to make the full dynticks working. This option stands for testing when an arch implements the - context tracking backend but doesn't yet fulfill all the + user context tracking backend but doesn't yet fulfill all the requirements to make the full dynticks feature working. Without the full dynticks, there is no way to test the support - for context tracking and the subsystems that rely on it: RCU + for user context tracking and the subsystems that rely on it: RCU userspace extended quiescent state and tickless cputime accounting. This option copes with the absence of the full - dynticks subsystem by forcing the context tracking on all + dynticks subsystem by forcing the user context tracking on all CPUs in the system. Say Y only if you're working on the development of an - architecture backend for the context tracking. + architecture backend for the user context tracking. Say N otherwise, this option brings an overhead that you don't want in production.
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 6/19 context_tracking: Take idle eqs entrypoints over RCU
In reply to Frederic WeisbeckerThe RCU dynticks counter is going to be merged into the context tracking subsystem. Start with moving the idle extended quiescent states entrypoints to RCU. For now those are dumb redirection to existing RCU calls.
--- Documentation/RCU/stallwarn.rst | 4 ++-- arch/arm/mach-imx/cpuidle-imx6q.c | 5 +++-- drivers/acpi/processor_idle.c | 5 +++-- drivers/cpuidle/cpuidle.c | 9 +++++---- include/linux/context_tracking.h | 8 ++++++++ include/linux/rcupdate.h | 2 +- kernel/context_tracking.c | 12 ++++++++++++ kernel/locking/lockdep.c | 2 +- kernel/rcu/Kconfig | 2 ++ kernel/rcu/tree.c | 2 -- kernel/rcu/update.c | 2 +- kernel/sched/idle.c | 11 ++++++----- 12 files changed, 44 insertions(+), 20 deletions(-)
Documentation/RCU/stallwarn.rst +2 -2
@@ -97,8 +97,8 @@ warnings: which will include additional debugging information. - A low-level kernel issue that either fails to invoke one of the - variants of rcu_user_enter(), rcu_user_exit(), rcu_idle_enter(), - rcu_idle_exit(), rcu_irq_enter(), or rcu_irq_exit() on the one + variants of rcu_user_enter(), rcu_user_exit(), ct_idle_enter(), + ct_idle_exit(), rcu_irq_enter(), or rcu_irq_exit() on the one hand, or that invokes one of them too many times on the other. Historically, the most frequent issue has been an omission of either irq_enter() or irq_exit(), which in turn invoke
arch/arm/mach-imx/cpuidle-imx6q.c +3 -2
@@ -3,6 +3,7 @@* Copyright (C) 2012 Freescale Semiconductor, Inc. */ +#include <linux/context_tracking.h> #include <linux/cpuidle.h> #include <linux/module.h> #include <asm/cpuidle.h>
@@ -24,9 +25,9 @@ static int imx6q_enter_wait(struct cpuidle_device *dev,imx6_set_lpm (WAIT_UNCLOCKED );raw_spin_unlock (&cpuidle_lock); -rcu_idle_enter (); +ct_idle_enter ();cpu_do_idle (); -rcu_idle_exit (); +ct_idle_exit ();raw_spin_lock (&cpuidle_lock);if (num_idle_cpus-- ==num_online_cpus ())
drivers/acpi/processor_idle.c +3 -2
@@ -22,6 +22,7 @@#include <linux/cpu.h> #include <linux/minmax.h> #include <acpi/processor.h> +#include <linux/context_tracking.h> /* * Include the apic definitions for x86 to have the APIC timer related defines
@@ -643,11 +644,11 @@ static int acpi_idle_enter_bm(struct cpuidle_driver *drv,raw_spin_unlock (&c3_lock); } -rcu_idle_enter (); +ct_idle_enter ();acpi_idle_do_entry (cx); -rcu_idle_exit (); +ct_idle_exit ();/* Re-enable bus master arbitration */ if (dis_bm) {
drivers/cpuidle/cpuidle.c +5 -4
@@ -23,6 +23,7 @@#include <linux/suspend.h> #include <linux/tick.h> #include <linux/mmu_context.h> +#include <linux/context_tracking.h> #include <trace/events/power.h> #include "cpuidle.h"
@@ -150,12 +151,12 @@ static void enter_s2idle_proper(struct cpuidle_driver *drv,*/ stop_critical_timings ();if (!(target_state->flags &CPUIDLE_FLAG_RCU_IDLE )) -rcu_idle_enter (); +ct_idle_enter (); target_state->enter_s2idle (dev, drv, index);if (WARN_ON_ONCE (!irqs_disabled ()))local_irq_disable ();if (!(target_state->flags &CPUIDLE_FLAG_RCU_IDLE )) -rcu_idle_exit (); +ct_idle_exit ();tick_unfreeze ();start_critical_timings ();
@@ -233,10 +234,10 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,stop_critical_timings ();if (!(target_state->flags &CPUIDLE_FLAG_RCU_IDLE )) -rcu_idle_enter (); +ct_idle_enter (); entered_state = target_state->enter (dev, drv, index);if (!(target_state->flags &CPUIDLE_FLAG_RCU_IDLE )) -rcu_idle_exit (); +ct_idle_exit ();start_critical_timings ();sched_clock_idle_wakeup_event ();
include/linux/context_tracking.h +8 -0
@@ -119,4 +119,12 @@ extern void context_tracking_init(void);static inline void context_tracking_init (void ) { }#endif /* CONFIG_CONTEXT_TRACKING_USER_FORCE */ +#ifdef CONFIG_CONTEXT_TRACKING +extern void ct_idle_enter (void ); +extern void ct_idle_exit (void ); +#else +static inline void ct_idle_enter (void ) { } +static inline void ct_idle_exit (void ) { } +#endif /* !CONFIG_CONTEXT_TRACKING */ +#endif
include/linux/rcupdate.h +1 -1
@@ -128,7 +128,7 @@ static inline void rcu_nocb_flush_deferred_wakeup(void) { }* @a: Code that RCU needs to pay attention to. * * RCU read-side critical sections are forbidden in the inner idle loop, -* that is, between the rcu_idle_enter() and the rcu_idle_exit() -- RCU +* that is, between the ct_idle_enter() and the ct_idle_exit() -- RCU * will happily ignore any such read-side critical sections. However, * things like powertop need tracepoints in the inner idle loop. *
kernel/context_tracking.c +12 -0
@@ -235,3 +235,15 @@ void __init context_tracking_init(void)#endif #endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ + +void ct_idle_enter (void ) +{ +rcu_idle_enter (); +} +EXPORT_SYMBOL_GPL (ct_idle_enter); + +void ct_idle_exit (void ) +{ +rcu_idle_exit (); +} +EXPORT_SYMBOL_GPL (ct_idle_exit);
kernel/locking/lockdep.c +1 -1
@@ -6539,7 +6539,7 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s)/* * If a CPU is in the RCU-free window in idle (ie: in the section -* between rcu_idle_enter() and rcu_idle_exit(), then RCU +* between ct_idle_enter() and ct_idle_exit(), then RCU * considers that CPU to be in an "extended quiescent state", * which means that RCU will be completely ignoring that CPU. * Therefore, rcu_read_lock() and friends have absolutely no
kernel/rcu/Kconfig +2 -0
@@ -8,6 +8,8 @@ menu "RCU Subsystem" config TREE_RCU bool default y if SMP + # Dynticks-idle tracking + select CONTEXT_TRACKING help This option selects the RCU implementation that is designed for very large SMP system with hundreds or
kernel/rcu/tree.c +0 -2
@@ -664,7 +664,6 @@ void rcu_idle_enter(void)lockdep_assert_irqs_disabled ();rcu_eqs_enter (false); } -EXPORT_SYMBOL_GPL (rcu_idle_enter);#ifdef CONFIG_NO_HZ_FULL
@@ -904,7 +903,6 @@ void rcu_idle_exit(void)rcu_eqs_exit (false);local_irq_restore (flags); } -EXPORT_SYMBOL_GPL (rcu_idle_exit);#ifdef CONFIG_NO_HZ_FULL /**
kernel/rcu/update.c +1 -1
@@ -85,7 +85,7 @@ module_param(rcu_normal_after_boot, int, 0444);* and while lockdep is disabled. * * Note that if the CPU is in the idle loop from an RCU point of view (ie: -* that we are in the section between rcu_idle_enter() and rcu_idle_exit()) +* that we are in the section between ct_idle_enter() and ct_idle_exit()) * then rcu_read_lock_held() sets ``*ret`` to false even if the CPU did an * rcu_read_lock(). The reason for this is that RCU ignores CPUs that are * in such a section, considering these as in extended quiescent state,
kernel/sched/idle.c +6 -5
@@ -7,6 +7,7 @@* tasks which are handled in sched/fair.c ) */ #include "sched.h" +#include <linux/context_tracking.h> #include <trace/events/power.h>
@@ -56,14 +57,14 @@ static noinline int __cpuidle cpu_idle_poll(void) {trace_cpu_idle (0 ,smp_processor_id ());stop_critical_timings (); -rcu_idle_enter (); +ct_idle_enter ();local_irq_enable ();while (!tif_need_resched () && (cpu_idle_force_poll ||tick_check_broadcast_expired ()))cpu_relax (); -rcu_idle_exit (); +ct_idle_exit ();start_critical_timings ();trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ());
@@ -101,12 +102,12 @@ void __cpuidle default_idle_call(void)* * Trace IRQs enable here, then switch off RCU, and have * arch_cpu_idle() use raw_local_irq_enable(). Note that -* rcu_idle_enter() relies on lockdep IRQ state, so switch that +* ct_idle_enter() relies on lockdep IRQ state, so switch that * last -- this is very similar to the entry code. */ trace_hardirqs_on_prepare ();lockdep_hardirqs_on_prepare (_THIS_IP_); -rcu_idle_enter (); +ct_idle_enter ();lockdep_hardirqs_on (_THIS_IP_);arch_cpu_idle ();
@@ -119,7 +120,7 @@ void __cpuidle default_idle_call(void)*/ raw_local_irq_disable ();lockdep_hardirqs_off (_THIS_IP_); -rcu_idle_exit (); +ct_idle_exit ();lockdep_hardirqs_on (_THIS_IP_);raw_local_irq_enable ();
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 7/19 context_tracking: Take IRQ eqs entrypoints over RCU
In reply to Frederic WeisbeckerThe RCU dynticks counter is going to be merged into the context tracking subsystem. Prepare with moving the IRQ extended quiescent states entrypoints to context tracking. For now those are dumb redirection to existing RCU calls.
--- .../RCU/Design/Requirements/Requirements.rst | 10 ++++---- Documentation/RCU/stallwarn.rst | 4 ++-- arch/Kconfig | 2 +- arch/arm64/kernel/entry-common.c | 6 ++--- arch/x86/mm/fault.c | 2 +- drivers/cpuidle/cpuidle-psci.c | 8 +++---- include/linux/context_tracking_irq.h | 17 +++++++++++++ include/linux/context_tracking_state.h | 1 + include/linux/entry-common.h | 10 ++++---- include/linux/rcupdate.h | 5 ++-- include/linux/tracepoint.h | 4 ++-- kernel/context_tracking.c | 24 +++++++++++++++++-- kernel/cpu_pm.c | 8 +++---- kernel/entry/common.c | 12 +++++----- kernel/softirq.c | 4 ++-- kernel/trace/trace.c | 6 ++--- 16 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 include/linux/context_tracking_irq.h
Documentation/RCU/Design/Requirements/Requirements.rst +5 -5
@@ -1844,10 +1844,10 @@ that meets this requirement. Furthermore, NMI handlers can be interrupted by what appear to RCU to be normal interrupts. One way that this can happen is for code that -directly invokes rcu_irq_enter() and rcu_irq_exit() to be called +directly invokes ct_irq_enter() and ct_irq_exit() to be called from an NMI handler. This astonishing fact of life prompted the current -code structure, which has rcu_irq_enter() invoking -rcu_nmi_enter() and rcu_irq_exit() invoking rcu_nmi_exit(). +code structure, which has ct_irq_enter() invoking +rcu_nmi_enter() and ct_irq_exit() invoking rcu_nmi_exit(). And yes, I also learned of this requirement the hard way. Loadable Modules
@@ -2195,7 +2195,7 @@ scheduling-clock interrupt be enabled when RCU needs it to be: sections, and RCU believes this CPU to be idle, no problem. This sort of thing is used by some architectures for light-weight exception handlers, which can then avoid the overhead of - rcu_irq_enter() and rcu_irq_exit() at exception entry and + ct_irq_enter() and ct_irq_exit() at exception entry and exit, respectively. Some go further and avoid the entireties of irq_enter() and irq_exit(). Just make very sure you are running some of your tests with
@@ -2226,7 +2226,7 @@ scheduling-clock interrupt be enabled when RCU needs it to be: +-----------------------------------------------------------------------+ | **Answer**: | +-----------------------------------------------------------------------+ -| One approach is to do ``rcu_irq_exit();rcu_irq_enter();`` every so | +| One approach is to do ``ct_irq_exit();ct_irq_enter();`` every so | | often. But given that long-running interrupt handlers can cause other | | problems, not least for response time, shouldn't you work to keep | | your interrupt handler's runtime within reasonable bounds? |
Documentation/RCU/stallwarn.rst +2 -2
@@ -98,11 +98,11 @@ warnings: - A low-level kernel issue that either fails to invoke one of the variants of rcu_user_enter(), rcu_user_exit(), ct_idle_enter(), - ct_idle_exit(), rcu_irq_enter(), or rcu_irq_exit() on the one + ct_idle_exit(), ct_irq_enter(), or ct_irq_exit() on the one hand, or that invokes one of them too many times on the other. Historically, the most frequent issue has been an omission of either irq_enter() or irq_exit(), which in turn invoke - rcu_irq_enter() or rcu_irq_exit(), respectively. Building your + ct_irq_enter() or ct_irq_exit(), respectively. Building your kernel with CONFIG_RCU_EQS_DEBUG=y can help track down these types of issues, which sometimes arise in architecture-specific code.
arch/Kconfig +1 -1
@@ -770,7 +770,7 @@ config HAVE_CONTEXT_TRACKING_USER Syscalls need to be wrapped inside user_exit()-user_enter(), either optimized behind static key or through the slow path using TIF_NOHZ flag. Exceptions handlers must be wrapped as well. Irqs are already - protected inside rcu_irq_enter/rcu_irq_exit() but preemption or signal + protected inside ct_irq_enter/ct_irq_exit() but preemption or signal handling on irq exit still need to be protected. config HAVE_CONTEXT_TRACKING_USER_OFFSTACK
arch/arm64/kernel/entry-common.c +3 -3
@@ -40,7 +40,7 @@ static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)if (!IS_ENABLED (CONFIG_TINY_RCU ) &&is_idle_task (current)) {lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_irq_enter (); +ct_irq_enter ();trace_hardirqs_off_finish (); regs->exit_rcu = true;
@@ -74,7 +74,7 @@ static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)if (regs->exit_rcu) {trace_hardirqs_on_prepare ();lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); -rcu_irq_exit (); +ct_irq_exit ();lockdep_hardirqs_on (CALLER_ADDR0 );return ; }
@@ -82,7 +82,7 @@ static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)trace_hardirqs_on (); }else {if (regs->exit_rcu) -rcu_irq_exit (); +ct_irq_exit (); } }
arch/x86/mm/fault.c +1 -1
@@ -1526,7 +1526,7 @@ DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault)/* * Entry handling for valid #PF from kernel mode is slightly -* different: RCU is already watching and rcu_irq_enter() must not +* different: RCU is already watching and ct_irq_enter() must not * be invoked because a kernel fault on a user space address might * sleep. *
drivers/cpuidle/cpuidle-psci.c +4 -4
@@ -68,12 +68,12 @@ static int __psci_enter_domain_idle_state(struct cpuidle_device *dev,return -1 ;/* Do runtime PM to manage a hierarchical CPU toplogy. */ -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();if (s2idle)dev_pm_genpd_suspend (pd_dev);else pm_runtime_put_sync_suspend (pd_dev); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson (); state =psci_get_domain_state ();if (!state)
@@ -81,12 +81,12 @@ static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, ret =psci_cpu_suspend_enter (state) ?-1 : idx; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();if (s2idle)dev_pm_genpd_resume (pd_dev);else pm_runtime_get_sync (pd_dev); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();cpu_pm_exit ();
include/linux/context_tracking_irq.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CONTEXT_TRACKING_IRQ_H +#define _LINUX_CONTEXT_TRACKING_IRQ_H + +#ifdef CONFIG_CONTEXT_TRACKING +void ct_irq_enter (void ); +void ct_irq_exit (void ); +void ct_irq_enter_irqson (void ); +void ct_irq_exit_irqson (void ); +#else +static inline void ct_irq_enter (void ) { } +static inline void ct_irq_exit (void ) { } +static inline void ct_irq_enter_irqson (void ) { } +static inline void ct_irq_exit_irqson (void ) { } +#endif + +#endif
include/linux/context_tracking_state.h +1 -0
@@ -4,6 +4,7 @@#include <linux/percpu.h> #include <linux/static_key.h> +#include <linux/context_tracking_irq.h> struct context_tracking {/*
include/linux/entry-common.h +5 -5
@@ -396,7 +396,7 @@ void irqentry_exit_to_user_mode(struct pt_regs *regs);/** * struct irqentry_state - Opaque object for exception state storage * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the -* exit path has to invoke rcu_irq_exit(). +* exit path has to invoke ct_irq_exit(). * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that * lockdep state is restored correctly on exit from nmi. *
@@ -434,12 +434,12 @@ typedef struct irqentry_state {* * For kernel mode entries RCU handling is done conditional. If RCU is * watching then the only RCU requirement is to check whether the tick has -* to be restarted. If RCU is not watching then rcu_irq_enter() has to be -* invoked on entry and rcu_irq_exit() on exit. +* to be restarted. If RCU is not watching then ct_irq_enter() has to be +* invoked on entry and ct_irq_exit() on exit. * -* Avoiding the rcu_irq_enter/exit() calls is an optimization but also +* Avoiding the ct_irq_enter/exit() calls is an optimization but also * solves the problem of kernel mode pagefaults which can schedule, which -* is not possible after invoking rcu_irq_enter() without undoing it. +* is not possible after invoking ct_irq_enter() without undoing it. * * For user mode entries irqentry_enter_from_user_mode() is invoked to * establish the proper context for NOHZ_FULL. Otherwise scheduling on exit
include/linux/rcupdate.h +3 -2
@@ -29,6 +29,7 @@#include <linux/lockdep.h> #include <asm/processor.h> #include <linux/cpumask.h> +#include <linux/context_tracking_irq.h> #define ULONG_CMP_GE (a, b) (ULONG_MAX / 2 >= (a) - (b))#define ULONG_CMP_LT (a, b) (ULONG_MAX / 2 < (a) - (b))
@@ -143,9 +144,9 @@ static inline void rcu_nocb_flush_deferred_wakeup(void) { }*/ #define RCU_NONIDLE (a) \ do { \ - rcu_irq_enter_irqson(); \ + ct_irq_enter_irqson(); \ do { a; } while (0); \ - rcu_irq_exit_irqson(); \ + ct_irq_exit_irqson(); \ } while (0)/*
include/linux/tracepoint.h +2 -2
@@ -200,13 +200,13 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)*/ \if (rcuidle) { \ __idx =srcu_read_lock_notrace (&tracepoint_srcu);\ -rcu_irq_enter_irqson (); \ +ct_irq_enter_irqson (); \ } \ \__DO_TRACE_CALL (name,TP_ARGS (args)); \ \if (rcuidle) { \ -rcu_irq_exit_irqson (); \ +ct_irq_exit_irqson (); \srcu_read_unlock_notrace (&tracepoint_srcu, __idx);\ } \ \
kernel/context_tracking.c +22 -2
@@ -75,7 +75,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* At this stage, only low level arch entry code remains and * then we'll run in userspace. We can assume there won't be * any RCU read-side critical section until the next call to -* user_exit() or rcu_irq_enter(). Let's remove RCU's dependency +* user_exit() or ct_irq_enter(). Let's remove RCU's dependency * on the tick. */ if (state ==CONTEXT_USER ) {
@@ -112,7 +112,7 @@ void ct_user_enter(enum ctx_state state)/* * Some contexts may involve an exception occuring in an irq, * leading to that nesting: -* rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit() +* ct_irq_enter() rcu_user_exit() rcu_user_exit() ct_irq_exit() * This would mess up the dyntick_nesting count though. And rcu_irq_*() * helpers are enough to protect RCU uses inside the exception. So * just return immediately if we detect we are in an IRQ.
@@ -247,3 +247,23 @@ void ct_idle_exit(void)rcu_idle_exit (); }EXPORT_SYMBOL_GPL (ct_idle_exit); + +noinstr void ct_irq_enter(void) +{ +rcu_irq_enter (); +} + +noinstr void ct_irq_exit(void) +{ +rcu_irq_exit (); +} + +void ct_irq_enter_irqson (void ) +{ +rcu_irq_enter_irqson (); +} + +void ct_irq_exit_irqson (void ) +{ +rcu_irq_exit_irqson (); +}
kernel/cpu_pm.c +4 -4
@@ -35,11 +35,11 @@ static int cpu_pm_notify(enum cpu_pm_event event)* disfunctional in cpu idle. Copy RCU_NONIDLE code to let RCU know * this. */ -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();rcu_read_lock (); ret =raw_notifier_call_chain (&cpu_pm_notifier.chain, event,NULL );rcu_read_unlock (); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();return notifier_to_errno (ret); }
@@ -49,11 +49,11 @@ static int cpu_pm_notify_robust(enum cpu_pm_event event_up, enum cpu_pm_event evunsigned long flags;int ret; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();raw_spin_lock_irqsave (&cpu_pm_notifier.lock, flags); ret =raw_notifier_call_chain_robust (&cpu_pm_notifier.chain, event_up, event_down,NULL );raw_spin_unlock_irqrestore (&cpu_pm_notifier.lock, flags); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();return notifier_to_errno (ret); }
kernel/entry/common.c +6 -6
@@ -327,7 +327,7 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs) }/* -* If this entry hit the idle task invoke rcu_irq_enter() whether +* If this entry hit the idle task invoke ct_irq_enter() whether * RCU is watching or not. * * Interrupts can nest when the first interrupt invokes softirq
@@ -338,12 +338,12 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)* not nested into another interrupt. * * Checking for rcu_is_watching() here would prevent the nesting -* interrupt to invoke rcu_irq_enter(). If that nested interrupt is +* interrupt to invoke ct_irq_enter(). If that nested interrupt is * the tick then rcu_flavor_sched_clock_irq() would wrongfully * assume that it is the first interrupt and eventually claim * quiescent state and end grace periods prematurely. * -* Unconditionally invoke rcu_irq_enter() so RCU state stays +* Unconditionally invoke ct_irq_enter() so RCU state stays * consistent. * * TINY_RCU does not support EQS, so let the compiler eliminate
@@ -356,7 +356,7 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)* as in irqentry_enter_from_user_mode(). */ lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_irq_enter (); +ct_irq_enter ();instrumentation_begin ();trace_hardirqs_off_finish ();instrumentation_end ();
@@ -414,7 +414,7 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state)trace_hardirqs_on_prepare ();lockdep_hardirqs_on_prepare (CALLER_ADDR0 );instrumentation_end (); -rcu_irq_exit (); +ct_irq_exit ();lockdep_hardirqs_on (CALLER_ADDR0 );return ; }
@@ -436,7 +436,7 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state)* was not watching on entry. */ if (state.exit_rcu) -rcu_irq_exit (); +ct_irq_exit (); } }
kernel/softirq.c +2 -2
@@ -607,7 +607,7 @@ void irq_enter_rcu(void)*/ void irq_enter (void ) { -rcu_irq_enter (); +ct_irq_enter ();irq_enter_rcu (); }
@@ -659,7 +659,7 @@ void irq_exit_rcu(void)void irq_exit (void ) {__irq_exit_rcu (); -rcu_irq_exit (); +ct_irq_exit ();/* must be last! */ lockdep_hardirq_exit (); }
kernel/trace/trace.c +3 -3
@@ -3088,15 +3088,15 @@ void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,/* * When an NMI triggers, RCU is enabled via rcu_nmi_enter(), * but if the above rcu_is_watching() failed, then the NMI -* triggered someplace critical, and rcu_irq_enter() should +* triggered someplace critical, and ct_irq_enter() should * not be called from NMI. */ if (unlikely (in_nmi ()))return ; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();__ftrace_trace_stack (buffer, trace_ctx, skip,NULL ); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson (); }/**
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 9/19 rcu/context-tracking: Remove rcu_irq_enter/exit()
In reply to Frederic WeisbeckerNow rcu_irq_enter/exit() is an unecessary middle call between ct_irq_enter/exit() and nmi_irq_enter/exit(). Take this opportunity to remove the former functions and move the comments above them to the new entrypoints.
--- include/linux/rcutiny.h | 4 -- include/linux/rcutree.h | 4 -- kernel/context_tracking.c | 59 ++++++++++++++++++++++++++-- kernel/rcu/tree.c | 83 --------------------------------------- 4 files changed, 55 insertions(+), 95 deletions(-)
include/linux/rcutiny.h +0 -4
@@ -98,10 +98,6 @@ static inline void rcu_cpu_stall_reset(void) { }static inline int rcu_jiffies_till_stall_check (void ) {return 21 *HZ ; }static inline void rcu_idle_enter (void ) { }static inline void rcu_idle_exit (void ) { } -static inline void rcu_irq_enter (void ) { } -static inline void rcu_irq_exit_irqson (void ) { } -static inline void rcu_irq_enter_irqson (void ) { } -static inline void rcu_irq_exit (void ) { }static inline void rcu_irq_exit_check_preempt (void ) { }#define rcu_is_idle_cpu (cpu) \ (is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq())
include/linux/rcutree.h +0 -4
@@ -51,10 +51,6 @@ void cond_synchronize_rcu(unsigned long oldstate);void rcu_idle_enter (void );void rcu_idle_exit (void ); -void rcu_irq_enter (void ); -void rcu_irq_exit (void ); -void rcu_irq_enter_irqson (void ); -void rcu_irq_exit_irqson (void );bool rcu_is_idle_cpu (int cpu);#ifdef CONFIG_PROVE_RCU
kernel/context_tracking.c +55 -4
79 lines not on this page · raw message
kernel/rcu/tree.c +0 -83
101 lines not on this page · raw message
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 12/19 rcu/context_tracking: Move dynticks_nmi_nesting to context tracking
In reply to Frederic WeisbeckerThe RCU eqs tracking is going to be performed by the context tracking subsystem. The related nesting counters thus need to be moved to the context tracking structure.
--- include/linux/context_tracking_state.h | 4 +++ kernel/context_tracking.c | 1 + kernel/rcu/rcu.h | 4 --- kernel/rcu/tree.c | 48 +++++++++++--------------- kernel/rcu/tree.h | 1 - kernel/rcu/tree_stall.h | 2 +- 6 files changed, 27 insertions(+), 33 deletions(-)
include/linux/context_tracking_state.h +4 -0
@@ -6,6 +6,9 @@#include <linux/static_key.h> #include <linux/context_tracking_irq.h> +/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ +#define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) +struct context_tracking {#ifdef CONFIG_CONTEXT_TRACKING_USER /*
@@ -25,6 +28,7 @@ struct context_tracking {#endif atomic_t dynticks;/* Even value for idle, else odd. */ long dynticks_nesting;/* Track process nesting level. */ +long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ };#ifdef CONFIG_CONTEXT_TRACKING
kernel/context_tracking.c +1 -0
@@ -234,6 +234,7 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , .dynticks_nesting =1 , .dynticks =ATOMIC_INIT (1 ), };
kernel/rcu/rcu.h +0 -4
@@ -12,10 +12,6 @@#include <trace/events/rcu.h> -/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ -#define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) - -/* * Grace-period counter management. */
kernel/rcu/tree.c +21 -27
144 lines not on this page · raw message
kernel/rcu/tree.h +0 -1
@@ -186,7 +186,6 @@ struct rcu_data {/* 3) dynticks interface. */ int dynticks_snap;/* Per-GP tracking for dynticks. */ -long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */ bool rcu_forced_tick;/* Forced tick to provide QS. */
kernel/rcu/tree_stall.h +1 -1
@@ -460,7 +460,7 @@ static void print_cpu_stall_info(int cpu)"!." [!delta], ticks_value, ticks_title,rcu_dynticks_snap (cpu) &0xfff , - ct->dynticks_nesting, rdp->dynticks_nmi_nesting, + ct->dynticks_nesting, ct->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu),data_race (rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart, falsepositive ? " (false positive?)" : "");
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 14/19 rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking
In reply to Frederic WeisbeckerMove the core RCU eqs/dynticks functions to context tracking so that we can later merge all that code within context tracking.
--- include/linux/context_tracking.h | 12 ++ include/linux/rcutree.h | 3 + kernel/context_tracking.c | 347 +++++++++++++++++++++++++++++++ kernel/rcu/tree.c | 326 +---------------------------- kernel/rcu/tree.h | 5 - kernel/rcu/tree_plugin.h | 36 +--- 6 files changed, 366 insertions(+), 363 deletions(-)
include/linux/context_tracking.h +12 -0
@@ -122,6 +122,18 @@ static inline void context_tracking_init(void) { }#ifdef CONFIG_CONTEXT_TRACKING extern void ct_idle_enter (void );extern void ct_idle_exit (void ); +extern unsigned long rcu_dynticks_inc (int incby); + +/* +* Is the current CPU in an extended quiescent state? +* +* No ordering, as we are sampling CPU-local information. +*/ +static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) +{ +return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); +} +#else static inline void ct_idle_enter (void ) { }static inline void ct_idle_exit (void ) { }
include/linux/rcutree.h +3 -0
@@ -59,6 +59,9 @@ void rcu_irq_exit_check_preempt(void);static inline void rcu_irq_exit_check_preempt (void ) { }#endif +struct task_struct ; +void rcu_preempt_deferred_qs (struct task_struct *t); +void exit_rcu (void );void rcu_scheduler_starting (void );
kernel/context_tracking.c +347 -0
353 lines not on this page · raw message
kernel/rcu/tree.c +3 -323
368 lines not on this page · raw message
kernel/rcu/tree.h +0 -5
@@ -426,7 +426,6 @@ static void rcu_cpu_kthread_setup(unsigned int cpu);static void rcu_spawn_one_boost_kthread (struct rcu_node *rnp);static bool rcu_preempt_has_tasks (struct rcu_node *rnp);static bool rcu_preempt_need_deferred_qs (struct task_struct *t); -static void rcu_preempt_deferred_qs (struct task_struct *t);static void zero_cpu_stall_ticks (struct rcu_data *rdp);static struct swait_queue_head *rcu_nocb_gp_get (struct rcu_node *rnp);static void rcu_nocb_gp_cleanup (struct swait_queue_head *sq);
@@ -466,10 +465,6 @@ do { \static void rcu_bind_gp_kthread (void );static bool rcu_nohz_full_cpu (void ); -static void rcu_dynticks_task_enter (void ); -static void rcu_dynticks_task_exit (void ); -static void rcu_dynticks_task_trace_enter (void ); -static void rcu_dynticks_task_trace_exit (void );/* Forward declarations for tree_stall.h */ static void record_gp_stall_check_time (void );
kernel/rcu/tree_plugin.h +1 -35
@@ -595,7 +595,7 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t)* evaluate safety in terms of interrupt, softirq, and preemption * disabling. */ -static void rcu_preempt_deferred_qs (struct task_struct *t) +void rcu_preempt_deferred_qs (struct task_struct *t) {unsigned long flags;
@@ -1283,37 +1283,3 @@ static void rcu_bind_gp_kthread(void)return ;housekeeping_affine (current,HK_FLAG_RCU ); } - -/* Record the current task on dyntick-idle entry. */ -static __always_inline void rcu_dynticks_task_enter(void) -{ -#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) -WRITE_ONCE (current->rcu_tasks_idle_cpu,smp_processor_id ()); -#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ -} - -/* Record no current task on dyntick-idle exit. */ -static __always_inline void rcu_dynticks_task_exit(void) -{ -#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) -WRITE_ONCE (current->rcu_tasks_idle_cpu,-1 ); -#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ -} - -/* Turn on heavyweight RCU tasks trace readers on idle/user entry. */ -static __always_inline void rcu_dynticks_task_trace_enter(void) -{ -#ifdef CONFIG_TASKS_TRACE_RCU -if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) - current->trc_reader_special.b.need_mb = true; -#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ -} - -/* Turn off heavyweight RCU tasks trace readers on idle/user exit. */ -static __always_inline void rcu_dynticks_task_trace_exit(void) -{ -#ifdef CONFIG_TASKS_TRACE_RCU -if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) - current->trc_reader_special.b.need_mb = false; -#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ -}
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 13/19 rcu/context-tracking: Move deferred nocb resched to context tracking
In reply to Frederic WeisbeckerTo prepare for migrating the RCU eqs accounting code to context tracking, split the last-resort deferred nocb resched from rcu_user_enter() and move it into a separate call from context tracking.
--- include/linux/rcutree.h | 6 ++++++ kernel/context_tracking.c | 8 ++++++++ kernel/rcu/tree.c | 15 ++------------- 3 files changed, 16 insertions(+), 13 deletions(-)
include/linux/rcutree.h +6 -0
@@ -78,4 +78,10 @@ int rcutree_dead_cpu(unsigned int cpu);int rcutree_dying_cpu (unsigned int cpu);void rcu_cpu_starting (unsigned int cpu); +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +void rcu_irq_work_resched (void ); +#else +static inline void rcu_irq_work_resched (void ) { } +#endif +#endif /* __LINUX_RCUTREE_H */
kernel/context_tracking.c +8 -0
@@ -60,6 +60,8 @@ static __always_inline void context_tracking_recursion_exit(void)*/ void noinstr __ct_user_enter(enum ctx_state state) { +lockdep_assert_irqs_disabled (); +/* Kernel threads aren't supposed to go to userspace */ WARN_ON_ONCE (!current->mm);
@@ -81,6 +83,12 @@ void noinstr __ct_user_enter(enum ctx_state state)vtime_user_enter (current);instrumentation_end (); } +/* +* Other than generic entry implementation, we may be past the last +* rescheduling opportunity in the entry code. Trigger a self IPI +* that will fire and reschedule once we resume in user/guest mode. +*/ +rcu_irq_work_resched ();rcu_user_enter (); }/*
kernel/rcu/tree.c +2 -13
@@ -686,7 +686,7 @@ static DEFINE_PER_CPU(struct irq_work, late_wakeup_work) =* last resort is to fire a local irq_work that will trigger a reschedule once IRQs * get re-enabled again. */ -noinstr static void rcu_irq_work_resched(void) +noinstr void rcu_irq_work_resched(void) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data);
@@ -702,10 +702,7 @@ noinstr static void rcu_irq_work_resched(void) }instrumentation_end (); } - -#else -static inline void rcu_irq_work_resched (void ) { } -#endif +#endif /* #if !defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK) */ /** * rcu_user_enter - inform RCU that we are resuming userspace.
@@ -720,14 +717,6 @@ static inline void rcu_irq_work_resched(void) { }*/ noinstr void rcu_user_enter(void) { -lockdep_assert_irqs_disabled (); - -/* -* Other than generic entry implementation, we may be past the last -* rescheduling opportunity in the entry code. Trigger a self IPI -* that will fire and reschedule once we resume in user/guest mode. -*/ -rcu_irq_work_resched ();rcu_eqs_enter (true); }
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 11/19 rcu/context_tracking: Move dynticks_nesting to context tracking
In reply to Frederic WeisbeckerThe RCU eqs tracking is going to be performed by the context tracking subsystem. The related nesting counters thus need to be moved to the context tracking structure.
--- include/linux/context_tracking_state.h | 1 + kernel/context_tracking.c | 1 + kernel/rcu/tree.c | 31 +++++++++++++------------- kernel/rcu/tree.h | 1 - kernel/rcu/tree_stall.h | 3 ++- 5 files changed, 20 insertions(+), 17 deletions(-)
include/linux/context_tracking_state.h +1 -0
@@ -24,6 +24,7 @@ struct context_tracking { } state;#endif atomic_t dynticks;/* Even value for idle, else odd. */ +long dynticks_nesting;/* Track process nesting level. */ };#ifdef CONFIG_CONTEXT_TRACKING
kernel/context_tracking.c +1 -0
@@ -234,6 +234,7 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks_nesting =1 , .dynticks =ATOMIC_INIT (1 ), };EXPORT_SYMBOL_GPL (context_tracking);
kernel/rcu/tree.c +16 -15
@@ -75,7 +75,6 @@/* Data structures. */ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { - .dynticks_nesting =1 , .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , #ifdef CONFIG_RCU_NOCB_CPU .cblist.flags = SEGCBLIST_RCU_CORE,
@@ -441,7 +440,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)lockdep_assert_irqs_disabled ();/* Check for counter underflows */ -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <0 ,"RCU dynticks_nesting counter underflow!" );RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 ,"RCU dynticks_nmi_nesting counter underflow/zero!" );
@@ -457,7 +456,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)WARN_ON_ONCE (!nesting && !is_idle_task (current));/* Does CPU appear to be idle from an RCU standpoint? */ -return __this_cpu_read (rcu_data.dynticks_nesting) ==0 ; +return __this_cpu_read (context_tracking.dynticks_nesting) ==0 ; }#define DEFAULT_RCU_BLIMIT (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) ? 1000 : 10)
@@ -624,16 +623,16 @@ static noinstr void rcu_eqs_enter(bool user)WARN_ON_ONCE (rdp->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE );WRITE_ONCE (rdp->dynticks_nmi_nesting,0 );WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && - rdp->dynticks_nesting ==0 ); -if (rdp->dynticks_nesting !=1 ) { + ct->dynticks_nesting ==0 ); +if (ct->dynticks_nesting !=1 ) {// RCU will still be watching, so just do accounting and leave. - rdp->dynticks_nesting--; + ct->dynticks_nesting--;return ; }lockdep_assert_irqs_disabled ();instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), rdp->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current);
@@ -641,7 +640,7 @@ static noinstr void rcu_eqs_enter(bool user)instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks));instrumentation_end (); -WRITE_ONCE (rdp->dynticks_nesting,0 );/* Avoid irq-access tearing. */ +WRITE_ONCE (ct->dynticks_nesting,0 );/* Avoid irq-access tearing. */ // RCU is watching here ... rcu_dynticks_eqs_enter ();// ... but is no longer watching here.
@@ -798,7 +797,7 @@ void rcu_irq_exit_check_preempt(void) {lockdep_assert_irqs_disabled (); -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <=0 ,"RCU dynticks_nesting counter underflow/zero!" ); RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) != DYNTICK_IRQ_NONIDLE,
@@ -824,11 +823,11 @@ static void noinstr rcu_eqs_exit(bool user)lockdep_assert_irqs_disabled (); rdp =this_cpu_ptr (&rcu_data); - oldval = rdp->dynticks_nesting; + oldval = ct->dynticks_nesting;WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && oldval <0 );if (oldval) {// RCU was already watching, so just do accounting and leave. - rdp->dynticks_nesting++; + ct->dynticks_nesting++;return ; }rcu_dynticks_task_exit ();
@@ -840,9 +839,9 @@ static void noinstr rcu_eqs_exit(bool user)// instrumentation for the noinstr rcu_dynticks_eqs_exit() instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -trace_rcu_dyntick (TPS ("End" ), rdp->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); -WRITE_ONCE (rdp->dynticks_nesting,1 ); +WRITE_ONCE (ct->dynticks_nesting,1 );WARN_ON_ONCE (rdp->dynticks_nmi_nesting);WRITE_ONCE (rdp->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE );instrumentation_end ();
@@ -4122,12 +4121,13 @@ static void rcu_init_new_rnp(struct rcu_node *rnp_leaf)static void __init rcu_boot_init_percpu_data (int cpu) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);/* Set up local state, ensuring consistent view of global state. */ rdp->grpmask =leaf_node_cpu_bit (rdp->mynode, cpu);INIT_WORK (&rdp->strict_work, strict_work_handler); -WARN_ON_ONCE (rdp->dynticks_nesting !=1 ); +WARN_ON_ONCE (ct->dynticks_nesting !=1 );WARN_ON_ONCE (rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu))); rdp->barrier_seq_snap = rcu_state.barrier_sequence; rdp->rcu_ofl_gp_seq = rcu_state.gp_seq;
@@ -4152,6 +4152,7 @@ rcu_boot_init_percpu_data(int cpu)int rcutree_prepare_cpu (unsigned int cpu) {unsigned long flags; +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp =rcu_get_root ();
@@ -4160,7 +4161,7 @@ int rcutree_prepare_cpu(unsigned int cpu) rdp->qlen_last_fqs_check =0 ; rdp->n_force_qs_snap =READ_ONCE (rcu_state.n_force_qs); rdp->blimit = blimit; - rdp->dynticks_nesting =1 ;/* CPU not up, no tearing. */ + ct->dynticks_nesting =1 ;/* CPU not up, no tearing. */ raw_spin_unlock_rcu_node (rnp);/* irqs remain disabled. */ /*
kernel/rcu/tree.h +0 -1
@@ -186,7 +186,6 @@ struct rcu_data {/* 3) dynticks interface. */ int dynticks_snap;/* Per-GP tracking for dynticks. */ -long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */
kernel/rcu/tree_stall.h +2 -1
@@ -429,6 +429,7 @@ static void print_cpu_stall_info(int cpu) {unsigned long delta;bool falsepositive; +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);char *ticks_title;unsigned long ticks_value;
@@ -459,7 +460,7 @@ static void print_cpu_stall_info(int cpu)"!." [!delta], ticks_value, ticks_title,rcu_dynticks_snap (cpu) &0xfff , - rdp->dynticks_nesting, rdp->dynticks_nmi_nesting, + ct->dynticks_nesting, rdp->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu),data_race (rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart, falsepositive ? " (false positive?)" : "");
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 10/19 rcu/context_tracking: Move dynticks counter to context tracking
In reply to Frederic WeisbeckerIn order to prepare for merging RCU dynticks counter into the context tracking state, move the rcu_data's dynticks field to the context tracking structure. It will later be mixed within the context tracking state itself.
--- include/linux/context_tracking_state.h | 10 ++++- kernel/context_tracking.c | 9 ++-- kernel/rcu/tree.c | 59 ++++++++++++++------------ kernel/rcu/tree.h | 1 - kernel/rcu/tree_exp.h | 2 +- kernel/rcu/tree_stall.h | 4 +- 6 files changed, 48 insertions(+), 37 deletions(-)
include/linux/context_tracking_state.h +8 -2
@@ -7,6 +7,7 @@#include <linux/context_tracking_irq.h> struct context_tracking { +#ifdef CONFIG_CONTEXT_TRACKING_USER /* * When active is false, probes are unset in order * to minimize overhead: TIF flags are cleared
@@ -21,11 +22,16 @@ struct context_tracking {CONTEXT_USER ,CONTEXT_GUEST , } state; +#endif +atomic_t dynticks;/* Even value for idle, else odd. */ }; -#ifdef CONFIG_CONTEXT_TRACKING_USER -extern struct static_key_false context_tracking_key; +#ifdef CONFIG_CONTEXT_TRACKING DECLARE_PER_CPU(struct context_tracking, context_tracking); +#endif + +#ifdef CONFIG_CONTEXT_TRACKING_USER +extern struct static_key_false context_tracking_key; static __always_inline bool context_tracking_enabled(void) {
kernel/context_tracking.c +6 -3
@@ -30,9 +30,6 @@DEFINE_STATIC_KEY_FALSE (context_tracking_key);EXPORT_SYMBOL_GPL (context_tracking_key); -DEFINE_PER_CPU(struct context_tracking, context_tracking); -EXPORT_SYMBOL_GPL (context_tracking); - static noinstr bool context_tracking_recursion_enter(void) {int recursion;
@@ -236,6 +233,12 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ +DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks =ATOMIC_INIT (1 ), +}; +EXPORT_SYMBOL_GPL (context_tracking); + +void ct_idle_enter (void ) {rcu_idle_enter ();
kernel/rcu/tree.c +31 -28
212 lines not on this page · raw message
kernel/rcu/tree.h +0 -1
@@ -188,7 +188,6 @@ struct rcu_data {int dynticks_snap;/* Per-GP tracking for dynticks. */ long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ -atomic_t dynticks;/* Even value for idle, else odd. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */ bool rcu_forced_tick;/* Forced tick to provide QS. */
kernel/rcu/tree_exp.h +1 -1
@@ -358,7 +358,7 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp) !(rnp->qsmaskinitnext & mask)) { mask_ofl_test |= mask; } else { - snap =rcu_dynticks_snap (rdp); + snap =rcu_dynticks_snap (cpu);if (rcu_dynticks_in_eqs (snap)) mask_ofl_test |= mask;else
kernel/rcu/tree_stall.h +2 -2
@@ -448,7 +448,7 @@ static void print_cpu_stall_info(int cpu) } delta =rcu_seq_ctr (rdp->mynode->gp_seq - rdp->rcu_iw_gp_seq); falsepositive =rcu_is_gp_kthread_starving (NULL ) && -rcu_dynticks_in_eqs (rcu_dynticks_snap (rdp)); +rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu)); pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%03x/%ld/%#lx softirq=%u/%u fqs=%ld %s\n", cpu, "O."[!!cpu_online(cpu)],
@@ -458,7 +458,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int )min (delta,9UL ) +'0' :"!." [!delta], ticks_value, ticks_title, -rcu_dynticks_snap (rdp) &0xfff , +rcu_dynticks_snap (cpu) &0xfff , rdp->dynticks_nesting, rdp->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu), data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 15/19 rcu/context-tracking: Remove unused and/or unecessary middle functions
In reply to Frederic WeisbeckerSome eqs functions are now only used internally by context tracking, so their public declarations can be removed.
Also middle functions such as rcu_user_*() and rcu_idle_*() which now directly call to rcu_eqs_enter() and rcu_eqs_exit() can be wiped out as well.
--- include/linux/hardirq.h | 8 --- include/linux/rcutiny.h | 2 - include/linux/rcutree.h | 2 - kernel/context_tracking.c | 137 ++++++++++++-------------------------- 4 files changed, 44 insertions(+), 105 deletions(-)
include/linux/hardirq.h +0 -8
@@ -92,14 +92,6 @@ void irq_exit_rcu(void);#define arch_nmi_exit () do { } while (0)#endif -#ifdef CONFIG_TINY_RCU -static inline void rcu_nmi_enter (void ) { } -static inline void rcu_nmi_exit (void ) { } -#else -extern void rcu_nmi_enter (void ); -extern void rcu_nmi_exit (void ); -#endif -/* * NMI vs Tracing * --------------
include/linux/rcutiny.h +0 -2
@@ -96,8 +96,6 @@ static inline int rcu_needs_cpu(void)static inline void rcu_virt_note_context_switch (int cpu) { }static inline void rcu_cpu_stall_reset (void ) { }static inline int rcu_jiffies_till_stall_check (void ) {return 21 *HZ ; } -static inline void rcu_idle_enter (void ) { } -static inline void rcu_idle_exit (void ) { }static inline void rcu_irq_exit_check_preempt (void ) { }#define rcu_is_idle_cpu (cpu) \ (is_idle_task(current) && !in_nmi() && !in_hardirq() && !in_serving_softirq())
include/linux/rcutree.h +0 -2
@@ -49,8 +49,6 @@ unsigned long start_poll_synchronize_rcu(void);bool poll_state_synchronize_rcu (unsigned long oldstate);void cond_synchronize_rcu (unsigned long oldstate); -void rcu_idle_enter (void ); -void rcu_idle_exit (void );bool rcu_is_idle_cpu (int cpu);#ifdef CONFIG_PROVE_RCU
kernel/context_tracking.c +44 -93
194 lines not on this page · raw message
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 8/19 context_tracking: Take NMI eqs entrypoints over RCU
In reply to Frederic WeisbeckerThe RCU dynticks counter is going to be merged into the context tracking subsystem. Prepare with moving the NMI extended quiescent states entrypoints to context tracking. For now those are dumb redirection to existing RCU calls.
--- Documentation/RCU/Design/Requirements/Requirements.rst | 2 +- arch/Kconfig | 2 +- arch/arm64/kernel/entry-common.c | 8 ++++---- include/linux/context_tracking_irq.h | 4 ++++ include/linux/hardirq.h | 4 ++-- kernel/context_tracking.c | 10 ++++++++++ kernel/entry/common.c | 4 ++-- kernel/extable.c | 4 ++-- kernel/trace/trace.c | 2 +- 9 files changed, 27 insertions(+), 13 deletions(-)
Documentation/RCU/Design/Requirements/Requirements.rst +1 -1
@@ -1847,7 +1847,7 @@ normal interrupts. One way that this can happen is for code that directly invokes ct_irq_enter() and ct_irq_exit() to be called from an NMI handler. This astonishing fact of life prompted the current code structure, which has ct_irq_enter() invoking -rcu_nmi_enter() and ct_irq_exit() invoking rcu_nmi_exit(). +ct_nmi_enter() and ct_irq_exit() invoking ct_nmi_exit(). And yes, I also learned of this requirement the hard way. Loadable Modules
arch/Kconfig +1 -1
@@ -785,7 +785,7 @@ config HAVE_CONTEXT_TRACKING_USER_OFFSTACK - Critical entry code isn't preemptible (or better yet: not interruptible). - - No use of RCU read side critical sections, unless rcu_nmi_enter() + - No use of RCU read side critical sections, unless ct_nmi_enter() got called. - No use of instrumentation, unless instrumentation_begin() got called.
arch/arm64/kernel/entry-common.c +4 -4
@@ -158,7 +158,7 @@ static void noinstr arm64_enter_nmi(struct pt_regs *regs)__nmi_enter ();lockdep_hardirqs_off (CALLER_ADDR0 );lockdep_hardirq_enter (); -rcu_nmi_enter (); +ct_nmi_enter ();trace_hardirqs_off_finish ();ftrace_nmi_enter ();
@@ -179,7 +179,7 @@ static void noinstr arm64_exit_nmi(struct pt_regs *regs)lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); } -rcu_nmi_exit (); +ct_nmi_exit ();lockdep_hardirq_exit ();if (restore)lockdep_hardirqs_on (CALLER_ADDR0 );
@@ -196,7 +196,7 @@ static void noinstr arm64_enter_el1_dbg(struct pt_regs *regs) regs->lockdep_hardirqs =lockdep_hardirqs_enabled ();lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_nmi_enter (); +ct_nmi_enter ();trace_hardirqs_off_finish (); }
@@ -215,7 +215,7 @@ static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); } -rcu_nmi_exit (); +ct_nmi_exit ();if (restore)lockdep_hardirqs_on (CALLER_ADDR0 ); }
include/linux/context_tracking_irq.h +4 -0
@@ -7,11 +7,15 @@ void ct_irq_enter(void);void ct_irq_exit (void );void ct_irq_enter_irqson (void );void ct_irq_exit_irqson (void ); +void ct_nmi_enter (void ); +void ct_nmi_exit (void );#else static inline void ct_irq_enter (void ) { }static inline void ct_irq_exit (void ) { }static inline void ct_irq_enter_irqson (void ) { }static inline void ct_irq_exit_irqson (void ) { } +static inline void ct_nmi_enter (void ) { } +static inline void ct_nmi_exit (void ) { }#endif #endif
include/linux/hardirq.h +2 -2
@@ -124,7 +124,7 @@ extern void rcu_nmi_exit(void); do { \ __nmi_enter(); \ lockdep_hardirq_enter(); \ - rcu_nmi_enter(); \ + ct_nmi_enter(); \ instrumentation_begin(); \ ftrace_nmi_enter(); \ instrumentation_end(); \
@@ -143,7 +143,7 @@ extern void rcu_nmi_exit(void);instrumentation_begin (); \ftrace_nmi_exit (); \instrumentation_end (); \ -rcu_nmi_exit (); \ +ct_nmi_exit (); \lockdep_hardirq_exit (); \__nmi_exit (); \ }while (0 )
kernel/context_tracking.c +10 -0
@@ -267,3 +267,13 @@ void ct_irq_exit_irqson(void) {rcu_irq_exit_irqson (); } + +noinstr void ct_nmi_enter(void) +{ +rcu_nmi_enter (); +} + +noinstr void ct_nmi_exit(void) +{ +rcu_nmi_exit (); +}
kernel/entry/common.c +2 -2
@@ -449,7 +449,7 @@ irqentry_state_t noinstr irqentry_nmi_enter(struct pt_regs *regs)__nmi_enter ();lockdep_hardirqs_off (CALLER_ADDR0 );lockdep_hardirq_enter (); -rcu_nmi_enter (); +ct_nmi_enter ();instrumentation_begin ();trace_hardirqs_off_finish ();
@@ -469,7 +469,7 @@ void noinstr irqentry_nmi_exit(struct pt_regs *regs, irqentry_state_t irq_state) }instrumentation_end (); -rcu_nmi_exit (); +ct_nmi_exit ();lockdep_hardirq_exit ();if (irq_state.lockdep)lockdep_hardirqs_on (CALLER_ADDR0 );
kernel/extable.c +2 -2
@@ -113,7 +113,7 @@ int kernel_text_address(unsigned long addr)/* Treat this like an NMI as it can happen anywhere */ if (no_rcu) -rcu_nmi_enter (); +ct_nmi_enter ();if (is_module_text_address (addr)) goto out;
@@ -126,7 +126,7 @@ int kernel_text_address(unsigned long addr) ret =0 ; out:if (no_rcu) -rcu_nmi_exit (); +ct_nmi_exit ();return ret; }
kernel/trace/trace.c +1 -1
@@ -3086,7 +3086,7 @@ void __trace_stack(struct trace_array *tr, unsigned int trace_ctx, }/* -* When an NMI triggers, RCU is enabled via rcu_nmi_enter(), +* When an NMI triggers, RCU is enabled via ct_nmi_enter(), * but if the above rcu_is_watching() failed, then the NMI * triggered someplace critical, and ct_irq_enter() should * not be called from NMI.
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 18/19 rcu/context_tracking: Merge dynticks counter and context tracking states
In reply to Frederic WeisbeckerUpdating the context tracking state and the RCU dynticks counter atomically in a single operation is a first step towards improving CPU isolation. This makes the context tracking state updates fully ordered and therefore allow for later enhancements such as postponing some work while a task is running isolated in userspace until it ever comes back to the kernel.
The state field becomes divided in two parts:
1) Lower bits for context tracking state:
CONTEXT_IDLE = 1,
CONTEXT_USER = 2,
CONTEXT_GUEST = 4,
A value of 0 means we are in CONTEXT_KERNEL.
2) Higher bits for RCU eqs dynticks counting:
RCU_DYNTICKS_IDX = 8
The dynticks counting is always incremented by this value. (state & RCU_DYNTICKS_IDX) means we are NOT in an extended quiescent state. This makes the chance for a collision more likely between two RCU dynticks snapshots but wrapping up 24 bits of eqs dynticks increments still takes some bad luck (also rdp.dynticks_snap could be converted from int to long?)
Some RCU eqs functions have been renamed to better reflect their broader scope that now include context tracking state.
--- include/linux/context_tracking.h | 4 +- include/linux/context_tracking_state.h | 33 ++++++--- kernel/context_tracking.c | 92 +++++++++++++------------- kernel/rcu/tree.c | 13 ++-- kernel/rcu/tree_stall.h | 2 +- 5 files changed, 81 insertions(+), 63 deletions(-)
include/linux/context_tracking.h +2 -2
@@ -110,7 +110,7 @@ static inline void context_tracking_init(void) { }#ifdef CONFIG_CONTEXT_TRACKING extern void ct_idle_enter (void );extern void ct_idle_exit (void ); -extern unsigned long rcu_dynticks_inc (int incby); +extern unsigned long ct_state_inc (int incby);/* * Is the current CPU in an extended quiescent state?
@@ -119,7 +119,7 @@ extern unsigned long rcu_dynticks_inc(int incby);*/ static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) { -return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); +return !(arch_atomic_read (this_cpu_ptr (&context_tracking.state)) &RCU_DYNTICKS_IDX ); }#else
include/linux/context_tracking_state.h +25 -8
@@ -9,13 +9,29 @@/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ #define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) +enum { +CONTEXT_IDLE_OFFSET =0 , +CONTEXT_USER_OFFSET , +CONTEXT_GUEST_OFFSET , +CONTEXT_MAX_OFFSET , +}; +enum ctx_state {CONTEXT_DISABLED =-1 ,/* returned by ct_state() if unknown */ CONTEXT_KERNEL =0 , -CONTEXT_USER , -CONTEXT_GUEST , +CONTEXT_IDLE =BIT (CONTEXT_IDLE_OFFSET ), +CONTEXT_USER =BIT (CONTEXT_USER_OFFSET ), +CONTEXT_GUEST =BIT (CONTEXT_GUEST_OFFSET ), +CONTEXT_MAX =BIT (CONTEXT_MAX_OFFSET ), }; +/* Even value for idle, else odd. */ +#define RCU_DYNTICKS_SHIFT CONTEXT_MAX_OFFSET +#define RCU_DYNTICKS_IDX CONTEXT_MAX + +#define CT_STATE_MASK (CONTEXT_MAX - 1) +#define CT_DYNTICKS_MASK (~CT_STATE_MASK) +struct context_tracking {#ifdef CONFIG_CONTEXT_TRACKING_USER /*
@@ -26,9 +42,8 @@ struct context_tracking {*/ bool active;int recursion; +#endif atomic_t state; -#endif -atomic_t dynticks;/* Even value for idle, else odd. */ long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ };
@@ -38,24 +53,26 @@ DECLARE_PER_CPU(struct context_tracking, context_tracking); static __always_inline int __ct_state(void) { -return atomic_read (this_cpu_ptr (&context_tracking.state)); +return atomic_read (this_cpu_ptr (&context_tracking.state)) &CT_STATE_MASK ; } static __always_inline int ct_dynticks(void) { -return atomic_read (this_cpu_ptr (&context_tracking.dynticks)); +return atomic_read (this_cpu_ptr (&context_tracking.state)) &CT_DYNTICKS_MASK ; } static __always_inline int ct_dynticks_cpu(int cpu) {struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -return atomic_read (&ct->dynticks); + +return atomic_read (&ct->state) &CT_DYNTICKS_MASK ; } static __always_inline int ct_dynticks_cpu_acquire(int cpu) {struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -return atomic_read_acquire (&ct->state); + +return atomic_read_acquire (&ct->state) &CT_DYNTICKS_MASK ; }#endif
kernel/context_tracking.c +47 -45
226 lines not on this page · raw message
kernel/rcu/tree.c +6 -7
@@ -272,9 +272,9 @@ void rcu_softirq_qs(void)*/ static void rcu_dynticks_eqs_online (void ) { -if (ct_dynticks () &0x1 ) +if (ct_dynticks () &RCU_DYNTICKS_IDX )return ; -rcu_dynticks_inc (1 ); +ct_state_inc (RCU_DYNTICKS_IDX ); }/*
@@ -293,7 +293,7 @@ static int rcu_dynticks_snap(int cpu)*/ static bool rcu_dynticks_in_eqs (int snap) { -return !(snap &0x1 ); +return !(snap &RCU_DYNTICKS_IDX ); }/* Return true if the specified CPU is currently idle from an RCU viewpoint. */
@@ -321,8 +321,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =ct_dynticks_cpu (cpu) & ~0x1 ; - + snap =ct_dynticks_cpu (cpu) & ~RCU_DYNTICKS_IDX ;smp_rmb ();// Order ->dynticks and *vp reads. if (READ_ONCE (*vp))return false;// Non-zero, so report failure;
@@ -348,9 +347,9 @@ notrace void rcu_momentary_dyntick_idle(void)int seq;raw_cpu_write (rcu_data.rcu_need_heavy_qs, false); - seq =rcu_dynticks_inc (2 ); + seq =ct_state_inc (2 *RCU_DYNTICKS_IDX );/* It is illegal to call this from idle state. */ -WARN_ON_ONCE (!(seq &0x1 )); +WARN_ON_ONCE (!(seq &RCU_DYNTICKS_IDX ));rcu_preempt_deferred_qs (current); }EXPORT_SYMBOL_GPL (rcu_momentary_dyntick_idle);
kernel/rcu/tree_stall.h +1 -1
@@ -459,7 +459,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int )min (delta,9UL ) +'0' :"!." [!delta], ticks_value, ticks_title, -rcu_dynticks_snap (cpu) &0xfff , + (rcu_dynticks_snap (cpu) >>RCU_DYNTICKS_SHIFT ) &0xfff , ct->dynticks_nesting, ct->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu), data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 19/19 context_tracking: Exempt CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
In reply to Frederic WeisbeckerSince a CPU may save the state of the context tracking using exception_enter() before calling into schedule(), we need all CPUs in the system to track user <-> kernel transitions and not just those that really need it (nohz_full CPUs).
The following illustrates the issue that could otherwise happen:
CPU 0 (not tracking) CPU 1 (tracking)
------------------- --------------------
// we are past user_enter()
// but this CPU is always in
// CONTEXT_KERNEL
// because it doesn't track user <-> kernel
ctx = exception_enter(); //ctx == CONTEXT_KERNEL
schedule();
===========================================>
return from schedule();
exception_exit(ctx);
//go to user in CONTEXT_KERNELHowever CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK doesn't play those games because schedule() can't be called between user_enter() and user_exit() under such config. In this situation we can spare context tracking on the CPUs that don't need it.
--- kernel/context_tracking.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/context_tracking.c +4 -3
@@ -374,7 +374,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* when the CPU runs in userspace. */ ct_kernel_exit (true,RCU_DYNTICKS_IDX + state); - }else { + }else if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK )) {/* * Even if context tracking is disabled on this CPU, because it's outside * the full dynticks mask for example, we still have to keep track of the
@@ -384,7 +384,8 @@ void noinstr __ct_user_enter(enum ctx_state state)* handler and then migrate to another CPU, that new CPU must know where * the exception returns by the time we call exception_exit(). * This information can only be provided by the previous CPU when it called -* exception_enter(). +* exception_enter(). CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK is +* excused though because it doesn't use exception_enter(). * OTOH we can spare the calls to vtime and RCU when context_tracking.active * is false because we know that CPU is not tickless. */
@@ -460,7 +461,7 @@ void noinstr __ct_user_exit(enum ctx_state state)trace_user_exit (0 );instrumentation_end (); } - }else { + }else if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK )) {atomic_sub (state, &ct->state); } }
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 17/19 rcu/context-tracking: Use accessor for dynticks counter value
In reply to Frederic WeisbeckerThe dynticks counter value is going to join the context tracking state in a single field. Use an accessor for this value to make the transition easier for all readers.
--- include/linux/context_tracking_state.h | 17 +++++++++++++++++ kernel/context_tracking.c | 10 +++++----- kernel/rcu/tree.c | 13 ++++--------- 3 files changed, 26 insertions(+), 14 deletions(-)
include/linux/context_tracking_state.h +17 -0
@@ -40,6 +40,23 @@ static __always_inline int __ct_state(void) {return atomic_read (this_cpu_ptr (&context_tracking.state)); } + +static __always_inline int ct_dynticks(void) +{ +return atomic_read (this_cpu_ptr (&context_tracking.dynticks)); +} + +static __always_inline int ct_dynticks_cpu(int cpu) +{ +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); +return atomic_read (&ct->dynticks); +} + +static __always_inline int ct_dynticks_cpu_acquire(int cpu) +{ +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); +return atomic_read_acquire (&ct->state); +}#endif #ifdef CONFIG_CONTEXT_TRACKING_USER
kernel/context_tracking.c +5 -5
@@ -133,7 +133,7 @@ static noinstr void rcu_eqs_enter(bool user)lockdep_assert_irqs_disabled ();instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,ct_dynticks ());WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current);
@@ -178,7 +178,7 @@ noinstr void ct_nmi_exit(void)*/ if (ct->dynticks_nmi_nesting !=1 ) {trace_rcu_dyntick (TPS ("--=" ), ct->dynticks_nmi_nesting, ct->dynticks_nmi_nesting -2 , -atomic_read (&ct->dynticks)); +ct_dynticks ());WRITE_ONCE (ct->dynticks_nmi_nesting,/* No store tearing. */ ct->dynticks_nmi_nesting -2 );instrumentation_end ();
@@ -186,7 +186,7 @@ noinstr void ct_nmi_exit(void) }/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ -trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,ct_dynticks ());WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ // instrumentation for the noinstr rcu_dynticks_eqs_enter()
@@ -231,7 +231,7 @@ static void noinstr rcu_eqs_exit(bool user)// instrumentation for the noinstr rcu_dynticks_eqs_exit() instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,ct_dynticks ());WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));WRITE_ONCE (ct->dynticks_nesting,1 );WARN_ON_ONCE (ct->dynticks_nmi_nesting);
@@ -292,7 +292,7 @@ noinstr void ct_nmi_enter(void)trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), ct->dynticks_nmi_nesting, - ct->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks)); + ct->dynticks_nmi_nesting + incby,ct_dynticks ());instrumentation_end ();WRITE_ONCE (ct->dynticks_nmi_nesting,/* Prevent store tearing. */ ct->dynticks_nmi_nesting + incby);
kernel/rcu/tree.c +4 -9
@@ -272,9 +272,7 @@ void rcu_softirq_qs(void)*/ static void rcu_dynticks_eqs_online (void ) { -struct context_tracking *ct =this_cpu_ptr (&context_tracking); - -if (atomic_read (&ct->dynticks) &0x1 ) +if (ct_dynticks () &0x1 )return ;rcu_dynticks_inc (1 ); }
@@ -285,10 +283,8 @@ static void rcu_dynticks_eqs_online(void)*/ static int rcu_dynticks_snap (int cpu) { -struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -smp_mb ();// Fundamental RCU ordering guarantee. -return atomic_read_acquire (&ct->dynticks); +return ct_dynticks_cpu_acquire (cpu); }/*
@@ -322,11 +318,10 @@ static bool rcu_dynticks_in_eqs_since(struct rcu_data *rdp, int snap)*/ bool rcu_dynticks_zero_in_eqs (int cpu,int *vp) { -struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =atomic_read (&ct->dynticks) & ~0x1 ; + snap =ct_dynticks_cpu (cpu) & ~0x1 ;smp_rmb ();// Order ->dynticks and *vp reads. if (READ_ONCE (*vp))
@@ -334,7 +329,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)smp_rmb ();// Order *vp read and ->dynticks re-read. // If still in the same extended quiescent state, we are good! -return snap ==atomic_read (&ct->dynticks); +return snap ==ct_dynticks_cpu (cpu); }/*
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerPATCH 16/19 context_tracking: Convert state to atomic_t
In reply to Frederic WeisbeckerContext tracking's state and dynticks counter are going to be merged in a single field so that both updates can happen atomically and at the same time. Prepare for that with converting the state into an atomic_t.
--- include/linux/context_tracking.h | 18 ++--------- include/linux/context_tracking_state.h | 42 +++++++++++++++++++++----- kernel/context_tracking.c | 15 +++++---- 3 files changed, 47 insertions(+), 28 deletions(-)
include/linux/context_tracking.h +3 -15
@@ -56,7 +56,7 @@ static inline enum ctx_state exception_enter(void) !context_tracking_enabled())return 0 ; - prev_ctx =this_cpu_read (context_tracking.state); + prev_ctx =__ct_state ();if (prev_ctx !=CONTEXT_KERNEL )ct_user_exit (prev_ctx);
@@ -86,26 +86,14 @@ static __always_inline void context_tracking_guest_exit(void)__ct_user_exit (CONTEXT_GUEST ); } -/** -* ct_state() - return the current context tracking state if known -* -* Returns the current cpu's context tracking state if context tracking -* is enabled. If context tracking is disabled, returns -* CONTEXT_DISABLED. This should be used primarily for debugging. -*/ -static __always_inline enum ctx_state ct_state(void) -{ -return context_tracking_enabled () ? -this_cpu_read (context_tracking.state) :CONTEXT_DISABLED ; -}#else static inline void user_enter (void ) { }static inline void user_exit (void ) { }static inline void user_enter_irqoff (void ) { }static inline void user_exit_irqoff (void ) { } -static inline enum ctx_state exception_enter (void ) {return 0 ; } +static inline int exception_enter (void ) {return 0 ; }static inline void exception_exit (enum ctx_state prev_ctx) { } -static inline enum ctx_state ct_state (void ) {return CONTEXT_DISABLED ; } +static inline int ct_state (void ) {return -1 ; } static __always_inline bool context_tracking_guest_enter(void) { return false; }static inline void context_tracking_guest_exit (void ) { }
include/linux/context_tracking_state.h +35 -7
68 lines not on this page · raw message
kernel/context_tracking.c +9 -6
@@ -337,6 +337,7 @@ static __always_inline void context_tracking_recursion_exit(void)*/ void noinstr __ct_user_enter(enum ctx_state state) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);lockdep_assert_irqs_disabled ();/* Kernel threads aren't supposed to go to userspace */
@@ -345,8 +346,8 @@ void noinstr __ct_user_enter(enum ctx_state state)if (!context_tracking_recursion_enter ())return ; -if (__this_cpu_read (context_tracking.state) != state) { -if (__this_cpu_read (context_tracking.active)) { +if (__ct_state () != state) { +if (ct->active) {/* * At this stage, only low level arch entry code remains and * then we'll run in userspace. We can assume there won't be
@@ -387,7 +388,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* OTOH we can spare the calls to vtime and RCU when context_tracking.active * is false because we know that CPU is not tickless. */ -__this_cpu_write (context_tracking.state, state); +atomic_set (&ct->state, state); }context_tracking_recursion_exit (); }
@@ -440,11 +441,13 @@ NOKPROBE_SYMBOL(user_enter_callable);*/ void noinstr __ct_user_exit(enum ctx_state state) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking); +if (!context_tracking_recursion_enter ())return ; -if (__this_cpu_read (context_tracking.state) == state) { -if (__this_cpu_read (context_tracking.active)) { +if (__ct_state () == state) { +if (ct->active) {/* * Exit RCU idle mode while entering the kernel because it can * run a RCU read side critical section anytime.
@@ -457,7 +460,7 @@ void noinstr __ct_user_exit(enum ctx_state state)instrumentation_end (); } } -__this_cpu_write (context_tracking.state,CONTEXT_KERNEL ); +atomic_set (&ct->state,CONTEXT_KERNEL ); }context_tracking_recursion_exit (); }
Signature · 1 line
2.25.1
Peter Zijlstra
maintainerRe: [PATCH 02/19] context_tracking: Rename context_tracking_user_enter/exit() to user_enter/exit_callable()
In reply to Frederic WeisbeckerQuoted 29 lines · Frederic Weisbecker
kernel/context_tracking.c +8
-3@@ -125,11 +125,16 @@ void context_tracking_enter(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_enter);EXPORT_SYMBOL_GPL (context_tracking_enter); -void context_tracking_user_enter (void ) +/** +* user_enter_callable() - Unfortunate ASM callable version of user_enter() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_enter_callable (void ) {user_enter (); } -NOKPROBE_SYMBOL (context_tracking_user_enter); +NOKPROBE_SYMBOL (user_enter_callable);/** * __ct_user_exit - Inform the context tracking that the CPU is @@ -182,11 +187,16 @@ void context_tracking_exit(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_exit);EXPORT_SYMBOL_GPL (context_tracking_exit); -void context_tracking_user_exit (void ) +/**
kernel/context_tracking.c void context_tracking_exit(enum ctx_state state) · line 199
Quoted 10 lines
kernel/context_tracking.c +6
-1+* user_exit_callable() - Unfortunate ASM callable version of user_exit() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_exit_callable (void ) {user_exit (); } -NOKPROBE_SYMBOL (context_tracking_user_exit); +NOKPROBE_SYMBOL (user_exit_callable);
I'm thinking all this wants to be noinstr instead of NOKPROBE_SYMBOL..
Peter Zijlstra
maintainerRe: [PATCH 04/19] context_tracking: Rename context_tracking_cpu_set() to context_tracking_cpu_track_user()
In reply to Frederic WeisbeckerQuoted 5 lines · Frederic Weisbecker
context_tracking_cpu_set()is called in order to tell a CPU to track user/kernel transitions. Since context tracking is going to expand in to also track transitions from/to idle/IRQ/NMIs, the scope of this function name becomes too broad and needs to be made more specific.
The previous patches did: s/context_tracking_/ct_/ on these names, and this one makes it longer still?
Peter Zijlstra
maintainerRe: [PATCH 06/19] context_tracking: Take idle eqs entrypoints over RCU
In reply to Frederic WeisbeckerQuoted 4 lines · Frederic Weisbecker
The RCU dynticks counter is going to be merged into the context tracking subsystem. Start with moving the idle extended quiescent states entrypoints to RCU. For now those are dumb redirection to existing RCU calls.
s/to/from/ right? You're taking them away from RCU and moving them to ct.
Peter Zijlstra
maintainerRe: [PATCH 03/19] context_tracking: Rename context_tracking_enter/exit() to ct_user_enter/exit()
In reply to Frederic WeisbeckerQuoted 34 lines · Frederic Weisbecker
kernel/context_tracking.c +4
-4@@ -103,7 +103,7 @@ void noinstr __ct_user_enter(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_enter); -void context_tracking_enter (enum ctx_state state) +void ct_user_enter (enum ctx_state state) {unsigned long flags;@@ -122,8 +122,8 @@ void context_tracking_enter(enum ctx_state state)__ct_user_enter (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_enter); -EXPORT_SYMBOL_GPL (context_tracking_enter); +NOKPROBE_SYMBOL (ct_user_enter); +EXPORT_SYMBOL_GPL (ct_user_enter);/** * user_enter_callable() - Unfortunate ASM callable version of user_enter() for @@ -173,7 +173,7 @@ void noinstr __ct_user_exit(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_exit); -void context_tracking_exit (enum ctx_state state) +void ct_user_exit (enum ctx_state state) {unsigned long flags;
kernel/context_tracking.c void context_tracking_exit(enum ctx_state state) · line 191
Quoted 10 lines
kernel/context_tracking.c +2
-2@@ -184,8 +184,8 @@ void context_tracking_exit(enum ctx_state state)__ct_user_exit (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_exit); -EXPORT_SYMBOL_GPL (context_tracking_exit); +NOKPROBE_SYMBOL (ct_user_exit); +EXPORT_SYMBOL_GPL (ct_user_exit);/** * user_exit_callable() - Unfortunate ASM callable version of user_exit() for
Why is it NOKPROBE but not notrace, also local_irq_*() include explicit tracepoints.
Peter Zijlstra
maintainerRe: [PATCH 09/19] rcu/context-tracking: Remove rcu_irq_enter/exit()
In reply to Frederic WeisbeckerQuoted 9 lines · Frederic Weisbecker
void
ct_irq_enter_irqson(void)
{kernel/context_tracking.c +5
-1-rcu_irq_enter_irqson (); +unsigned long flags; + +local_irq_save (flags); +ct_irq_enter (); +local_irq_restore (flags); }
kernel/context_tracking.c void ct_idle_exit(void) · line 320
Quoted 10 lines
kernel/context_tracking.c +5
-1void ct_irq_exit_irqson (void ) { -rcu_irq_exit_irqson (); +unsigned long flags; + +local_irq_save (flags); +ct_irq_exit (); +local_irq_restore (flags); }
I know you're just copying code around, but this is broken per construction :/
On the irq_enter site, local_irq_save() will hit a tracepoint, which requires RCU, which will only be made available by the ct_irq_enter(). Same in reverse for the exit case.
Re: [PATCH 19/19] context_tracking: Exempt CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
In reply to Frederic WeisbeckerHi Frederic,
Quoted 50 lines · Frederic Weisbecker
Since a CPU may save the state of the context tracking using
exception_enter()before calling intoschedule(), we need all CPUs in the system to track user <-> kernel transitions and not just those that really need it (nohz_fullCPUs).The following illustrates the issue that could otherwise happen:
CPU 0 (not tracking) CPU 1 (tracking) ------------------- -------------------- // we are past user_enter() // but this CPU is always in // CONTEXT_KERNEL // because it doesn't track user <-> kernel ctx = exception_enter(); //ctx == CONTEXT_KERNEL schedule(); ===========================================> return from schedule(); exception_exit(ctx); //go to user in CONTEXT_KERNELHowever
CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACKdoesn't play those games becauseschedule()can't be called betweenuser_enter()anduser_exit()under such config. In this situation we can spare context tracking on the CPUs that don't need it.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- kernel/context_tracking.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/context_tracking.c +0
-0
kernel/context_tracking.c void noinstr __ct_user_enter(enum ctx_state state) · line 377
Quoted 5 lines
kernel/context_tracking.c +1
-1@@ -374,7 +374,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* when the CPU runs in userspace. */ ct_kernel_exit (true,RCU_DYNTICKS_IDX + state); - }else { + }else if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK )) {
user entry code assumes that state will be kept on all CPUs as long as context tracking is enabled. See kernel/entry/common.c:
static __always_inline void __enter_from_user_mode(struct pt_regs *regs)
{
arch_check_user_regs(regs);
lockdep_hardirqs_off(CALLER_ADDR0); CT_WARN_ON(ct_state() != CONTEXT_USER); <-- NOT HAPPY ABOUT THIS CHANGE
user_exit_irqoff();
instrumentation_begin();
trace_hardirqs_off_finish();
instrumentation_end();}
Regards,
Nicolas
Re: [PATCH 15/19] rcu/context-tracking: Remove unused and/or unecessary middle functions
In reply to Frederic WeisbeckerQuoted 22 lines · Frederic Weisbecker
Some eqs functions are now only used internally by context tracking, so their public declarations can be removed.
Also middle functions such as rcu_user_*() and rcu_idle_*() which now directly call to
rcu_eqs_enter()andrcu_eqs_exit()can be wiped out as well.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>
Quoted 1 line
---
You missed rcu_user_{enter,exit} declarations in rcupdate.h
There are also comments refering to them in kernel/context_tracking.c and Documentation/RCU/stallwarn.rst.
Regards,
Nicolas
Re: [PATCH 16/19] context_tracking: Convert state to atomic_t
In reply to Frederic WeisbeckerQuoted 22 lines · Frederic Weisbecker
Context tracking's state and dynticks counter are going to be merged in a single field so that both updates can happen atomically and at the same time. Prepare for that with converting the state into an
atomic_t.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>---
static__always_inlineboolcontext_tracking_in_user(void){
include/linux/context_tracking_state.h static inline bool context_tracking_enabled_this_cpu(void) · line 87
Quoted 3 lines
include/linux/context_tracking_state.h +1
-1-return __this_cpu_read (context_tracking.state) ==CONTEXT_USER ; +return __ct_state () ==CONTEXT_USER ; }
I was wondering whether it'd make more sense to use ct_state() for extra safety vs preemption, but it turns out the function isn't being used at all.
I figure it'd be better to remove it altogether and leave ct_state() as the goto function for this sort of checks.
kernel/context_tracking.c static __always_inline void context_tracking_recursion_exit(void) · line 340
Quoted 11 lines
#else
static inline boolcontext_tracking_in_user(void){ return false; }kernel/context_tracking.c +1
-0@@ -337,6 +337,7 @@ static __always_inline void context_tracking_recursion_exit(void)*/ void noinstr __ct_user_enter(enum ctx_state state) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);
I wonder if there is any value to having __ct_state() take 'struct context_tracking *ct' as an argument to avoid a redundant this_cpu_ptr()...
kernel/context_tracking.c void noinstr __ct_user_enter(enum ctx_state state) · line 349
Quoted 10 lines
kernel/context_tracking.c +1
-2lockdep_assert_irqs_disabled ();/* Kernel threads aren't supposed to go to userspace */ @@ -345,8 +346,8 @@ void noinstr __ct_user_enter(enum ctx_state state)if (!context_tracking_recursion_enter ())return ; -if (__this_cpu_read (context_tracking.state) != state) { -if (__this_cpu_read (context_tracking.active)) { +if (__ct_state () != state) {
...here (and in __ct_user_exit()).
Regards,
Nicolas
Frederic Weisbecker
maintainerRe: [PATCH 02/19] context_tracking: Rename context_tracking_user_enter/exit() to user_enter/exit_callable()
In reply to Peter ZijlstraQuoted 28 lines · Peter Zijlstra
Quoted 27 lines · Frederic Weisbecker
kernel/context_tracking.c +7
-2@@ -125,11 +125,16 @@ void context_tracking_enter(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_enter);EXPORT_SYMBOL_GPL (context_tracking_enter); -void context_tracking_user_enter (void ) +/** +* user_enter_callable() - Unfortunate ASM callable version of user_enter() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_enter_callable (void ) {user_enter (); } -NOKPROBE_SYMBOL (context_tracking_user_enter); +NOKPROBE_SYMBOL (user_enter_callable);/** * __ct_user_exit - Inform the context tracking that the CPU is @@ -182,11 +187,16 @@ void context_tracking_exit(enum ctx_state state)NOKPROBE_SYMBOL (context_tracking_exit);EXPORT_SYMBOL_GPL (context_tracking_exit);
Quoted 14 lines
kernel/context_tracking.c void context_tracking_exit(enum ctx_state state) · line 199
Quoted 12 lines
kernel/context_tracking.c +7
-2-void context_tracking_user_exit (void ) +/** +* user_exit_callable() - Unfortunate ASM callable version of user_exit() for +* archs that didn't manage to check the context tracking +* static key from low level code. +*/ +void user_exit_callable (void ) {user_exit (); } -NOKPROBE_SYMBOL (context_tracking_user_exit); +NOKPROBE_SYMBOL (user_exit_callable);I'm thinking all this wants to be noinstr instead of
NOKPROBE_SYMBOL..
Good point, I'll fix that ahead.
Frederic Weisbecker
maintainerRe: [PATCH 04/19] context_tracking: Rename context_tracking_cpu_set() to context_tracking_cpu_track_user()
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 5 lines · Frederic Weisbecker
context_tracking_cpu_set()is called in order to tell a CPU to track user/kernel transitions. Since context tracking is going to expand in to also track transitions from/to idle/IRQ/NMIs, the scope of this function name becomes too broad and needs to be made more specific.The previous patches did: s/context_tracking_/ct_/ on these names, and this one makes it longer still?
Right, in fact I added the renames afterward and forgot to update that patch. Will do.
Thanks.
Frederic Weisbecker
maintainerRe: [PATCH 06/19] context_tracking: Take idle eqs entrypoints over RCU
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker
The RCU dynticks counter is going to be merged into the context tracking subsystem. Start with moving the idle extended quiescent states entrypoints to RCU. For now those are dumb redirection to existing RCU calls.
s/to/from/ right? You're taking them away from RCU and moving them to ct.
Right!
Frederic Weisbecker
maintainerRe: [PATCH 03/19] context_tracking: Rename context_tracking_enter/exit() to ct_user_enter/exit()
In reply to Peter ZijlstraQuoted 43 lines · Peter Zijlstra
Quoted 42 lines · Frederic Weisbecker
kernel/context_tracking.c +6
-6@@ -103,7 +103,7 @@ void noinstr __ct_user_enter(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_enter); -void context_tracking_enter (enum ctx_state state) +void ct_user_enter (enum ctx_state state) {unsigned long flags;@@ -122,8 +122,8 @@ void context_tracking_enter(enum ctx_state state)__ct_user_enter (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_enter); -EXPORT_SYMBOL_GPL (context_tracking_enter); +NOKPROBE_SYMBOL (ct_user_enter); +EXPORT_SYMBOL_GPL (ct_user_enter);/** * user_enter_callable() - Unfortunate ASM callable version of user_enter() for @@ -173,7 +173,7 @@ void noinstr __ct_user_exit(enum ctx_state state) }EXPORT_SYMBOL_GPL (__ct_user_exit); -void context_tracking_exit (enum ctx_state state) +void ct_user_exit (enum ctx_state state) {unsigned long flags;@@ -184,8 +184,8 @@ void context_tracking_exit(enum ctx_state state)__ct_user_exit (state);local_irq_restore (flags); } -NOKPROBE_SYMBOL (context_tracking_exit); -EXPORT_SYMBOL_GPL (context_tracking_exit); +NOKPROBE_SYMBOL (ct_user_exit); +EXPORT_SYMBOL_GPL (ct_user_exit);
Quoted 5 lines
kernel/context_tracking.c void context_tracking_exit(enum ctx_state state) · line 191
Quoted 2 lines
kernel/context_tracking.c +0
-0/** * user_exit_callable() - Unfortunate ASM callable version of user_exit() for Why is it NOKPROBE but not notrace, also local_irq_*() include explicit tracepoints.
Again stuff I need to fix ahead. Thanks for catching that.
Thanks!
Frederic Weisbecker
maintainerRe: [PATCH 09/19] rcu/context-tracking: Remove rcu_irq_enter/exit()
In reply to Peter ZijlstraQuoted 24 lines · Peter Zijlstra
Quoted 9 lines · Frederic Weisbecker
void
ct_irq_enter_irqson(void)
{kernel/context_tracking.c +5
-1-rcu_irq_enter_irqson (); +unsigned long flags; + +local_irq_save (flags); +ct_irq_enter (); +local_irq_restore (flags); }kernel/context_tracking.c void ct_idle_exit(void) · line 320
Quoted 10 lines
kernel/context_tracking.c +5
-1void ct_irq_exit_irqson (void ) { -rcu_irq_exit_irqson (); +unsigned long flags; + +local_irq_save (flags); +ct_irq_exit (); +local_irq_restore (flags); }I know you're just copying code around, but this is broken per construction :/
Quoted 3 lines
On the
irq_entersite,local_irq_save()will hit a tracepoint, which requires RCU, which will only be made available by thect_irq_enter(). Same in reverse for the exit case.
Ouch. And playing a game similar to that in default_idle_call() is going to be trickier because rcu_irq_enter() may or may not exit an RCU-off mode. But it's feasible. Again I'll fix it ahead.
Thanks!
Re: [PATCH 01/19] context_tracking: Rename __context_tracking_enter/exit() to __ct_user_enter/exit()
In reply to Frederic WeisbeckerQuoted 6 lines · Frederic Weisbecker
The context tracking namespace is going to expand and some new functions will require even longer names. Start shrinking the
context_trackingprefix to "ct" as is already the case for some existing macros, this will make the introduction of new functions easier.Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 150 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking.h | 12 ++++++------ kernel/context_tracking.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-)include/linux/context_tracking.h +6
-6@@ -14,8 +14,8 @@extern void context_tracking_cpu_set (int cpu);/* Called with interrupts disabled. */ -extern void __context_tracking_enter (enum ctx_state state); -extern void __context_tracking_exit (enum ctx_state state); +extern void __ct_user_enter (enum ctx_state state); +extern void __ct_user_exit (enum ctx_state state);extern void context_tracking_enter (enum ctx_state state);extern void context_tracking_exit (enum ctx_state state);@@ -38,13 +38,13 @@ static inline void user_exit(void) static __always_inline void user_enter_irqoff(void) {if (context_tracking_enabled ()) -__context_tracking_enter (CONTEXT_USER ); +__ct_user_enter (CONTEXT_USER ); } static __always_inline void user_exit_irqoff(void) {if (context_tracking_enabled ()) -__context_tracking_exit (CONTEXT_USER ); +__ct_user_exit (CONTEXT_USER ); }static inline enum ctx_state exception_enter (void )@@ -74,7 +74,7 @@ static inline void exception_exit(enum ctx_state prev_ctx) static __always_inline bool context_tracking_guest_enter(void) {if (context_tracking_enabled ()) -__context_tracking_enter (CONTEXT_GUEST ); +__ct_user_enter (CONTEXT_GUEST );return context_tracking_enabled_this_cpu (); }@@ -82,7 +82,7 @@ static __always_inline bool context_tracking_guest_enter(void) static __always_inline void context_tracking_guest_exit(void) {if (context_tracking_enabled ()) -__context_tracking_exit (CONTEXT_GUEST ); +__ct_user_exit (CONTEXT_GUEST ); }/** kernel/context_tracking.c +10
-10@@ -51,15 +51,15 @@ static __always_inline void context_tracking_recursion_exit(void) }/** -* context_tracking_enter - Inform the context tracking that the CPU is going -* enter user or guest space mode. +* __ct_user_enter - Inform the context tracking that the CPU is going +* to enter user or guest space mode. * * This function must be called right before we switch from the kernel * to user or guest space, when it's guaranteed the remaining kernel * instructions to execute won't use any RCU read side critical section * because this function sets RCU in extended quiescent state. */ -void noinstr __context_tracking_enter(enum ctx_state state) +void noinstr __ct_user_enter(enum ctx_state state) {/* Kernel threads aren't supposed to go to userspace */ WARN_ON_ONCE (!current->mm);@@ -101,7 +101,7 @@ void noinstr __context_tracking_enter(enum ctx_state state) }context_tracking_recursion_exit (); } -EXPORT_SYMBOL_GPL (__context_tracking_enter); +EXPORT_SYMBOL_GPL (__ct_user_enter);void context_tracking_enter (enum ctx_state state) {@@ -119,7 +119,7 @@ void context_tracking_enter(enum ctx_state state)return ;local_irq_save (flags); -__context_tracking_enter (state); +__ct_user_enter (state);local_irq_restore (flags); }NOKPROBE_SYMBOL (context_tracking_enter);@@ -132,8 +132,8 @@ void context_tracking_user_enter(void)NOKPROBE_SYMBOL (context_tracking_user_enter);/** -* context_tracking_exit - Inform the context tracking that the CPU is -* exiting user or guest mode and entering the kernel. +* __ct_user_exit - Inform the context tracking that the CPU is +* exiting user or guest mode and entering the kernel. * * This function must be called after we entered the kernel from user or * guest space before any use of RCU read side critical section. This @@ -143,7 +143,7 @@ NOKPROBE_SYMBOL(context_tracking_user_enter);* This call supports re-entrancy. This way it can be called from any exception * handler without needing to know if we came from userspace or not. */ -void noinstr __context_tracking_exit(enum ctx_state state) +void noinstr __ct_user_exit(enum ctx_state state) {if (!context_tracking_recursion_enter ())return ;@@ -166,7 +166,7 @@ void noinstr __context_tracking_exit(enum ctx_state state) }context_tracking_recursion_exit (); } -EXPORT_SYMBOL_GPL (__context_tracking_exit); +EXPORT_SYMBOL_GPL (__ct_user_exit);void context_tracking_exit (enum ctx_state state) {@@ -176,7 +176,7 @@ void context_tracking_exit(enum ctx_state state)return ;local_irq_save (flags); -__context_tracking_exit (state); +__ct_user_exit (state);local_irq_restore (flags); }NOKPROBE_SYMBOL (context_tracking_exit);Signature · 1 line
2.25.1
Paul E. McKenney
maintainerRe: [PATCH 05/19] context_tracking: Split user tracking Kconfig
In reply to Frederic WeisbeckerQuoted 3 lines · Frederic Weisbecker
Context tracking is going to be used not only to track user transitions but also idle/IRQs/NMIs. The user tracking part will then become a seperate feature. Prepare
Kconfigfor that.
s/seperate/separate/ # nit
Quoted 60 lines
Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- .../time/context-tracking/arch-support.txt | 6 ++--- arch/Kconfig | 4 ++-- arch/arm/Kconfig | 2 +- arch/arm/kernel/entry-common.S | 4 ++-- arch/arm/kernel/entry-header.S | 4 ++-- arch/arm64/Kconfig | 2 +- arch/csky/Kconfig | 2 +- arch/csky/kernel/entry.S | 4 ++-- arch/mips/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/context_tracking.h | 2 +- arch/riscv/Kconfig | 2 +- arch/riscv/kernel/entry.S | 6 ++--- arch/sparc/Kconfig | 2 +- arch/sparc/kernel/rtrap_64.S | 2 +- arch/x86/Kconfig | 4 ++-- include/linux/context_tracking.h | 12 +++++----- include/linux/context_tracking_state.h | 4 ++-- init/Kconfig | 4 ++-- kernel/context_tracking.c | 6 ++++- kernel/sched/core.c | 2 +- kernel/time/Kconfig | 22 +++++++++++-------- 22 files changed, 54 insertions(+), 46 deletions(-)Documentation/features/time/context-tracking/arch-support.txt +3
-3@@ -1,7 +1,7 @@ # -# Feature name: context-tracking -# Kconfig: HAVE_CONTEXT_TRACKING -# description: arch supports context tracking for NO_HZ_FULL +# Feature name: user-context-tracking +# Kconfig: HAVE_CONTEXT_TRACKING_USER +# description: arch supports user context tracking for NO_HZ_FULL # ----------------------- | arch |status|arch/Kconfig +0
-0
arch/Kconfig config HAVE_ARCH_WITHIN_STACK_FRAMES · line 765
Quoted 5 lines
arch/Kconfig +1
-1@@ -762,7 +762,7 @@ config HAVE_ARCH_WITHIN_STACK_FRAMES and similar) by implementing an inline arch_within_stack_frames(), which is used by CONFIG_HARDENED_USERCOPY. -config HAVE_CONTEXT_TRACKING +config HAVE_CONTEXT_TRACKING_USER
Just checking... This means that only some configs will see userland execution as being different than kernel execution, correct? (Which is the case today, to be fair.)
Thanx, Paul
Quoted 427 lines
arch/Kconfig +1
-1bool help Provide kernel/user boundaries probes necessary for subsystems@@ -773,7 +773,7 @@ config HAVE_CONTEXT_TRACKING protected inside rcu_irq_enter/rcu_irq_exit() but preemption or signal handling on irq exit still need to be protected. -config HAVE_CONTEXT_TRACKING_OFFSTACK +config HAVE_CONTEXT_TRACKING_USER_OFFSTACK bool help Architecture neither relies on exception_enter()/exception_exit()arch/arm/Kconfig +1
-1@@ -81,7 +81,7 @@ config ARM select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE select HAVE_ARM_SMCCC if CPU_V7 select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32 - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK if !XIP_KERNEL select HAVE_DMA_CONTIGUOUS if MMUarch/arm/kernel/entry-common.S +2
-2@@ -26,7 +26,7 @@ #include "entry-header.S" saved_psr .req r8 -#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING) +#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING_USER) saved_pc .req r9 #define TRACE(x...) x #else@@ -36,7 +36,7 @@ saved_pc .req lr .section .entry.text,"ax",%progbits .align 5 -#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \ +#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING_USER) || \ IS_ENABLED(CONFIG_DEBUG_RSEQ)) /* * This is the fast syscall return path. We do as little as possible here,arch/arm/kernel/entry-header.S +2
-2@@ -361,7 +361,7 @@ * between user and kernel mode. */ .macro ct_user_exit, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER .if \save stmdb sp!, {r0-r3, ip, lr} bl user_exit_callable@@ -373,7 +373,7 @@ .endm .macro ct_user_enter, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER .if \save stmdb sp!, {r0-r3, ip, lr} bl user_enter_callablearch/arm64/Kconfig +1
-1@@ -169,7 +169,7 @@ config ARM64 select HAVE_C_RECORDMCOUNT select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACEarch/csky/Kconfig +1
-1@@ -42,7 +42,7 @@ config CSKY select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_SECCOMP_FILTER - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_VIRT_CPU_ACCOUNTING_GEN select HAVE_DEBUG_BUGVERBOSE select HAVE_DEBUG_KMEMLEAKarch/csky/kernel/entry.S +2
-2@@ -19,7 +19,7 @@ .endm .macro context_tracking -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER mfcr a0, epsr btsti a0, 31 bt 1f@@ -159,7 +159,7 @@ ret_from_exception: and r10, r9 cmpnei r10, 0 bt exit_work -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER jbsr user_enter_callable #endif 1:arch/mips/Kconfig +1
-1@@ -55,7 +55,7 @@ config MIPS select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_TIF_NOHZ select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAKarch/powerpc/Kconfig +1
-1@@ -192,7 +192,7 @@ config PPC select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING if PPC64 + select HAVE_CONTEXT_TRACKING_USER if PPC64 select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK select HAVE_DEBUG_STACKOVERFLOWarch/powerpc/include/asm/context_tracking.h +1
-1@@ -2,7 +2,7 @@#ifndef _ASM_POWERPC_CONTEXT_TRACKING_H#define _ASM_POWERPC_CONTEXT_TRACKING_H -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER #define SCHEDULE_USER bl schedule_user#else #define SCHEDULE_USER bl schedulearch/riscv/Kconfig +1
-1@@ -80,7 +80,7 @@ config RISCV select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_VMAP_STACK if MMU && 64BIT select HAVE_ASM_MODVERSIONS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS if MMU select HAVE_EBPF_JIT if MMUarch/riscv/kernel/entry.S +3
-3@@ -111,7 +111,7 @@ _save_context: call trace_hardirqs_off #endif -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER /* If previous state is in user mode, call user_exit_callable(). */ li a0, SR_PP and a0, s1, a0@@ -176,7 +176,7 @@ handle_syscall: */ csrs CSR_STATUS, SR_IE #endif -#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING) +#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING_USER) /* Recover a0 - a7 for system calls */ REG_L a0, PT_A0(sp) REG_L a1, PT_A1(sp)@@ -251,7 +251,7 @@ resume_userspace: andi s1, s0, _TIF_WORK_MASK bnez s1, work_pending -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER call user_enter_callable #endifarch/sparc/Kconfig +1
-1@@ -71,7 +71,7 @@ config SPARC64 select HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD select HAVE_SYSCALL_TRACEPOINTS - select HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER select HAVE_TIF_NOHZ select HAVE_DEBUG_KMEMLEAK select IOMMU_HELPERarch/sparc/kernel/rtrap_64.S +1
-1@@ -15,7 +15,7 @@ #include <asm/visasm.h> #include <asm/processor.h> -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER # define SCHEDULE_USER schedule_user #else # define SCHEDULE_USER schedulearch/x86/Kconfig +2
-2@@ -182,8 +182,8 @@ config X86 select HAVE_ASM_MODVERSIONS select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL - select HAVE_CONTEXT_TRACKING if X86_64 - select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING + select HAVE_CONTEXT_TRACKING_USER if X86_64 + select HAVE_CONTEXT_TRACKING_USER_OFFSTACK if HAVE_CONTEXT_TRACKING_USER select HAVE_C_RECORDMCOUNT select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION select HAVE_DEBUG_KMEMLEAKinclude/linux/context_tracking.h +6
-6@@ -10,7 +10,7 @@#include <asm/ptrace.h> -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER extern void context_tracking_cpu_track_user (int cpu);/* Called with interrupts disabled. */ @@ -52,7 +52,7 @@ static inline enum ctx_state exception_enter(void) {enum ctx_state prev_ctx; -if (IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) || +if (IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) || !context_tracking_enabled ())return 0 ;@@ -65,7 +65,7 @@ static inline enum ctx_state exception_enter(void)static inline void exception_exit (enum ctx_state prev_ctx) { -if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) && +if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) &&context_tracking_enabled ()) {if (prev_ctx !=CONTEXT_KERNEL )ct_user_enter (prev_ctx);@@ -109,14 +109,14 @@ static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; } static __always_inline bool context_tracking_guest_enter(void) { return false; }static inline void context_tracking_guest_exit (void ) { } -#endif /* !CONFIG_CONTEXT_TRACKING */ +#endif /* !CONFIG_CONTEXT_TRACKING_USER */ #define CT_WARN_ON (cond) WARN_ON(context_tracking_enabled() && (cond)) -#ifdef CONFIG_CONTEXT_TRACKING_FORCE +#ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE extern void context_tracking_init (void );#else static inline void context_tracking_init (void ) { } -#endif /* CONFIG_CONTEXT_TRACKING_FORCE */ +#endif /* CONFIG_CONTEXT_TRACKING_USER_FORCE */ #endif include/linux/context_tracking_state.h +2
-2@@ -22,7 +22,7 @@ struct context_tracking { } state; }; -#ifdef CONFIG_CONTEXT_TRACKING +#ifdef CONFIG_CONTEXT_TRACKING_USER extern struct static_key_false context_tracking_key; DECLARE_PER_CPU(struct context_tracking, context_tracking);@@ -50,6 +50,6 @@ static inline bool context_tracking_in_user(void) { return false; }static inline bool context_tracking_enabled (void ) {return false; }static inline bool context_tracking_enabled_cpu (int cpu) {return false; }static inline bool context_tracking_enabled_this_cpu (void ) {return false; } -#endif /* CONFIG_CONTEXT_TRACKING */ +#endif /* CONFIG_CONTEXT_TRACKING_USER */ #endif init/Kconfig +2
-2@@ -498,11 +498,11 @@ config VIRT_CPU_ACCOUNTING_NATIVE config VIRT_CPU_ACCOUNTING_GEN bool "Full dynticks CPU time accounting" - depends on HAVE_CONTEXT_TRACKING + depends on HAVE_CONTEXT_TRACKING_USER depends on HAVE_VIRT_CPU_ACCOUNTING_GEN depends on GENERIC_CLOCKEVENTS select VIRT_CPU_ACCOUNTING - select CONTEXT_TRACKING + select CONTEXT_TRACKING_USER help Select this option to enable task and CPU time accounting on full dynticks systems. This accounting is implemented by watching everykernel/context_tracking.c +5
-1@@ -22,6 +22,8 @@#include <linux/export.h> #include <linux/kprobes.h> +#ifdef CONFIG_CONTEXT_TRACKING_USER +#define CREATE_TRACE_POINTS #include <trace/events/context_tracking.h> @@ -222,7 +224,7 @@ void __init context_tracking_cpu_track_user(int cpu) initialized = true; } -#ifdef CONFIG_CONTEXT_TRACKING_FORCE +#ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE void __init context_tracking_init (void ) {int cpu;@@ -231,3 +233,5 @@ void __init context_tracking_init(void)context_tracking_cpu_track_user (cpu); }#endif + +#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ kernel/sched/core.c +1
-1@@ -6398,7 +6398,7 @@ void __sched schedule_idle(void) }while (need_resched ()); } -#if defined(CONFIG_CONTEXT_TRACKING ) && !defined(CONFIG_HAVE_CONTEXT_TRACKING_OFFSTACK ) +#if defined(CONFIG_CONTEXT_TRACKING_USER ) && !defined(CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK ) asmlinkage __visible void __sched schedule_user(void) {/* kernel/time/Kconfig +13
-9@@ -111,7 +111,7 @@ config NO_HZ_FULL # NO_HZ_COMMON dependency # We need at least one periodic CPU for timekeeping depends on SMP - depends on HAVE_CONTEXT_TRACKING + depends on HAVE_CONTEXT_TRACKING_USER # VIRT_CPU_ACCOUNTING_GEN dependency depends on HAVE_VIRT_CPU_ACCOUNTING_GEN select NO_HZ_COMMON@@ -140,28 +140,32 @@ endchoice config CONTEXT_TRACKING bool -config CONTEXT_TRACKING_FORCE - bool "Force context tracking" - depends on CONTEXT_TRACKING +config CONTEXT_TRACKING_USER + select CONTEXT_TRACKING + bool + +config CONTEXT_TRACKING_USER_FORCE + bool "Force user context tracking" + depends on CONTEXT_TRACKING_USER default y if !NO_HZ_FULL help The major pre-requirement for full dynticks to work is to - support the context tracking subsystem. But there are also + support the user context tracking subsystem. But there are also other dependencies to provide in order to make the full dynticks working. This option stands for testing when an arch implements the - context tracking backend but doesn't yet fulfill all the + user context tracking backend but doesn't yet fulfill all the requirements to make the full dynticks feature working. Without the full dynticks, there is no way to test the support - for context tracking and the subsystems that rely on it: RCU + for user context tracking and the subsystems that rely on it: RCU userspace extended quiescent state and tickless cputime accounting. This option copes with the absence of the full - dynticks subsystem by forcing the context tracking on all + dynticks subsystem by forcing the user context tracking on all CPUs in the system. Say Y only if you're working on the development of an - architecture backend for the context tracking. + architecture backend for the user context tracking. Say N otherwise, this option brings an overhead that you don't want in production.Signature · 1 line
2.25.1
Re: [PATCH 07/19] context_tracking: Take IRQ eqs entrypoints over RCU
In reply to Frederic WeisbeckerQuoted 6 lines · Frederic Weisbecker
The RCU dynticks counter is going to be merged into the context tracking subsystem. Prepare with moving the IRQ extended quiescent states entrypoints to context tracking. For now those are dumb redirection to existing RCU calls.
Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 469 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- .../RCU/Design/Requirements/Requirements.rst | 10 ++++---- Documentation/RCU/stallwarn.rst | 4 ++-- arch/Kconfig | 2 +- arch/arm64/kernel/entry-common.c | 6 ++--- arch/x86/mm/fault.c | 2 +- drivers/cpuidle/cpuidle-psci.c | 8 +++---- include/linux/context_tracking_irq.h | 17 +++++++++++++ include/linux/context_tracking_state.h | 1 + include/linux/entry-common.h | 10 ++++---- include/linux/rcupdate.h | 5 ++-- include/linux/tracepoint.h | 4 ++-- kernel/context_tracking.c | 24 +++++++++++++++++-- kernel/cpu_pm.c | 8 +++---- kernel/entry/common.c | 12 +++++----- kernel/softirq.c | 4 ++-- kernel/trace/trace.c | 6 ++--- 16 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 include/linux/context_tracking_irq.hDocumentation/RCU/Design/Requirements/Requirements.rst +5
-5@@ -1844,10 +1844,10 @@ that meets this requirement. Furthermore, NMI handlers can be interrupted by what appear to RCU to be normal interrupts. One way that this can happen is for code that -directly invokes rcu_irq_enter() and rcu_irq_exit() to be called +directly invokes ct_irq_enter() and ct_irq_exit() to be called from an NMI handler. This astonishing fact of life prompted the current -code structure, which has rcu_irq_enter() invoking -rcu_nmi_enter() and rcu_irq_exit() invoking rcu_nmi_exit(). +code structure, which has ct_irq_enter() invoking +rcu_nmi_enter() and ct_irq_exit() invoking rcu_nmi_exit(). And yes, I also learned of this requirement the hard way. Loadable Modules@@ -2195,7 +2195,7 @@ scheduling-clock interrupt be enabled when RCU needs it to be: sections, and RCU believes this CPU to be idle, no problem. This sort of thing is used by some architectures for light-weight exception handlers, which can then avoid the overhead of - rcu_irq_enter() and rcu_irq_exit() at exception entry and + ct_irq_enter() and ct_irq_exit() at exception entry and exit, respectively. Some go further and avoid the entireties of irq_enter() and irq_exit(). Just make very sure you are running some of your tests with@@ -2226,7 +2226,7 @@ scheduling-clock interrupt be enabled when RCU needs it to be: +-----------------------------------------------------------------------+ | **Answer**: | +-----------------------------------------------------------------------+ -| One approach is to do ``rcu_irq_exit();rcu_irq_enter();`` every so | +| One approach is to do ``ct_irq_exit();ct_irq_enter();`` every so | | often. But given that long-running interrupt handlers can cause other | | problems, not least for response time, shouldn't you work to keep | | your interrupt handler's runtime within reasonable bounds? |Documentation/RCU/stallwarn.rst +2
-2@@ -98,11 +98,11 @@ warnings: - A low-level kernel issue that either fails to invoke one of the variants of rcu_user_enter(), rcu_user_exit(), ct_idle_enter(), - ct_idle_exit(), rcu_irq_enter(), or rcu_irq_exit() on the one + ct_idle_exit(), ct_irq_enter(), or ct_irq_exit() on the one hand, or that invokes one of them too many times on the other. Historically, the most frequent issue has been an omission of either irq_enter() or irq_exit(), which in turn invoke - rcu_irq_enter() or rcu_irq_exit(), respectively. Building your + ct_irq_enter() or ct_irq_exit(), respectively. Building your kernel with CONFIG_RCU_EQS_DEBUG=y can help track down these types of issues, which sometimes arise in architecture-specific code.arch/Kconfig +1
-1@@ -770,7 +770,7 @@ config HAVE_CONTEXT_TRACKING_USER Syscalls need to be wrapped inside user_exit()-user_enter(), either optimized behind static key or through the slow path using TIF_NOHZ flag. Exceptions handlers must be wrapped as well. Irqs are already - protected inside rcu_irq_enter/rcu_irq_exit() but preemption or signal + protected inside ct_irq_enter/ct_irq_exit() but preemption or signal handling on irq exit still need to be protected. config HAVE_CONTEXT_TRACKING_USER_OFFSTACKarch/arm64/kernel/entry-common.c +3
-3@@ -40,7 +40,7 @@ static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)if (!IS_ENABLED (CONFIG_TINY_RCU ) &&is_idle_task (current)) {lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_irq_enter (); +ct_irq_enter ();trace_hardirqs_off_finish (); regs->exit_rcu = true;@@ -74,7 +74,7 @@ static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)if (regs->exit_rcu) {trace_hardirqs_on_prepare ();lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); -rcu_irq_exit (); +ct_irq_exit ();lockdep_hardirqs_on (CALLER_ADDR0 );return ; }@@ -82,7 +82,7 @@ static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)trace_hardirqs_on (); }else {if (regs->exit_rcu) -rcu_irq_exit (); +ct_irq_exit (); } }arch/x86/mm/fault.c +1
-1@@ -1526,7 +1526,7 @@ DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault)/* * Entry handling for valid #PF from kernel mode is slightly -* different: RCU is already watching and rcu_irq_enter() must not +* different: RCU is already watching and ct_irq_enter() must not * be invoked because a kernel fault on a user space address might * sleep. * drivers/cpuidle/cpuidle-psci.c +4
-4@@ -68,12 +68,12 @@ static int __psci_enter_domain_idle_state(struct cpuidle_device *dev,return -1 ;/* Do runtime PM to manage a hierarchical CPU toplogy. */ -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();if (s2idle)dev_pm_genpd_suspend (pd_dev);else pm_runtime_put_sync_suspend (pd_dev); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson (); state =psci_get_domain_state ();if (!state)@@ -81,12 +81,12 @@ static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, ret =psci_cpu_suspend_enter (state) ?-1 : idx; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();if (s2idle)dev_pm_genpd_resume (pd_dev);else pm_runtime_get_sync (pd_dev); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();cpu_pm_exit ();include/linux/context_tracking_irq.h new file +17
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CONTEXT_TRACKING_IRQ_H +#define _LINUX_CONTEXT_TRACKING_IRQ_H + +#ifdef CONFIG_CONTEXT_TRACKING +void ct_irq_enter (void ); +void ct_irq_exit (void ); +void ct_irq_enter_irqson (void ); +void ct_irq_exit_irqson (void ); +#else +static inline void ct_irq_enter (void ) { } +static inline void ct_irq_exit (void ) { } +static inline void ct_irq_enter_irqson (void ) { } +static inline void ct_irq_exit_irqson (void ) { } +#endif + +#endif include/linux/context_tracking_state.h +1
-0@@ -4,6 +4,7 @@#include <linux/percpu.h> #include <linux/static_key.h> +#include <linux/context_tracking_irq.h> struct context_tracking {/* include/linux/entry-common.h +5
-5@@ -396,7 +396,7 @@ void irqentry_exit_to_user_mode(struct pt_regs *regs);/** * struct irqentry_state - Opaque object for exception state storage * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the -* exit path has to invoke rcu_irq_exit(). +* exit path has to invoke ct_irq_exit(). * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that * lockdep state is restored correctly on exit from nmi. * @@ -434,12 +434,12 @@ typedef struct irqentry_state {* * For kernel mode entries RCU handling is done conditional. If RCU is * watching then the only RCU requirement is to check whether the tick has -* to be restarted. If RCU is not watching then rcu_irq_enter() has to be -* invoked on entry and rcu_irq_exit() on exit. +* to be restarted. If RCU is not watching then ct_irq_enter() has to be +* invoked on entry and ct_irq_exit() on exit. * -* Avoiding the rcu_irq_enter/exit() calls is an optimization but also +* Avoiding the ct_irq_enter/exit() calls is an optimization but also * solves the problem of kernel mode pagefaults which can schedule, which -* is not possible after invoking rcu_irq_enter() without undoing it. +* is not possible after invoking ct_irq_enter() without undoing it. * * For user mode entries irqentry_enter_from_user_mode() is invoked to * establish the proper context for NOHZ_FULL. Otherwise scheduling on exit include/linux/rcupdate.h +3
-2@@ -29,6 +29,7 @@#include <linux/lockdep.h> #include <asm/processor.h> #include <linux/cpumask.h> +#include <linux/context_tracking_irq.h> #define ULONG_CMP_GE (a, b) (ULONG_MAX / 2 >= (a) - (b))#define ULONG_CMP_LT (a, b) (ULONG_MAX / 2 < (a) - (b))@@ -143,9 +144,9 @@ static inline void rcu_nocb_flush_deferred_wakeup(void) { }*/ #define RCU_NONIDLE (a) \ do { \ - rcu_irq_enter_irqson(); \ + ct_irq_enter_irqson(); \ do { a; } while (0); \ - rcu_irq_exit_irqson(); \ + ct_irq_exit_irqson(); \ } while (0)/* include/linux/tracepoint.h +2
-2@@ -200,13 +200,13 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)*/ \if (rcuidle) { \ __idx =srcu_read_lock_notrace (&tracepoint_srcu);\ -rcu_irq_enter_irqson (); \ +ct_irq_enter_irqson (); \ } \ \__DO_TRACE_CALL (name,TP_ARGS (args)); \ \if (rcuidle) { \ -rcu_irq_exit_irqson (); \ +ct_irq_exit_irqson (); \srcu_read_unlock_notrace (&tracepoint_srcu, __idx);\ } \ \kernel/context_tracking.c +22
-2@@ -75,7 +75,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* At this stage, only low level arch entry code remains and * then we'll run in userspace. We can assume there won't be * any RCU read-side critical section until the next call to -* user_exit() or rcu_irq_enter(). Let's remove RCU's dependency +* user_exit() or ct_irq_enter(). Let's remove RCU's dependency * on the tick. */ if (state ==CONTEXT_USER ) {@@ -112,7 +112,7 @@ void ct_user_enter(enum ctx_state state)/* * Some contexts may involve an exception occuring in an irq, * leading to that nesting: -* rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit() +* ct_irq_enter() rcu_user_exit() rcu_user_exit() ct_irq_exit() * This would mess up the dyntick_nesting count though. And rcu_irq_*() * helpers are enough to protect RCU uses inside the exception. So * just return immediately if we detect we are in an IRQ. @@ -247,3 +247,23 @@ void ct_idle_exit(void)rcu_idle_exit (); }EXPORT_SYMBOL_GPL (ct_idle_exit); + +noinstr void ct_irq_enter(void) +{ +rcu_irq_enter (); +} + +noinstr void ct_irq_exit(void) +{ +rcu_irq_exit (); +} + +void ct_irq_enter_irqson (void ) +{ +rcu_irq_enter_irqson (); +} + +void ct_irq_exit_irqson (void ) +{ +rcu_irq_exit_irqson (); +}kernel/cpu_pm.c +4
-4@@ -35,11 +35,11 @@ static int cpu_pm_notify(enum cpu_pm_event event)* disfunctional in cpu idle. Copy RCU_NONIDLE code to let RCU know * this. */ -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();rcu_read_lock (); ret =raw_notifier_call_chain (&cpu_pm_notifier.chain, event,NULL );rcu_read_unlock (); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();return notifier_to_errno (ret); }@@ -49,11 +49,11 @@ static int cpu_pm_notify_robust(enum cpu_pm_event event_up, enum cpu_pm_event evunsigned long flags;int ret; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();raw_spin_lock_irqsave (&cpu_pm_notifier.lock, flags); ret =raw_notifier_call_chain_robust (&cpu_pm_notifier.chain, event_up, event_down,NULL );raw_spin_unlock_irqrestore (&cpu_pm_notifier.lock, flags); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson ();return notifier_to_errno (ret); }kernel/entry/common.c +6
-6@@ -327,7 +327,7 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs) }/* -* If this entry hit the idle task invoke rcu_irq_enter() whether +* If this entry hit the idle task invoke ct_irq_enter() whether * RCU is watching or not. * * Interrupts can nest when the first interrupt invokes softirq @@ -338,12 +338,12 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)* not nested into another interrupt. * * Checking for rcu_is_watching() here would prevent the nesting -* interrupt to invoke rcu_irq_enter(). If that nested interrupt is +* interrupt to invoke ct_irq_enter(). If that nested interrupt is * the tick then rcu_flavor_sched_clock_irq() would wrongfully * assume that it is the first interrupt and eventually claim * quiescent state and end grace periods prematurely. * -* Unconditionally invoke rcu_irq_enter() so RCU state stays +* Unconditionally invoke ct_irq_enter() so RCU state stays * consistent. * * TINY_RCU does not support EQS, so let the compiler eliminate @@ -356,7 +356,7 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)* as in irqentry_enter_from_user_mode(). */ lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_irq_enter (); +ct_irq_enter ();instrumentation_begin ();trace_hardirqs_off_finish ();instrumentation_end ();@@ -414,7 +414,7 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state)trace_hardirqs_on_prepare ();lockdep_hardirqs_on_prepare (CALLER_ADDR0 );instrumentation_end (); -rcu_irq_exit (); +ct_irq_exit ();lockdep_hardirqs_on (CALLER_ADDR0 );return ; }@@ -436,7 +436,7 @@ noinstr void irqentry_exit(struct pt_regs *regs, irqentry_state_t state)* was not watching on entry. */ if (state.exit_rcu) -rcu_irq_exit (); +ct_irq_exit (); } }kernel/softirq.c +2
-2@@ -607,7 +607,7 @@ void irq_enter_rcu(void)*/ void irq_enter (void ) { -rcu_irq_enter (); +ct_irq_enter ();irq_enter_rcu (); }@@ -659,7 +659,7 @@ void irq_exit_rcu(void)void irq_exit (void ) {__irq_exit_rcu (); -rcu_irq_exit (); +ct_irq_exit ();/* must be last! */ lockdep_hardirq_exit (); }kernel/trace/trace.c +3
-3@@ -3088,15 +3088,15 @@ void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,/* * When an NMI triggers, RCU is enabled via rcu_nmi_enter(), * but if the above rcu_is_watching() failed, then the NMI -* triggered someplace critical, and rcu_irq_enter() should +* triggered someplace critical, and ct_irq_enter() should * not be called from NMI. */ if (unlikely (in_nmi ()))return ; -rcu_irq_enter_irqson (); +ct_irq_enter_irqson ();__ftrace_trace_stack (buffer, trace_ctx, skip,NULL ); -rcu_irq_exit_irqson (); +ct_irq_exit_irqson (); }/** Signature · 1 line
2.25.1
Re: [PATCH 08/19] context_tracking: Take NMI eqs entrypoints over RCU
In reply to Frederic WeisbeckerQuoted 6 lines · Frederic Weisbecker
The RCU dynticks counter is going to be merged into the context tracking subsystem. Prepare with moving the NMI extended quiescent states entrypoints to context tracking. For now those are dumb redirection to existing RCU calls.
Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 212 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- Documentation/RCU/Design/Requirements/Requirements.rst | 2 +- arch/Kconfig | 2 +- arch/arm64/kernel/entry-common.c | 8 ++++---- include/linux/context_tracking_irq.h | 4 ++++ include/linux/hardirq.h | 4 ++-- kernel/context_tracking.c | 10 ++++++++++ kernel/entry/common.c | 4 ++-- kernel/extable.c | 4 ++-- kernel/trace/trace.c | 2 +- 9 files changed, 27 insertions(+), 13 deletions(-)Documentation/RCU/Design/Requirements/Requirements.rst +1
-1@@ -1847,7 +1847,7 @@ normal interrupts. One way that this can happen is for code that directly invokes ct_irq_enter() and ct_irq_exit() to be called from an NMI handler. This astonishing fact of life prompted the current code structure, which has ct_irq_enter() invoking -rcu_nmi_enter() and ct_irq_exit() invoking rcu_nmi_exit(). +ct_nmi_enter() and ct_irq_exit() invoking ct_nmi_exit(). And yes, I also learned of this requirement the hard way. Loadable Modulesarch/Kconfig +1
-1@@ -785,7 +785,7 @@ config HAVE_CONTEXT_TRACKING_USER_OFFSTACK - Critical entry code isn't preemptible (or better yet: not interruptible). - - No use of RCU read side critical sections, unless rcu_nmi_enter() + - No use of RCU read side critical sections, unless ct_nmi_enter() got called. - No use of instrumentation, unless instrumentation_begin() got called.arch/arm64/kernel/entry-common.c +4
-4@@ -158,7 +158,7 @@ static void noinstr arm64_enter_nmi(struct pt_regs *regs)__nmi_enter ();lockdep_hardirqs_off (CALLER_ADDR0 );lockdep_hardirq_enter (); -rcu_nmi_enter (); +ct_nmi_enter ();trace_hardirqs_off_finish ();ftrace_nmi_enter ();@@ -179,7 +179,7 @@ static void noinstr arm64_exit_nmi(struct pt_regs *regs)lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); } -rcu_nmi_exit (); +ct_nmi_exit ();lockdep_hardirq_exit ();if (restore)lockdep_hardirqs_on (CALLER_ADDR0 );@@ -196,7 +196,7 @@ static void noinstr arm64_enter_el1_dbg(struct pt_regs *regs) regs->lockdep_hardirqs =lockdep_hardirqs_enabled ();lockdep_hardirqs_off (CALLER_ADDR0 ); -rcu_nmi_enter (); +ct_nmi_enter ();trace_hardirqs_off_finish (); }@@ -215,7 +215,7 @@ static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)lockdep_hardirqs_on_prepare (CALLER_ADDR0 ); } -rcu_nmi_exit (); +ct_nmi_exit ();if (restore)lockdep_hardirqs_on (CALLER_ADDR0 ); }include/linux/context_tracking_irq.h +4
-0@@ -7,11 +7,15 @@ void ct_irq_enter(void);void ct_irq_exit (void );void ct_irq_enter_irqson (void );void ct_irq_exit_irqson (void ); +void ct_nmi_enter (void ); +void ct_nmi_exit (void );#else static inline void ct_irq_enter (void ) { }static inline void ct_irq_exit (void ) { }static inline void ct_irq_enter_irqson (void ) { }static inline void ct_irq_exit_irqson (void ) { } +static inline void ct_nmi_enter (void ) { } +static inline void ct_nmi_exit (void ) { }#endif #endif include/linux/hardirq.h +2
-2@@ -124,7 +124,7 @@ extern void rcu_nmi_exit(void); do { \ __nmi_enter(); \ lockdep_hardirq_enter(); \ - rcu_nmi_enter(); \ + ct_nmi_enter(); \ instrumentation_begin(); \ ftrace_nmi_enter(); \ instrumentation_end(); \@@ -143,7 +143,7 @@ extern void rcu_nmi_exit(void);instrumentation_begin (); \ftrace_nmi_exit (); \instrumentation_end (); \ -rcu_nmi_exit (); \ +ct_nmi_exit (); \lockdep_hardirq_exit (); \__nmi_exit (); \ }while (0 )kernel/context_tracking.c +10
-0@@ -267,3 +267,13 @@ void ct_irq_exit_irqson(void) {rcu_irq_exit_irqson (); } + +noinstr void ct_nmi_enter(void) +{ +rcu_nmi_enter (); +} + +noinstr void ct_nmi_exit(void) +{ +rcu_nmi_exit (); +}kernel/entry/common.c +2
-2@@ -449,7 +449,7 @@ irqentry_state_t noinstr irqentry_nmi_enter(struct pt_regs *regs)__nmi_enter ();lockdep_hardirqs_off (CALLER_ADDR0 );lockdep_hardirq_enter (); -rcu_nmi_enter (); +ct_nmi_enter ();instrumentation_begin ();trace_hardirqs_off_finish ();@@ -469,7 +469,7 @@ void noinstr irqentry_nmi_exit(struct pt_regs *regs, irqentry_state_t irq_state) }instrumentation_end (); -rcu_nmi_exit (); +ct_nmi_exit ();lockdep_hardirq_exit ();if (irq_state.lockdep)lockdep_hardirqs_on (CALLER_ADDR0 );kernel/extable.c +2
-2@@ -113,7 +113,7 @@ int kernel_text_address(unsigned long addr)/* Treat this like an NMI as it can happen anywhere */ if (no_rcu) -rcu_nmi_enter (); +ct_nmi_enter ();if (is_module_text_address (addr)) goto out;@@ -126,7 +126,7 @@ int kernel_text_address(unsigned long addr) ret =0 ; out:if (no_rcu) -rcu_nmi_exit (); +ct_nmi_exit ();return ret; }kernel/trace/trace.c +1
-1@@ -3086,7 +3086,7 @@ void __trace_stack(struct trace_array *tr, unsigned int trace_ctx, }/* -* When an NMI triggers, RCU is enabled via rcu_nmi_enter(), +* When an NMI triggers, RCU is enabled via ct_nmi_enter(), * but if the above rcu_is_watching() failed, then the NMI * triggered someplace critical, and ct_irq_enter() should * not be called from NMI. Signature · 1 line
2.25.1
Re: [PATCH 10/19] rcu/context_tracking: Move dynticks counter to context tracking
In reply to Frederic WeisbeckerQuoted 6 lines · Frederic Weisbecker
In order to prepare for merging RCU dynticks counter into the context tracking state, move the rcu_data's dynticks field to the context tracking structure. It will later be mixed within the context tracking state itself.
Signed-off-by Frederic Weisbecker <[email protected]>
Assuming that the context_tracking_state.h definitions get everywhere they need to go in all configurations:
Quoted 369 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking_state.h | 10 ++++- kernel/context_tracking.c | 9 ++-- kernel/rcu/tree.c | 59 ++++++++++++++------------ kernel/rcu/tree.h | 1 - kernel/rcu/tree_exp.h | 2 +- kernel/rcu/tree_stall.h | 4 +- 6 files changed, 48 insertions(+), 37 deletions(-)include/linux/context_tracking_state.h +8
-2@@ -7,6 +7,7 @@#include <linux/context_tracking_irq.h> struct context_tracking { +#ifdef CONFIG_CONTEXT_TRACKING_USER /* * When active is false, probes are unset in order * to minimize overhead: TIF flags are cleared @@ -21,11 +22,16 @@ struct context_tracking {CONTEXT_USER ,CONTEXT_GUEST , } state; +#endif +atomic_t dynticks;/* Even value for idle, else odd. */ }; -#ifdef CONFIG_CONTEXT_TRACKING_USER -extern struct static_key_false context_tracking_key; +#ifdef CONFIG_CONTEXT_TRACKING DECLARE_PER_CPU(struct context_tracking, context_tracking); +#endif + +#ifdef CONFIG_CONTEXT_TRACKING_USER +extern struct static_key_false context_tracking_key; static __always_inline bool context_tracking_enabled(void) {kernel/context_tracking.c +6
-3@@ -30,9 +30,6 @@DEFINE_STATIC_KEY_FALSE (context_tracking_key);EXPORT_SYMBOL_GPL (context_tracking_key); -DEFINE_PER_CPU(struct context_tracking, context_tracking); -EXPORT_SYMBOL_GPL (context_tracking); - static noinstr bool context_tracking_recursion_enter(void) {int recursion;@@ -236,6 +233,12 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ +DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks =ATOMIC_INIT (1 ), +}; +EXPORT_SYMBOL_GPL (context_tracking); + +void ct_idle_enter (void ) {rcu_idle_enter ();kernel/rcu/tree.c +31
-28@@ -77,7 +77,6 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { .dynticks_nesting =1 , .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , - .dynticks =ATOMIC_INIT (1 ), #ifdef CONFIG_RCU_NOCB_CPU .cblist.flags =SEGCBLIST_RCU_CORE , #endif@@ -268,7 +267,7 @@ void rcu_softirq_qs(void)*/ static noinline noinstr unsigned long rcu_dynticks_inc(int incby) { -return arch_atomic_add_return (incby,this_cpu_ptr (&rcu_data.dynticks)); +return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.dynticks)); }/* @@ -324,9 +323,9 @@ static noinstr void rcu_dynticks_eqs_exit(void)*/ static void rcu_dynticks_eqs_online (void ) { -struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct context_tracking *ct =this_cpu_ptr (&context_tracking); -if (atomic_read (&rdp->dynticks) &0x1 ) +if (atomic_read (&ct->dynticks) &0x1 )return ;rcu_dynticks_inc (1 ); }@@ -338,17 +337,19 @@ static void rcu_dynticks_eqs_online(void)*/ static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) { -return !(arch_atomic_read (this_cpu_ptr (&rcu_data.dynticks)) &0x1 ); +return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); }/* * Snapshot the ->dynticks counter with full ordering so as to allow * stable comparison of this counter with past and future snapshots. */ -static int rcu_dynticks_snap (struct rcu_data *rdp) +static int rcu_dynticks_snap (int cpu) { +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); +smp_mb ();// Fundamental RCU ordering guarantee. -return atomic_read_acquire (&rdp->dynticks); +return atomic_read_acquire (&ct->dynticks); }/* @@ -363,9 +364,7 @@ static bool rcu_dynticks_in_eqs(int snap)/* Return true if the specified CPU is currently idle from an RCU viewpoint. */ bool rcu_is_idle_cpu (int cpu) { -struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu); - -return rcu_dynticks_in_eqs (rcu_dynticks_snap (rdp)); +return rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu)); }/* @@ -375,7 +374,7 @@ bool rcu_is_idle_cpu(int cpu)*/ static bool rcu_dynticks_in_eqs_since (struct rcu_data *rdp,int snap) { -return snap !=rcu_dynticks_snap (rdp); +return snap !=rcu_dynticks_snap (rdp->cpu); }/* @@ -384,11 +383,11 @@ static bool rcu_dynticks_in_eqs_since(struct rcu_data *rdp, int snap)*/ bool rcu_dynticks_zero_in_eqs (int cpu,int *vp) { -struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu); +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =atomic_read (&rdp->dynticks) & ~0x1 ; + snap =atomic_read (&ct->dynticks) & ~0x1 ;smp_rmb ();// Order ->dynticks and *vp reads. if (READ_ONCE (*vp))@@ -396,7 +395,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)smp_rmb ();// Order *vp read and ->dynticks re-read. // If still in the same extended quiescent state, we are good! -return snap ==atomic_read (&rdp->dynticks); +return snap ==atomic_read (&ct->dynticks); }/* @@ -620,6 +619,7 @@ EXPORT_SYMBOL_GPL(rcutorture_get_gp_data); static noinstr void rcu_eqs_enter(bool user) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct context_tracking *ct =this_cpu_ptr (&context_tracking);WARN_ON_ONCE (rdp->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE );WRITE_ONCE (rdp->dynticks_nmi_nesting,0 );@@ -633,12 +633,12 @@ static noinstr void rcu_eqs_enter(bool user)lockdep_assert_irqs_disabled ();instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), rdp->dynticks_nesting,0 ,atomic_read (&rdp->dynticks)); +trace_rcu_dyntick (TPS ("Start" ), rdp->dynticks_nesting,0 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current);// instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&rdp->dynticks,sizeof (rdp->dynticks)); +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks));instrumentation_end ();WRITE_ONCE (rdp->dynticks_nesting,0 );/* Avoid irq-access tearing. */ @@ -740,7 +740,7 @@ noinstr void rcu_user_enter(void)* rcu_nmi_exit - inform RCU of exit from NMI context * * If we are returning from the outermost NMI handler that interrupted an -* RCU-idle period, update rdp->dynticks and rdp->dynticks_nmi_nesting +* RCU-idle period, update ct->dynticks and rdp->dynticks_nmi_nesting * to let the RCU grace-period handling know that the CPU is back to * being RCU-idle. * @@ -749,6 +749,7 @@ noinstr void rcu_user_enter(void)*/ noinstr void rcu_nmi_exit(void) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =this_cpu_ptr (&rcu_data);instrumentation_begin ();@@ -766,7 +767,7 @@ noinstr void rcu_nmi_exit(void)*/ if (rdp->dynticks_nmi_nesting !=1 ) {trace_rcu_dyntick (TPS ("--=" ), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting -2 , -atomic_read (&rdp->dynticks)); +atomic_read (&ct->dynticks));WRITE_ONCE (rdp->dynticks_nmi_nesting,/* No store tearing. */ rdp->dynticks_nmi_nesting -2 );instrumentation_end ();@@ -774,11 +775,11 @@ noinstr void rcu_nmi_exit(void) }/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ -trace_rcu_dyntick (TPS ("Startirq" ), rdp->dynticks_nmi_nesting,0 ,atomic_read (&rdp->dynticks)); +trace_rcu_dyntick (TPS ("Startirq" ), rdp->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks));WRITE_ONCE (rdp->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ // instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&rdp->dynticks,sizeof (rdp->dynticks)); +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks));instrumentation_end ();// RCU is watching here ... @@ -817,6 +818,7 @@ void rcu_irq_exit_check_preempt(void)*/ static void noinstr rcu_eqs_exit(bool user) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp;long oldval;@@ -836,9 +838,9 @@ static void noinstr rcu_eqs_exit(bool user)instrumentation_begin ();// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&rdp->dynticks,sizeof (rdp->dynticks)); +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -trace_rcu_dyntick (TPS ("End" ), rdp->dynticks_nesting,1 ,atomic_read (&rdp->dynticks)); +trace_rcu_dyntick (TPS ("End" ), rdp->dynticks_nesting,1 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));WRITE_ONCE (rdp->dynticks_nesting,1 );WARN_ON_ONCE (rdp->dynticks_nmi_nesting);@@ -944,7 +946,7 @@ void __rcu_irq_enter_check_tick(void)/** * rcu_nmi_enter - inform RCU of entry to NMI context * -* If the CPU was idle from RCU's viewpoint, update rdp->dynticks and +* If the CPU was idle from RCU's viewpoint, update ct->dynticks and * rdp->dynticks_nmi_nesting to let the RCU grace-period handling know * that the CPU is active. This implementation permits nested NMIs, as * long as the nesting level does not overflow an int. (You will probably @@ -957,6 +959,7 @@ noinstr void rcu_nmi_enter(void) {long incby =2 ;struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct context_tracking *ct =this_cpu_ptr (&context_tracking);/* Complain about underflow. */ WARN_ON_ONCE (rdp->dynticks_nmi_nesting <0 );@@ -980,9 +983,9 @@ noinstr void rcu_nmi_enter(void)instrumentation_begin ();// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs() -instrument_atomic_read (&rdp->dynticks,sizeof (rdp->dynticks)); +instrument_atomic_read (&ct->dynticks,sizeof (ct->dynticks));// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&rdp->dynticks,sizeof (rdp->dynticks)); +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); incby =1 ; }else if (!in_nmi ()) {@@ -994,7 +997,7 @@ noinstr void rcu_nmi_enter(void)trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), rdp->dynticks_nmi_nesting, - rdp->dynticks_nmi_nesting + incby,atomic_read (&rdp->dynticks)); + rdp->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks));instrumentation_end ();WRITE_ONCE (rdp->dynticks_nmi_nesting,/* Prevent store tearing. */ rdp->dynticks_nmi_nesting + incby);@@ -1138,7 +1141,7 @@ static void rcu_gpnum_ovf(struct rcu_node *rnp, struct rcu_data *rdp)*/ static int dyntick_save_progress_counter (struct rcu_data *rdp) { - rdp->dynticks_snap =rcu_dynticks_snap (rdp); + rdp->dynticks_snap =rcu_dynticks_snap (rdp->cpu);if (rcu_dynticks_in_eqs (rdp->dynticks_snap)) {trace_rcu_fqs (rcu_state.name, rdp->gp_seq, rdp->cpu,TPS ("dti" ));rcu_gpnum_ovf (rdp->mynode, rdp);@@ -4125,7 +4128,7 @@ rcu_boot_init_percpu_data(int cpu) rdp->grpmask =leaf_node_cpu_bit (rdp->mynode, cpu);INIT_WORK (&rdp->strict_work, strict_work_handler);WARN_ON_ONCE (rdp->dynticks_nesting !=1 ); -WARN_ON_ONCE (rcu_dynticks_in_eqs (rcu_dynticks_snap (rdp))); +WARN_ON_ONCE (rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu))); rdp->barrier_seq_snap = rcu_state.barrier_sequence; rdp->rcu_ofl_gp_seq = rcu_state.gp_seq; rdp->rcu_ofl_gp_flags =RCU_GP_CLEANED ;kernel/rcu/tree.h +0
-1@@ -188,7 +188,6 @@ struct rcu_data {int dynticks_snap;/* Per-GP tracking for dynticks. */ long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ -atomic_t dynticks;/* Even value for idle, else odd. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */ bool rcu_forced_tick;/* Forced tick to provide QS. */ kernel/rcu/tree_exp.h +1
-1@@ -358,7 +358,7 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp) !(rnp->qsmaskinitnext & mask)) { mask_ofl_test |= mask; } else { - snap =rcu_dynticks_snap (rdp); + snap =rcu_dynticks_snap (cpu);if (rcu_dynticks_in_eqs (snap)) mask_ofl_test |= mask;else kernel/rcu/tree_stall.h +2
-2@@ -448,7 +448,7 @@ static void print_cpu_stall_info(int cpu) } delta =rcu_seq_ctr (rdp->mynode->gp_seq - rdp->rcu_iw_gp_seq); falsepositive =rcu_is_gp_kthread_starving (NULL ) && -rcu_dynticks_in_eqs (rcu_dynticks_snap (rdp)); +rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu)); pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%03x/%ld/%#lx softirq=%u/%u fqs=%ld %s\n", cpu, "O."[!!cpu_online(cpu)],@@ -458,7 +458,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int )min (delta,9UL ) +'0' :"!." [!delta], ticks_value, ticks_title, -rcu_dynticks_snap (rdp) &0xfff , +rcu_dynticks_snap (cpu) &0xfff , rdp->dynticks_nesting, rdp->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu), data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,Signature · 1 line
2.25.1
Re: [PATCH 11/19] rcu/context_tracking: Move dynticks_nesting to context tracking
In reply to Frederic WeisbeckerQuoted 5 lines · Frederic Weisbecker
The RCU eqs tracking is going to be performed by the context tracking subsystem. The related nesting counters thus need to be moved to the context tracking structure.
Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 209 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking_state.h | 1 + kernel/context_tracking.c | 1 + kernel/rcu/tree.c | 31 +++++++++++++------------- kernel/rcu/tree.h | 1 - kernel/rcu/tree_stall.h | 3 ++- 5 files changed, 20 insertions(+), 17 deletions(-)include/linux/context_tracking_state.h +1
-0@@ -24,6 +24,7 @@ struct context_tracking { } state;#endif atomic_t dynticks;/* Even value for idle, else odd. */ +long dynticks_nesting;/* Track process nesting level. */ };#ifdef CONFIG_CONTEXT_TRACKING kernel/context_tracking.c +1
-0@@ -234,6 +234,7 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks_nesting =1 , .dynticks =ATOMIC_INIT (1 ), };EXPORT_SYMBOL_GPL (context_tracking);kernel/rcu/tree.c +16
-15@@ -75,7 +75,6 @@/* Data structures. */ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { - .dynticks_nesting =1 , .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , #ifdef CONFIG_RCU_NOCB_CPU .cblist.flags = SEGCBLIST_RCU_CORE,@@ -441,7 +440,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)lockdep_assert_irqs_disabled ();/* Check for counter underflows */ -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <0 ,"RCU dynticks_nesting counter underflow!" );RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 ,"RCU dynticks_nmi_nesting counter underflow/zero!" );@@ -457,7 +456,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)WARN_ON_ONCE (!nesting && !is_idle_task (current));/* Does CPU appear to be idle from an RCU standpoint? */ -return __this_cpu_read (rcu_data.dynticks_nesting) ==0 ; +return __this_cpu_read (context_tracking.dynticks_nesting) ==0 ; }#define DEFAULT_RCU_BLIMIT (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) ? 1000 : 10)@@ -624,16 +623,16 @@ static noinstr void rcu_eqs_enter(bool user)WARN_ON_ONCE (rdp->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE );WRITE_ONCE (rdp->dynticks_nmi_nesting,0 );WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && - rdp->dynticks_nesting ==0 ); -if (rdp->dynticks_nesting !=1 ) { + ct->dynticks_nesting ==0 ); +if (ct->dynticks_nesting !=1 ) {// RCU will still be watching, so just do accounting and leave. - rdp->dynticks_nesting--; + ct->dynticks_nesting--;return ; }lockdep_assert_irqs_disabled ();instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), rdp->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current);@@ -641,7 +640,7 @@ static noinstr void rcu_eqs_enter(bool user)instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks));instrumentation_end (); -WRITE_ONCE (rdp->dynticks_nesting,0 );/* Avoid irq-access tearing. */ +WRITE_ONCE (ct->dynticks_nesting,0 );/* Avoid irq-access tearing. */ // RCU is watching here ... rcu_dynticks_eqs_enter ();// ... but is no longer watching here. @@ -798,7 +797,7 @@ void rcu_irq_exit_check_preempt(void) {lockdep_assert_irqs_disabled (); -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <=0 ,"RCU dynticks_nesting counter underflow/zero!" ); RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) != DYNTICK_IRQ_NONIDLE,@@ -824,11 +823,11 @@ static void noinstr rcu_eqs_exit(bool user)lockdep_assert_irqs_disabled (); rdp =this_cpu_ptr (&rcu_data); - oldval = rdp->dynticks_nesting; + oldval = ct->dynticks_nesting;WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && oldval <0 );if (oldval) {// RCU was already watching, so just do accounting and leave. - rdp->dynticks_nesting++; + ct->dynticks_nesting++;return ; }rcu_dynticks_task_exit ();@@ -840,9 +839,9 @@ static void noinstr rcu_eqs_exit(bool user)// instrumentation for the noinstr rcu_dynticks_eqs_exit() instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -trace_rcu_dyntick (TPS ("End" ), rdp->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); -WRITE_ONCE (rdp->dynticks_nesting,1 ); +WRITE_ONCE (ct->dynticks_nesting,1 );WARN_ON_ONCE (rdp->dynticks_nmi_nesting);WRITE_ONCE (rdp->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE );instrumentation_end ();@@ -4122,12 +4121,13 @@ static void rcu_init_new_rnp(struct rcu_node *rnp_leaf)static void __init rcu_boot_init_percpu_data (int cpu) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);/* Set up local state, ensuring consistent view of global state. */ rdp->grpmask =leaf_node_cpu_bit (rdp->mynode, cpu);INIT_WORK (&rdp->strict_work, strict_work_handler); -WARN_ON_ONCE (rdp->dynticks_nesting !=1 ); +WARN_ON_ONCE (ct->dynticks_nesting !=1 );WARN_ON_ONCE (rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu))); rdp->barrier_seq_snap = rcu_state.barrier_sequence; rdp->rcu_ofl_gp_seq = rcu_state.gp_seq;@@ -4152,6 +4152,7 @@ rcu_boot_init_percpu_data(int cpu)int rcutree_prepare_cpu (unsigned int cpu) {unsigned long flags; +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp =rcu_get_root ();@@ -4160,7 +4161,7 @@ int rcutree_prepare_cpu(unsigned int cpu) rdp->qlen_last_fqs_check =0 ; rdp->n_force_qs_snap =READ_ONCE (rcu_state.n_force_qs); rdp->blimit = blimit; - rdp->dynticks_nesting =1 ;/* CPU not up, no tearing. */ + ct->dynticks_nesting =1 ;/* CPU not up, no tearing. */ raw_spin_unlock_rcu_node (rnp);/* irqs remain disabled. */ /* kernel/rcu/tree.h +0
-1@@ -186,7 +186,6 @@ struct rcu_data {/* 3) dynticks interface. */ int dynticks_snap;/* Per-GP tracking for dynticks. */ -long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */ kernel/rcu/tree_stall.h +2
-1@@ -429,6 +429,7 @@ static void print_cpu_stall_info(int cpu) {unsigned long delta;bool falsepositive; +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);char *ticks_title;unsigned long ticks_value;@@ -459,7 +460,7 @@ static void print_cpu_stall_info(int cpu)"!." [!delta], ticks_value, ticks_title,rcu_dynticks_snap (cpu) &0xfff , - rdp->dynticks_nesting, rdp->dynticks_nmi_nesting, + ct->dynticks_nesting, rdp->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu),data_race (rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart, falsepositive ? " (false positive?)" : "");Signature · 1 line
2.25.1
Re: [PATCH 12/19] rcu/context_tracking: Move dynticks_nmi_nesting to context tracking
In reply to Frederic WeisbeckerQuoted 5 lines · Frederic Weisbecker
The RCU eqs tracking is going to be performed by the context tracking subsystem. The related nesting counters thus need to be moved to the context tracking structure.
Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 260 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking_state.h | 4 +++ kernel/context_tracking.c | 1 + kernel/rcu/rcu.h | 4 --- kernel/rcu/tree.c | 48 +++++++++++--------------- kernel/rcu/tree.h | 1 - kernel/rcu/tree_stall.h | 2 +- 6 files changed, 27 insertions(+), 33 deletions(-)include/linux/context_tracking_state.h +4
-0@@ -6,6 +6,9 @@#include <linux/static_key.h> #include <linux/context_tracking_irq.h> +/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ +#define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) +struct context_tracking {#ifdef CONFIG_CONTEXT_TRACKING_USER /* @@ -25,6 +28,7 @@ struct context_tracking {#endif atomic_t dynticks;/* Even value for idle, else odd. */ long dynticks_nesting;/* Track process nesting level. */ +long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ };#ifdef CONFIG_CONTEXT_TRACKING kernel/context_tracking.c +1
-0@@ -234,6 +234,7 @@ void __init context_tracking_init(void)#endif /* #ifdef CONFIG_CONTEXT_TRACKING_USER */ DEFINE_PER_CPU(struct context_tracking, context_tracking) = { + .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , .dynticks_nesting =1 , .dynticks =ATOMIC_INIT (1 ), };kernel/rcu/rcu.h +0
-4@@ -12,10 +12,6 @@#include <trace/events/rcu.h> -/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ -#define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) - -/* * Grace-period counter management. */ kernel/rcu/tree.c +21
-27@@ -75,7 +75,6 @@/* Data structures. */ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { - .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE ,#ifdef CONFIG_RCU_NOCB_CPU .cblist.flags = SEGCBLIST_RCU_CORE,#endif @@ -442,11 +441,11 @@ static int rcu_is_cpu_rrupt_from_idle(void)/* Check for counter underflows */ RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <0 ,"RCU dynticks_nesting counter underflow!" ); -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nmi_nesting) <=0 ,"RCU dynticks_nmi_nesting counter underflow/zero!" );/* Are we at first interrupt nesting level? */ - nesting =__this_cpu_read (rcu_data.dynticks_nmi_nesting); + nesting =__this_cpu_read (context_tracking.dynticks_nmi_nesting);if (nesting >1 )return false;@@ -617,11 +616,10 @@ EXPORT_SYMBOL_GPL(rcutorture_get_gp_data);*/ static noinstr void rcu_eqs_enter(bool user) { -struct rcu_data *rdp =this_cpu_ptr (&rcu_data);struct context_tracking *ct =this_cpu_ptr (&context_tracking); -WARN_ON_ONCE (rdp->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE ); -WRITE_ONCE (rdp->dynticks_nmi_nesting,0 ); +WARN_ON_ONCE (ct->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE ); +WRITE_ONCE (ct->dynticks_nmi_nesting,0 );WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && ct->dynticks_nesting ==0 );if (ct->dynticks_nesting !=1 ) {@@ -739,7 +737,7 @@ noinstr void rcu_user_enter(void)* rcu_nmi_exit - inform RCU of exit from NMI context * * If we are returning from the outermost NMI handler that interrupted an -* RCU-idle period, update ct->dynticks and rdp->dynticks_nmi_nesting +* RCU-idle period, update ct->dynticks and ct->dynticks_nmi_nesting * to let the RCU grace-period handling know that the CPU is back to * being RCU-idle. * @@ -749,7 +747,6 @@ noinstr void rcu_user_enter(void) noinstr void rcu_nmi_exit(void) {struct context_tracking *ct =this_cpu_ptr (&context_tracking); -struct rcu_data *rdp =this_cpu_ptr (&rcu_data);instrumentation_begin ();/* @@ -757,25 +754,25 @@ noinstr void rcu_nmi_exit(void)* (We are exiting an NMI handler, so RCU better be paying attention * to us!) */ -WARN_ON_ONCE (rdp->dynticks_nmi_nesting <=0 ); +WARN_ON_ONCE (ct->dynticks_nmi_nesting <=0 );WARN_ON_ONCE (rcu_dynticks_curr_cpu_in_eqs ());/* * If the nesting level is not 1, the CPU wasn't RCU-idle, so * leave it in non-RCU-idle state. */ -if (rdp->dynticks_nmi_nesting !=1 ) { -trace_rcu_dyntick (TPS ("--=" ), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting -2 , +if (ct->dynticks_nmi_nesting !=1 ) { +trace_rcu_dyntick (TPS ("--=" ), ct->dynticks_nmi_nesting, ct->dynticks_nmi_nesting -2 ,atomic_read (&ct->dynticks)); -WRITE_ONCE (rdp->dynticks_nmi_nesting,/* No store tearing. */ - rdp->dynticks_nmi_nesting -2 ); +WRITE_ONCE (ct->dynticks_nmi_nesting,/* No store tearing. */ + ct->dynticks_nmi_nesting -2 );instrumentation_end ();return ; }/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ -trace_rcu_dyntick (TPS ("Startirq" ), rdp->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); -WRITE_ONCE (rdp->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ +trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); +WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ // instrumentation for the noinstr rcu_dynticks_eqs_enter() instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks));@@ -799,7 +796,7 @@ void rcu_irq_exit_check_preempt(void)RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <=0 ,"RCU dynticks_nesting counter underflow/zero!" ); -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) != +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nmi_nesting) !=DYNTICK_IRQ_NONIDLE ,"Bad RCU dynticks_nmi_nesting counter\n" ); RCU_LOCKDEP_WARN(rcu_dynticks_curr_cpu_in_eqs(),@@ -818,11 +815,9 @@ void rcu_irq_exit_check_preempt(void) static void noinstr rcu_eqs_exit(bool user) {struct context_tracking *ct =this_cpu_ptr (&context_tracking); -struct rcu_data *rdp;long oldval;lockdep_assert_irqs_disabled (); - rdp =this_cpu_ptr (&rcu_data); oldval = ct->dynticks_nesting;WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && oldval <0 );if (oldval) {@@ -842,8 +837,8 @@ static void noinstr rcu_eqs_exit(bool user)trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks));WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));WRITE_ONCE (ct->dynticks_nesting,1 ); -WARN_ON_ONCE (rdp->dynticks_nmi_nesting); -WRITE_ONCE (rdp->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE ); +WARN_ON_ONCE (ct->dynticks_nmi_nesting); +WRITE_ONCE (ct->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE );instrumentation_end (); }@@ -946,7 +941,7 @@ void __rcu_irq_enter_check_tick(void)* rcu_nmi_enter - inform RCU of entry to NMI context * * If the CPU was idle from RCU's viewpoint, update ct->dynticks and -* rdp->dynticks_nmi_nesting to let the RCU grace-period handling know +* ct->dynticks_nmi_nesting to let the RCU grace-period handling know * that the CPU is active. This implementation permits nested NMIs, as * long as the nesting level does not overflow an int. (You will probably * run out of stack space first.) @@ -957,11 +952,10 @@ void __rcu_irq_enter_check_tick(void) noinstr void rcu_nmi_enter(void) {long incby =2 ; -struct rcu_data *rdp =this_cpu_ptr (&rcu_data);struct context_tracking *ct =this_cpu_ptr (&context_tracking);/* Complain about underflow. */ -WARN_ON_ONCE (rdp->dynticks_nmi_nesting <0 ); +WARN_ON_ONCE (ct->dynticks_nmi_nesting <0 );/* * If idle from RCU viewpoint, atomically increment ->dynticks @@ -995,11 +989,11 @@ noinstr void rcu_nmi_enter(void) }trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), - rdp->dynticks_nmi_nesting, - rdp->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks)); + ct->dynticks_nmi_nesting, + ct->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks));instrumentation_end (); -WRITE_ONCE (rdp->dynticks_nmi_nesting,/* Prevent store tearing. */ - rdp->dynticks_nmi_nesting + incby); +WRITE_ONCE (ct->dynticks_nmi_nesting,/* Prevent store tearing. */ + ct->dynticks_nmi_nesting + incby);barrier (); }kernel/rcu/tree.h +0
-1@@ -186,7 +186,6 @@ struct rcu_data {/* 3) dynticks interface. */ int dynticks_snap;/* Per-GP tracking for dynticks. */ -long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ bool rcu_need_heavy_qs;/* GP old, so heavy quiescent state! */ bool rcu_urgent_qs;/* GP old need light quiescent state. */ bool rcu_forced_tick;/* Forced tick to provide QS. */ kernel/rcu/tree_stall.h +1
-1@@ -460,7 +460,7 @@ static void print_cpu_stall_info(int cpu)"!." [!delta], ticks_value, ticks_title,rcu_dynticks_snap (cpu) &0xfff , - ct->dynticks_nesting, rdp->dynticks_nmi_nesting, + ct->dynticks_nesting, ct->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu),data_race (rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart, falsepositive ? " (false positive?)" : "");Signature · 1 line
2.25.1
Re: [PATCH 13/19] rcu/context-tracking: Move deferred nocb resched to context tracking
In reply to Frederic WeisbeckerQuoted 5 lines · Frederic Weisbecker
To prepare for migrating the RCU eqs accounting code to context tracking, split the last-resort deferred nocb resched from
rcu_user_enter()and move it into a separate call from context tracking.Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 104 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/rcutree.h | 6 ++++++ kernel/context_tracking.c | 8 ++++++++ kernel/rcu/tree.c | 15 ++------------- 3 files changed, 16 insertions(+), 13 deletions(-)include/linux/rcutree.h +6
-0@@ -78,4 +78,10 @@ int rcutree_dead_cpu(unsigned int cpu);int rcutree_dying_cpu (unsigned int cpu);void rcu_cpu_starting (unsigned int cpu); +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +void rcu_irq_work_resched (void ); +#else +static inline void rcu_irq_work_resched (void ) { } +#endif +#endif /* __LINUX_RCUTREE_H */ kernel/context_tracking.c +8
-0@@ -60,6 +60,8 @@ static __always_inline void context_tracking_recursion_exit(void)*/ void noinstr __ct_user_enter(enum ctx_state state) { +lockdep_assert_irqs_disabled (); +/* Kernel threads aren't supposed to go to userspace */ WARN_ON_ONCE (!current->mm);@@ -81,6 +83,12 @@ void noinstr __ct_user_enter(enum ctx_state state)vtime_user_enter (current);instrumentation_end (); } +/* +* Other than generic entry implementation, we may be past the last +* rescheduling opportunity in the entry code. Trigger a self IPI +* that will fire and reschedule once we resume in user/guest mode. +*/ +rcu_irq_work_resched ();rcu_user_enter (); }/* kernel/rcu/tree.c +2
-13@@ -686,7 +686,7 @@ static DEFINE_PER_CPU(struct irq_work, late_wakeup_work) =* last resort is to fire a local irq_work that will trigger a reschedule once IRQs * get re-enabled again. */ -noinstr static void rcu_irq_work_resched(void) +noinstr void rcu_irq_work_resched(void) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data);@@ -702,10 +702,7 @@ noinstr static void rcu_irq_work_resched(void) }instrumentation_end (); } - -#else -static inline void rcu_irq_work_resched (void ) { } -#endif +#endif /* #if !defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK) */ /** * rcu_user_enter - inform RCU that we are resuming userspace. @@ -720,14 +717,6 @@ static inline void rcu_irq_work_resched(void) { }*/ noinstr void rcu_user_enter(void) { -lockdep_assert_irqs_disabled (); - -/* -* Other than generic entry implementation, we may be past the last -* rescheduling opportunity in the entry code. Trigger a self IPI -* that will fire and reschedule once we resume in user/guest mode. -*/ -rcu_irq_work_resched ();rcu_eqs_enter (true); }Signature · 1 line
2.25.1
Re: [PATCH 14/19] rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking
In reply to Frederic WeisbeckerQuoted 4 lines · Frederic Weisbecker
Move the core RCU eqs/dynticks functions to context tracking so that we can later merge all that code within context tracking.
Signed-off-by Frederic Weisbecker <[email protected]>
I am not sure that you want rcu_dynticks_task_enter() and friends in context tracking, but I have no objection to them living there. ;-)
Quoted 874 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking.h | 12 ++ include/linux/rcutree.h | 3 + kernel/context_tracking.c | 347 +++++++++++++++++++++++++++++++ kernel/rcu/tree.c | 326 +---------------------------- kernel/rcu/tree.h | 5 - kernel/rcu/tree_plugin.h | 36 +--- 6 files changed, 366 insertions(+), 363 deletions(-)include/linux/context_tracking.h +12
-0@@ -122,6 +122,18 @@ static inline void context_tracking_init(void) { }#ifdef CONFIG_CONTEXT_TRACKING extern void ct_idle_enter (void );extern void ct_idle_exit (void ); +extern unsigned long rcu_dynticks_inc (int incby); + +/* +* Is the current CPU in an extended quiescent state? +* +* No ordering, as we are sampling CPU-local information. +*/ +static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) +{ +return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); +} +#else static inline void ct_idle_enter (void ) { }static inline void ct_idle_exit (void ) { }include/linux/rcutree.h +3
-0@@ -59,6 +59,9 @@ void rcu_irq_exit_check_preempt(void);static inline void rcu_irq_exit_check_preempt (void ) { }#endif +struct task_struct ; +void rcu_preempt_deferred_qs (struct task_struct *t); +void exit_rcu (void );void rcu_scheduler_starting (void );kernel/context_tracking.c +347
-0@@ -21,6 +21,353 @@#include <linux/hardirq.h> #include <linux/export.h> #include <linux/kprobes.h> +#include <trace/events/rcu.h> + +#define TPS (x) tracepoint_string(x) + +/* Record the current task on dyntick-idle entry. */ +static __always_inline void rcu_dynticks_task_enter(void) +{ +#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) +WRITE_ONCE (current->rcu_tasks_idle_cpu,smp_processor_id ()); +#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ +} + +/* Record no current task on dyntick-idle exit. */ +static __always_inline void rcu_dynticks_task_exit(void) +{ +#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) +WRITE_ONCE (current->rcu_tasks_idle_cpu,-1 ); +#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ +} + +/* Turn on heavyweight RCU tasks trace readers on idle/user entry. */ +static __always_inline void rcu_dynticks_task_trace_enter(void) +{ +#ifdef CONFIG_TASKS_TRACE_RCU +if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) + current->trc_reader_special.b.need_mb = true; +#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ +} + +/* Turn off heavyweight RCU tasks trace readers on idle/user exit. */ +static __always_inline void rcu_dynticks_task_trace_exit(void) +{ +#ifdef CONFIG_TASKS_TRACE_RCU +if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) + current->trc_reader_special.b.need_mb = false; +#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ +} + +/* +* Increment the current CPU's context_tracking structure's ->dynticks field +* with ordering. Return the new value. +*/ +noinstr unsigned long rcu_dynticks_inc (int incby) +{ +return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.dynticks)); +} + +/* +* Record entry into an extended quiescent state. This is only to be +* called when not already in an extended quiescent state, that is, +* RCU is watching prior to the call to this function and is no longer +* watching upon return. +*/ +static noinstr void rcu_dynticks_eqs_enter(void) +{ +int seq; + +/* +* CPUs seeing atomic_add_return() must see prior RCU read-side +* critical sections, and we also must force ordering with the +* next idle sojourn. +*/ +rcu_dynticks_task_trace_enter ();// Before ->dynticks update! + seq =rcu_dynticks_inc (1 ); +// RCU is no longer watching. Better be in extended quiescent state! +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && (seq &0x1 )); +} + +/* +* Record exit from an extended quiescent state. This is only to be +* called from an extended quiescent state, that is, RCU is not watching +* prior to the call to this function and is watching upon return. +*/ +static noinstr void rcu_dynticks_eqs_exit(void) +{ +int seq; + +/* +* CPUs seeing atomic_add_return() must see prior idle sojourns, +* and we also must force ordering with the next RCU read-side +* critical section. +*/ + seq =rcu_dynticks_inc (1 ); +// RCU is now watching. Better not be in an extended quiescent state! +rcu_dynticks_task_trace_exit ();// After ->dynticks update! +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !(seq &0x1 )); +} + +/* +* Enter an RCU extended quiescent state, which can be either the +* idle loop or adaptive-tickless usermode execution. +* +* We crowbar the ->dynticks_nmi_nesting field to zero to allow for +* the possibility of usermode upcalls having messed up our count +* of interrupt nesting level during the prior busy period. +*/ +static noinstr void rcu_eqs_enter(bool user) +{ +struct context_tracking *ct =this_cpu_ptr (&context_tracking); + +WARN_ON_ONCE (ct->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE ); +WRITE_ONCE (ct->dynticks_nmi_nesting,0 ); +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && + ct->dynticks_nesting ==0 ); +if (ct->dynticks_nesting !=1 ) { +// RCU will still be watching, so just do accounting and leave. + ct->dynticks_nesting--; +return ; + } + +lockdep_assert_irqs_disabled (); +instrumentation_begin (); +trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); +rcu_preempt_deferred_qs (current); + +// instrumentation for the noinstr rcu_dynticks_eqs_enter() +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); + +instrumentation_end (); +WRITE_ONCE (ct->dynticks_nesting,0 );/* Avoid irq-access tearing. */ +// RCU is watching here ... +rcu_dynticks_eqs_enter (); +// ... but is no longer watching here. +rcu_dynticks_task_enter (); +} + +/** +* rcu_idle_enter - inform RCU that current CPU is entering idle +* +* Enter idle mode, in other words, -leave- the mode in which RCU +* read-side critical sections can occur. (Though RCU read-side +* critical sections can occur in irq handlers in idle, a possibility +* handled by irq_enter() and irq_exit().) +* +* If you add or remove a call to rcu_idle_enter(), be sure to test with +* CONFIG_RCU_EQS_DEBUG=y. +*/ +void rcu_idle_enter (void ) +{ +lockdep_assert_irqs_disabled (); +rcu_eqs_enter (false); +} + +#ifdef CONFIG_NO_HZ_FULL +/** +* rcu_user_enter - inform RCU that we are resuming userspace. +* +* Enter RCU idle mode right before resuming userspace. No use of RCU +* is permitted between this call and rcu_user_exit(). This way the +* CPU doesn't need to maintain the tick for RCU maintenance purposes +* when the CPU runs in userspace. +* +* If you add or remove a call to rcu_user_enter(), be sure to test with +* CONFIG_RCU_EQS_DEBUG=y. +*/ +noinstr void rcu_user_enter(void) +{ +rcu_eqs_enter (true); +} +#endif /* CONFIG_NO_HZ_FULL */ + +/** +* rcu_nmi_exit - inform RCU of exit from NMI context +* +* If we are returning from the outermost NMI handler that interrupted an +* RCU-idle period, update ct->dynticks and ct->dynticks_nmi_nesting +* to let the RCU grace-period handling know that the CPU is back to +* being RCU-idle. +* +* If you add or remove a call to rcu_nmi_exit(), be sure to test +* with CONFIG_RCU_EQS_DEBUG=y. +*/ +noinstr void rcu_nmi_exit(void) +{ +struct context_tracking *ct =this_cpu_ptr (&context_tracking); + +instrumentation_begin (); +/* +* Check for ->dynticks_nmi_nesting underflow and bad ->dynticks. +* (We are exiting an NMI handler, so RCU better be paying attention +* to us!) +*/ +WARN_ON_ONCE (ct->dynticks_nmi_nesting <=0 ); +WARN_ON_ONCE (rcu_dynticks_curr_cpu_in_eqs ()); + +/* +* If the nesting level is not 1, the CPU wasn't RCU-idle, so +* leave it in non-RCU-idle state. +*/ +if (ct->dynticks_nmi_nesting !=1 ) { +trace_rcu_dyntick (TPS ("--=" ), ct->dynticks_nmi_nesting, ct->dynticks_nmi_nesting -2 , +atomic_read (&ct->dynticks)); +WRITE_ONCE (ct->dynticks_nmi_nesting,/* No store tearing. */ + ct->dynticks_nmi_nesting -2 ); +instrumentation_end (); +return ; + } + +/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ +trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); +WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ + +// instrumentation for the noinstr rcu_dynticks_eqs_enter() +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); +instrumentation_end (); + +// RCU is watching here ... +rcu_dynticks_eqs_enter (); +// ... but is no longer watching here. + +if (!in_nmi ()) +rcu_dynticks_task_enter (); +} + +/* +* Exit an RCU extended quiescent state, which can be either the +* idle loop or adaptive-tickless usermode execution. +* +* We crowbar the ->dynticks_nmi_nesting field to DYNTICK_IRQ_NONIDLE to +* allow for the possibility of usermode upcalls messing up our count of +* interrupt nesting level during the busy period that is just now starting. +*/ +static void noinstr rcu_eqs_exit(bool user) +{ +struct context_tracking *ct =this_cpu_ptr (&context_tracking); +long oldval; + +lockdep_assert_irqs_disabled (); + oldval = ct->dynticks_nesting; +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && oldval <0 ); +if (oldval) { +// RCU was already watching, so just do accounting and leave. + ct->dynticks_nesting++; +return ; + } +rcu_dynticks_task_exit (); +// RCU is not watching here ... +rcu_dynticks_eqs_exit (); +// ... but is watching here. +instrumentation_begin (); + +// instrumentation for the noinstr rcu_dynticks_eqs_exit() +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); + +trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); +WRITE_ONCE (ct->dynticks_nesting,1 ); +WARN_ON_ONCE (ct->dynticks_nmi_nesting); +WRITE_ONCE (ct->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE ); +instrumentation_end (); +} + +/** +* rcu_idle_exit - inform RCU that current CPU is leaving idle +* +* Exit idle mode, in other words, -enter- the mode in which RCU +* read-side critical sections can occur. +* +* If you add or remove a call to rcu_idle_exit(), be sure to test with +* CONFIG_RCU_EQS_DEBUG=y. +*/ +void rcu_idle_exit (void ) +{ +unsigned long flags; + +local_irq_save (flags); +rcu_eqs_exit (false); +local_irq_restore (flags); +} +EXPORT_SYMBOL_GPL (rcu_idle_exit); + +#ifdef CONFIG_NO_HZ_FULL +/** +* rcu_user_exit - inform RCU that we are exiting userspace. +* +* Exit RCU idle mode while entering the kernel because it can +* run a RCU read side critical section anytime. +* +* If you add or remove a call to rcu_user_exit(), be sure to test with +* CONFIG_RCU_EQS_DEBUG=y. +*/ +void noinstr rcu_user_exit(void) +{ +rcu_eqs_exit (true); +} +#endif /* ifdef CONFIG_NO_HZ_FULL */ + +/** +* rcu_nmi_enter - inform RCU of entry to NMI context +* +* If the CPU was idle from RCU's viewpoint, update ct->dynticks and +* ct->dynticks_nmi_nesting to let the RCU grace-period handling know +* that the CPU is active. This implementation permits nested NMIs, as +* long as the nesting level does not overflow an int. (You will probably +* run out of stack space first.) +* +* If you add or remove a call to rcu_nmi_enter(), be sure to test +* with CONFIG_RCU_EQS_DEBUG=y. +*/ +noinstr void rcu_nmi_enter(void) +{ +long incby =2 ; +struct context_tracking *ct =this_cpu_ptr (&context_tracking); + +/* Complain about underflow. */ +WARN_ON_ONCE (ct->dynticks_nmi_nesting <0 ); + +/* +* If idle from RCU viewpoint, atomically increment ->dynticks +* to mark non-idle and increment ->dynticks_nmi_nesting by one. +* Otherwise, increment ->dynticks_nmi_nesting by two. This means +* if ->dynticks_nmi_nesting is equal to one, we are guaranteed +* to be in the outermost NMI handler that interrupted an RCU-idle +* period (observation due to Andy Lutomirski). +*/ +if (rcu_dynticks_curr_cpu_in_eqs ()) { + +if (!in_nmi ()) +rcu_dynticks_task_exit (); + +// RCU is not watching here ... +rcu_dynticks_eqs_exit (); +// ... but is watching here. + +instrumentation_begin (); +// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs() +instrument_atomic_read (&ct->dynticks,sizeof (ct->dynticks)); +// instrumentation for the noinstr rcu_dynticks_eqs_exit() +instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); + + incby =1 ; + }else if (!in_nmi ()) { +instrumentation_begin (); +rcu_irq_enter_check_tick (); + }else { +instrumentation_begin (); + } + +trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), + ct->dynticks_nmi_nesting, + ct->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks)); +instrumentation_end (); +WRITE_ONCE (ct->dynticks_nmi_nesting,/* Prevent store tearing. */ + ct->dynticks_nmi_nesting + incby); +barrier (); +}#ifdef CONFIG_CONTEXT_TRACKING_USER kernel/rcu/tree.c +3
-323@@ -62,6 +62,7 @@#include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/kasan.h> +#include <linux/context_tracking.h> #include "../time/tick-internal.h" #include "tree.h" @@ -259,56 +260,6 @@ void rcu_softirq_qs(void)rcu_tasks_qs (current, false); } -/* -* Increment the current CPU's rcu_data structure's ->dynticks field -* with ordering. Return the new value. -*/ -static noinline noinstr unsigned long rcu_dynticks_inc(int incby) -{ -return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.dynticks)); -} - -/* -* Record entry into an extended quiescent state. This is only to be -* called when not already in an extended quiescent state, that is, -* RCU is watching prior to the call to this function and is no longer -* watching upon return. -*/ -static noinstr void rcu_dynticks_eqs_enter(void) -{ -int seq; - -/* -* CPUs seeing atomic_add_return() must see prior RCU read-side -* critical sections, and we also must force ordering with the -* next idle sojourn. -*/ -rcu_dynticks_task_trace_enter ();// Before ->dynticks update! - seq =rcu_dynticks_inc (1 ); -// RCU is no longer watching. Better be in extended quiescent state! -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && (seq &0x1 )); -} - -/* -* Record exit from an extended quiescent state. This is only to be -* called from an extended quiescent state, that is, RCU is not watching -* prior to the call to this function and is watching upon return. -*/ -static noinstr void rcu_dynticks_eqs_exit(void) -{ -int seq; - -/* -* CPUs seeing atomic_add_return() must see prior idle sojourns, -* and we also must force ordering with the next RCU read-side -* critical section. -*/ - seq =rcu_dynticks_inc (1 ); -// RCU is now watching. Better not be in an extended quiescent state! -rcu_dynticks_task_trace_exit ();// After ->dynticks update! -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !(seq &0x1 )); -} -/* * Reset the current CPU's ->dynticks counter to indicate that the * newly onlined CPU is no longer in an extended quiescent state. @@ -328,16 +279,6 @@ static void rcu_dynticks_eqs_online(void)rcu_dynticks_inc (1 ); } -/* -* Is the current CPU in an extended quiescent state? -* -* No ordering, as we are sampling CPU-local information. -*/ -static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) -{ -return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); -} -/* * Snapshot the ->dynticks counter with full ordering so as to allow * stable comparison of this counter with past and future snapshots. @@ -606,65 +547,7 @@ void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags, }EXPORT_SYMBOL_GPL (rcutorture_get_gp_data); -/* -* Enter an RCU extended quiescent state, which can be either the -* idle loop or adaptive-tickless usermode execution. -* -* We crowbar the ->dynticks_nmi_nesting field to zero to allow for -* the possibility of usermode upcalls having messed up our count -* of interrupt nesting level during the prior busy period. -*/ -static noinstr void rcu_eqs_enter(bool user) -{ -struct context_tracking *ct =this_cpu_ptr (&context_tracking); - -WARN_ON_ONCE (ct->dynticks_nmi_nesting !=DYNTICK_IRQ_NONIDLE ); -WRITE_ONCE (ct->dynticks_nmi_nesting,0 ); -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && - ct->dynticks_nesting ==0 ); -if (ct->dynticks_nesting !=1 ) { -// RCU will still be watching, so just do accounting and leave. - ct->dynticks_nesting--; -return ; - } - -lockdep_assert_irqs_disabled (); -instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); -rcu_preempt_deferred_qs (current); - -// instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); - -instrumentation_end (); -WRITE_ONCE (ct->dynticks_nesting,0 );/* Avoid irq-access tearing. */ -// RCU is watching here ... -rcu_dynticks_eqs_enter (); -// ... but is no longer watching here. -rcu_dynticks_task_enter (); -} - -/** -* rcu_idle_enter - inform RCU that current CPU is entering idle -* -* Enter idle mode, in other words, -leave- the mode in which RCU -* read-side critical sections can occur. (Though RCU read-side -* critical sections can occur in irq handlers in idle, a possibility -* handled by irq_enter() and irq_exit().) -* -* If you add or remove a call to rcu_idle_enter(), be sure to test with -* CONFIG_RCU_EQS_DEBUG=y. -*/ -void rcu_idle_enter (void ) -{ -lockdep_assert_irqs_disabled (); -rcu_eqs_enter (false); -} - -#ifdef CONFIG_NO_HZ_FULL - -#if !defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK ) +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK ))/* * An empty function that will trigger a reschedule on * IRQ tail once IRQs get re-enabled on userspace/guest resume. @@ -702,78 +585,7 @@ noinstr void rcu_irq_work_resched(void) }instrumentation_end (); } -#endif /* #if !defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK) */ - -/** -* rcu_user_enter - inform RCU that we are resuming userspace. -* -* Enter RCU idle mode right before resuming userspace. No use of RCU -* is permitted between this call and rcu_user_exit(). This way the -* CPU doesn't need to maintain the tick for RCU maintenance purposes -* when the CPU runs in userspace. -* -* If you add or remove a call to rcu_user_enter(), be sure to test with -* CONFIG_RCU_EQS_DEBUG=y. -*/ -noinstr void rcu_user_enter(void) -{ -rcu_eqs_enter (true); -} - -#endif /* CONFIG_NO_HZ_FULL */ - -/** -* rcu_nmi_exit - inform RCU of exit from NMI context -* -* If we are returning from the outermost NMI handler that interrupted an -* RCU-idle period, update ct->dynticks and ct->dynticks_nmi_nesting -* to let the RCU grace-period handling know that the CPU is back to -* being RCU-idle. -* -* If you add or remove a call to rcu_nmi_exit(), be sure to test -* with CONFIG_RCU_EQS_DEBUG=y. -*/ -noinstr void rcu_nmi_exit(void) -{ -struct context_tracking *ct =this_cpu_ptr (&context_tracking); - -instrumentation_begin (); -/* -* Check for ->dynticks_nmi_nesting underflow and bad ->dynticks. -* (We are exiting an NMI handler, so RCU better be paying attention -* to us!) -*/ -WARN_ON_ONCE (ct->dynticks_nmi_nesting <=0 ); -WARN_ON_ONCE (rcu_dynticks_curr_cpu_in_eqs ()); - -/* -* If the nesting level is not 1, the CPU wasn't RCU-idle, so -* leave it in non-RCU-idle state. -*/ -if (ct->dynticks_nmi_nesting !=1 ) { -trace_rcu_dyntick (TPS ("--=" ), ct->dynticks_nmi_nesting, ct->dynticks_nmi_nesting -2 , -atomic_read (&ct->dynticks)); -WRITE_ONCE (ct->dynticks_nmi_nesting,/* No store tearing. */ - ct->dynticks_nmi_nesting -2 ); -instrumentation_end (); -return ; - } - -/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ -trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); -WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ - -// instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -instrumentation_end (); - -// RCU is watching here ... -rcu_dynticks_eqs_enter (); -// ... but is no longer watching here. - -if (!in_nmi ()) -rcu_dynticks_task_enter (); -} +#endif /* #if defined(CONFIG_NO_HZ_FULL) && (!defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK)) */ #ifdef CONFIG_PROVE_RCU /** @@ -793,77 +605,6 @@ void rcu_irq_exit_check_preempt(void) }#endif /* #ifdef CONFIG_PROVE_RCU */ -/* -* Exit an RCU extended quiescent state, which can be either the -* idle loop or adaptive-tickless usermode execution. -* -* We crowbar the ->dynticks_nmi_nesting field to DYNTICK_IRQ_NONIDLE to -* allow for the possibility of usermode upcalls messing up our count of -* interrupt nesting level during the busy period that is just now starting. -*/ -static void noinstr rcu_eqs_exit(bool user) -{ -struct context_tracking *ct =this_cpu_ptr (&context_tracking); -long oldval; - -lockdep_assert_irqs_disabled (); - oldval = ct->dynticks_nesting; -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && oldval <0 ); -if (oldval) { -// RCU was already watching, so just do accounting and leave. - ct->dynticks_nesting++; -return ; - } -rcu_dynticks_task_exit (); -// RCU is not watching here ... -rcu_dynticks_eqs_exit (); -// ... but is watching here. -instrumentation_begin (); - -// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); - -trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current)); -WRITE_ONCE (ct->dynticks_nesting,1 ); -WARN_ON_ONCE (ct->dynticks_nmi_nesting); -WRITE_ONCE (ct->dynticks_nmi_nesting,DYNTICK_IRQ_NONIDLE ); -instrumentation_end (); -} - -/** -* rcu_idle_exit - inform RCU that current CPU is leaving idle -* -* Exit idle mode, in other words, -enter- the mode in which RCU -* read-side critical sections can occur. -* -* If you add or remove a call to rcu_idle_exit(), be sure to test with -* CONFIG_RCU_EQS_DEBUG=y. -*/ -void rcu_idle_exit (void ) -{ -unsigned long flags; - -local_irq_save (flags); -rcu_eqs_exit (false); -local_irq_restore (flags); -} - -#ifdef CONFIG_NO_HZ_FULL -/** -* rcu_user_exit - inform RCU that we are exiting userspace. -* -* Exit RCU idle mode while entering the kernel because it can -* run a RCU read side critical section anytime. -* -* If you add or remove a call to rcu_user_exit(), be sure to test with -* CONFIG_RCU_EQS_DEBUG=y. -*/ -void noinstr rcu_user_exit(void) -{ -rcu_eqs_exit (true); -} -/** * __rcu_irq_enter_check_tick - Enable scheduler tick on CPU if RCU needs it. * @@ -924,67 +665,6 @@ void __rcu_irq_enter_check_tick(void) }raw_spin_unlock_rcu_node (rdp->mynode); } -#endif /* CONFIG_NO_HZ_FULL */ - -/** -* rcu_nmi_enter - inform RCU of entry to NMI context -* -* If the CPU was idle from RCU's viewpoint, update ct->dynticks and -* ct->dynticks_nmi_nesting to let the RCU grace-period handling know -* that the CPU is active. This implementation permits nested NMIs, as -* long as the nesting level does not overflow an int. (You will probably -* run out of stack space first.) -* -* If you add or remove a call to rcu_nmi_enter(), be sure to test -* with CONFIG_RCU_EQS_DEBUG=y. -*/ -noinstr void rcu_nmi_enter(void) -{ -long incby =2 ; -struct context_tracking *ct =this_cpu_ptr (&context_tracking); - -/* Complain about underflow. */ -WARN_ON_ONCE (ct->dynticks_nmi_nesting <0 ); - -/* -* If idle from RCU viewpoint, atomically increment ->dynticks -* to mark non-idle and increment ->dynticks_nmi_nesting by one. -* Otherwise, increment ->dynticks_nmi_nesting by two. This means -* if ->dynticks_nmi_nesting is equal to one, we are guaranteed -* to be in the outermost NMI handler that interrupted an RCU-idle -* period (observation due to Andy Lutomirski). -*/ -if (rcu_dynticks_curr_cpu_in_eqs ()) { - -if (!in_nmi ()) -rcu_dynticks_task_exit (); - -// RCU is not watching here ... -rcu_dynticks_eqs_exit (); -// ... but is watching here. - -instrumentation_begin (); -// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs() -instrument_atomic_read (&ct->dynticks,sizeof (ct->dynticks)); -// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); - - incby =1 ; - }else if (!in_nmi ()) { -instrumentation_begin (); -rcu_irq_enter_check_tick (); - }else { -instrumentation_begin (); - } - -trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), - ct->dynticks_nmi_nesting, - ct->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks)); -instrumentation_end (); -WRITE_ONCE (ct->dynticks_nmi_nesting,/* Prevent store tearing. */ - ct->dynticks_nmi_nesting + incby); -barrier (); -}/* * Check to see if any future non-offloaded RCU-related work will need kernel/rcu/tree.h +0
-5@@ -426,7 +426,6 @@ static void rcu_cpu_kthread_setup(unsigned int cpu);static void rcu_spawn_one_boost_kthread (struct rcu_node *rnp);static bool rcu_preempt_has_tasks (struct rcu_node *rnp);static bool rcu_preempt_need_deferred_qs (struct task_struct *t); -static void rcu_preempt_deferred_qs (struct task_struct *t);static void zero_cpu_stall_ticks (struct rcu_data *rdp);static struct swait_queue_head *rcu_nocb_gp_get (struct rcu_node *rnp);static void rcu_nocb_gp_cleanup (struct swait_queue_head *sq);@@ -466,10 +465,6 @@ do { \static void rcu_bind_gp_kthread (void );static bool rcu_nohz_full_cpu (void ); -static void rcu_dynticks_task_enter (void ); -static void rcu_dynticks_task_exit (void ); -static void rcu_dynticks_task_trace_enter (void ); -static void rcu_dynticks_task_trace_exit (void );/* Forward declarations for tree_stall.h */ static void record_gp_stall_check_time (void );kernel/rcu/tree_plugin.h +1
-35@@ -595,7 +595,7 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t)* evaluate safety in terms of interrupt, softirq, and preemption * disabling. */ -static void rcu_preempt_deferred_qs (struct task_struct *t) +void rcu_preempt_deferred_qs (struct task_struct *t) {unsigned long flags;@@ -1283,37 +1283,3 @@ static void rcu_bind_gp_kthread(void)return ;housekeeping_affine (current,HK_FLAG_RCU ); } - -/* Record the current task on dyntick-idle entry. */ -static __always_inline void rcu_dynticks_task_enter(void) -{ -#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) -WRITE_ONCE (current->rcu_tasks_idle_cpu,smp_processor_id ()); -#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ -} - -/* Record no current task on dyntick-idle exit. */ -static __always_inline void rcu_dynticks_task_exit(void) -{ -#if defined(CONFIG_TASKS_RCU ) && defined(CONFIG_NO_HZ_FULL ) -WRITE_ONCE (current->rcu_tasks_idle_cpu,-1 ); -#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ -} - -/* Turn on heavyweight RCU tasks trace readers on idle/user entry. */ -static __always_inline void rcu_dynticks_task_trace_enter(void) -{ -#ifdef CONFIG_TASKS_TRACE_RCU -if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) - current->trc_reader_special.b.need_mb = true; -#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ -} - -/* Turn off heavyweight RCU tasks trace readers on idle/user exit. */ -static __always_inline void rcu_dynticks_task_trace_exit(void) -{ -#ifdef CONFIG_TASKS_TRACE_RCU -if (IS_ENABLED (CONFIG_TASKS_TRACE_RCU_READ_MB )) - current->trc_reader_special.b.need_mb = false; -#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */ -}Signature · 1 line
2.25.1
Re: [PATCH 17/19] rcu/context-tracking: Use accessor for dynticks counter value
In reply to Frederic WeisbeckerQuoted 5 lines · Frederic Weisbecker
The dynticks counter value is going to join the context tracking state in a single field. Use an accessor for this value to make the transition easier for all readers.
Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 149 lines
Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking_state.h | 17 +++++++++++++++++ kernel/context_tracking.c | 10 +++++----- kernel/rcu/tree.c | 13 ++++--------- 3 files changed, 26 insertions(+), 14 deletions(-)include/linux/context_tracking_state.h +17
-0@@ -40,6 +40,23 @@ static __always_inline int __ct_state(void) {return atomic_read (this_cpu_ptr (&context_tracking.state)); } + +static __always_inline int ct_dynticks(void) +{ +return atomic_read (this_cpu_ptr (&context_tracking.dynticks)); +} + +static __always_inline int ct_dynticks_cpu(int cpu) +{ +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); +return atomic_read (&ct->dynticks); +} + +static __always_inline int ct_dynticks_cpu_acquire(int cpu) +{ +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); +return atomic_read_acquire (&ct->state); +}#endif #ifdef CONFIG_CONTEXT_TRACKING_USER kernel/context_tracking.c +5
-5@@ -133,7 +133,7 @@ static noinstr void rcu_eqs_enter(bool user)lockdep_assert_irqs_disabled ();instrumentation_begin (); -trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Start" ), ct->dynticks_nesting,0 ,ct_dynticks ());WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current);@@ -178,7 +178,7 @@ noinstr void ct_nmi_exit(void)*/ if (ct->dynticks_nmi_nesting !=1 ) {trace_rcu_dyntick (TPS ("--=" ), ct->dynticks_nmi_nesting, ct->dynticks_nmi_nesting -2 , -atomic_read (&ct->dynticks)); +ct_dynticks ());WRITE_ONCE (ct->dynticks_nmi_nesting,/* No store tearing. */ ct->dynticks_nmi_nesting -2 );instrumentation_end ();@@ -186,7 +186,7 @@ noinstr void ct_nmi_exit(void) }/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */ -trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,ct_dynticks ());WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ // instrumentation for the noinstr rcu_dynticks_eqs_enter() @@ -231,7 +231,7 @@ static void noinstr rcu_eqs_exit(bool user)// instrumentation for the noinstr rcu_dynticks_eqs_exit() instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); -trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,atomic_read (&ct->dynticks)); +trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,ct_dynticks ());WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));WRITE_ONCE (ct->dynticks_nesting,1 );WARN_ON_ONCE (ct->dynticks_nmi_nesting);@@ -292,7 +292,7 @@ noinstr void ct_nmi_enter(void)trace_rcu_dyntick (incby ==1 ?TPS ("Endirq" ) :TPS ("++=" ), ct->dynticks_nmi_nesting, - ct->dynticks_nmi_nesting + incby,atomic_read (&ct->dynticks)); + ct->dynticks_nmi_nesting + incby,ct_dynticks ());instrumentation_end ();WRITE_ONCE (ct->dynticks_nmi_nesting,/* Prevent store tearing. */ ct->dynticks_nmi_nesting + incby);kernel/rcu/tree.c +4
-9@@ -272,9 +272,7 @@ void rcu_softirq_qs(void)*/ static void rcu_dynticks_eqs_online (void ) { -struct context_tracking *ct =this_cpu_ptr (&context_tracking); - -if (atomic_read (&ct->dynticks) &0x1 ) +if (ct_dynticks () &0x1 )return ;rcu_dynticks_inc (1 ); }@@ -285,10 +283,8 @@ static void rcu_dynticks_eqs_online(void)*/ static int rcu_dynticks_snap (int cpu) { -struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -smp_mb ();// Fundamental RCU ordering guarantee. -return atomic_read_acquire (&ct->dynticks); +return ct_dynticks_cpu_acquire (cpu); }/* @@ -322,11 +318,10 @@ static bool rcu_dynticks_in_eqs_since(struct rcu_data *rdp, int snap)*/ bool rcu_dynticks_zero_in_eqs (int cpu,int *vp) { -struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =atomic_read (&ct->dynticks) & ~0x1 ; + snap =ct_dynticks_cpu (cpu) & ~0x1 ;smp_rmb ();// Order ->dynticks and *vp reads. if (READ_ONCE (*vp))@@ -334,7 +329,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)smp_rmb ();// Order *vp read and ->dynticks re-read. // If still in the same extended quiescent state, we are good! -return snap ==atomic_read (&ct->dynticks); +return snap ==ct_dynticks_cpu (cpu); }/* Signature · 1 line
2.25.1
Paul E. McKenney
maintainerRe: [PATCH 18/19] rcu/context_tracking: Merge dynticks counter and context tracking states
In reply to Frederic WeisbeckerQuoted 7 lines · Frederic Weisbecker
Updating the context tracking state and the RCU dynticks counter atomically in a single operation is a first step towards improving CPU isolation. This makes the context tracking state updates fully ordered and therefore allow for later enhancements such as postponing some work while a task is running isolated in userspace until it ever comes back to the kernel.
Quoted 7 lines
The state field becomes divided in two parts:
1) Lower bits for context tracking state:
CONTEXT_IDLE= 1,
CONTEXT_USER= 2,
CONTEXT_GUEST= 4,
And the CONTEXT_DISABLED value of -1 works because you can have only one of the above three bits set at a time?
Except that RCU needs this to unconditionally at least distinguish between kernel and idle, given the prevalence of CONFIG_NO_HZ_IDLE=y. So does the CONTEXT_DISABLED really happen anymore?
A few more questions interspersed below.
Thanx, Paul
Quoted 345 lines
A value of 0 means we are in
CONTEXT_KERNEL.2) Higher bits for RCU eqs dynticks counting:
RCU_DYNTICKS_IDX= 8The dynticks counting is always incremented by this value. (state &
RCU_DYNTICKS_IDX) means we are NOT in an extended quiescent state. This makes the chance for a collision more likely between two RCU dynticks snapshots but wrapping up 24 bits of eqs dynticks increments still takes some bad luck (also rdp.dynticks_snap could be converted from int to long?)Some RCU eqs functions have been renamed to better reflect their broader scope that now include context tracking state.
Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- include/linux/context_tracking.h | 4 +- include/linux/context_tracking_state.h | 33 ++++++--- kernel/context_tracking.c | 92 +++++++++++++------------- kernel/rcu/tree.c | 13 ++-- kernel/rcu/tree_stall.h | 2 +- 5 files changed, 81 insertions(+), 63 deletions(-)include/linux/context_tracking.h +2
-2@@ -110,7 +110,7 @@ static inline void context_tracking_init(void) { }#ifdef CONFIG_CONTEXT_TRACKING extern void ct_idle_enter (void );extern void ct_idle_exit (void ); -extern unsigned long rcu_dynticks_inc (int incby); +extern unsigned long ct_state_inc (int incby);/* * Is the current CPU in an extended quiescent state? @@ -119,7 +119,7 @@ extern unsigned long rcu_dynticks_inc(int incby);*/ static __always_inline bool rcu_dynticks_curr_cpu_in_eqs(void) { -return !(arch_atomic_read (this_cpu_ptr (&context_tracking.dynticks)) &0x1 ); +return !(arch_atomic_read (this_cpu_ptr (&context_tracking.state)) &RCU_DYNTICKS_IDX ); }#else include/linux/context_tracking_state.h +25
-8@@ -9,13 +9,29 @@/* Offset to allow distinguishing irq vs. task-based idle entry/exit. */ #define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) +enum { +CONTEXT_IDLE_OFFSET =0 , +CONTEXT_USER_OFFSET , +CONTEXT_GUEST_OFFSET , +CONTEXT_MAX_OFFSET , +}; +enum ctx_state { CONTEXT_> DISABLED = -1, /* returned by ct_state() if unknown */CONTEXT_KERNEL =0 , -CONTEXT_USER , -CONTEXT_GUEST , +CONTEXT_IDLE =BIT (CONTEXT_IDLE_OFFSET ), +CONTEXT_USER =BIT (CONTEXT_USER_OFFSET ), +CONTEXT_GUEST =BIT (CONTEXT_GUEST_OFFSET ), +CONTEXT_MAX =BIT (CONTEXT_MAX_OFFSET ), }; +/* Even value for idle, else odd. */ +#define RCU_DYNTICKS_SHIFT CONTEXT_MAX_OFFSET +#define RCU_DYNTICKS_IDX CONTEXT_MAX + +#define CT_STATE_MASK (CONTEXT_MAX - 1) +#define CT_DYNTICKS_MASK (~CT_STATE_MASK) +struct context_tracking {#ifdef CONFIG_CONTEXT_TRACKING_USER /* @@ -26,9 +42,8 @@ struct context_tracking {*/ bool active;int recursion; +#endif atomic_t state; -#endif -atomic_t dynticks;/* Even value for idle, else odd. */ long dynticks_nesting;/* Track process nesting level. */ long dynticks_nmi_nesting;/* Track irq/NMI nesting level. */ };@@ -38,24 +53,26 @@ DECLARE_PER_CPU(struct context_tracking, context_tracking); static __always_inline int __ct_state(void) { -return atomic_read (this_cpu_ptr (&context_tracking.state)); +return atomic_read (this_cpu_ptr (&context_tracking.state)) &CT_STATE_MASK ; } static __always_inline int ct_dynticks(void) { -return atomic_read (this_cpu_ptr (&context_tracking.dynticks)); +return atomic_read (this_cpu_ptr (&context_tracking.state)) &CT_DYNTICKS_MASK ; } static __always_inline int ct_dynticks_cpu(int cpu) {struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -return atomic_read (&ct->dynticks); + +return atomic_read (&ct->state) &CT_DYNTICKS_MASK ; } static __always_inline int ct_dynticks_cpu_acquire(int cpu) {struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu); -return atomic_read_acquire (&ct->state); + +return atomic_read_acquire (&ct->state) &CT_DYNTICKS_MASK ; }#endif kernel/context_tracking.c +41
-40@@ -63,9 +63,9 @@ static __always_inline void rcu_dynticks_task_trace_exit(void)* Increment the current CPU's context_tracking structure's ->dynticks field * with ordering. Return the new value. */ -noinstr unsigned long rcu_dynticks_inc (int incby) +noinstr unsigned long ct_state_inc (int incby) { -return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.dynticks)); +return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.state)); }/* @@ -74,7 +74,7 @@ noinstr unsigned long rcu_dynticks_inc(int incby)* RCU is watching prior to the call to this function and is no longer * watching upon return. */ -static noinstr void rcu_dynticks_eqs_enter(void) +static noinstr void ct_kernel_exit_state(int offset) {int seq;@@ -84,9 +84,9 @@ static noinstr void rcu_dynticks_eqs_enter(void)* next idle sojourn. */ rcu_dynticks_task_trace_enter ();// Before ->dynticks update! - seq =rcu_dynticks_inc (1 ); + seq =ct_state_inc (offset);// RCU is no longer watching. Better be in extended quiescent state! -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && (seq &0x1 )); +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && (seq &RCU_DYNTICKS_IDX )); }/* @@ -94,7 +94,7 @@ static noinstr void rcu_dynticks_eqs_enter(void)* called from an extended quiescent state, that is, RCU is not watching * prior to the call to this function and is watching upon return. */ -static noinstr void rcu_dynticks_eqs_exit(void) +static noinstr void ct_kernel_enter_state(int offset) {int seq;@@ -103,10 +103,10 @@ static noinstr void rcu_dynticks_eqs_exit(void)* and we also must force ordering with the next RCU read-side * critical section. */ - seq =rcu_dynticks_inc (1 ); + seq =ct_state_inc (offset);// RCU is now watching. Better not be in an extended quiescent state! rcu_dynticks_task_trace_exit ();// After ->dynticks update! -WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !(seq &0x1 )); +WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !(seq &RCU_DYNTICKS_IDX )); }/* @@ -117,7 +117,7 @@ static noinstr void rcu_dynticks_eqs_exit(void)* the possibility of usermode upcalls having messed up our count * of interrupt nesting level during the prior busy period. */ -static noinstr void rcu_eqs_enter(bool user) +static noinstr void ct_kernel_exit(bool user, int offset) {struct context_tracking *ct =this_cpu_ptr (&context_tracking);@@ -137,13 +137,13 @@ static noinstr void rcu_eqs_enter(bool user)WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));rcu_preempt_deferred_qs (current); -// instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); +// instrumentation for the noinstr ct_kernel_exit_state() +instrument_atomic_write (&ct->state,sizeof (ct->state));instrumentation_end ();WRITE_ONCE (ct->dynticks_nesting,0 );/* Avoid irq-access tearing. */ // RCU is watching here ... -rcu_dynticks_eqs_enter (); +ct_kernel_exit_state (offset);// ... but is no longer watching here. rcu_dynticks_task_enter (); }@@ -152,7 +152,7 @@ static noinstr void rcu_eqs_enter(bool user)* ct_nmi_exit - inform RCU of exit from NMI context * * If we are returning from the outermost NMI handler that interrupted an -* RCU-idle period, update ct->dynticks and ct->dynticks_nmi_nesting +* RCU-idle period, update ct->state and ct->dynticks_nmi_nesting * to let the RCU grace-period handling know that the CPU is back to * being RCU-idle. * @@ -189,12 +189,12 @@ noinstr void ct_nmi_exit(void)trace_rcu_dyntick (TPS ("Startirq" ), ct->dynticks_nmi_nesting,0 ,ct_dynticks ());WRITE_ONCE (ct->dynticks_nmi_nesting,0 );/* Avoid store tearing. */ -// instrumentation for the noinstr rcu_dynticks_eqs_enter() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); +// instrumentation for the noinstr ct_kernel_exit_state() +instrument_atomic_write (&ct->state,sizeof (ct->state));instrumentation_end ();// RCU is watching here ... -rcu_dynticks_eqs_enter (); +ct_kernel_exit_state (RCU_DYNTICKS_IDX );// ... but is no longer watching here. if (!in_nmi ())@@ -209,7 +209,7 @@ noinstr void ct_nmi_exit(void)* allow for the possibility of usermode upcalls messing up our count of * interrupt nesting level during the busy period that is just now starting. */ -static void noinstr rcu_eqs_exit(bool user) +static void noinstr ct_kernel_enter(bool user, int offset) {struct context_tracking *ct =this_cpu_ptr (&context_tracking);long oldval;@@ -224,12 +224,12 @@ static void noinstr rcu_eqs_exit(bool user) }rcu_dynticks_task_exit ();// RCU is not watching here ... -rcu_dynticks_eqs_exit (); +ct_kernel_enter_state (offset);// ... but is watching here. instrumentation_begin (); -// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); +// instrumentation for the noinstr ct_kernel_enter_state() +instrument_atomic_write (&ct->state,sizeof (ct->state));trace_rcu_dyntick (TPS ("End" ), ct->dynticks_nesting,1 ,ct_dynticks ());WARN_ON_ONCE (IS_ENABLED (CONFIG_RCU_EQS_DEBUG ) && !user && !is_idle_task (current));@@ -242,7 +242,7 @@ static void noinstr rcu_eqs_exit(bool user)/** * ct_nmi_enter - inform RCU of entry to NMI context * -* If the CPU was idle from RCU's viewpoint, update ct->dynticks and +* If the CPU was idle from RCU's viewpoint, update ct->state and * ct->dynticks_nmi_nesting to let the RCU grace-period handling know * that the CPU is active. This implementation permits nested NMIs, as * long as the nesting level does not overflow an int. (You will probably @@ -273,14 +273,14 @@ noinstr void ct_nmi_enter(void)rcu_dynticks_task_exit ();// RCU is not watching here ... -rcu_dynticks_eqs_exit (); +ct_kernel_enter_state (RCU_DYNTICKS_IDX );// ... but is watching here. instrumentation_begin ();// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs() -instrument_atomic_read (&ct->dynticks,sizeof (ct->dynticks)); -// instrumentation for the noinstr rcu_dynticks_eqs_exit() -instrument_atomic_write (&ct->dynticks,sizeof (ct->dynticks)); +instrument_atomic_read (&ct->state,sizeof (ct->state)); +// instrumentation for the noinstr ct_kernel_enter_state() +instrument_atomic_write (&ct->state,sizeof (ct->state)); incby =1 ; }else if (!in_nmi ()) {@@ -373,22 +373,23 @@ void noinstr __ct_user_enter(enum ctx_state state)* CPU doesn't need to maintain the tick for RCU maintenance purposes * when the CPU runs in userspace. */ -rcu_eqs_enter (true); +ct_kernel_exit (true,RCU_DYNTICKS_IDX + state); + }else { +/* +* Even if context tracking is disabled on this CPU, because it's outside +* the full dynticks mask for example, we still have to keep track of the +* context transitions and states to prevent inconsistency on those of +* other CPUs. +* If a task triggers an exception in userspace, sleep on the exception +* handler and then migrate to another CPU, that new CPU must know where +* the exception returns by the time we call exception_exit(). +* This information can only be provided by the previous CPU when it called +* exception_enter(). +* OTOH we can spare the calls to vtime and RCU when context_tracking.active +* is false because we know that CPU is not tickless. +*/ +atomic_add (state, &ct->state); } -/* -* Even if context tracking is disabled on this CPU, because it's outside -* the full dynticks mask for example, we still have to keep track of the -* context transitions and states to prevent inconsistency on those of -* other CPUs. -* If a task triggers an exception in userspace, sleep on the exception -* handler and then migrate to another CPU, that new CPU must know where -* the exception returns by the time we call exception_exit(). -* This information can only be provided by the previous CPU when it called -* exception_enter(). -* OTOH we can spare the calls to vtime and RCU when context_tracking.active -* is false because we know that CPU is not tickless. -*/ -atomic_set (&ct->state, state); }context_tracking_recursion_exit (); }@@ -452,15 +453,16 @@ void noinstr __ct_user_exit(enum ctx_state state)* Exit RCU idle mode while entering the kernel because it can * run a RCU read side critical section anytime. */
kernel/context_tracking.c void noinstr __ct_user_exit(enum ctx_state state) · line 464
Quoted 10 lines
kernel/context_tracking.c +3
-1-rcu_eqs_exit (true); +ct_kernel_enter (true,RCU_DYNTICKS_IDX - state);if (state ==CONTEXT_USER ) {instrumentation_begin ();vtime_user_exit (current);trace_user_exit (0 );instrumentation_end (); } + }else { +atomic_sub (state, &ct->state);
OK, atomic_sub() got my attention. What is going on here? ;-)
Quoted 24 lines
kernel/context_tracking.c +2
-3} -atomic_set (&ct->state,CONTEXT_KERNEL ); }context_tracking_recursion_exit (); }@@ -530,7 +532,7 @@ void __init context_tracking_init(void) DEFINE_PER_CPU(struct context_tracking, context_tracking) = { .dynticks_nmi_nesting =DYNTICK_IRQ_NONIDLE , .dynticks_nesting =1 , - .dynticks =ATOMIC_INIT (1 ), + .state =ATOMIC_INIT (RCU_DYNTICKS_IDX ), };EXPORT_SYMBOL_GPL (context_tracking);@@ -548,7 +550,7 @@ EXPORT_SYMBOL_GPL(context_tracking);void ct_idle_enter (void ) {lockdep_assert_irqs_disabled (); -rcu_eqs_enter (false); +ct_kernel_exit (false,RCU_DYNTICKS_IDX +CONTEXT_IDLE ); }EXPORT_SYMBOL_GPL (ct_idle_enter);
kernel/context_tracking.c void ct_idle_exit(void) · line 571
Quoted 5 lines
kernel/context_tracking.c +1
-1@@ -566,7 +568,7 @@ void ct_idle_exit(void)unsigned long flags;local_irq_save (flags); -rcu_eqs_exit (false); +ct_kernel_enter (false,RCU_DYNTICKS_IDX -CONTEXT_IDLE );
Nice! This works because all transitions must be either from or to kernel context, correct?
Quoted 29 lines
kernel/context_tracking.c +0
-0local_irq_restore (flags); }kernel/rcu/tree.c +3
-3@@ -272,9 +272,9 @@ void rcu_softirq_qs(void)*/ static void rcu_dynticks_eqs_online (void ) { -if (ct_dynticks () &0x1 ) +if (ct_dynticks () &RCU_DYNTICKS_IDX )return ; -rcu_dynticks_inc (1 ); +ct_state_inc (RCU_DYNTICKS_IDX ); }/* @@ -293,7 +293,7 @@ static int rcu_dynticks_snap(int cpu)*/ static bool rcu_dynticks_in_eqs (int snap) { -return !(snap &0x1 ); +return !(snap &RCU_DYNTICKS_IDX ); }/* Return true if the specified CPU is currently idle from an RCU viewpoint. */
kernel/rcu/tree.c bool rcu_dynticks_zero_in_eqs(int cpu, int *vp) · line 324
Quoted 6 lines
kernel/rcu/tree.c +1
-2@@ -321,8 +321,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =ct_dynticks_cpu (cpu) & ~0x1 ; - + snap =ct_dynticks_cpu (cpu) & ~RCU_DYNTICKS_IDX ;
Do we also need to get rid of the low-order bits? Or is that happening elsewhere? Or is there some reason that they can stick around?
Quoted 20 lines
kernel/rcu/tree.c +2
-2smp_rmb ();// Order ->dynticks and *vp reads. if (READ_ONCE (*vp))return false;// Non-zero, so report failure; @@ -348,9 +347,9 @@ notrace void rcu_momentary_dyntick_idle(void)int seq;raw_cpu_write (rcu_data.rcu_need_heavy_qs, false); - seq =rcu_dynticks_inc (2 ); + seq =ct_state_inc (2 *RCU_DYNTICKS_IDX );/* It is illegal to call this from idle state. */ -WARN_ON_ONCE (!(seq &0x1 )); +WARN_ON_ONCE (!(seq &RCU_DYNTICKS_IDX ));rcu_preempt_deferred_qs (current); }EXPORT_SYMBOL_GPL (rcu_momentary_dyntick_idle);kernel/rcu/tree_stall.h +0
-0
kernel/rcu/tree_stall.h static void print_cpu_stall_info(int cpu) · line 462
Quoted 5 lines
kernel/rcu/tree_stall.h +1
-1@@ -459,7 +459,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int )min (delta,9UL ) +'0' :"!." [!delta], ticks_value, ticks_title, - rcu_dynticks_snap(cpu) & 0xfff, + (rcu_dynticks_snap(cpu) >> RCU_DYNTICKS_SHIFT) & 0xfff ,
Actually, the low-ordder several bits are useful when debugging, so could you please not shift them away? Maybe also go to 0xffff to allow for more bits taken?
Quoted 6 lines
kernel/rcu/tree_stall.h +0
-0ct->dynticks_nesting, ct->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu), data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,Signature · 1 line
2.25.1
Quoted 20 lines · Frederic Weisbecker
This mixes up the RCU dynticks counter and the context tracking state updates into a single atomic instruction. This may serve several purposes:
1) Improve CPU isolation with deferring some disturbances until sensitive userspace workload completes and goes to the kernel. This can take several forms, for example
smp_call_function_housekeeping()oron_each_housekeeping_cpu()to enqueue and execute work on all housekeeping CPUs. Then an atomic operation onct->statecan defer the work onnohz_fullCPUs until they run in kernel (or IPI them if they are in kernel mode), see this proposal by Peter:https://lore.kernel.org/all/[email protected]/#r2) Unearth sysidle (https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git/commit/?h=sysidle.2017.05.11a&id=fe5ac724d81a3c7803e60c2232718f212f3f38d4)
This feature allowed to shutdown the tick on the last housekeeping
CPU once the rest of the system is fully idle. We needed some proper
fully ordered context tracking for that.Inspired by Peterz: https://lore.kernel.org/all/[email protected]
Quoted 8 lines
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
rcu/context-trackingHEAD:
e4eaff86ec91c1cbde9a113cf5232dac9f897337Thanks,
Frederic
---
I've been testing patches 1 to 18 on my nohz_full setup. Everything is looking good so far.
Regards,
Nicolas
Frederic Weisbecker
maintainerRe: [PATCH 19/19] context_tracking: Exempt CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK from non-active tracking
In reply to nicolas saenz julienneQuoted 62 lines · nicolas saenz julienne
Hi Frederic,
Quoted 50 lines · Frederic Weisbecker
Since a CPU may save the state of the context tracking using
exception_enter()before calling intoschedule(), we need all CPUs in the system to track user <-> kernel transitions and not just those that really need it (nohz_fullCPUs).The following illustrates the issue that could otherwise happen:
CPU 0 (not tracking) CPU 1 (tracking) ------------------- -------------------- // we are past user_enter() // but this CPU is always in // CONTEXT_KERNEL // because it doesn't track user <-> kernel ctx = exception_enter(); //ctx == CONTEXT_KERNEL schedule(); ===========================================> return from schedule(); exception_exit(ctx); //go to user in CONTEXT_KERNELHowever
CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACKdoesn't play those games becauseschedule()can't be called betweenuser_enter()anduser_exit()under such config. In this situation we can spare context tracking on the CPUs that don't need it.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>--- kernel/context_tracking.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/context_tracking.c +0
-0kernel/context_tracking.c void noinstr __ct_user_enter(enum ctx_state state) · line 377
Quoted 5 lines
kernel/context_tracking.c +1
-1@@ -374,7 +374,7 @@ void noinstr __ct_user_enter(enum ctx_state state)* when the CPU runs in userspace. */ ct_kernel_exit (true,RCU_DYNTICKS_IDX + state); - }else { + }else if (!IS_ENABLED (CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK )) {user entry code assumes that state will be kept on all CPUs as long as context tracking is enabled. See
kernel/entry/common.c:
Quoted 7 lines
static __always_inline void __enter_from_user_mode(struct pt_regs *regs) { arch_check_user_regs(regs); lockdep_hardirqs_off(CALLER_ADDR0);CT_WARN_ON(ct_state() != CONTEXT_USER); <-- NOT HAPPY ABOUT THIS CHANGE
Good point!
So I need to do:
#ifdef CONFIG_HAVE_CONTEXT_TRACKING_USER_OFFSTACK
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled_this_cpu() && (cond)) #else
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled() && (cond)) #endif
Thanks.
Quoted 9 lines
user_exit_irqoff(); instrumentation_begin(); trace_hardirqs_off_finish(); instrumentation_end();}
Regards,
Nicolas
Frederic Weisbecker
maintainerRe: [PATCH 15/19] rcu/context-tracking: Remove unused and/or unecessary middle functions
In reply to nicolas saenz julienneQuoted 25 lines · nicolas saenz julienne
Quoted 22 lines · Frederic Weisbecker
Some eqs functions are now only used internally by context tracking, so their public declarations can be removed.
Also middle functions such as rcu_user_*() and rcu_idle_*() which now directly call to
rcu_eqs_enter()andrcu_eqs_exit()can be wiped out as well.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>Quoted 1 line
---
Quoted 4 lines
You missed rcu_user_{enter,exit} declarations in
rcupdate.hThere are also comments refering to them in
kernel/context_tracking.candDocumentation/RCU/stallwarn.rst.
And I thought nobody would notice ;-)
Thanks!
Frederic Weisbecker
maintainerRe: [PATCH 16/19] context_tracking: Convert state to atomic_t
In reply to nicolas saenz julienneQuoted 30 lines · nicolas saenz julienne
Quoted 22 lines · Frederic Weisbecker
Context tracking's state and dynticks counter are going to be merged in a single field so that both updates can happen atomically and at the same time. Prepare for that with converting the state into an
atomic_t.Signed-off-by Frederic Weisbecker <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Neeraj Upadhyay <[email protected]>Cc Uladzislau Rezki <[email protected]>Cc Joel Fernandes <[email protected]>Cc Boqun Feng <[email protected]>Cc Nicolas Saenz Julienne <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Xiongfeng Wang <[email protected]>Cc Yu Liao<[email protected]>Cc Phil Auld <[email protected]>Cc Paul Gortmaker<[email protected]>Cc Alex Belits <[email protected]>---
static__always_inlineboolcontext_tracking_in_user(void){include/linux/context_tracking_state.h static inline bool context_tracking_enabled_this_cpu(void) · line 87
Quoted 3 lines
include/linux/context_tracking_state.h +1
-1-return __this_cpu_read (context_tracking.state) ==CONTEXT_USER ; +return __ct_state () ==CONTEXT_USER ; }I was wondering whether it'd make more sense to use
ct_state()for extra safety vs preemption, but it turns out the function isn't being used at all.
Quoted 2 lines
I figure it'd be better to remove it altogether and leave
ct_state()as the goto function for this sort of checks.
Ah even better!
Quoted 23 lines
kernel/context_tracking.c static __always_inline void context_tracking_recursion_exit(void) · line 340
Quoted 12 lines
#else
static inline boolcontext_tracking_in_user(void){ return false; }kernel/context_tracking.c +1
-0@@ -337,6 +337,7 @@ static __always_inline void context_tracking_recursion_exit(void)*/ void noinstr __ct_user_enter(enum ctx_state state) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);I wonder if there is any value to having
__ct_state()take 'structcontext_tracking*ct' as an argument to avoid a redundantthis_cpu_ptr()...Quoted 7 lines
kernel/context_tracking.c +0
-0lockdep_assert_irqs_disabled ();/* Kernel threads aren't supposed to go to userspace */ @@ -345,8 +346,8 @@ void noinstr __ct_user_enter(enum ctx_state state)if (!context_tracking_recursion_enter ())return ;
Quoted 5 lines
kernel/context_tracking.c void noinstr __ct_user_enter(enum ctx_state state) · line 349
Quoted 3 lines
kernel/context_tracking.c +1
-2-if (__this_cpu_read (context_tracking.state) != state) { -if (__this_cpu_read (context_tracking.active)) { +if (__ct_state () != state) {...here (and in
__ct_user_exit()).
Hmm, I'll check that.
Thanks!
Frederic Weisbecker
maintainerRe: [PATCH 05/19] context_tracking: Split user tracking Kconfig
In reply to Paul E. McKenneyQuoted 6 lines · Paul E. McKenney
Quoted 3 lines · Frederic Weisbecker
Context tracking is going to be used not only to track user transitions but also idle/IRQs/NMIs. The user tracking part will then become a seperate feature. Prepare
Kconfigfor that.s/seperate/separate/ # nit
Thanks, of course I'm never sure about that one.
Quoted 8 lines
Quoted 8 lines
arch/Kconfig +0
-0@@ -762,7 +762,7 @@ config HAVE_ARCH_WITHIN_STACK_FRAMES and similar) by implementing an inline arch_within_stack_frames(), which is used by CONFIG_HARDENED_USERCOPY.
Quoted 6 lines
arch/Kconfig config HAVE_ARCH_WITHIN_STACK_FRAMES · line 765
Quoted 2 lines
arch/Kconfig +1
-1-config HAVE_CONTEXT_TRACKING +config HAVE_CONTEXT_TRACKING_USERJust checking... This means that only some configs will see userland execution as being different than kernel execution, correct? (Which is the case today, to be fair.)
Exactly!
Thanks!
Frederic Weisbecker
maintainerRe: [PATCH 14/19] rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking
In reply to Paul E. McKenneyQuoted 8 lines · Paul E. McKenney
Quoted 4 lines · Frederic Weisbecker
Move the core RCU eqs/dynticks functions to context tracking so that we can later merge all that code within context tracking.
Signed-off-by Frederic Weisbecker <[email protected]>I am not sure that you want
rcu_dynticks_task_enter()and friends in context tracking, but I have no objection to them living there. ;-)
I initially tried to keep them in RCU headers but their use of "current" would imply a circular dependency with sched.h.
Not much appealing alternatives could be:
* macrofying them
* uninline them and keep in RCU
...
Paul E. McKenney
maintainerRe: [PATCH 14/19] rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking
Quoted 13 lines · Frederic Weisbecker
Quoted 8 lines · Paul E. McKenney
Quoted 4 lines · Frederic Weisbecker
Move the core RCU eqs/dynticks functions to context tracking so that we can later merge all that code within context tracking.
Signed-off-by Frederic Weisbecker <[email protected]>I am not sure that you want
rcu_dynticks_task_enter()and friends in context tracking, but I have no objection to them living there. ;-)I initially tried to keep them in RCU headers but their use of "current" would imply a circular dependency with
sched.h.
Quoted 6 lines
Not much appealing alternatives could be:
* macrofying them
* uninline them and keep in RCU...
Sounds like good reasons for them to live outside of kernel/rcu.
Thanx, Paul
Frederic Weisbecker
maintainerRe: [PATCH 18/19] rcu/context_tracking: Merge dynticks counter and context tracking states
In reply to Paul E. McKenneyQuoted 16 lines · Paul E. McKenney
Quoted 7 lines · Frederic Weisbecker
Updating the context tracking state and the RCU dynticks counter atomically in a single operation is a first step towards improving CPU isolation. This makes the context tracking state updates fully ordered and therefore allow for later enhancements such as postponing some work while a task is running isolated in userspace until it ever comes back to the kernel.
Quoted 7 lines
The state field becomes divided in two parts:
1) Lower bits for context tracking state:
CONTEXT_IDLE= 1,
CONTEXT_USER= 2,
CONTEXT_GUEST= 4,
Quoted 8 lines
And the
CONTEXT_DISABLEDvalue of -1 works because you can have only one of the above three bits set at a time?Except that RCU needs this to unconditionally at least distinguish between kernel and idle, given the prevalence of
CONFIG_NO_HZ_IDLE=y. So does theCONTEXT_DISABLEDreally happen anymore?A few more questions interspersed below.
The value of CONTEXT_DISABLED is never stored in the ct->state. It is just returned as is when CONTEXT_TRACKING is disabled. So this shouldn't conflict with RCU.
Quoted 8 lines
Quoted 8 lines
kernel/context_tracking.c +1
-1@@ -452,15 +453,16 @@ void noinstr __ct_user_exit(enum ctx_state state)* Exit RCU idle mode while entering the kernel because it can * run a RCU read side critical section anytime. */ -rcu_eqs_exit (true); +ct_kernel_enter (true,RCU_DYNTICKS_IDX - state);if (state ==CONTEXT_USER ) {instrumentation_begin ();
Quoted 8 lines
kernel/context_tracking.c void noinstr __ct_user_exit(enum ctx_state state) · line 464
Quoted 6 lines
kernel/context_tracking.c +2
-0vtime_user_exit (current);trace_user_exit (0 );instrumentation_end (); } + }else { +atomic_sub (state, &ct->state);OK,
atomic_sub()got my attention. What is going on here? ;-)
Right :-)
So that's when context tracking user is running but RCU doesn't track user. This is for example when NO_HZ_FULL=n but VIRT_CPU_ACCOUNTING_GEN=y.
I might remove that standalone VIRT_CPU_ACCOUNTING_GEN=y one day but for now it's there.
Anyway so in this case we only want to track KERNEL <-> USER from context tracking POV, but we don't need the DYNTICKS_RCU_IDX part, hence the spared ordering.
But it still needs to be atomic because NMIs may increase DYNTICKS_RCU_IDX on the same field.
Quoted 12 lines
Quoted 12 lines
kernel/context_tracking.c +1
-1@@ -548,7 +550,7 @@ EXPORT_SYMBOL_GPL(context_tracking);void ct_idle_enter (void ) {lockdep_assert_irqs_disabled (); -rcu_eqs_enter (false); +ct_kernel_exit (false,RCU_DYNTICKS_IDX +CONTEXT_IDLE ); }EXPORT_SYMBOL_GPL (ct_idle_enter);@@ -566,7 +568,7 @@ void ct_idle_exit(void)unsigned long flags;
Quoted 6 lines
kernel/context_tracking.c void ct_idle_exit(void) · line 571
Quoted 3 lines
kernel/context_tracking.c +1
-1local_irq_save (flags); -rcu_eqs_exit (false); +ct_kernel_enter (false,RCU_DYNTICKS_IDX -CONTEXT_IDLE );Nice! This works because all transitions must be either from or to kernel context, correct?
Exactly. There is no such thing as IDLE -> USER -> GUEST, etc... There has to be KERNEL in the middle of each. Because we never call rcu_idle_enter() -> rcu_user_enter() for example. The has to be rcu_idle_exit() in the middle.
(famous last words).
Quoted 11 lines
kernel/rcu/tree.c bool rcu_dynticks_zero_in_eqs(int cpu, int *vp) · line 324
Quoted 8 lines
kernel/rcu/tree.c +1
-2/* Return true if the specified CPU is currently idle from an RCU viewpoint. */ @@ -321,8 +321,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =ct_dynticks_cpu (cpu) & ~0x1 ; - + snap =ct_dynticks_cpu (cpu) & ~RCU_DYNTICKS_IDX ;Do we also need to get rid of the low-order bits? Or is that happening elsewhere? Or is there some reason that they can stick around?
Yep, ct_dynticks_cpu() clears the low order CONTEXT_* bits.
Quoted 6 lines
Quoted 6 lines
kernel/rcu/tree_stall.h +0
-0@@ -459,7 +459,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
Quoted 8 lines
kernel/rcu/tree_stall.h static void print_cpu_stall_info(int cpu) · line 462
Quoted 4 lines
kernel/rcu/tree_stall.h +1
-1"!." [!delta], ticks_value, ticks_title, - rcu_dynticks_snap(cpu) & 0xfff, + (rcu_dynticks_snap(cpu) >> RCU_DYNTICKS_SHIFT) & 0xfff ,Actually, the low-ordder several bits are useful when debugging, so could you please not shift them away? Maybe also go to
0xffffto allow for more bits taken?
Yeah that makes sense, I'll change that.
Thanks a lot for the reviews!
Paul E. McKenney
maintainerRe: [PATCH 18/19] rcu/context_tracking: Merge dynticks counter and context tracking states
Quoted 24 lines · Frederic Weisbecker
Quoted 23 lines · Paul E. McKenney
Quoted 7 lines · Frederic Weisbecker
Updating the context tracking state and the RCU dynticks counter atomically in a single operation is a first step towards improving CPU isolation. This makes the context tracking state updates fully ordered and therefore allow for later enhancements such as postponing some work while a task is running isolated in userspace until it ever comes back to the kernel.
Quoted 7 lines
The state field becomes divided in two parts:
1) Lower bits for context tracking state:
CONTEXT_IDLE= 1,
CONTEXT_USER= 2,
CONTEXT_GUEST= 4,And the
CONTEXT_DISABLEDvalue of -1 works because you can have only one of the above three bits set at a time?Except that RCU needs this to unconditionally at least distinguish between kernel and idle, given the prevalence of
CONFIG_NO_HZ_IDLE=y. So does theCONTEXT_DISABLEDreally happen anymore?
Quoted 5 lines
Quoted 1 line
A few more questions interspersed below.
The value of
CONTEXT_DISABLEDis never stored in thect->state. It is just returned as is whenCONTEXT_TRACKINGis disabled. So this shouldn't conflict with RCU.
Whew! ;-)
Quoted 25 lines
Quoted 8 lines
Quoted 8 lines
kernel/context_tracking.c +1
-1@@ -452,15 +453,16 @@ void noinstr __ct_user_exit(enum ctx_state state)* Exit RCU idle mode while entering the kernel because it can * run a RCU read side critical section anytime. */ -rcu_eqs_exit (true); +ct_kernel_enter (true,RCU_DYNTICKS_IDX - state);if (state ==CONTEXT_USER ) {instrumentation_begin ();Quoted 8 lines
kernel/context_tracking.c void noinstr __ct_user_exit(enum ctx_state state) · line 464
Quoted 6 lines
kernel/context_tracking.c +2
-0vtime_user_exit (current);trace_user_exit (0 );instrumentation_end (); } + }else { +atomic_sub (state, &ct->state);OK,
atomic_sub()got my attention. What is going on here? ;-)Right :-)
So that's when context tracking user is running but RCU doesn't track user. This is for example when NO_HZ_FULL=n but VIRT_CPU_ACCOUNTING_GEN=y.
I might remove that standalone VIRT_CPU_ACCOUNTING_GEN=y one day but for now it's there.
Quoted 6 lines
Anyway so in this case we only want to track KERNEL <-> USER from context tracking POV, but we don't need the
DYNTICKS_RCU_IDXpart, hence the spared ordering.But it still needs to be atomic because NMIs may increase
DYNTICKS_RCU_IDXon the same field.
OK, so the idea is because NO_HZ_FULL=n, RCU doesn't care about user space execution?
How about looking at it the other way? Is there some reason that RCU shouldn't take advantage of the userspace-execution information when it exists? For example, in the NO_HZ_FULL=n but VIRT_CPU_ACCOUNTING_GEN=y case, is there some chance that RCU would be ignoring a non-noinstr function?
Quoted 19 lines
Quoted 12 lines
Quoted 12 lines
kernel/context_tracking.c +1
-1@@ -548,7 +550,7 @@ EXPORT_SYMBOL_GPL(context_tracking);void ct_idle_enter (void ) {lockdep_assert_irqs_disabled (); -rcu_eqs_enter (false); +ct_kernel_exit (false,RCU_DYNTICKS_IDX +CONTEXT_IDLE ); }EXPORT_SYMBOL_GPL (ct_idle_enter);@@ -566,7 +568,7 @@ void ct_idle_exit(void)unsigned long flags;Quoted 6 lines
kernel/context_tracking.c void ct_idle_exit(void) · line 571
Quoted 3 lines
kernel/context_tracking.c +1
-1local_irq_save (flags); -rcu_eqs_exit (false); +ct_kernel_enter (false,RCU_DYNTICKS_IDX -CONTEXT_IDLE );Nice! This works because all transitions must be either from or to kernel context, correct?
Quoted 6 lines
Exactly. There is no such thing as IDLE -> USER -> GUEST, etc... There has to be KERNEL in the middle of each. Because we never call
rcu_idle_enter()->rcu_user_enter()for example. The has to bercu_idle_exit()in the middle.(famous last words).
Works for me, for the moment, anyway. ;-)
Quoted 12 lines
Quoted 11 lines
kernel/rcu/tree.c bool rcu_dynticks_zero_in_eqs(int cpu, int *vp) · line 324
Quoted 8 lines
kernel/rcu/tree.c +1
-2/* Return true if the specified CPU is currently idle from an RCU viewpoint. */ @@ -321,8 +321,7 @@ bool rcu_dynticks_zero_in_eqs(int cpu, int *vp)int snap;// If not quiescent, force back to earlier extended quiescent state. - snap =ct_dynticks_cpu (cpu) & ~0x1 ; - + snap =ct_dynticks_cpu (cpu) & ~RCU_DYNTICKS_IDX ;Do we also need to get rid of the low-order bits? Or is that happening elsewhere? Or is there some reason that they can stick around?
Quoted 1 line
Yep,
ct_dynticks_cpu()clears the low order CONTEXT_* bits.
Whew! ;-)
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
kernel/rcu/tree_stall.h +0
-0@@ -459,7 +459,7 @@ static void print_cpu_stall_info(int cpu) rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :Quoted 8 lines
kernel/rcu/tree_stall.h static void print_cpu_stall_info(int cpu) · line 462
Quoted 4 lines
kernel/rcu/tree_stall.h +1
-1"!." [!delta], ticks_value, ticks_title, - rcu_dynticks_snap(cpu) & 0xfff, + (rcu_dynticks_snap(cpu) >> RCU_DYNTICKS_SHIFT) & 0xfff ,Actually, the low-ordder several bits are useful when debugging, so could you please not shift them away? Maybe also go to
0xffffto allow for more bits taken?
Quoted 3 lines
Yeah that makes sense, I'll change that.
Thanks a lot for the reviews!
Thank you for the series!
Thanx, Paul
Peter Zijlstra
maintainerRe: [PATCH 16/19] context_tracking: Convert state to atomic_t
In reply to Frederic Weisbeckerinclude/linux/context_tracking_state.h struct context_tracking { · line 42
Quoted 4 lines · Frederic Weisbecker
include/linux/context_tracking_state.h +4
-0+static __always_inline int __ct_state(void) +{ +return atomic_read (this_cpu_ptr (&context_tracking.state)); +}
One arguably horrible thing to do would be to write it like:
return __this_cpu_read(context_tracking.state.counter);
IIRC that will actually DTRT since atomic_read() is basically defined to be READ_ONCE() and this_cpu_read() implies the same.
Only PowerPC and s390 implement arch_atomic_read() in asm, but I don't think they have a particularly good reason to. The only other weird case is Alpha, where READ_ONCE() implies smp_mb() because Alpha. I'm not sure we care about that case, hmm?
The same can be done for ct_dynticks(), which is basically the same function with a different mask.
As mentioned elsewhere, ct_state() appears unused at the end of the ride.
Peter Zijlstra
maintainerRe: [PATCH 14/19] rcu/context-tracking: Move RCU-dynticks internal functions to context_tracking
In reply to Frederic Weisbeckerkernel/context_tracking.c line 69
Quoted 4 lines · Frederic Weisbecker
kernel/context_tracking.c +4
-0+noinstr unsigned long rcu_dynticks_inc (int incby) +{ +return arch_atomic_add_return (incby,this_cpu_ptr (&context_tracking.dynticks)); +}
noinstr implies noinline, making the above a rather sad little function; would it perhaps be better to make it __always_inline ?
Also; I could imagine myself doing an arch special for this such that x86 generates:
LOCK XADD [reg], %gs:[var]
But that's for later I suppose, it would be but a little tweak to perpcu_add_return_op()
Peter Zijlstra
maintainerRe: [PATCH 11/19] rcu/context_tracking: Move dynticks_nesting to context tracking
In reply to Frederic WeisbeckerQuoted 20 lines · Frederic Weisbecker
kernel/rcu/tree.c +2
-2@@ -441,7 +440,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)lockdep_assert_irqs_disabled ();/* Check for counter underflows */ -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <0 ,"RCU dynticks_nesting counter underflow!" );RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nmi_nesting) <=0 ,"RCU dynticks_nmi_nesting counter underflow/zero!" );@@ -457,7 +456,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)WARN_ON_ONCE (!nesting && !is_idle_task (current));/* Does CPU appear to be idle from an RCU standpoint? */ -return __this_cpu_read (rcu_data.dynticks_nesting) ==0 ; +return __this_cpu_read (context_tracking.dynticks_nesting) ==0 ; }#define DEFAULT_RCU_BLIMIT (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) ? 1000 : 10)
kernel/rcu/tree.c void rcu_irq_exit_check_preempt(void) · line 803
Quoted 8 lines
kernel/rcu/tree.c +1
-1@@ -798,7 +797,7 @@ void rcu_irq_exit_check_preempt(void) {lockdep_assert_irqs_disabled (); -RCU_LOCKDEP_WARN (__this_cpu_read (rcu_data.dynticks_nesting) <=0 , +RCU_LOCKDEP_WARN (__this_cpu_read (context_tracking.dynticks_nesting) <=0 ,"RCU dynticks_nesting counter underflow/zero!" ); RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) != DYNTICK_IRQ_NONIDLE,
Would it make sense to create __ct_wrappers() to access the dynticks_{nmi_,}_nesting counters ?
Quoted 37 lines
kernel/rcu/tree.c +3
-1@@ -4122,12 +4121,13 @@ static void rcu_init_new_rnp(struct rcu_node *rnp_leaf)static void __init rcu_boot_init_percpu_data (int cpu) { +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);/* Set up local state, ensuring consistent view of global state. */ rdp->grpmask =leaf_node_cpu_bit (rdp->mynode, cpu);INIT_WORK (&rdp->strict_work, strict_work_handler); -WARN_ON_ONCE (rdp->dynticks_nesting !=1 ); +WARN_ON_ONCE (ct->dynticks_nesting !=1 );WARN_ON_ONCE (rcu_dynticks_in_eqs (rcu_dynticks_snap (cpu))); rdp->barrier_seq_snap = rcu_state.barrier_sequence; rdp->rcu_ofl_gp_seq = rcu_state.gp_seq;@@ -4152,6 +4152,7 @@ rcu_boot_init_percpu_data(int cpu)int rcutree_prepare_cpu (unsigned int cpu) {unsigned long flags; +struct context_tracking *ct =per_cpu_ptr (&context_tracking, cpu);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp =rcu_get_root ();kernel/rcu/tree_stall.h +1
-0@@ -429,6 +429,7 @@ static void print_cpu_stall_info(int cpu) {unsigned long delta;bool falsepositive; +struct context_tracking *ct =this_cpu_ptr (&context_tracking);struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);char *ticks_title;unsigned long ticks_value;
kernel/rcu/tree_stall.h static void print_cpu_stall_info(int cpu) · line 466
Quoted 8 lines
kernel/rcu/tree_stall.h +1
-1@@ -459,7 +460,7 @@ static void print_cpu_stall_info(int cpu)"!." [!delta], ticks_value, ticks_title,rcu_dynticks_snap (cpu) &0xfff , - rdp->dynticks_nesting, rdp->dynticks_nmi_nesting, + ct->dynticks_nesting, rdp->dynticks_nmi_nesting, rdp->softirq_snap,kstat_softirqs_cpu (RCU_SOFTIRQ , cpu),data_race (rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart, falsepositive ? " (false positive?)" : "");
And perhaps helpers here too? RCU grubbing in the context_tracking internals seems a bit yuck.
Will Deacon
maintainerRe: [PATCH 16/19] context_tracking: Convert state to atomic_t
In reply to Peter ZijlstraQuoted 10 lines · Peter Zijlstra
include/linux/context_tracking_state.h struct context_tracking { · line 42
Quoted 4 lines · Frederic Weisbecker
include/linux/context_tracking_state.h +4
-0+static __always_inline int __ct_state(void) +{ +return atomic_read (this_cpu_ptr (&context_tracking.state)); +}One arguably horrible thing to do would be to write it like:
return __this_cpu_read(context_tracking.state.counter);
Quoted 7 lines
IIRC that will actually DTRT since
atomic_read()is basically defined to beREAD_ONCE()andthis_cpu_read()implies the same.Only PowerPC and s390 implement
arch_atomic_read()in asm, but I don't think they have a particularly good reason to. The only other weird case is Alpha, whereREAD_ONCE()impliessmp_mb()because Alpha. I'm not sure we care about that case, hmm?
If we don't care about the dependency ordering, then __READ_ONCE() is the chappy to use if the types don't get in the way too much.
Will