Received: by 10.223.176.46 with SMTP id f43csp1729868wra; Wed, 24 Jan 2018 22:32:43 -0800 (PST) X-Google-Smtp-Source: AH8x226rT6bublWtO4lpTF+qr3iCysDDkCzZehDM9JnaIFkO/nXNZd71267AzSB9n5irWhL+DXLM X-Received: by 2002:a17:902:7795:: with SMTP id o21-v6mr403625pll.314.1516861963172; Wed, 24 Jan 2018 22:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516861963; cv=none; d=google.com; s=arc-20160816; b=wNkxedO3yzyeuLfTYsxAGQL/JDfPyNs5th6npTavzBKTOOfkOVmGvCsDiU6PmG+mq7 N5DA4gErCxOy9iKHZuZB+RRPpM1pOpCeZ0uBYanpxDUDlmSGSBB7CzdzZA6gEi3oql6F J55PFZVUJHtWS+aHYhVfYiHTD8qDPiXWnew66KiUtmX7b6HR+IxMq+PwqMnN8Knd9aL9 m2dheV7+ed03odhNFq66A8Nb1OhjIsnHUTQjTxI2LVi0RzY5RgyMCpZSNjhf2NG44Vj3 EouTRKCu4OjIixSXWPA8hOLGYvODRgmAebuTHw5bocWzQLn8qPZT1qqk0+slVCdMOm7n Dplg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=EY51Tg0Ooo+nqaGK+LqGgTlm6+8lnNFt4+5u9De61Qk=; b=ap1UFuGfN7xjWkShrqYNxXXE1VIylZdKy0DNRpWulaDXJHlifYol6a2XPQ8vuq6rgQ ecx9UlU1oRZeMtOBy5lmg2Obj+sulK+c9unYCXtVPLjPUb8s8K4TMwZ/TkbyCXBXSa6t J/FRenrEW6A8KjAt6H/ySvxZwsofaIgQSAiZSKzLZ5GafR6z4ymlh0kOU6UTmT4T48Or z5Bgdp9Ng/xVY4F6QOtfIYHKgNqXWjuHxBLEjjBTSvH1kLBBDxmh0Qcx/+/ckIDR59X9 I2Ct7dmDLUnwvilGn6GA3E9oLPY2cv3QmJvJ8sfzwtgceyeNt2IRs9DNPW3iOZxu/5B4 qEAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6-v6si1474413pll.559.2018.01.24.22.32.29; Wed, 24 Jan 2018 22:32:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751240AbeAYGad (ORCPT + 99 others); Thu, 25 Jan 2018 01:30:33 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57218 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751184AbeAYGaK (ORCPT ); Thu, 25 Jan 2018 01:30:10 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0P6TSaq083951 for ; Thu, 25 Jan 2018 01:30:04 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fq9nbgy1s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 25 Jan 2018 01:30:03 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 25 Jan 2018 01:29:58 -0500 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 25 Jan 2018 01:29:56 -0500 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0P6TuWH56099054; Thu, 25 Jan 2018 06:29:56 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77D19B204E; Thu, 25 Jan 2018 01:26:54 -0500 (EST) Received: from paulmck-ThinkPad-W541 (unknown [9.85.153.144]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id B1986B2054; Thu, 25 Jan 2018 01:26:53 -0500 (EST) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 5DFAF16C23E7; Wed, 24 Jan 2018 22:20:31 -0800 (PST) Date: Wed, 24 Jan 2018 22:20:31 -0800 From: "Paul E. McKenney" 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 Reply-To: paulmck@linux.vnet.ibm.com References: <1516694381-20333-1-git-send-email-lianglihao@huawei.com> <1516694381-20333-8-git-send-email-lianglihao@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516694381-20333-8-git-send-email-lianglihao@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18012506-0008-0000-0000-000002C7019F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008423; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000247; SDB=6.00980015; UDB=6.00496769; IPR=6.00759317; BA=6.00005794; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00019197; XFM=3.00000015; UTC=2018-01-25 06:29:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18012506-0009-0000-0000-0000380949AC Message-Id: <20180125062031.GW3741@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-25_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801250090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 23, 2018 at 03:59:32PM +0800, lianglihao@huawei.com wrote: > From: Lihao Liang > > This is PRCU's counterpart of RCU's call_rcu() API. > > Reviewed-by: Heng Zhang > Signed-off-by: Lihao Liang > --- > 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 > +#include > #include > #include > > #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 > #include > #include > +#include > #include > #include > #include > @@ -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 > -#include > #include > -#include > +#include > #include > - > +#include > #include > > +#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 >