public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: lianglihao@huawei.com
Cc: guohanjun@huawei.com, heng.z@huawei.com, hb.chen@huawei.com,
	lihao.liang@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 07/16] prcu: Implement call_prcu() API
Date: Wed, 24 Jan 2018 22:20:31 -0800	[thread overview]
Message-ID: <20180125062031.GW3741@linux.vnet.ibm.com> (raw)
In-Reply-To: <1516694381-20333-8-git-send-email-lianglihao@huawei.com>

On Tue, Jan 23, 2018 at 03:59:32PM +0800, lianglihao@huawei.com wrote:
> From: Lihao Liang <lianglihao@huawei.com>
> 
> This is PRCU's counterpart of RCU's call_rcu() API.
> 
> Reviewed-by: Heng Zhang <heng.z@huawei.com>
> Signed-off-by: Lihao Liang <lianglihao@huawei.com>
> ---
>  include/linux/prcu.h | 25 ++++++++++++++++++++
>  init/main.c          |  2 ++
>  kernel/rcu/prcu.c    | 67 +++++++++++++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 91 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/prcu.h b/include/linux/prcu.h
> index 653b4633..e5e09c9b 100644
> --- a/include/linux/prcu.h
> +++ b/include/linux/prcu.h
> @@ -2,15 +2,36 @@
>  #define __LINUX_PRCU_H
> 
>  #include <linux/atomic.h>
> +#include <linux/types.h>
>  #include <linux/mutex.h>
>  #include <linux/wait.h>
> 
>  #define CONFIG_PRCU
> 
> +struct prcu_version_head {
> +	unsigned long long version;
> +	struct prcu_version_head *next;
> +};
> +
> +/* Simple unsegmented callback list for PRCU. */
> +struct prcu_cblist {
> +	struct rcu_head *head;
> +	struct rcu_head **tail;
> +	struct prcu_version_head *version_head;
> +	struct prcu_version_head **version_tail;
> +	long len;
> +};
> +
> +#define PRCU_CBLIST_INITIALIZER(n) { \
> +	.head = NULL, .tail = &n.head, \
> +	.version_head = NULL, .version_tail = &n.version_head, \
> +}
> +
>  struct prcu_local_struct {
>  	unsigned int locked;
>  	unsigned int online;
>  	unsigned long long version;
> +	struct prcu_cblist cblist;
>  };
> 
>  struct prcu_struct {
> @@ -24,6 +45,8 @@ struct prcu_struct {
>  void prcu_read_lock(void);
>  void prcu_read_unlock(void);
>  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);
> 
>  #else /* #ifdef CONFIG_PRCU */
> @@ -31,6 +54,8 @@ void prcu_note_context_switch(void);
>  #define prcu_read_lock() do {} while (0)
>  #define prcu_read_unlock() do {} while (0)
>  #define synchronize_prcu() do {} while (0)
> +#define call_prcu() do {} while (0)
> +#define prcu_init() do {} while (0)
>  #define prcu_note_context_switch() do {} while (0)
> 
>  #endif /* #ifdef CONFIG_PRCU */
> diff --git a/init/main.c b/init/main.c
> index f8665104..4925964e 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -38,6 +38,7 @@
>  #include <linux/smp.h>
>  #include <linux/profile.h>
>  #include <linux/rcupdate.h>
> +#include <linux/prcu.h>
>  #include <linux/moduleparam.h>
>  #include <linux/kallsyms.h>
>  #include <linux/writeback.h>
> @@ -574,6 +575,7 @@ asmlinkage __visible void __init start_kernel(void)
>  	workqueue_init_early();
> 
>  	rcu_init();
> +	prcu_init();
> 
>  	/* Trace events are available after this */
>  	trace_init();
> diff --git a/kernel/rcu/prcu.c b/kernel/rcu/prcu.c
> index a00b9420..f198285c 100644
> --- a/kernel/rcu/prcu.c
> +++ b/kernel/rcu/prcu.c
> @@ -1,11 +1,12 @@
>  #include <linux/smp.h>
> -#include <linux/prcu.h>
>  #include <linux/percpu.h>
> -#include <linux/compiler.h>
> +#include <linux/prcu.h>
>  #include <linux/sched.h>
> -
> +#include <linux/slab.h>
>  #include <asm/barrier.h>
> 
> +#include "rcu.h"
> +
>  DEFINE_PER_CPU_SHARED_ALIGNED(struct prcu_local_struct, prcu_local);
> 
>  struct prcu_struct global_prcu = {
> @@ -16,6 +17,16 @@ struct prcu_struct global_prcu = {
>  };
>  struct prcu_struct *prcu = &global_prcu;
> 
> +/* Initialize simple callback list. */
> +static void prcu_cblist_init(struct prcu_cblist *rclp)
> +{
> +	rclp->head = NULL;
> +	rclp->tail = &rclp->head;
> +	rclp->version_head = NULL;
> +	rclp->version_tail = &rclp->version_head;
> +	rclp->len = 0;
> +}
> +
>  static inline void prcu_report(struct prcu_local_struct *local)
>  {
>  	unsigned long long global_version;
> @@ -123,3 +134,53 @@ void prcu_note_context_switch(void)
>  	prcu_report(local);
>  	put_cpu_ptr(&prcu_local);
>  }
> +
> +void call_prcu(struct rcu_head *head, rcu_callback_t func)
> +{
> +	unsigned long flags;
> +	struct prcu_local_struct *local;
> +	struct prcu_cblist *rclp;
> +	struct prcu_version_head *vhp;
> +
> +	debug_rcu_head_queue(head);
> +
> +	/* Use GFP_ATOMIC with IRQs disabled */
> +	vhp = kmalloc(sizeof(struct prcu_version_head), GFP_ATOMIC);
> +	if (!vhp)
> +		return;

Silently failing to post the callback can cause system hangs.  I suggest
finding some way to avoid allocating on the call_prcu() code path.

							Thanx, Paul

> +
> +	head->func = func;
> +	head->next = NULL;
> +	vhp->next = NULL;
> +
> +	local_irq_save(flags);
> +	local = this_cpu_ptr(&prcu_local);
> +	vhp->version = local->version;
> +	rclp = &local->cblist;
> +	rclp->len++;
> +	*rclp->tail = head;
> +	rclp->tail = &head->next;
> +	*rclp->version_tail = vhp;
> +	rclp->version_tail = &vhp->next;
> +	local_irq_restore(flags);
> +}
> +EXPORT_SYMBOL(call_prcu);
> +
> +void prcu_init_local_struct(int cpu)
> +{
> +	struct prcu_local_struct *local;
> +
> +	local = per_cpu_ptr(&prcu_local, cpu);
> +	local->locked = 0;
> +	local->online = 0;
> +	local->version = 0;
> +	prcu_cblist_init(&local->cblist);
> +}
> +
> +void __init prcu_init(void)
> +{
> +	int cpu;
> +
> +	for_each_possible_cpu(cpu)
> +		prcu_init_local_struct(cpu);
> +}
> -- 
> 2.14.1.729.g59c0ea183
> 

  reply	other threads:[~2018-01-25  6:30 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 [this message]
2018-01-26  8:44     ` Lihao Liang
2018-01-26 22:22       ` Paul E. McKenney
2018-01-23  7:59 ` [PATCH RFC 08/16] prcu: Implement PRCU callback processing lianglihao
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=20180125062031.GW3741@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=guohanjun@huawei.com \
    --cc=hb.chen@huawei.com \
    --cc=heng.z@huawei.com \
    --cc=lianglihao@huawei.com \
    --cc=lihao.liang@gmail.com \
    --cc=linux-kernel@vger.kernel.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