Skip to contentSkip to conversation

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

PATCH Superseded Zhen Lei 3 participants 4 messages Apr 26, 2022 – May 16, 2022 RCU

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

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

The local variable 'need_rcu_nocb_mask' is true only if CONFIG_NO_HZ_FULL is defined. So branch "if (need_rcu_nocb_mask)" can be moved within the scope of "#if defined(CONFIG_NO_HZ_FULL)". At this point, using variable 'need_rcu_nocb_mask' is not necessary, so delete it.

No functional changes, but the code looks a little more concise.

---
 kernel/rcu/tree_nocb.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/rcu/tree_nocb.h +2 -6
index 636d0546a4e932e..1e334e217f0afb7 100644
@@ -1165,15 +1165,10 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
 	struct rcu_data *rdp;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
-		need_rcu_nocb_mask = true;
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
-	if (need_rcu_nocb_mask) {
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
 		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");
@@ -1182,6 +1177,7 @@ void __init rcu_init_nohz(void)
 		}
 		rcu_nocb_is_setup = true;
 	}
+#endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (!rcu_nocb_is_setup)
 		return;
Signature · 1 line
2.26.0.106.g9fadedd
#1 lore raw
Quoted 20 lines · Zhen Lei

The local variable 'need_rcu_nocb_mask' is true only if CONFIG_NO_HZ_FULL is defined. So branch "if (need_rcu_nocb_mask)" can be moved within the scope of "#if defined(CONFIG_NO_HZ_FULL)". At this point, using variable 'need_rcu_nocb_mask' is not necessary, so delete it.

No functional changes, but the code looks a little more concise.

---
 kernel/rcu/tree_nocb.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/rcu/tree_nocb.h +0 -0
index 636d0546a4e932e..1e334e217f0afb7 100644
@@ -1165,15 +1165,10 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;

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

Quoted 10 lines
kernel/rcu/tree_nocb.h +1 -6
-	bool need_rcu_nocb_mask = false;
 	struct rcu_data *rdp;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
-		need_rcu_nocb_mask = true;
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
-	if (need_rcu_nocb_mask) {
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {

Thanks! I suspect though that the introduction of CONFIG_RCU_NOCB_CPU_DEFAULT_ALL has made this patch unecessary.

Quoted 14 lines
kernel/rcu/tree_nocb.h +1 -0
 		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");
@@ -1182,6 +1177,7 @@ void __init rcu_init_nohz(void)
 		}
 		rcu_nocb_is_setup = true;
 	}
+#endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (!rcu_nocb_is_setup)
 		return;
Signature · 1 line
2.26.0.106.g9fadedd
maintainer
#2 lore raw
In reply to Zhen Lei
Quoted 8 lines · Zhen Lei

The local variable 'need_rcu_nocb_mask' is true only if CONFIG_NO_HZ_FULL is defined. So branch "if (need_rcu_nocb_mask)" can be moved within the scope of "#if defined(CONFIG_NO_HZ_FULL)". At this point, using variable 'need_rcu_nocb_mask' is not necessary, so delete it.

No functional changes, but the code looks a little more concise.

First, please accept my apologies for the late reply and for the overly active spam filters.

One question below.

Thanx, Paul

Quoted 11 lines
---
 kernel/rcu/tree_nocb.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/rcu/tree_nocb.h +0 -0
index 636d0546a4e932e..1e334e217f0afb7 100644
@@ -1165,15 +1165,10 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {

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

Quoted 10 lines
kernel/rcu/tree_nocb.h +0 -6
 	int cpu;
-	bool need_rcu_nocb_mask = false;
 	struct rcu_data *rdp;
 
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
-		need_rcu_nocb_mask = true;
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
-	if (need_rcu_nocb_mask) {

Could you please test this on a kernel built with CONFIG_NO_HZ_FULL=n and CONFIG_RCU_NOCB_CPU=y? If that works, please add an explanation of why it works to the commit log above and repost the patch.

Quoted 15 lines
kernel/rcu/tree_nocb.h +2 -0
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
 		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");
@@ -1182,6 +1177,7 @@ void __init rcu_init_nohz(void)
 		}
 		rcu_nocb_is_setup = true;
 	}
+#endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (!rcu_nocb_is_setup)
 		return;
Signature · 1 line
2.26.0.106.g9fadedd
#3 lore raw
Quoted 32 lines · Paul E. McKenney
Quoted 8 lines · Zhen Lei

The local variable 'need_rcu_nocb_mask' is true only if CONFIG_NO_HZ_FULL is defined. So branch "if (need_rcu_nocb_mask)" can be moved within the scope of "#if defined(CONFIG_NO_HZ_FULL)". At this point, using variable 'need_rcu_nocb_mask' is not necessary, so delete it.

No functional changes, but the code looks a little more concise.

First, please accept my apologies for the late reply and for the overly active spam filters.

One question below.

Thanx, Paul

Quoted 15 lines
---
 kernel/rcu/tree_nocb.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/rcu/tree_nocb.h +0 -1
index 636d0546a4e932e..1e334e217f0afb7 100644
@@ -1165,15 +1165,10 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
 void __init rcu_init_nohz(void)
 {
 	int cpu;
-	bool need_rcu_nocb_mask = false;
 	struct rcu_data *rdp;
 
Quoted 9 lines

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

Quoted 6 lines
kernel/rcu/tree_nocb.h +0 -5
 #if defined(CONFIG_NO_HZ_FULL)
-	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
-		need_rcu_nocb_mask = true;
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
-	if (need_rcu_nocb_mask) {

Could you please test this on a kernel built with CONFIG_NO_HZ_FULL=n and CONFIG_RCU_NOCB_CPU=y? If that works, please add an explanation

OK, I will test it.

Quoted 1 line

of why it works to the commit log above and repost the patch.

Sorry, If I had written pseudocode in the commit log, it would have been clear, as below:

-----------------before-----------------

        bool need_rcu_nocb_mask = false;

#if defined(CONFIG_NO_HZ_FULL)
if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
need_rcu_nocb_mask = true; <---- //Move it here, then delete all 'need_rcu_nocb_mask' related code

#endif /* #if defined(CONFIG_NO_HZ_FULL) */          |
                                                     |
        if (need_rcu_nocb_mask) {                    |  //Can only be true above
                ...                             -----
        }

-----------------after-----------------

#if defined(CONFIG_NO_HZ_FULL)
        if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
                ...
	}

#endif /* #if defined(CONFIG_NO_HZ_FULL) */

I'm doing clean up on the premise that the original code is correct.

Quoted 18 lines
Quoted 16 lines
kernel/rcu/tree_nocb.h +2 -0
+	if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
 		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");
@@ -1182,6 +1177,7 @@ void __init rcu_init_nohz(void)
 		}
 		rcu_nocb_is_setup = true;
 	}
+#endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
 	if (!rcu_nocb_is_setup)
 		return;
Signature · 1 line
2.26.0.106.g9fadedd

.

Signature · 2 lines
Regards,
  Zhen Lei