From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, laijs@cn.fujitsu.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
dvhart@linux.intel.com, fweisbec@gmail.com, oleg@redhat.com,
bobby.prani@gmail.com,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH v4 tip/core/rcu 11/11] rcu: Defer rcu_tasks_kthread() creation till first call_rcu_tasks()
Date: Mon, 4 Aug 2014 12:20:54 -0700 [thread overview]
Message-ID: <1407180054-19805-11-git-send-email-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <1407180054-19805-1-git-send-email-paulmck@linux.vnet.ibm.com>
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
It is expected that many sites will have CONFIG_TASKS_RCU=y, but
will never actually invoke call_rcu_tasks(). For such sites, creating
rcu_tasks_kthread() at boot is wasteful. This commit therefore defers
creation of this kthread until the time of the first call_rcu_tasks().
This of course means that the first call_rcu_tasks() must be invoked
from process context after the scheduler is fully operational.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
kernel/rcu/update.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index 1ac99efc17aa..ad2a8df43757 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -378,7 +378,12 @@ DEFINE_SRCU(tasks_rcu_exit_srcu);
static int rcu_task_stall_timeout __read_mostly = HZ * 60 * 3;
module_param(rcu_task_stall_timeout, int, 0644);
-/* Post an RCU-tasks callback. */
+static void rcu_spawn_tasks_kthread(void);
+
+/*
+ * Post an RCU-tasks callback. First call must be from process context
+ * after the scheduler if fully operational.
+ */
void call_rcu_tasks(struct rcu_head *rhp, void (*func)(struct rcu_head *rhp))
{
unsigned long flags;
@@ -391,8 +396,10 @@ void call_rcu_tasks(struct rcu_head *rhp, void (*func)(struct rcu_head *rhp))
*rcu_tasks_cbs_tail = rhp;
rcu_tasks_cbs_tail = &rhp->next;
raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);
- if (needwake)
+ if (needwake) {
+ rcu_spawn_tasks_kthread();
wake_up(&rcu_tasks_cbs_wq);
+ }
}
EXPORT_SYMBOL_GPL(call_rcu_tasks);
@@ -619,15 +626,27 @@ static int __noreturn rcu_tasks_kthread(void *arg)
}
}
-/* Spawn rcu_tasks_kthread() at boot time. */
-static int __init rcu_spawn_tasks_kthread(void)
+/* Spawn rcu_tasks_kthread() at first call to call_rcu_tasks(). */
+static void rcu_spawn_tasks_kthread(void)
{
- struct task_struct __maybe_unused *t;
+ static DEFINE_MUTEX(rcu_tasks_kthread_mutex);
+ static struct task_struct *rcu_tasks_kthread_ptr;
+ struct task_struct *t;
+ if (ACCESS_ONCE(rcu_tasks_kthread_ptr)) {
+ smp_mb(); /* Ensure caller sees full kthread. */
+ return;
+ }
+ mutex_lock(&rcu_tasks_kthread_mutex);
+ if (rcu_tasks_kthread_ptr) {
+ mutex_unlock(&rcu_tasks_kthread_mutex);
+ return;
+ }
t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
BUG_ON(IS_ERR(t));
- return 0;
+ smp_mb(); /* Ensure others see full kthread. */
+ ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
+ mutex_unlock(&rcu_tasks_kthread_mutex);
}
-early_initcall(rcu_spawn_tasks_kthread);
#endif /* #ifdef CONFIG_TASKS_RCU */
--
1.8.1.5
prev parent reply other threads:[~2014-08-04 19:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-04 19:20 [PATCH v4 tip/core/rcu 0/11] RCU-tasks implementation Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 01/11] rcu: Add call_rcu_tasks() Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 02/11] rcu: Provide cond_resched_rcu_qs() to force quiescent states in long loops Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 03/11] rcu: Add synchronous grace-period waiting for RCU-tasks Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 04/11] rcu: Make TASKS_RCU handle tasks that are almost done exiting Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 05/11] rcu: Export RCU-tasks APIs to GPL modules Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 06/11] rcutorture: Add torture tests for RCU-tasks Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 07/11] rcutorture: Add RCU-tasks test cases Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 08/11] rcu: Add stall-warning checks for RCU-tasks Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 09/11] rcu: Improve RCU-tasks energy efficiency Paul E. McKenney
2014-08-04 19:20 ` [PATCH v4 tip/core/rcu 10/11] documentation: Add verbiage on RCU-tasks stall warning messages Paul E. McKenney
2014-08-04 19:20 ` Paul E. McKenney [this message]
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=1407180054-19805-11-git-send-email-paulmck@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=bobby.prani@gmail.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=dvhart@linux.intel.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®