Skip to contentSkip to conversation

rcu: Bunch of cleanups

PATCH Applied Frederic Weisbecker 2 participants 13 messages Feb 16, 2022 – Feb 17, 2022 RCU

lore
Share & tools
lore

Frederic Weisbecker

author maintainer
#0 lore raw

cover rcu: Bunch of cleanups

Hi,

Just a bit of housekeeping.

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
rcu/dev

HEAD: be4d4c3ba8c4ceeba9dc9df4de5451c7261161f3

Thanks,
Frederic
---

Frederic Weisbecker (5):
rcu: Remove rcu_is_nocb_cpu()
rcu/nocb: Move rcu_nocb_is_setup to rcu_state
rcu: Assume rcu_init() is called before smp
rcu: Initialize boost kthread only for boot node prior SMP initialization rcu/nocb: Initialize nocb kthreads only for boot CPU prior SMP initialization

 kernel/rcu/rcu.h         |  2 --
 kernel/rcu/tree.c        | 25 +++++++++++++++++--------
 kernel/rcu/tree.h        |  3 +--
 kernel/rcu/tree_nocb.h   | 41 +++++------------------------------------
 kernel/rcu/tree_plugin.h | 16 ----------------
 5 files changed, 23 insertions(+), 64 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 rcu: Remove rcu_is_nocb_cpu()

It's an unused leftover that can now be removed.

---
 kernel/rcu/rcu.h       | 2 --
 kernel/rcu/tree_nocb.h | 8 --------
 2 files changed, 10 deletions(-)
kernel/rcu/rcu.h +0 -2
index 819f9d979e61..44efedd921d0 100644
@@ -549,10 +549,8 @@ void rcu_gp_slow_unregister(atomic_t *rgssp);
 #endif /* #else #ifdef CONFIG_TINY_RCU */
 
 #ifdef CONFIG_RCU_NOCB_CPU
-bool rcu_is_nocb_cpu(int cpu);
 void rcu_bind_current_to_nocb(void);
 #else
-static inline bool rcu_is_nocb_cpu(int cpu) { return false; }
 static inline void rcu_bind_current_to_nocb(void) { }
 #endif
 
kernel/rcu/tree_nocb.h +0 -8
index 636d0546a4e9..02e1d05a11fc 100644
@@ -215,14 +215,6 @@ static void rcu_init_one_nocb(struct rcu_node *rnp)
 	init_swait_queue_head(&rnp->nocb_gp_wq[1]);
 }
 
-/* Is the specified CPU a no-CBs CPU? */
-bool rcu_is_nocb_cpu(int cpu)
-{
-	if (cpumask_available(rcu_nocb_mask))
-		return cpumask_test_cpu(cpu, rcu_nocb_mask);
-	return false;
-}
-
 static bool __wake_nocb_gp(struct rcu_data *rdp_gp,
 			   struct rcu_data *rdp,
 			   bool force, unsigned long flags)
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/5 rcu/nocb: Move rcu_nocb_is_setup to rcu_state

In reply to Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.h      |  1 +
 kernel/rcu/tree_nocb.h | 15 ++++++---------
 2 files changed, 7 insertions(+), 9 deletions(-)
kernel/rcu/tree.h +1 -0
index 19fc9acce3ce..735fc410d76a 100644
@@ -368,6 +368,7 @@ struct rcu_state {
 	arch_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
 						/* Synchronize offline with */
 						/*  GP pre-initialization. */
+	int nocb_is_setup;			/* nocb is setup from boot */
 };
 
 /* Values for rcu_state structure's gp_flags field. */
kernel/rcu/tree_nocb.h +6 -9
index 02e1d05a11fc..494e65445773 100644
@@ -60,9 +60,6 @@ static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp)
  * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters.
  * If the list is invalid, a warning is emitted and all CPUs are offloaded.
  */
-
-static bool rcu_nocb_is_setup;
-
 static int __init rcu_nocb_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&rcu_nocb_mask);
@@ -72,7 +69,7 @@ static int __init rcu_nocb_setup(char *str)
 			cpumask_setall(rcu_nocb_mask);
 		}
 	}
-	rcu_nocb_is_setup = true;
+	rcu_state.nocb_is_setup = true;
 	return 1;
 }
 __setup("rcu_nocbs", rcu_nocb_setup);
@@ -1165,17 +1162,17 @@ void __init rcu_init_nohz(void)
 		need_rcu_nocb_mask = true;
 #endif /* #if defined(CONFIG_NO_HZ_FULL) */
 
-	if (need_rcu_nocb_mask) {
+	if (rcu_state.nocb_is_setup) {
 		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;
 			}
 		}
-		rcu_nocb_is_setup = true;
+		rcu_state.nocb_is_setup = true;
 	}
 
-	if (!rcu_nocb_is_setup)
+	if (!rcu_state.nocb_is_setup)
 		return;
 
 #if defined(CONFIG_NO_HZ_FULL)
@@ -1233,7 +1230,7 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 	struct task_struct *t;
 	struct sched_param sp;
 
-	if (!rcu_scheduler_fully_active || !rcu_nocb_is_setup)
+	if (!rcu_scheduler_fully_active || !rcu_state.nocb_is_setup)
 		return;
 
 	/* If there already is an rcuo kthread, then nothing to do. */
@@ -1279,7 +1276,7 @@ static void __init rcu_spawn_nocb_kthreads(void)
 {
 	int cpu;
 
-	if (rcu_nocb_is_setup) {
+	if (rcu_state.nocb_is_setup) {
 		for_each_online_cpu(cpu)
 			rcu_spawn_cpu_nocb_kthread(cpu);
 	}
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

Thanx, Paul

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

commit 1a4f308b3b3841ef10043fe6c3dd12fc872b0400

Author: Paul E. McKenney <[email protected]>
Date:   Wed Feb 16 13:27:42 2022 -0800

squash! rcu/nocb: Move rcu_nocb_is_setup to rcu_state

[ paulmck: Remove unused need_rcu_nocb_mask local variable. ]

kernel/rcu/tree_nocb.h +0 -6
index 9d6d4786bc703..9d97aa1f4d6ce 100644
@@ -1154,14 +1154,8 @@ 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 (rcu_state.nocb_is_setup) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
maintainer
#4 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
Quoted 3 lines

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

TASKS03, TREE04, and TREE07 don't like this much, according to git bisect. They are the ones with nohz_full CPUs, in case that is crucial. Trying again after reverting this commit locally.

If that works, I would be tempted to try the modification shown below.

Thoughts?

Thanx, Paul

Quoted 17 lines

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

commit 1a4f308b3b3841ef10043fe6c3dd12fc872b0400

Author: Paul E. McKenney <[email protected]>
Date:   Wed Feb 16 13:27:42 2022 -0800

squash! rcu/nocb: Move rcu_nocb_is_setup to rcu_state

[ paulmck: Remove unused need_rcu_nocb_mask local variable. ]

kernel/rcu/tree_nocb.h +0 -0
index 9d6d4786bc703..9d97aa1f4d6ce 100644

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

Quoted 9 lines
kernel/rcu/tree_nocb.h +0 -4
@@ -1154,14 +1154,8 @@ 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;
		rcu_state.nocb_is_setup = true;
Quoted 5 lines
kernel/rcu/tree_nocb.h +0 -2
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
 	if (rcu_state.nocb_is_setup) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
maintainer
#5 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 16 lines · Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
Quoted 3 lines

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

Quoted 5 lines

TASKS03, TREE04, and TREE07 don't like this much, according to git bisect. They are the ones with nohz_full CPUs, in case that is crucial. Trying again after reverting this commit locally.

If that works, I would be tempted to try the modification shown below.

And that does pass significant rcutorture testing, but over to you. ;-)

Thanx, Paul

Quoted 34 lines
Quoted 17 lines

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

commit 1a4f308b3b3841ef10043fe6c3dd12fc872b0400

Author: Paul E. McKenney <[email protected]>
Date:   Wed Feb 16 13:27:42 2022 -0800

squash! rcu/nocb: Move rcu_nocb_is_setup to rcu_state

[ paulmck: Remove unused need_rcu_nocb_mask local variable. ]

kernel/rcu/tree_nocb.h +0 -0
index 9d6d4786bc703..9d97aa1f4d6ce 100644

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

Quoted 9 lines
kernel/rcu/tree_nocb.h +0 -4
@@ -1154,14 +1154,8 @@ 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;
		rcu_state.nocb_is_setup = true;
Quoted 5 lines
kernel/rcu/tree_nocb.h +0 -2
-#endif /* #if defined(CONFIG_NO_HZ_FULL) */
-
 	if (rcu_state.nocb_is_setup) {
 		if (!cpumask_available(rcu_nocb_mask)) {
 			if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
author maintainer
#6 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 17 lines · Paul E. McKenney
Quoted 16 lines · Paul E. McKenney
Quoted 14 lines · Paul E. McKenney
Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

Quoted 7 lines
Quoted 5 lines

TASKS03, TREE04, and TREE07 don't like this much, according to git bisect. They are the ones with nohz_full CPUs, in case that is crucial. Trying again after reverting this commit locally.

If that works, I would be tempted to try the modification shown below.

And that does pass significant rcutorture testing, but over to you. ;-)

Ah no we still need that variable, but I screwed up and wrongly converted need_rcu_nocb_mask to rcu_state.nocb_is_setup somewhere.

Here is the v2 of the culprit patch (sorry):

---
From: Frederic Weisbecker <[email protected]>
Date: Mon, 14 Feb 2022 14:23:39 +0100
Subject: [PATCH] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.h      |  1 +
 kernel/rcu/tree_nocb.h | 13 +++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/rcu/tree.h +1 -0
index 19fc9acce3ce..735fc410d76a 100644
@@ -368,6 +368,7 @@ struct rcu_state {
 	arch_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
 						/* Synchronize offline with */
 						/*  GP pre-initialization. */
+	int nocb_is_setup;			/* nocb is setup from boot */
 };
 
 /* Values for rcu_state structure's gp_flags field. */
kernel/rcu/tree_nocb.h +5 -8
index 02e1d05a11fc..3c00240833d6 100644
@@ -60,9 +60,6 @@ static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp)
  * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters.
  * If the list is invalid, a warning is emitted and all CPUs are offloaded.
  */
-
-static bool rcu_nocb_is_setup;
-
 static int __init rcu_nocb_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&rcu_nocb_mask);
@@ -72,7 +69,7 @@ static int __init rcu_nocb_setup(char *str)
 			cpumask_setall(rcu_nocb_mask);
 		}
 	}
-	rcu_nocb_is_setup = true;
+	rcu_state.nocb_is_setup = true;
 	return 1;
 }
 __setup("rcu_nocbs", rcu_nocb_setup);
@@ -1172,10 +1169,10 @@ void __init rcu_init_nohz(void)
 				return;
 			}
 		}
-		rcu_nocb_is_setup = true;
+		rcu_state.nocb_is_setup = true;
 	}
 
-	if (!rcu_nocb_is_setup)
+	if (!rcu_state.nocb_is_setup)
 		return;
 
 #if defined(CONFIG_NO_HZ_FULL)
@@ -1233,7 +1230,7 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 	struct task_struct *t;
 	struct sched_param sp;
 
-	if (!rcu_scheduler_fully_active || !rcu_nocb_is_setup)
+	if (!rcu_scheduler_fully_active || !rcu_state.nocb_is_setup)
 		return;
 
 	/* If there already is an rcuo kthread, then nothing to do. */
@@ -1279,7 +1276,7 @@ static void __init rcu_spawn_nocb_kthreads(void)
 {
 	int cpu;
 
-	if (rcu_nocb_is_setup) {
+	if (rcu_state.nocb_is_setup) {
 		for_each_online_cpu(cpu)
 			rcu_spawn_cpu_nocb_kthread(cpu);
 	}
Signature · 1 line
2.25.1
maintainer
#7 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 22 lines · Frederic Weisbecker
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
Quoted 3 lines

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

TASKS03, TREE04, and TREE07 don't like this much, according to git bisect. They are the ones with nohz_full CPUs, in case that is crucial. Trying again after reverting this commit locally.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

If that works, I would be tempted to try the modification shown below.

And that does pass significant rcutorture testing, but over to you. ;-)

Ah no we still need that variable, but I screwed up and wrongly converted need_rcu_nocb_mask to rcu_state.nocb_is_setup somewhere.

Here is the v2 of the culprit patch (sorry):

Been there, done that! ;-)

I pulled this one in and I will let you know how it goes.

Thanx, Paul

Quoted 87 lines

---
From: Frederic Weisbecker <[email protected]>
Date: Mon, 14 Feb 2022 14:23:39 +0100
Subject: [PATCH] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.h      |  1 +
 kernel/rcu/tree_nocb.h | 13 +++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/rcu/tree.h +1 -0
index 19fc9acce3ce..735fc410d76a 100644
@@ -368,6 +368,7 @@ struct rcu_state {
 	arch_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
 						/* Synchronize offline with */
 						/*  GP pre-initialization. */
+	int nocb_is_setup;			/* nocb is setup from boot */
 };
 
 /* Values for rcu_state structure's gp_flags field. */
kernel/rcu/tree_nocb.h +5 -8
index 02e1d05a11fc..3c00240833d6 100644
@@ -60,9 +60,6 @@ static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp)
  * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters.
  * If the list is invalid, a warning is emitted and all CPUs are offloaded.
  */
-
-static bool rcu_nocb_is_setup;
-
 static int __init rcu_nocb_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&rcu_nocb_mask);
@@ -72,7 +69,7 @@ static int __init rcu_nocb_setup(char *str)
 			cpumask_setall(rcu_nocb_mask);
 		}
 	}
-	rcu_nocb_is_setup = true;
+	rcu_state.nocb_is_setup = true;
 	return 1;
 }
 __setup("rcu_nocbs", rcu_nocb_setup);
@@ -1172,10 +1169,10 @@ void __init rcu_init_nohz(void)
 				return;
 			}
 		}
-		rcu_nocb_is_setup = true;
+		rcu_state.nocb_is_setup = true;
 	}
 
-	if (!rcu_nocb_is_setup)
+	if (!rcu_state.nocb_is_setup)
 		return;
 
 #if defined(CONFIG_NO_HZ_FULL)
@@ -1233,7 +1230,7 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 	struct task_struct *t;
 	struct sched_param sp;
 
-	if (!rcu_scheduler_fully_active || !rcu_nocb_is_setup)
+	if (!rcu_scheduler_fully_active || !rcu_state.nocb_is_setup)
 		return;
 
 	/* If there already is an rcuo kthread, then nothing to do. */
@@ -1279,7 +1276,7 @@ static void __init rcu_spawn_nocb_kthreads(void)
 {
 	int cpu;
 
-	if (rcu_nocb_is_setup) {
+	if (rcu_state.nocb_is_setup) {
 		for_each_online_cpu(cpu)
 			rcu_spawn_cpu_nocb_kthread(cpu);
 	}
Signature · 1 line
2.25.1
maintainer
#8 lore raw

Re: [PATCH 2/5] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

Quoted 27 lines · Paul E. McKenney
Quoted 26 lines · Frederic Weisbecker
Quoted 24 lines · Paul E. McKenney
Quoted 16 lines · Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Frederic Weisbecker

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
Quoted 3 lines

Build testing for CONFIG_NO_HZ_FULL=n kernels suggested the following patch be merged into this one. Or does this variable need to be used somewhere? Either way, please let me know!

Quoted 5 lines

TASKS03, TREE04, and TREE07 don't like this much, according to git bisect. They are the ones with nohz_full CPUs, in case that is crucial. Trying again after reverting this commit locally.

If that works, I would be tempted to try the modification shown below.

And that does pass significant rcutorture testing, but over to you. ;-)

Quoted 8 lines
Quoted 4 lines

Ah no we still need that variable, but I screwed up and wrongly converted need_rcu_nocb_mask to rcu_state.nocb_is_setup somewhere.

Here is the v2 of the culprit patch (sorry):

Been there, done that! ;-)

I pulled this one in and I will let you know how it goes.

And it passed moderate rcutorture testing with flying colors! ;-)

So let's see what -next makes of it...

Thanx, Paul

Quoted 87 lines
Quoted 87 lines

---
From: Frederic Weisbecker <[email protected]>
Date: Mon, 14 Feb 2022 14:23:39 +0100
Subject: [PATCH] rcu/nocb: Move rcu_nocb_is_setup to rcu_state

In order to avoid scattering the global RCU states, move the RCU nocb initialization witness within rcu_state.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.h      |  1 +
 kernel/rcu/tree_nocb.h | 13 +++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
kernel/rcu/tree.h +1 -0
index 19fc9acce3ce..735fc410d76a 100644
@@ -368,6 +368,7 @@ struct rcu_state {
 	arch_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
 						/* Synchronize offline with */
 						/*  GP pre-initialization. */
+	int nocb_is_setup;			/* nocb is setup from boot */
 };
 
 /* Values for rcu_state structure's gp_flags field. */
kernel/rcu/tree_nocb.h +5 -8
index 02e1d05a11fc..3c00240833d6 100644
@@ -60,9 +60,6 @@ static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp)
  * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters.
  * If the list is invalid, a warning is emitted and all CPUs are offloaded.
  */
-
-static bool rcu_nocb_is_setup;
-
 static int __init rcu_nocb_setup(char *str)
 {
 	alloc_bootmem_cpumask_var(&rcu_nocb_mask);
@@ -72,7 +69,7 @@ static int __init rcu_nocb_setup(char *str)
 			cpumask_setall(rcu_nocb_mask);
 		}
 	}
-	rcu_nocb_is_setup = true;
+	rcu_state.nocb_is_setup = true;
 	return 1;
 }
 __setup("rcu_nocbs", rcu_nocb_setup);
@@ -1172,10 +1169,10 @@ void __init rcu_init_nohz(void)
 				return;
 			}
 		}
-		rcu_nocb_is_setup = true;
+		rcu_state.nocb_is_setup = true;
 	}
 
-	if (!rcu_nocb_is_setup)
+	if (!rcu_state.nocb_is_setup)
 		return;
 
 #if defined(CONFIG_NO_HZ_FULL)
@@ -1233,7 +1230,7 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 	struct task_struct *t;
 	struct sched_param sp;
 
-	if (!rcu_scheduler_fully_active || !rcu_nocb_is_setup)
+	if (!rcu_scheduler_fully_active || !rcu_state.nocb_is_setup)
 		return;
 
 	/* If there already is an rcuo kthread, then nothing to do. */
@@ -1279,7 +1276,7 @@ static void __init rcu_spawn_nocb_kthreads(void)
 {
 	int cpu;
 
-	if (rcu_nocb_is_setup) {
+	if (rcu_state.nocb_is_setup) {
 		for_each_online_cpu(cpu)
 			rcu_spawn_cpu_nocb_kthread(cpu);
 	}
Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH 3/5 rcu: Assume rcu_init() is called before smp

In reply to Frederic Weisbecker

rcu_init() is called way before SMP is initialized and therefore only the boot CPU should be online at this stage.

Simplify the boot per-cpu initialization according to this constraint.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
kernel/rcu/tree.c +8 -6
index 86eec6a0f1a1..83dec1db86cf 100644
@@ -4813,7 +4813,7 @@ static void __init kfree_rcu_batch_init(void)
 
 void __init rcu_init(void)
 {
-	int cpu;
+	int cpu = smp_processor_id();
 
 	rcu_early_boot_tests();
 
@@ -4833,11 +4833,13 @@ void __init rcu_init(void)
 	 * or the scheduler are operational.
 	 */
 	pm_notifier(rcu_pm_notify, 0);
-	for_each_online_cpu(cpu) {
-		rcutree_prepare_cpu(cpu);
-		rcu_cpu_starting(cpu);
-		rcutree_online_cpu(cpu);
-	}
+
+	/* This is early on boot, we expect a single CPU */
+	WARN_ON(num_online_cpus() > 1);
+
+	rcutree_prepare_cpu(cpu);
+	rcu_cpu_starting(cpu);
+	rcutree_online_cpu(cpu);
 
 	/* Create workqueue for Tree SRCU and for expedited GPs. */
 	rcu_gp_wq = alloc_workqueue("rcu_gp", WQ_MEM_RECLAIM, 0);
Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH 4/5 rcu: Initialize boost kthread only for boot node prior SMP initialization

In reply to Frederic Weisbecker

rcu_spawn_gp_kthread() is called as an early initcall, which means that SMP initialization hasn't happened yet and the boot CPU is the only one online. Therefore only the boost kthread for the leaf node of the boot CPU needs to be created at this stage.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.c        |  5 ++++-
 kernel/rcu/tree.h        |  1 -
 kernel/rcu/tree_plugin.h | 16 ----------------
 3 files changed, 4 insertions(+), 18 deletions(-)
kernel/rcu/tree.c +4 -1
index 83dec1db86cf..4a98417c2e28 100644
@@ -4508,6 +4508,7 @@ static int __init rcu_spawn_gp_kthread(void)
 	struct rcu_node *rnp;
 	struct sched_param sp;
 	struct task_struct *t;
+	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
 
 	rcu_scheduler_fully_active = 1;
 	t = kthread_create(rcu_gp_kthread, NULL, "%s", rcu_state.name);
@@ -4526,7 +4527,9 @@ static int __init rcu_spawn_gp_kthread(void)
 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	wake_up_process(t);
 	rcu_spawn_nocb_kthreads();
-	rcu_spawn_boost_kthreads();
+	/* This is a pre-SMP initcall, we expect a single CPU */
+	WARN_ON(num_online_cpus() > 1);
+	rcu_spawn_one_boost_kthread(rdp->mynode);
 	rcu_spawn_core_kthreads();
 	return 0;
 }
kernel/rcu/tree.h +0 -1
index 735fc410d76a..48c772fc353f 100644
@@ -426,7 +426,6 @@ static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
 static bool rcu_is_callbacks_kthread(void);
 static void rcu_cpu_kthread_setup(unsigned int cpu);
 static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp);
-static void __init rcu_spawn_boost_kthreads(void);
 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);
kernel/rcu/tree_plugin.h +0 -16
index 6082dd23408f..90925a589774 100644
@@ -1226,18 +1226,6 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
 	free_cpumask_var(cm);
 }
 
-/*
- * Spawn boost kthreads -- called as soon as the scheduler is running.
- */
-static void __init rcu_spawn_boost_kthreads(void)
-{
-	struct rcu_node *rnp;
-
-	rcu_for_each_leaf_node(rnp)
-		if (rcu_rnp_online_cpus(rnp))
-			rcu_spawn_one_boost_kthread(rnp);
-}
-
 #else /* #ifdef CONFIG_RCU_BOOST */
 
 static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
@@ -1263,10 +1251,6 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
 {
 }
 
-static void __init rcu_spawn_boost_kthreads(void)
-{
-}
-
 #endif /* #else #ifdef CONFIG_RCU_BOOST */
 
 /*
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH 5/5 rcu/nocb: Initialize nocb kthreads only for boot CPU prior SMP initialization

In reply to Frederic Weisbecker

rcu_spawn_gp_kthread() is called as an early initcall, which means that SMP initialization hasn't happened yet and the boot CPU is the only one online. Therefore only the NOCB kthreads related to the boot CPU need to be created at this stage.

Cc Neeraj Upadhyay <[email protected]>
Cc Uladzislau Rezki <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Boqun Feng <[email protected]>
---
 kernel/rcu/tree.c      |  6 +++++-
 kernel/rcu/tree.h      |  1 -
 kernel/rcu/tree_nocb.h | 20 --------------------
 3 files changed, 5 insertions(+), 22 deletions(-)
kernel/rcu/tree.c +5 -1
index 4a98417c2e28..3e9a8ec222e4 100644
@@ -4526,9 +4526,13 @@ static int __init rcu_spawn_gp_kthread(void)
 	smp_store_release(&rcu_state.gp_kthread, t);  /* ^^^ */
 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	wake_up_process(t);
-	rcu_spawn_nocb_kthreads();
 	/* This is a pre-SMP initcall, we expect a single CPU */
 	WARN_ON(num_online_cpus() > 1);
+	/*
+	 * Those kthreads couldn't be created on rcu_init() -> rcutree_prepare_cpu()
+	 * due to rcu_scheduler_fully_active.
+	 */
+	rcu_spawn_cpu_nocb_kthread(smp_processor_id());
 	rcu_spawn_one_boost_kthread(rdp->mynode);
 	rcu_spawn_core_kthreads();
 	return 0;
kernel/rcu/tree.h +0 -1
index 48c772fc353f..e3296ecde277 100644
@@ -443,7 +443,6 @@ static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp, int level);
 static bool do_nocb_deferred_wakeup(struct rcu_data *rdp);
 static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
 static void rcu_spawn_cpu_nocb_kthread(int cpu);
-static void __init rcu_spawn_nocb_kthreads(void);
 static void show_rcu_nocb_state(struct rcu_data *rdp);
 static void rcu_nocb_lock(struct rcu_data *rdp);
 static void rcu_nocb_unlock(struct rcu_data *rdp);
kernel/rcu/tree_nocb.h +0 -20
index 494e65445773..9d6d4786bc70 100644
@@ -1266,22 +1266,6 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 	WRITE_ONCE(rdp->nocb_gp_kthread, rdp_gp->nocb_gp_kthread);
 }
 
-/*
- * Once the scheduler is running, spawn rcuo kthreads for all online
- * no-CBs CPUs.  This assumes that the early_initcall()s happen before
- * non-boot CPUs come online -- if this changes, we will need to add
- * some mutual exclusion.
- */
-static void __init rcu_spawn_nocb_kthreads(void)
-{
-	int cpu;
-
-	if (rcu_state.nocb_is_setup) {
-		for_each_online_cpu(cpu)
-			rcu_spawn_cpu_nocb_kthread(cpu);
-	}
-}
-
 /* How many CB CPU IDs per GP kthread?  Default of -1 for sqrt(nr_cpu_ids). */
 static int rcu_nocb_gp_stride = -1;
 module_param(rcu_nocb_gp_stride, int, 0444);
@@ -1538,10 +1522,6 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
 {
 }
 
-static void __init rcu_spawn_nocb_kthreads(void)
-{
-}
-
 static void show_rcu_nocb_state(struct rcu_data *rdp)
 {
 }
Signature · 1 line
2.25.1
maintainer Applied
#12 lore raw
In reply to Frederic Weisbecker
Quoted 8 lines · Frederic Weisbecker

Hi,

Just a bit of housekeeping.

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
rcu/dev

HEAD: be4d4c3ba8c4ceeba9dc9df4de5451c7261161f3

Queued and pushed, thank you! I reworked 3/5 to make it clear that the preceding (existing) block comment still applieds to that whole section of code and did the usual wordsmithing.

Nice to get rid of those unused functions and to avoid the unnecessary for_each_online_cpu() loops!

Thanx, Paul

Quoted 18 lines

Thanks,
Frederic
---

Frederic Weisbecker (5):
rcu: Remove rcu_is_nocb_cpu()
rcu/nocb: Move rcu_nocb_is_setup to rcu_state
rcu: Assume rcu_init() is called before smp
rcu: Initialize boost kthread only for boot node prior SMP initialization rcu/nocb: Initialize nocb kthreads only for boot CPU prior SMP initialization

 kernel/rcu/rcu.h         |  2 --
 kernel/rcu/tree.c        | 25 +++++++++++++++++--------
 kernel/rcu/tree.h        |  3 +--
 kernel/rcu/tree_nocb.h   | 41 +++++------------------------------------
 kernel/rcu/tree_plugin.h | 16 ----------------
 5 files changed, 23 insertions(+), 64 deletions(-)