mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <lianglihao@huawei.com>
To: <paulmck@linux.vnet.ibm.com>
Cc: <guohanjun@huawei.com>, <heng.z@huawei.com>, <hb.chen@huawei.com>,
	<lihao.liang@gmail.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH RFC 08/16] prcu: Implement PRCU callback processing
Date: Tue, 23 Jan 2018 15:59:33 +0800	[thread overview]
Message-ID: <1516694381-20333-9-git-send-email-lianglihao@huawei.com> (raw)
In-Reply-To: <1516694381-20333-1-git-send-email-lianglihao@huawei.com>

From: Lihao Liang <lianglihao@huawei.com>

Currently, PRCU core processing only consists of callback processing
in prcu_process_callbacks(), which is triggered by the scheduling-clock
interrupt.

Reviewed-by: Heng Zhang <heng.z@huawei.com>
Signed-off-by: Lihao Liang <lianglihao@huawei.com>
---
 include/linux/interrupt.h |  3 ++
 include/linux/prcu.h      |  8 +++++
 kernel/rcu/prcu.c         | 86 +++++++++++++++++++++++++++++++++++++++++++++++
 kernel/rcu/tree.c         |  1 +
 kernel/time/timer.c       |  2 ++
 5 files changed, 100 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 0991f973..f05ef62a 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -456,6 +456,9 @@ enum
 	SCHED_SOFTIRQ,
 	HRTIMER_SOFTIRQ, /* Unused, but kept as tools rely on the
 			    numbering. Sigh! */
+#ifdef CONFIG_PRCU
+	PRCU_SOFTIRQ,
+#endif
 	RCU_SOFTIRQ,    /* Preferable RCU should always be the last softirq */
 
 	NR_SOFTIRQS
diff --git a/include/linux/prcu.h b/include/linux/prcu.h
index e5e09c9b..4e7d5d65 100644
--- a/include/linux/prcu.h
+++ b/include/linux/prcu.h
@@ -31,11 +31,13 @@ struct prcu_local_struct {
 	unsigned int locked;
 	unsigned int online;
 	unsigned long long version;
+	unsigned long long cb_version;
 	struct prcu_cblist cblist;
 };
 
 struct prcu_struct {
 	atomic64_t global_version;
+	atomic64_t cb_version;
 	atomic_t active_ctr;
 	struct mutex mtx;
 	wait_queue_head_t wait_q;
@@ -48,6 +50,9 @@ void synchronize_prcu(void);
 void call_prcu(struct rcu_head *head, rcu_callback_t func);
 void prcu_init(void);
 void prcu_note_context_switch(void);
+int prcu_pending(void);
+void invoke_prcu_core(void);
+void prcu_check_callbacks(void);
 
 #else /* #ifdef CONFIG_PRCU */
 
@@ -57,6 +62,9 @@ void prcu_note_context_switch(void);
 #define call_prcu() do {} while (0)
 #define prcu_init() do {} while (0)
 #define prcu_note_context_switch() do {} while (0)
+#define prcu_pending() 0
+#define invoke_prcu_core() do {} while (0)
+#define prcu_check_callbacks() do {} while (0)
 
 #endif /* #ifdef CONFIG_PRCU */
 #endif /* __LINUX_PRCU_H */
diff --git a/kernel/rcu/prcu.c b/kernel/rcu/prcu.c
index f198285c..373039c5 100644
--- a/kernel/rcu/prcu.c
+++ b/kernel/rcu/prcu.c
@@ -1,6 +1,7 @@
 #include <linux/smp.h>
 #include <linux/percpu.h>
 #include <linux/prcu.h>
+#include <linux/interrupt.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <asm/barrier.h>
@@ -11,6 +12,7 @@ DEFINE_PER_CPU_SHARED_ALIGNED(struct prcu_local_struct, prcu_local);
 
 struct prcu_struct global_prcu = {
 	.global_version = ATOMIC64_INIT(0),
+	.cb_version = ATOMIC64_INIT(0),
 	.active_ctr = ATOMIC_INIT(0),
 	.mtx = __MUTEX_INITIALIZER(global_prcu.mtx),
 	.wait_q = __WAIT_QUEUE_HEAD_INITIALIZER(global_prcu.wait_q)
@@ -27,6 +29,35 @@ static void prcu_cblist_init(struct prcu_cblist *rclp)
 	rclp->len = 0;
 }
 
+/*
+ * Dequeue the oldest rcu_head structure from the specified callback list;
+ * store the callback grace period version number into the version pointer.
+ */
+static struct rcu_head *prcu_cblist_dequeue(struct prcu_cblist *rclp)
+{
+	struct rcu_head *rhp;
+	struct prcu_version_head *vhp;
+
+	rhp = rclp->head;
+	if (!rhp) {
+		WARN_ON(vhp);
+		WARN_ON(rclp->len);
+		return NULL;
+	}
+
+	vhp = rclp->version_head;
+	rclp->version_head = vhp->next;
+	rclp->head = rhp->next;
+	rclp->len--;
+
+	if (!rclp->head) {
+		rclp->tail = &rclp->head;
+		rclp->version_tail = &rclp->version_head;
+	}
+
+	return rhp;
+}
+
 static inline void prcu_report(struct prcu_local_struct *local)
 {
 	unsigned long long global_version;
@@ -117,6 +148,7 @@ void synchronize_prcu(void)
 	if (atomic_read(&prcu->active_ctr))
 		wait_event(prcu->wait_q, !atomic_read(&prcu->active_ctr));
 
+	atomic64_set(&prcu->cb_version, version);
 	mutex_unlock(&prcu->mtx);
 }
 EXPORT_SYMBOL(synchronize_prcu);
@@ -166,6 +198,58 @@ void call_prcu(struct rcu_head *head, rcu_callback_t func)
 }
 EXPORT_SYMBOL(call_prcu);
 
+int prcu_pending(void)
+{
+	struct prcu_local_struct *local = get_cpu_ptr(&prcu_local);
+	unsigned long long cb_version = local->cb_version;
+	struct prcu_cblist *rclp = &local->cblist;
+
+	put_cpu_ptr(&prcu_local);
+	return cb_version < atomic64_read(&prcu->cb_version) && rclp->head;
+}
+
+void invoke_prcu_core(void)
+{
+	if (cpu_online(smp_processor_id()))
+		raise_softirq(PRCU_SOFTIRQ);
+}
+
+void prcu_check_callbacks(void)
+{
+	if (prcu_pending())
+		invoke_prcu_core();
+}
+
+static __latent_entropy void prcu_process_callbacks(struct softirq_action *unused)
+{
+	unsigned long flags;
+	unsigned long long cb_version;
+	struct prcu_local_struct *local;
+	struct prcu_cblist *rclp;
+	struct rcu_head *rhp;
+	struct prcu_version_head *vhp;
+
+	if (cpu_is_offline(smp_processor_id()))
+		return;
+
+	cb_version = atomic64_read(&prcu->cb_version);
+
+	/* Disable interrupts to prevent races with call_prcu() */
+	local_irq_save(flags);
+	local = this_cpu_ptr(&prcu_local);
+	rclp = &local->cblist;
+	rhp = rclp->head;
+	vhp = rclp->version_head;
+	for (; rhp && vhp && vhp->version < cb_version;
+	     rhp = rclp->head, vhp = rclp->version_head) {
+		rhp = prcu_cblist_dequeue(rclp);
+		debug_rcu_head_unqueue(rhp);
+		rhp->func(rhp);
+	}
+	local->cb_version = cb_version;
+	local_irq_restore(flags);
+}
+
 void prcu_init_local_struct(int cpu)
 {
 	struct prcu_local_struct *local;
@@ -174,6 +258,7 @@ void prcu_init_local_struct(int cpu)
 	local->locked = 0;
 	local->online = 0;
 	local->version = 0;
+	local->cb_version = 0;
 	prcu_cblist_init(&local->cblist);
 }
 
@@ -181,6 +266,7 @@ void __init prcu_init(void)
 {
 	int cpu;
 
+	open_softirq(PRCU_SOFTIRQ, prcu_process_callbacks);
 	for_each_possible_cpu(cpu)
 		prcu_init_local_struct(cpu);
 }
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index e354e475..46910114 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2852,6 +2852,7 @@ void rcu_check_callbacks(int user)
 {
 	trace_rcu_utilization(TPS("Start scheduler-tick"));
 	increment_cpu_stall_ticks();
+
 	if (user || rcu_is_cpu_rrupt_from_idle()) {
 
 		/*
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index d3f33020..ed863e63 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -44,6 +44,7 @@
 #include <linux/sched/debug.h>
 #include <linux/slab.h>
 #include <linux/compat.h>
+#include <linux/prcu.h>
 
 #include <linux/uaccess.h>
 #include <asm/unistd.h>
@@ -1568,6 +1569,7 @@ void update_process_times(int user_tick)
 	/* Note: this timer irq context must be accounted for as well. */
 	account_process_tick(p, user_tick);
 	run_local_timers();
+	prcu_check_callbacks();
 	rcu_check_callbacks(user_tick);
 #ifdef CONFIG_IRQ_WORK
 	if (in_irq())
-- 
2.14.1.729.g59c0ea183

  parent reply	other threads:[~2018-01-23  8:10 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23  7:59 [PATCH RFC 00/16] A new RCU implementation based on a fast consensus protocol lianglihao
2018-01-23  7:59 ` [PATCH RFC 01/16] prcu: Add PRCU implementation lianglihao
2018-01-24 11:26   ` Peter Zijlstra
2018-01-24 17:15     ` Lihao Liang
2018-01-24 20:19       ` Peter Zijlstra
2018-01-25  6:16   ` Paul E. McKenney
2018-01-25  7:30     ` Boqun Feng
2018-01-30  5:34       ` zhangheng (AC)
2018-01-30  6:40         ` Boqun Feng
2018-01-30 10:42           ` zhangheng (AC)
2018-01-27  7:35     ` Lihao Liang
2018-01-30  3:58     ` zhangheng (AC)
2018-01-29  9:10   ` Lai Jiangshan
2018-01-30  6:21     ` zhangheng (AC)
2018-01-23  7:59 ` [PATCH RFC 02/16] rcutorture: Add PRCU rcu_torture_ops lianglihao
2018-01-23  7:59 ` [PATCH RFC 03/16] rcutorture: Add PRCU test config files lianglihao
2018-01-25  6:27   ` Paul E. McKenney
2018-01-23  7:59 ` [PATCH RFC 04/16] rcuperf: Add PRCU rcu_perf_ops lianglihao
2018-01-23  7:59 ` [PATCH RFC 05/16] rcuperf: Add PRCU test config files lianglihao
2018-01-23  7:59 ` [PATCH RFC 06/16] rcuperf: Set gp_exp to true for tests to run lianglihao
2018-01-25  6:18   ` Paul E. McKenney
2018-01-26  8:33     ` Lihao Liang
2018-01-23  7:59 ` [PATCH RFC 07/16] prcu: Implement call_prcu() API lianglihao
2018-01-25  6:20   ` Paul E. McKenney
2018-01-26  8:44     ` Lihao Liang
2018-01-26 22:22       ` Paul E. McKenney
2018-01-23  7:59 ` lianglihao [this message]
2018-01-23  7:59 ` [PATCH RFC 09/16] prcu: Implement prcu_barrier() API lianglihao
2018-01-25  6:24   ` Paul E. McKenney
2018-01-23  7:59 ` [PATCH RFC 10/16] rcutorture: Test call_prcu() and prcu_barrier() lianglihao
2018-01-23  7:59 ` [PATCH RFC 11/16] rcutorture: Add basic ARM64 support to run scripts lianglihao
2018-01-23  7:59 ` [PATCH RFC 12/16] prcu: Add PRCU Kconfig parameter lianglihao
2018-01-23  7:59 ` [PATCH RFC 13/16] prcu: Comment source code lianglihao
2018-01-23  7:59 ` [PATCH RFC 14/16] rcuperf: Add config files with various CONFIG_NR_CPUS lianglihao
2018-01-23  7:59 ` [PATCH RFC 15/16] rcutorture: Add scripts to run experiments lianglihao
2018-01-25  6:28   ` Paul E. McKenney
2018-01-23  7:59 ` [PATCH RFC 16/16] Add GPLv2 license lianglihao
2018-01-25  5:53 ` [PATCH RFC 00/16] A new RCU implementation based on a fast consensus protocol Paul E. McKenney
2018-01-27  7:22   ` Lihao Liang
2018-01-27  7:57     ` Paul E. McKenney
2018-01-27  9:57       ` Lihao Liang
2018-01-27 23:46         ` Paul E. McKenney
2018-01-27 23:41       ` 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=1516694381-20333-9-git-send-email-lianglihao@huawei.com \
    --to=lianglihao@huawei.com \
    --cc=guohanjun@huawei.com \
    --cc=hb.chen@huawei.com \
    --cc=heng.z@huawei.com \
    --cc=lihao.liang@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /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®