Skip to contentSkip to conversation

rcu/nocb: Delete local variable 'need_rcu_nocb_mask' in rcu_init_nohz()

PATCH Superseded Zhen Lei 3 participants 7 messages Sep 1, 2022 – Sep 13, 2022 RCU

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

v6 cover rcu/nocb: Delete local variable 'need_rcu_nocb_mask' in rcu_init_nohz()

v5 --> v6:
1. Frist, update patch 1/2, so that, CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y takes effect only when there are no 'rcu_nocbs=' and 'nohz_full='. Retain the same semantics as the original.
2. Then, add patch 2/2, so that, CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y takes effect as long as there is no "rcu_nocbs=" boot parameter. This is suggested by Frederic Weisbecker.

Test cases and test results as below:
----------------------------------------------------------------------
| CONFIG_NO_HZ_FULL | CONFIG_RCU_NOCB_CPU_DEFAULT_ALL | cmdline |
----------------------------------------------------------------------

1)         N         |                 N               |     none      |
2)         N         |                 N               | rcu_nocbs=1-2 |
3)         Y         |                 N               | nohz_full=2-3 |
4)         Y         |                 N               | rcu_nocbs=1 nohz_full=3 |
5)         Y         |                 Y               |      none     |
6)         Y         |                 Y               | rcu_nocbs=1-2 |
7)         Y         |                 Y               | nohz_full=2-3 |
8)         Y         |                 Y               | rcu_nocbs=1 nohz_full=3 |

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

dmesg | grep "Offload RCU callbacks"
1) none
2) Offload RCU callbacks from CPUs: 1-2.
3) Offload RCU callbacks from CPUs: 2-3.
4) Offload RCU callbacks from CPUs: 1,3.
5) Offload RCU callbacks from CPUs: 0-3.
6) Offload RCU callbacks from CPUs: 1-2.
7) Offload RCU callbacks from CPUs: 0-3.
8) Offload RCU callbacks from CPUs: 1,3.

v4 --> v5:
1. Cancel eliminate rcu_state.nocb_is_setup. It is useful for case 1) below.

Test cases and test results as below:
----------------------------------------------------------------------
| CONFIG_NO_HZ_FULL | CONFIG_RCU_NOCB_CPU_DEFAULT_ALL | cmdline |
----------------------------------------------------------------------

1)         N         |                 N               |     none      |
2)         N         |                 N               | rcu_nocbs=1-2 |
3)         Y         |                 N               | nohz_full=1-2 |
4)         Y         |                 Y               |     none      |

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

1)

[ 1018.082417] rcu-torture:--- End of test: SUCCESS (default)
root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB
CONFIG_RCU_NOCB_CPU=y
# CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set
root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL
# CONFIG_NO_HZ_FULL is not set
root@genericarmv8:~# cat /proc/cmdline
console=ttyS0 earlyprintk=serial root=/dev/sda rw

2) 3) 4)
The same to v4.

v3 --> v4:
Fix a build warning.
- struct cpumask *cpumask = NULL;
+ const struct cpumask *cpumask = NULL;

v2 --> v3:
1. Eliminate rcu_state.nocb_is_setup
2. Update the code based on the above patch and commit b37a667c6242 ("rcu/nocb: Add an option to offload all CPUs on boot").

Test cases and test results as below:

----------------------------------------------------------------------
| CONFIG_NO_HZ_FULL | CONFIG_RCU_NOCB_CPU_DEFAULT_ALL | cmdline |
----------------------------------------------------------------------

1)         N         |                 N               |     none      |
2)         N         |                 N               | rcu_nocbs=1-2 |
3)         Y         |                 N               | nohz_full=1-2 |
4)         Y         |                 Y               |     none      |

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

1)

[ 1085.691770] rcu-torture:--- End of test: SUCCESS: (default)
root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
[    0.000000] rcu:     Offload RCU callbacks from CPUs: (none).
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB
CONFIG_RCU_NOCB_CPU=y
# CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set
root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL
# CONFIG_NO_HZ_FULL is not set
root@genericarmv8:~# cat /proc/cmdline
console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000

2)

[ 1022.532198] rcu-torture:--- End of test: SUCCESS: (default)
root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
[    0.000000] rcu:     Offload RCU callbacks from CPUs: 1-2.
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB
CONFIG_RCU_NOCB_CPU=y
# CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set
root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL
# CONFIG_NO_HZ_FULL is not set
root@genericarmv8:~# cat /proc/cmdline
console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000 rcu_nocbs=1-2

3)

[ 1011.714712] rcu-torture:--- End of test: SUCCESS: (default)
root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
[    0.000000] rcu:     Offload RCU callbacks from CPUs: 1-2.
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB
CONFIG_RCU_NOCB_CPU=y
# CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set
root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL
CONFIG_NO_HZ_FULL=y
root@genericarmv8:~# cat /proc/cmdline
console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000 nohz_full=1-2

4)

[ 1031.047094] rcu-torture:--- End of test: SUCCESS: (default)
root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
[    0.000000] rcu:     Offload RCU callbacks from CPUs: 0-3.
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB
CONFIG_RCU_NOCB_CPU=y
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y
root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL
CONFIG_NO_HZ_FULL=y
root@genericarmv8:~# cat /proc/cmdline
console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000

v1 --> v2:
Update commit message.

Zhen Lei (2):
rcu: Simplify rcu_init_nohz() cpumask handling
rcu: Offload callback processing from all CPUs in the absence of
rcu_nocbs=

 kernel/rcu/Kconfig     |  4 ++--
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 2 files changed, 14 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v6 1/2 rcu: Simplify rcu_init_nohz() cpumask handling

In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.

But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.

---
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +12 -23
index 0a5f0ef41484518..8b6dceeabde0b4d 100644
@@ -1210,45 +1210,34 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
-	bool offload_all = false;
 	struct rcu_data *rdp;
-
-#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup) {
-		need_rcu_nocb_mask = true;
-		offload_all = true;
-	}
-#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
+	const struct cpumask *cpumask = NULL;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(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 (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
+		cpumask = tick_nohz_full_mask;
+#endif
+
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_state.nocb_is_setup && !cpumask)
+		cpumask = cpu_possible_mask;
+#endif
 
-	if (need_rcu_nocb_mask) {
+	if (cpumask) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
 				pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
 				return;
 			}
 		}
+
+		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
 		rcu_state.nocb_is_setup = true;
 	}
 
 	if (!rcu_state.nocb_is_setup)
 		return;
 
-#if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running)
-		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.25.1
#2 lore raw

Re: [PATCH v6 1/2] rcu: Simplify rcu_init_nohz() cpumask handling

Quoted 7 lines · Zhen Lei

In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.

Quoted 7 lines

But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.

Sorry, I forgot remove this "Signed-off-by".

Quoted 68 lines
---
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +12 -23
index 0a5f0ef41484518..8b6dceeabde0b4d 100644
@@ -1210,45 +1210,34 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
-	bool offload_all = false;
 	struct rcu_data *rdp;
-
-#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup) {
-		need_rcu_nocb_mask = true;
-		offload_all = true;
-	}
-#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
+	const struct cpumask *cpumask = NULL;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(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 (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
+		cpumask = tick_nohz_full_mask;
+#endif
+
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_state.nocb_is_setup && !cpumask)
+		cpumask = cpu_possible_mask;
+#endif
 
-	if (need_rcu_nocb_mask) {
+	if (cpumask) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
 				pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
 				return;
 			}
 		}
+
+		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
 		rcu_state.nocb_is_setup = true;
 	}
 
 	if (!rcu_state.nocb_is_setup)
 		return;
 
-#if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running)
-		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 · 2 lines
Regards,
  Zhen Lei
maintainer
#3 lore raw

Re: [PATCH v6 1/2] rcu: Simplify rcu_init_nohz() cpumask handling

Quoted 15 lines · Leizhen (ThunderTown)
Quoted 12 lines · Zhen Lei

In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.

But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.

Quoted 4 lines
Quoted 2 lines

Sorry, I forgot remove this "Signed-off-by".

Not a problem, especially given that in view of my oversight on the previous version, I am going to let Frederic take first crack at this version. ;-)

Thanx, Paul

Quoted 72 lines
Quoted 68 lines
---
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +12 -23
index 0a5f0ef41484518..8b6dceeabde0b4d 100644
@@ -1210,45 +1210,34 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
-	bool offload_all = false;
 	struct rcu_data *rdp;
-
-#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup) {
-		need_rcu_nocb_mask = true;
-		offload_all = true;
-	}
-#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
+	const struct cpumask *cpumask = NULL;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(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 (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
+		cpumask = tick_nohz_full_mask;
+#endif
+
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_state.nocb_is_setup && !cpumask)
+		cpumask = cpu_possible_mask;
+#endif
 
-	if (need_rcu_nocb_mask) {
+	if (cpumask) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
 				pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
 				return;
 			}
 		}
+
+		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
 		rcu_state.nocb_is_setup = true;
 	}
 
 	if (!rcu_state.nocb_is_setup)
 		return;
 
-#if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running)
-		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 · 2 lines
Regards,
  Zhen Lei
maintainer Acked-by on v6 1/2
#4 lore raw

Re: [PATCH v6 1/2] rcu: Simplify rcu_init_nohz() cpumask handling

In reply to Zhen Lei
Quoted 43 lines · Zhen Lei

In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.

But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.

---
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +1 -12
index 0a5f0ef41484518..8b6dceeabde0b4d 100644
@@ -1210,45 +1210,34 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
-	bool offload_all = false;
 	struct rcu_data *rdp;
-
-#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup) {
-		need_rcu_nocb_mask = true;
-		offload_all = true;
-	}
-#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
+	const struct cpumask *cpumask = NULL;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
-		need_rcu_nocb_mask = true;
-		offload_all = false; /* NO_HZ_FULL has its own mask. */

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

Quoted 10 lines
kernel/rcu/tree_nocb.h +8 -2
-	}
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
+		cpumask = tick_nohz_full_mask;
+#endif
+
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_state.nocb_is_setup && !cpumask)
+		cpumask = cpu_possible_mask;
+#endif

Good, and it can even use a simple condition:

if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) &&

    !rcu_state.nocb_is_setup && !cpumask)
    cpumask = cpu_possible_mask;
Quoted 31 lines
kernel/rcu/tree_nocb.h +3 -9
-	if (need_rcu_nocb_mask) {
+	if (cpumask) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
 				pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
 				return;
 			}
 		}
+
+		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
 		rcu_state.nocb_is_setup = true;
 	}
 
 	if (!rcu_state.nocb_is_setup)
 		return;
 
-#if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running)
-		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.25.1
#5 lore raw

Re: [PATCH v6 1/2] rcu: Simplify rcu_init_nohz() cpumask handling

Quoted 57 lines · Frederic Weisbecker
Quoted 43 lines · Zhen Lei

In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.

But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.

---
 kernel/rcu/tree_nocb.h | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +1 -12
index 0a5f0ef41484518..8b6dceeabde0b4d 100644
@@ -1210,45 +1210,34 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
-	bool offload_all = false;
 	struct rcu_data *rdp;
-
-#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup) {
-		need_rcu_nocb_mask = true;
-		offload_all = true;
-	}
-#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
+	const struct cpumask *cpumask = NULL;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
-		need_rcu_nocb_mask = true;
-		offload_all = false; /* NO_HZ_FULL has its own mask. */

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

Quoted 10 lines
kernel/rcu/tree_nocb.h +8 -2
-	}
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
+		cpumask = tick_nohz_full_mask;
+#endif
+
+#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
+	if (!rcu_state.nocb_is_setup && !cpumask)
+		cpumask = cpu_possible_mask;
+#endif

Good, and it can even use a simple condition:

Quoted 3 lines

if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) &&

    !rcu_state.nocb_is_setup && !cpumask)
    cpumask = cpu_possible_mask;

Okay, I'll revise it in v7.

Quoted 38 lines
Quoted 31 lines
kernel/rcu/tree_nocb.h +3 -9
-	if (need_rcu_nocb_mask) {
+	if (cpumask) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
 				pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
 				return;
 			}
 		}
+
+		cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
 		rcu_state.nocb_is_setup = true;
 	}
 
 	if (!rcu_state.nocb_is_setup)
 		return;
 
-#if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running)
-		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.25.1

.

Signature · 2 lines
Regards,
  Zhen Lei
author
#6 lore raw

PATCH v6 2/2 rcu: Offload callback processing from all CPUs in the absence of rcu_nocbs=

In reply to Zhen Lei

Offload callback processing from all CPUs as long as there is no "rcu_nocbs=" boot parameter. This also means: whether CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y takes effect does not depend on the absence of "nohz_full=".

---
 kernel/rcu/Kconfig     | 4 ++--
 kernel/rcu/tree_nocb.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/rcu/Kconfig +2 -2
index d471d22a5e21b43..35b94f5f6767f00 100644
@@ -270,8 +270,8 @@ config RCU_NOCB_CPU_DEFAULT_ALL
 	default n
 	help
 	  Use this option to offload callback processing from all CPUs
-	  by default, in the absence of the rcu_nocbs or nohz_full boot
-	  parameter. This also avoids the need to use any boot parameters
+	  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.
kernel/rcu/tree_nocb.h +1 -1
index 8b6dceeabde0b4d..cfbdd78d6c33158 100644
@@ -1219,7 +1219,7 @@ void __init rcu_init_nohz(void)
 #endif
 
 #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
-	if (!rcu_state.nocb_is_setup && !cpumask)
+	if (!rcu_state.nocb_is_setup)
 		cpumask = cpu_possible_mask;
 #endif
 
Signature · 1 line
2.25.1