From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 02/32] rcu-tasks: Split rcu_tasks_one_gp() from rcu_tasks_kthread()
Date: Mon, 20 Jun 2022 15:53:41 -0700 [thread overview]
Message-ID: <20220620225411.3842519-2-paulmck@kernel.org> (raw)
In-Reply-To: <20220620225402.GA3842369@paulmck-ThinkPad-P17-Gen-1>
This commit abstracts most of the rcu_tasks_kthread() function's loop
body into a new rcu_tasks_one_gp() function. It also introduces
a new ->tasks_gp_mutex to synchronize concurrent calls to this new
rcu_tasks_one_gp() function. This commit is preparation for allowing
RCU tasks grace periods to be driven by the calling task during the
mid-boot dead zone.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/tasks.h | 58 ++++++++++++++++++++++++++++------------------
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
index b8690a412c5bf..d7b12f524e81c 100644
--- a/kernel/rcu/tasks.h
+++ b/kernel/rcu/tasks.h
@@ -48,6 +48,7 @@ struct rcu_tasks_percpu {
* struct rcu_tasks - Definition for a Tasks-RCU-like mechanism.
* @cbs_wait: RCU wait allowing a new callback to get kthread's attention.
* @cbs_gbl_lock: Lock protecting callback list.
+ * @tasks_gp_mutex: Mutex protecting grace period, needed during mid-boot dead zone.
* @kthread_ptr: This flavor's grace-period/callback-invocation kthread.
* @gp_func: This flavor's grace-period-wait function.
* @gp_state: Grace period's most recent state transition (debugging).
@@ -79,6 +80,7 @@ struct rcu_tasks_percpu {
struct rcu_tasks {
struct rcuwait cbs_wait;
raw_spinlock_t cbs_gbl_lock;
+ struct mutex tasks_gp_mutex;
int gp_state;
int gp_sleep;
int init_fract;
@@ -119,6 +121,7 @@ static struct rcu_tasks rt_name = \
{ \
.cbs_wait = __RCUWAIT_INITIALIZER(rt_name.wait), \
.cbs_gbl_lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name.cbs_gbl_lock), \
+ .tasks_gp_mutex = __MUTEX_INITIALIZER(rt_name.tasks_gp_mutex), \
.gp_func = gp, \
.call_func = call, \
.rtpcpu = &rt_name ## __percpu, \
@@ -502,10 +505,37 @@ static void rcu_tasks_invoke_cbs_wq(struct work_struct *wp)
rcu_tasks_invoke_cbs(rtp, rtpcp);
}
-/* RCU-tasks kthread that detects grace periods and invokes callbacks. */
-static int __noreturn rcu_tasks_kthread(void *arg)
+// Wait for one grace period.
+static void rcu_tasks_one_gp(struct rcu_tasks *rtp)
{
int needgpcb;
+
+ mutex_lock(&rtp->tasks_gp_mutex);
+ set_tasks_gp_state(rtp, RTGS_WAIT_CBS);
+
+ // If there were none, wait a bit and start over.
+ rcuwait_wait_event(&rtp->cbs_wait,
+ (needgpcb = rcu_tasks_need_gpcb(rtp)),
+ TASK_IDLE);
+
+ if (needgpcb & 0x2) {
+ // Wait for one grace period.
+ set_tasks_gp_state(rtp, RTGS_WAIT_GP);
+ rtp->gp_start = jiffies;
+ rcu_seq_start(&rtp->tasks_gp_seq);
+ rtp->gp_func(rtp);
+ rcu_seq_end(&rtp->tasks_gp_seq);
+ }
+
+ // Invoke callbacks.
+ set_tasks_gp_state(rtp, RTGS_INVOKE_CBS);
+ rcu_tasks_invoke_cbs(rtp, per_cpu_ptr(rtp->rtpcpu, 0));
+ mutex_unlock(&rtp->tasks_gp_mutex);
+}
+
+// RCU-tasks kthread that detects grace periods and invokes callbacks.
+static int __noreturn rcu_tasks_kthread(void *arg)
+{
struct rcu_tasks *rtp = arg;
/* Run on housekeeping CPUs by default. Sysadm can move if desired. */
@@ -519,27 +549,11 @@ static int __noreturn rcu_tasks_kthread(void *arg)
* This loop is terminated by the system going down. ;-)
*/
for (;;) {
- set_tasks_gp_state(rtp, RTGS_WAIT_CBS);
-
- /* If there were none, wait a bit and start over. */
- rcuwait_wait_event(&rtp->cbs_wait,
- (needgpcb = rcu_tasks_need_gpcb(rtp)),
- TASK_IDLE);
-
- if (needgpcb & 0x2) {
- // Wait for one grace period.
- set_tasks_gp_state(rtp, RTGS_WAIT_GP);
- rtp->gp_start = jiffies;
- rcu_seq_start(&rtp->tasks_gp_seq);
- rtp->gp_func(rtp);
- rcu_seq_end(&rtp->tasks_gp_seq);
- }
-
- /* Invoke callbacks. */
- set_tasks_gp_state(rtp, RTGS_INVOKE_CBS);
- rcu_tasks_invoke_cbs(rtp, per_cpu_ptr(rtp->rtpcpu, 0));
+ // Wait for one grace period and invoke any callbacks
+ // that are ready.
+ rcu_tasks_one_gp(rtp);
- /* Paranoid sleep to keep this from entering a tight loop */
+ // Paranoid sleep to keep this from entering a tight loop.
schedule_timeout_idle(rtp->gp_sleep);
}
}
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-06-20 22:55 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 22:54 [PATCH rcu 0/32] RCU Tasks updates for v5.20 Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 01/32] rcu-tasks: Check for abandoned callbacks Paul E. McKenney
2022-06-20 22:53 ` Paul E. McKenney [this message]
2022-06-20 22:53 ` [PATCH rcu 03/32] rcu-tasks: Move synchronize_rcu_tasks_generic() down Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 04/32] rcu-tasks: Drive synchronous grace periods from calling task Paul E. McKenney
2022-09-01 10:36 ` Sascha Hauer
2022-09-01 17:27 ` Paul E. McKenney
2022-09-01 17:33 ` Paul E. McKenney
2022-09-02 11:52 ` Sascha Hauer
2022-09-02 12:04 ` Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 05/32] rcu-tasks: Merge state into .b.need_qs and atomically update Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 06/32] rcu-tasks: Remove rcu_tasks_trace_postgp() wait for counter Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 07/32] rcu-tasks: Make trc_read_check_handler() fetch ->trc_reader_nesting only once Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 08/32] rcu-tasks: Idle tasks on offline CPUs are in quiescent states Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 09/32] rcu-tasks: Handle idle tasks for recently offlined CPUs Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 10/32] rcu-tasks: RCU Tasks Trace grace-period kthread has implicit QS Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 11/32] rcu-tasks: Make rcu_note_context_switch() unconditionally call rcu_tasks_qs() Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 12/32] rcu-tasks: Simplify trc_inspect_reader() QS logic Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 13/32] rcu-tasks: Add slow-IPI indicator to RCU Tasks Trace stall warnings Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 14/32] rcu-tasks: Flag offline CPUs in " Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 15/32] rcu-tasks: Make RCU Tasks Trace stall warnings print full .b.need_qs field Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 16/32] rcu-tasks: Make RCU Tasks Trace stall warning handle idle offline tasks Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 17/32] rcu-tasks: Add data structures for lightweight grace periods Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 18/32] rcu-tasks: Track blocked RCU Tasks Trace readers Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 19/32] rcu-tasks: Untrack blocked RCU Tasks Trace at reader end Paul E. McKenney
2022-06-20 22:53 ` [PATCH rcu 20/32] rcu-tasks: Add blocked-task indicator to RCU Tasks Trace stall warnings Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 21/32] rcu-tasks: Move rcu_tasks_trace_pertask() before rcu_tasks_trace_pregp_step() Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 22/32] rcu-tasks: Avoid rcu_tasks_trace_pertask() duplicate list additions Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 23/32] rcu-tasks: Scan running tasks for RCU Tasks Trace readers Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 24/32] rcu-tasks: Pull in tasks blocked within " Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 25/32] rcu-tasks: Stop RCU Tasks Trace from scanning idle tasks Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 26/32] rcu-tasks: Stop RCU Tasks Trace from scanning full tasks list Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 27/32] rcu-tasks: Maintain a count of tasks blocking RCU Tasks Trace grace period Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 28/32] rcu-tasks: Eliminate RCU Tasks Trace IPIs to online CPUs Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 29/32] rcu-tasks: Disable and enable CPU hotplug in same function Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 30/32] rcu-tasks: Update comments Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 31/32] rcu-tasks: Be more patient for RCU Tasks boot-time testing Paul E. McKenney
2022-06-20 22:54 ` [PATCH rcu 32/32] rcu-tasks: Use delayed_work to delay rcu_tasks_verify_self_tests() Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220620225411.3842519-2-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox