2024-02-23 00:26:25

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 0/4] Refactor TASKS_RCU for lazy preemption

Hello!

This series refactors the NEED_TASKS_RCU option so that the conditional
processing is in one place in kernel/rcu/Kconfig. This makes it easier
to make sure that Tasks RCU is enabled in PREEMPT_AUTO kernels, given
that such kernels are preemptible, even if only lazily so. After all,
it takes only one lazy preemption from a trampoline to significantly
degrade your kernel's actuarial statistics.

1. Create NEED_TASKS_RCU to factor out enablement logic.

2. Select new NEED_TASKS_RCU Kconfig option.

3. Select new NEED_TASKS_RCU Kconfig option.

4. Select new NEED_TASKS_RCU Kconfig option.

Thanx, Paul

------------------------------------------------------------------------

arch/Kconfig | 4 ++--
kernel/bpf/Kconfig | 2 +-
kernel/rcu/Kconfig | 6 +++++-
kernel/trace/Kconfig | 4 ++--
4 files changed, 10 insertions(+), 6 deletions(-)


2024-02-23 00:26:54

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 4/4] tracing: Select new NEED_TASKS_RCU Kconfig option

Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
"select TASKS_RCU if PREEMPTION". This works, but requires any change in
this enablement logic to be replicated across all such "select" clauses.
A new NEED_TASKS_RCU Kconfig option has been created to allow this
enablement logic to be in one place in kernel/rcu/Kconfig.

Therefore, select the new NEED_TASKS_RCU Kconfig option instead of the
old TASKS_RCU option.

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: <[email protected]>
Cc: Ankur Arora <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Mark Rutland <[email protected]>
---
kernel/trace/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 61c541c36596d..6cdc5ff919b09 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -163,7 +163,7 @@ config TRACING
select BINARY_PRINTF
select EVENT_TRACING
select TRACE_CLOCK
- select TASKS_RCU if PREEMPTION
+ select NEED_TASKS_RCU

config GENERIC_TRACER
bool
@@ -204,7 +204,7 @@ config FUNCTION_TRACER
select GENERIC_TRACER
select CONTEXT_SWITCH_TRACER
select GLOB
- select TASKS_RCU if PREEMPTION
+ select NEED_TASKS_RCU
select TASKS_RUDE_RCU
help
Enable the kernel to trace every kernel function. This is done
--
2.40.1


2024-02-23 00:26:55

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 1/4] rcu: Create NEED_TASKS_RCU to factor out enablement logic

Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
"select TASKS_RCU if PREEMPTION". This works, but requires any change in
this enablement logic to be replicated across all such "select" clauses.
This commit therefore creates a new NEED_TASKS_RCU Kconfig option so
that the default value of TASKS_RCU can depend on a combination of this
new option and any needed enablement logic, so that this logic is in
one place.

While in the area, also anticipate a likely future change by adding
PREEMPT_AUTO to that logic.

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Ankur Arora <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Steven Rostedt <[email protected]>
---
kernel/rcu/Kconfig | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/Kconfig b/kernel/rcu/Kconfig
index 7dca0138260c3..3e079de0f5b43 100644
--- a/kernel/rcu/Kconfig
+++ b/kernel/rcu/Kconfig
@@ -85,9 +85,13 @@ config FORCE_TASKS_RCU
idle, and user-mode execution as quiescent states. Not for
manual selection in most cases.

-config TASKS_RCU
+config NEED_TASKS_RCU
bool
default n
+
+config TASKS_RCU
+ bool
+ default NEED_TASKS_RCU && (PREEMPTION || PREEMPT_AUTO)
select IRQ_WORK

config FORCE_TASKS_RUDE_RCU
--
2.40.1


2024-02-23 00:27:22

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 3/4] arch: Select new NEED_TASKS_RCU Kconfig option

Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
"select TASKS_RCU if PREEMPTION". This works, but requires any change in
this enablement logic to be replicated across all such "select" clauses.
A new NEED_TASKS_RCU Kconfig option has been created to allow this
enablement logic to be in one place in kernel/rcu/Kconfig.

Therefore, select the new NEED_TASKS_RCU Kconfig option instead of the
old TASKS_RCU option.

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Douglas Anderson <[email protected]>
Cc: Ankur Arora <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Steven Rostedt <[email protected]>
---
arch/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index c91917b508736..154f994547632 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -55,7 +55,7 @@ config KPROBES
depends on MODULES
depends on HAVE_KPROBES
select KALLSYMS
- select TASKS_RCU if PREEMPTION
+ select NEED_TASKS_RCU
help
Kprobes allows you to trap at almost any kernel address and
execute a callback function. register_kprobe() establishes
@@ -104,7 +104,7 @@ config STATIC_CALL_SELFTEST
config OPTPROBES
def_bool y
depends on KPROBES && HAVE_OPTPROBES
- select TASKS_RCU if PREEMPTION
+ select NEED_TASKS_RCU

config KPROBES_ON_FTRACE
def_bool y
--
2.40.1


2024-02-23 00:27:23

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH rcu 2/4] bpf: Select new NEED_TASKS_RCU Kconfig option

Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
"select TASKS_RCU if PREEMPTION". This works, but requires any change in
this enablement logic to be replicated across all such "select" clauses.
A new NEED_TASKS_RCU Kconfig option has been created to allow this
enablement logic to be in one place in kernel/rcu/Kconfig.

Therefore, make BPF select the new NEED_TASKS_RCU Kconfig option.

Signed-off-by: Paul E. McKenney <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Andrii Nakryiko <[email protected]>
Cc: Martin KaFai Lau <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Yonghong Song <[email protected]>
Cc: John Fastabend <[email protected]>
Cc: KP Singh <[email protected]>
Cc: Stanislav Fomichev <[email protected]>
Cc: Hao Luo <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: <[email protected]>
Cc: Ankur Arora <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Steven Rostedt <[email protected]>
---
kernel/bpf/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
index 6a906ff930065..ce9fbc3b27ecf 100644
--- a/kernel/bpf/Kconfig
+++ b/kernel/bpf/Kconfig
@@ -27,7 +27,7 @@ config BPF_SYSCALL
bool "Enable bpf() system call"
select BPF
select IRQ_WORK
- select TASKS_RCU if PREEMPTION
+ select NEED_TASKS_RCU
select TASKS_TRACE_RCU
select BINARY_PRINTF
select NET_SOCK_MSG if NET
--
2.40.1


2024-02-23 01:35:12

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH rcu 3/4] arch: Select new NEED_TASKS_RCU Kconfig option

On Thu, 22 Feb 2024 16:26:26 -0800
"Paul E. McKenney" <[email protected]> wrote:

> Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
> "select TASKS_RCU if PREEMPTION". This works, but requires any change in
> this enablement logic to be replicated across all such "select" clauses.
> A new NEED_TASKS_RCU Kconfig option has been created to allow this
> enablement logic to be in one place in kernel/rcu/Kconfig.
>
> Therefore, select the new NEED_TASKS_RCU Kconfig option instead of the
> old TASKS_RCU option.
>
> Signed-off-by: Paul E. McKenney <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Heiko Carstens <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Douglas Anderson <[email protected]>
> Cc: Ankur Arora <[email protected]>
> Cc: Mark Rutland <[email protected]>
> Cc: Steven Rostedt <[email protected]>

Reviewed-by: Steven Rostedt (Google) <[email protected]>

-- Steve

> ---
> arch/Kconfig | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/Kconfig b/arch/Kconfig
> index c91917b508736..154f994547632 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -55,7 +55,7 @@ config KPROBES
> depends on MODULES
> depends on HAVE_KPROBES
> select KALLSYMS
> - select TASKS_RCU if PREEMPTION
> + select NEED_TASKS_RCU
> help
> Kprobes allows you to trap at almost any kernel address and
> execute a callback function. register_kprobe() establishes
> @@ -104,7 +104,7 @@ config STATIC_CALL_SELFTEST
> config OPTPROBES
> def_bool y
> depends on KPROBES && HAVE_OPTPROBES
> - select TASKS_RCU if PREEMPTION
> + select NEED_TASKS_RCU
>
> config KPROBES_ON_FTRACE
> def_bool y


2024-02-23 04:57:05

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH rcu 3/4] arch: Select new NEED_TASKS_RCU Kconfig option

On Thu, Feb 22, 2024 at 08:36:51PM -0500, Steven Rostedt wrote:
> On Thu, 22 Feb 2024 16:26:26 -0800
> "Paul E. McKenney" <[email protected]> wrote:
>
> > Currently, if a Kconfig option depends on TASKS_RCU, it conditionally does
> > "select TASKS_RCU if PREEMPTION". This works, but requires any change in
> > this enablement logic to be replicated across all such "select" clauses.
> > A new NEED_TASKS_RCU Kconfig option has been created to allow this
> > enablement logic to be in one place in kernel/rcu/Kconfig.
> >
> > Therefore, select the new NEED_TASKS_RCU Kconfig option instead of the
> > old TASKS_RCU option.
> >
> > Signed-off-by: Paul E. McKenney <[email protected]>
> > Cc: Andrew Morton <[email protected]>
> > Cc: Thomas Gleixner <[email protected]>
> > Cc: Heiko Carstens <[email protected]>
> > Cc: Arnd Bergmann <[email protected]>
> > Cc: Douglas Anderson <[email protected]>
> > Cc: Ankur Arora <[email protected]>
> > Cc: Mark Rutland <[email protected]>
> > Cc: Steven Rostedt <[email protected]>
>
> Reviewed-by: Steven Rostedt (Google) <[email protected]>

Thank you! I will apply on my next rebase.

Thanx, Paul

> -- Steve
>
> > ---
> > arch/Kconfig | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index c91917b508736..154f994547632 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -55,7 +55,7 @@ config KPROBES
> > depends on MODULES
> > depends on HAVE_KPROBES
> > select KALLSYMS
> > - select TASKS_RCU if PREEMPTION
> > + select NEED_TASKS_RCU
> > help
> > Kprobes allows you to trap at almost any kernel address and
> > execute a callback function. register_kprobe() establishes
> > @@ -104,7 +104,7 @@ config STATIC_CALL_SELFTEST
> > config OPTPROBES
> > def_bool y
> > depends on KPROBES && HAVE_OPTPROBES
> > - select TASKS_RCU if PREEMPTION
> > + select NEED_TASKS_RCU
> >
> > config KPROBES_ON_FTRACE
> > def_bool y
>

2024-02-23 11:42:36

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH rcu 0/4] Refactor TASKS_RCU for lazy preemption

On Thu, Feb 22, 2024 at 04:26:18PM -0800, Paul E. McKenney wrote:
> Hello!

Hi!

> This series refactors the NEED_TASKS_RCU option so that the conditional
> processing is in one place in kernel/rcu/Kconfig. This makes it easier
> to make sure that Tasks RCU is enabled in PREEMPT_AUTO kernels, given
> that such kernels are preemptible, even if only lazily so. After all,
> it takes only one lazy preemption from a trampoline to significantly
> degrade your kernel's actuarial statistics.
>
> 1. Create NEED_TASKS_RCU to factor out enablement logic.
>
> 2. Select new NEED_TASKS_RCU Kconfig option.
>
> 3. Select new NEED_TASKS_RCU Kconfig option.
>
> 4. Select new NEED_TASKS_RCU Kconfig option.

For the series:

Acked-by: Mark Rutland <[email protected]>

Mark.