Skip to contentSkip to conversation

rcu/nocb: Add an option to offload all CPUs on boot

PATCH Superseded Joel Fernandes (Google) 2 participants 3 messages Apr 15, 2022 – Apr 18, 2022

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 rcu/nocb: Add an option to offload all CPUs on boot

From: Joel Fernandes <[email protected]>

On systems with CONFIG_RCU_NOCB_CPU=y, there is no default mask provided which ends up not offloading any CPU. This patch removes a dependency from the bootloader having to know about RCU, about how many CPUs the system has, and about how to provide the mask.

With the new option enabled, all CPUs will be offloaded on boot.

---
v2 was forcing the option to override no_cbs=
v3 is back to v1 but with a config option defaulting to 'n'.

 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 kernel/rcu/Kconfig                              | 13 +++++++++++++
 kernel/rcu/tree_nocb.h                          | 16 ++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -0
index f5a27f067db9..7648a7dd335e 100644
@@ -4398,6 +4398,9 @@
 			no-callback mode from boot but the mode may be
 			toggled at runtime via cpusets.
 
+			Note that this argument takes precedence over
+			the CONFIG_RCU_NOCB_CPU_DEFAULT_ALL option.
+
 	rcu_nocb_poll	[KNL]
 			Rather than requiring that offloaded CPUs
 			(specified by rcu_nocbs= above) explicitly
kernel/rcu/Kconfig +13 -0
index bf8e341e75b4..2f8bd694ed85 100644
@@ -223,6 +223,19 @@ config RCU_NOCB_CPU
 	  Say Y here if you need reduced OS jitter, despite added overhead.
 	  Say N here if you are unsure.
 
+config RCU_NOCB_CPU_DEFAULT_ALL
+	bool "Offload RCU callback processing from all CPUs by default"
+	depends on RCU_NOCB_CPU
+	default n
+	help
+	  Use this option to offload callback processing from all CPUs
+	  by default, in the absence of the rcu_nocbs boot parameter.
+	  This also avoids the need to use any boot parameters to achieve
+	  the effect of offloading all CPUs on boot.
+
+	  Say Y here if you want offload all CPUs by default on boot.
+	  Say N here if you are unsure.
+
 config TASKS_TRACE_RCU_READ_MB
 	bool "Tasks Trace RCU readers use memory barriers in user and idle"
 	depends on RCU_EXPERT
kernel/rcu/tree_nocb.h +14 -2
index eeafb546a7a0..673fa0d1f801 100644
@@ -1165,12 +1165,21 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
+	bool need_rcu_nocb_mask = false, offload_all = false;
 	struct rcu_data *rdp;
 
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_nocb_is_setup) {
+		need_rcu_nocb_mask = true;
+		offload_all = true;
+	}
+#endif
+
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
+	if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask)) {
 		need_rcu_nocb_mask = true;
+		offload_all = false; /* NO_HZ_FULL has its own mask. */
+	}
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (need_rcu_nocb_mask) {
@@ -1191,6 +1200,9 @@ void __init rcu_init_nohz(void)
 		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
+	if (offload_all)
+		cpumask_setall(rcu_nocb_mask);
+
 	if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
 		pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n");
 		cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
maintainer
#1 lore raw
Quoted 1 line · Joel Fernandes (Google)

From: Joel Fernandes <[email protected]>

Much better, thank you!

Quoted 4 lines

On systems with CONFIG_RCU_NOCB_CPU=y, there is no default mask provided which ends up not offloading any CPU. This patch removes a dependency from the bootloader having to know about RCU, about how many CPUs the system has, and about how to provide the mask.

The "about how many CPUs the system has" does not apply to current mainline, in which "rcu_nocbs=0-N" says to offload all CPUs. It can be added back in for a backport to v5.10. ;-)

Quoted 3 lines

With the new option enabled, all CPUs will be offloaded on boot.

I second Joel's call for testing and add to that a call for additional review.

My thought is to queue this after some independent testing.

Quoted 14 lines

---
v2 was forcing the option to override no_cbs=
v3 is back to v1 but with a config option defaulting to 'n'.

 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 kernel/rcu/Kconfig                              | 13 +++++++++++++
 kernel/rcu/tree_nocb.h                          | 16 ++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index f5a27f067db9..7648a7dd335e 100644

Documentation/admin-guide/kernel-parameters.txt line 4402

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +2 -0
@@ -4398,6 +4398,9 @@
 			no-callback mode from boot but the mode may be
 			toggled at runtime via cpusets.
 
+			Note that this argument takes precedence over
+			the CONFIG_RCU_NOCB_CPU_DEFAULT_ALL option.

Very good, thank you!

Do we want to say the same about nohz_full? Or am I misreading the code below?

Quoted 9 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
+
 	rcu_nocb_poll	[KNL]
 			Rather than requiring that offloaded CPUs
 			(specified by rcu_nocbs= above) explicitly
kernel/rcu/Kconfig +0 -0
index bf8e341e75b4..2f8bd694ed85 100644

kernel/rcu/Kconfig config RCU_NOCB_CPU · line 228

Quoted 6 lines
kernel/rcu/Kconfig +3 -0
@@ -223,6 +223,19 @@ config RCU_NOCB_CPU
 	  Say Y here if you need reduced OS jitter, despite added overhead.
 	  Say N here if you are unsure.
 
+config RCU_NOCB_CPU_DEFAULT_ALL
+	bool "Offload RCU callback processing from all CPUs by default"
+	depends on RCU_NOCB_CPU

The needed dependency on RCU_EXPERT is provided transitively via RCU_NOCB_CPU, so this should be OK. (To check, build a .config file, queue this patch, and do "make oldconfig". If any questions are asked, a change is needed.)

kernel/rcu/Kconfig config RCU_NOCB_CPU · line 232

Quoted 4 lines
kernel/rcu/Kconfig +4 -0
+	default n
+	help
+	  Use this option to offload callback processing from all CPUs
+	  by default, in the absence of the rcu_nocbs boot parameter.

And also in the absence of the nohz_full boot parameter, correct?

Quoted 14 lines
kernel/rcu/Kconfig +6 -0
+	  This also avoids the need to use any boot parameters to achieve
+	  the effect of offloading all CPUs on boot.
+
+	  Say Y here if you want offload all CPUs by default on boot.
+	  Say N here if you are unsure.
+
 config TASKS_TRACE_RCU_READ_MB
 	bool "Tasks Trace RCU readers use memory barriers in user and idle"
 	depends on RCU_EXPERT
kernel/rcu/tree_nocb.h +0 -0
index eeafb546a7a0..673fa0d1f801 100644

kernel/rcu/tree_nocb.h EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); · line 1168

Quoted 5 lines
kernel/rcu/tree_nocb.h +1 -1
@@ -1165,12 +1165,21 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
+	bool need_rcu_nocb_mask = false, offload_all = false;

Please use the extra line to perserve alphabetical order. (I do know about inverse tree, though I have no idea why it is considered to be a good thing.)

kernel/rcu/tree_nocb.h EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); · line 1176

Quoted 8 lines
kernel/rcu/tree_nocb.h +6 -0
 	struct rcu_data *rdp;
 
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_nocb_is_setup) {
+		need_rcu_nocb_mask = true;
+		offload_all = true;
+	}
+#endif

It would be nice to be able to use IS_ENABLED() here and below, but that is a separate issue. For one thing, need_rcu_nocb_mask would need to be defined unconditionally. So this is fine as it is for this patch.

kernel/rcu/tree_nocb.h EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); · line 1181

Quoted 6 lines
kernel/rcu/tree_nocb.h +3 -1
+
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
+	if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask)) {
 		need_rcu_nocb_mask = true;
+		offload_all = false; /* NO_HZ_FULL has its own mask. */

This is good, and is also why I am asking for the addition of nohz_full above.

Quoted 17 lines
kernel/rcu/tree_nocb.h +4 -0
+	}
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (need_rcu_nocb_mask) {
@@ -1191,6 +1200,9 @@ void __init rcu_init_nohz(void)
 		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
+	if (offload_all)
+		cpumask_setall(rcu_nocb_mask);
+
 	if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
 		pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n");
 		cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
#2 lore raw
Quoted 5 lines · Paul E. McKenney
Quoted 1 line · Joel Fernandes (Google)

From: Joel Fernandes <[email protected]>

Much better, thank you!

Quoted 8 lines
Quoted 4 lines

On systems with CONFIG_RCU_NOCB_CPU=y, there is no default mask provided which ends up not offloading any CPU. This patch removes a dependency from the bootloader having to know about RCU, about how many CPUs the system has, and about how to provide the mask.

The "about how many CPUs the system has" does not apply to current mainline, in which "rcu_nocbs=0-N" says to offload all CPUs. It can be added back in for a backport to v5.10. ;-)

True, will fix.

Quoted 19 lines

My thought is to queue this after some independent testing.

Quoted 17 lines

---
v2 was forcing the option to override no_cbs=
v3 is back to v1 but with a config option defaulting to 'n'.

 Documentation/admin-guide/kernel-parameters.txt |  3 +++
 kernel/rcu/Kconfig                              | 13 +++++++++++++
 kernel/rcu/tree_nocb.h                          | 16 ++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index f5a27f067db9..7648a7dd335e 100644
@@ -4398,6 +4398,9 @@
 			no-callback mode from boot but the mode may be
 			toggled at runtime via cpusets.
 
Quoted 7 lines

Documentation/admin-guide/kernel-parameters.txt line 4402

Quoted 2 lines
Documentation/admin-guide/kernel-parameters.txt +2 -0
+			Note that this argument takes precedence over
+			the CONFIG_RCU_NOCB_CPU_DEFAULT_ALL option.

Very good, thank you!

Do we want to say the same about nohz_full? Or am I misreading the code below?

You're right, will fix.

Quoted 12 lines
Quoted 12 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
+
 	rcu_nocb_poll	[KNL]
 			Rather than requiring that offloaded CPUs
 			(specified by rcu_nocbs= above) explicitly
kernel/rcu/Kconfig +0 -0
index bf8e341e75b4..2f8bd694ed85 100644
@@ -223,6 +223,19 @@ config RCU_NOCB_CPU
 	  Say Y here if you need reduced OS jitter, despite added overhead.
 	  Say N here if you are unsure.
 
Quoted 8 lines

kernel/rcu/Kconfig config RCU_NOCB_CPU · line 228

Quoted 3 lines
kernel/rcu/Kconfig +3 -0
+config RCU_NOCB_CPU_DEFAULT_ALL
+	bool "Offload RCU callback processing from all CPUs by default"
+	depends on RCU_NOCB_CPU

The needed dependency on RCU_EXPERT is provided transitively via RCU_NOCB_CPU, so this should be OK. (To check, build a .config file, queue this patch, and do "make oldconfig". If any questions are asked, a change is needed.)

Ok. I did that and no questions were asked.

Quoted 6 lines

kernel/rcu/Kconfig config RCU_NOCB_CPU · line 232

Quoted 4 lines
kernel/rcu/Kconfig +4 -0
+	default n
+	help
+	  Use this option to offload callback processing from all CPUs
+	  by default, in the absence of the rcu_nocbs boot parameter.

And also in the absence of the nohz_full boot parameter, correct?

Yes, fixed.

Quoted 15 lines
Quoted 15 lines
kernel/rcu/Kconfig +6 -0
+	  This also avoids the need to use any boot parameters to achieve
+	  the effect of offloading all CPUs on boot.
+
+	  Say Y here if you want offload all CPUs by default on boot.
+	  Say N here if you are unsure.
+
 config TASKS_TRACE_RCU_READ_MB
 	bool "Tasks Trace RCU readers use memory barriers in user and idle"
 	depends on RCU_EXPERT
kernel/rcu/tree_nocb.h +0 -0
index eeafb546a7a0..673fa0d1f801 100644
@@ -1165,12 +1165,21 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
Quoted 8 lines

kernel/rcu/tree_nocb.h EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); · line 1168

Quoted 4 lines
kernel/rcu/tree_nocb.h +1 -1
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
+	bool need_rcu_nocb_mask = false, offload_all = false;

Please use the extra line to perserve alphabetical order. (I do know about inverse tree, though I have no idea why it is considered to be a good thing.)

Done.

thanks,

- Joel