From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751264AbeAYGaf (ORCPT ); Thu, 25 Jan 2018 01:30:35 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41422 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751178AbeAYGaH (ORCPT ); Thu, 25 Jan 2018 01:30:07 -0500 Date: Wed, 24 Jan 2018 22:24:57 -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 09/16] prcu: Implement prcu_barrier() API Reply-To: paulmck@linux.vnet.ibm.com References: <1516694381-20333-1-git-send-email-lianglihao@huawei.com> <1516694381-20333-10-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-10-git-send-email-lianglihao@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18012506-0040-0000-0000-000003E90356 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.00759316; 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:56 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18012506-0041-0000-0000-000007DE6AAC Message-Id: <20180125062457.GX3741@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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 23, 2018 at 03:59:34PM +0800, lianglihao@huawei.com wrote: > From: Lihao Liang > > This is PRCU's counterpart of RCU's rcu_barrier() API. > > Reviewed-by: Heng Zhang > Signed-off-by: Lihao Liang > --- > include/linux/prcu.h | 7 ++++++ > kernel/rcu/prcu.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 70 insertions(+) > > diff --git a/include/linux/prcu.h b/include/linux/prcu.h > index 4e7d5d65..cce967fd 100644 > --- a/include/linux/prcu.h > +++ b/include/linux/prcu.h > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > > #define CONFIG_PRCU > > @@ -32,6 +33,7 @@ struct prcu_local_struct { > unsigned int online; > unsigned long long version; > unsigned long long cb_version; > + struct rcu_head barrier_head; > struct prcu_cblist cblist; > }; > > @@ -39,8 +41,11 @@ struct prcu_struct { > atomic64_t global_version; > atomic64_t cb_version; > atomic_t active_ctr; > + atomic_t barrier_cpu_count; > struct mutex mtx; > + struct mutex barrier_mtx; > wait_queue_head_t wait_q; > + struct completion barrier_completion; > }; > > #ifdef CONFIG_PRCU > @@ -48,6 +53,7 @@ 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_barrier(void); > void prcu_init(void); > void prcu_note_context_switch(void); > int prcu_pending(void); > @@ -60,6 +66,7 @@ void prcu_check_callbacks(void); > #define prcu_read_unlock() do {} while (0) > #define synchronize_prcu() do {} while (0) > #define call_prcu() do {} while (0) > +#define prcu_barrier() do {} while (0) > #define prcu_init() do {} while (0) > #define prcu_note_context_switch() do {} while (0) > #define prcu_pending() 0 > diff --git a/kernel/rcu/prcu.c b/kernel/rcu/prcu.c > index 373039c5..2664d091 100644 > --- a/kernel/rcu/prcu.c > +++ b/kernel/rcu/prcu.c > @@ -15,6 +15,7 @@ struct prcu_struct global_prcu = { > .cb_version = ATOMIC64_INIT(0), > .active_ctr = ATOMIC_INIT(0), > .mtx = __MUTEX_INITIALIZER(global_prcu.mtx), > + .barrier_mtx = __MUTEX_INITIALIZER(global_prcu.barrier_mtx), > .wait_q = __WAIT_QUEUE_HEAD_INITIALIZER(global_prcu.wait_q) > }; > struct prcu_struct *prcu = &global_prcu; > @@ -250,6 +251,68 @@ static __latent_entropy void prcu_process_callbacks(struct softirq_action *unuse > local_irq_restore(flags); > } > > +/* > + * PRCU callback function for prcu_barrier(). > + * If we are last, wake up the task executing prcu_barrier(). > + */ > +static void prcu_barrier_callback(struct rcu_head *rhp) > +{ > + if (atomic_dec_and_test(&prcu->barrier_cpu_count)) > + complete(&prcu->barrier_completion); > +} > + > +/* > + * Called with preemption disabled, and from cross-cpu IRQ context. > + */ > +static void prcu_barrier_func(void *info) > +{ > + struct prcu_local_struct *local = this_cpu_ptr(&prcu_local); > + > + atomic_inc(&prcu->barrier_cpu_count); > + call_prcu(&local->barrier_head, prcu_barrier_callback); > +} > + > +/* Waiting for all PRCU callbacks to complete. */ > +void prcu_barrier(void) > +{ > + int cpu; > + > + /* Take mutex to serialize concurrent prcu_barrier() requests. */ > + mutex_lock(&prcu->barrier_mtx); > + > + /* > + * Initialize the count to one rather than to zero in order to > + * avoid a too-soon return to zero in case of a short grace period > + * (or preemption of this task). > + */ > + init_completion(&prcu->barrier_completion); > + atomic_set(&prcu->barrier_cpu_count, 1); > + > + /* > + * Register a new callback on each CPU using IPI to prevent races > + * with call_prcu(). When that callback is invoked, we will know > + * that all of the corresponding CPU's preceding callbacks have > + * been invoked. > + */ > + for_each_possible_cpu(cpu) > + smp_call_function_single(cpu, prcu_barrier_func, NULL, 1); This code seems to be assuming CONFIG_HOTPLUG_CPU=n. This might explain your rcutorture failure. > + /* Decrement the count as we initialize it to one. */ > + if (atomic_dec_and_test(&prcu->barrier_cpu_count)) > + complete(&prcu->barrier_completion); > + > + /* > + * Now that we have an prcu_barrier_callback() callback on each > + * CPU, and thus each counted, remove the initial count. > + * Wait for all prcu_barrier_callback() callbacks to be invoked. > + */ > + wait_for_completion(&prcu->barrier_completion); > + > + /* Other rcu_barrier() invocations can now safely proceed. */ > + mutex_unlock(&prcu->barrier_mtx); > +} > +EXPORT_SYMBOL(prcu_barrier); > + > void prcu_init_local_struct(int cpu) > { > struct prcu_local_struct *local; > -- > 2.14.1.729.g59c0ea183 >