Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A69ACC433F5 for ; Fri, 7 Oct 2022 08:35:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbiJGIfh (ORCPT ); Fri, 7 Oct 2022 04:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbiJGIfe (ORCPT ); Fri, 7 Oct 2022 04:35:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3154233E1D for ; Fri, 7 Oct 2022 01:35:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC78561AFB for ; Fri, 7 Oct 2022 08:35:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C393C433C1; Fri, 7 Oct 2022 08:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665131731; bh=tB7QbW+MrkAo8hiWaa/USfJzRfi3HhV4J6V9hNU7vcI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=AlxX5VwOTPL7d3gozwnwi8ixtAgTxN/FZeSv4iUWcBDu1Jb9cdyerG/scFQRwjIKv Hszj8dw2CsvxzNP1a+ctrx/wpAvij3vIrU1HKkXdcxY9IIXe9zOLx99b3rB8NDUQr8 HFNGwfN29H5jUr4b1eD3Wdr/++IxObyfzYn62CgpUP/ltddceQMYQvJAy2Yi8uH+cq sWX1qK1GkFi0L3YlJ2WltMunp6InihmMuu90oRiQw+AasLvH827pVGIXT9PKbV15FR LjUZHxTgeHnW2DVEqJ/Cjag9bHz0AuIUFSBI1/NR1Z2N6A1ax5N9tjwuAAxtKIkQ4z uzmMjI63mLnPw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C44785C0A1F; Fri, 7 Oct 2022 01:35:30 -0700 (PDT) Date: Fri, 7 Oct 2022 01:35:30 -0700 From: "Paul E. McKenney" To: 5486 <3164135486@qq.com> Cc: rcu Subject: Re: =?utf-8?B?5Zue5aSN77ya5Zue5aSN77ya5Zue?= =?utf-8?B?5aSN77ya5Zue5aSN77yaUmU6?= Message-ID: <20221007083530.GF4196@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org Good diagram, thank you! But that call to on_each_cpu() looks like this: on_each_cpu(rcu_barrier_func, NULL, 0, 1); Doesn't that last parameter of "1" mean that on_each_cpu() cannot return until after CPU 3's call to rcu_barrier_func() finishes? Thanx, Paul On Fri, Oct 07, 2022 at 04:03:12PM +0800, 5486 wrote: > 原始邮件 > > > > 发件人:"Paul E. McKenney"< paulmck@kernel.org >; > > 发件时间:2022/10/7 2:43 > > 收件人:"5486"< 3164135486@qq.com >; > > 抄送人:"rcu"< rcu@vger.kernel.org >; > > 主题:回复:回复:回复:Re: > > > On Fri, Oct 07, 2022 at 12:55:49AM +0800, 5486 wrote: > > > Note that the last argument to on_each_cpu() is "1", that is, > > > on_each_cpu() does not return until rcu_barrier_func() has executed on > > > all CPUs. > > o . > > > > > > > > >Can your scenario happen? > > > > rcu_barrier_func  execution is not enough,the goal is finish all the rcu callback functions. > > > > so it can. > > OK, then please show the sequence of calls to rcu_barrier_func() and > rcu_barrier_callback() on their respective CPUs, along with their effects > on rcu_barrier_cpu_count, in order to show exactly how this can happen. > > Thanx, Paul > > > 原始邮件 > > > > > > > > 发件人:"Paul E. McKenney"< paulmck@kernel.org >; > > > > 发件时间:2022/10/7 0:46 > > > > 收件人:"5486"< 3164135486@qq.com >; > > > > 抄送人:"rcu"< rcu@vger.kernel.org >; > > > > 主题:回复:回复:Re: > > > > > > On Fri, Oct 07, 2022 at 12:38:56AM +0800, 5486 wrote: > > > In fact suppose there are for cpuscpu0 cpu1 cpu2 cpu3 > > > > > > > > > the value of rcu_barrier_cpu_count may be > > > > > > > > > 1  cpu0 2 -> 1 cpu1 2 -> 1 cpu2 2 -> 1 > > > then on_each_cpu finished rcu_barrier_cpu_count decreased to be 0 > > > then complete(&rcu_barrier_completion); rcu_barrier finished.but rcu_barrier_func of cpu3 may not have been executed. > > > > Note that the last argument to on_each_cpu() is "1", that is, > > on_each_cpu() does not return until rcu_barrier_func() has executed on > > all CPUs. > > > > Can your scenario happen? > > > > Thanx, Paul > > > > > 原始邮件 > > > > > > > > > > > > 发件人:"Paul E. McKenney"< paulmck@kernel.org >; > > > > > > 发件时间:2022/10/6 19:57 > > > > > > 收件人:"5486"< 3164135486@qq.com >; > > > > > > 抄送人:"rcu"< rcu@vger.kernel.org >; > > > > > > 主题:回复:Re: > > > > > > > > > On Thu, Oct 06, 2022 at 05:56:35PM +0800, 5486 wrote: > > > > My problem is  some grace period can take very little time shorter than the one iteration of on_each_cpu itself。So the complete() can execute on one cpu before the last of all.   > > > > > > And that is the bug. Very good! > > > > > > > but now > > > > The key is on_each_cpu  ,it is really clever that on_each_cpu  will prevent completion of any grace periods. Concealed Mechanism! > > > > Is it? > > > > In this ancient version code have  real race-condition bugs .I will take some time to study to find it and reply to you. > > > > it is about on_each_cpu have not prohibit preemption? ,I did not cover more things related to the operationg system. > > > > > > Suppose the code instead read as follows? > > > > > > void rcu_barrier(void) > > > { > > > BUG_ON(in_interrupt()); > > > /* Take cpucontrol semaphore to protect against CPU hotplug */ > > > down(&rcu_barrier_sema); > > > init_completion(&rcu_barrier_completion); > > > atomic_set(&rcu_barrier_cpu_count, 1); > > > on_each_cpu(rcu_barrier_func, NULL, 0, 1); > > > if (atomic_dec_and_test(&rcu_barrier_cpu_count)) > > > complete(&rcu_barrier_completion); > > > wait_for_completion(&rcu_barrier_completion); > > > up(&rcu_barrier_sema); > > > } > > > > > > Would that work? Or are there additional bugs? > > > > > > Thanx, Paul > > > > > > > Chao,Li > > > > > > > > > > > > 原始邮件 > > > > > > > > > > > > > > > > 发件人:"Paul E. McKenney"< paulmck@kernel.org >; > > > > > > > > 发件时间:2022/10/5 21:01 > > > > > > > > 收件人:"5486"< 3164135486@qq.com >; > > > > > > > > 抄送人:"rcu"< rcu@vger.kernel.org >; > > > > > > > > 主题:Re: Dear Pualmack help i have a problem with rcu code > > > > > > > > > > > > On Tue, Oct 04, 2022 at 03:04:19AM +0800, 5486 wrote: > > > > > Dear Pualmack i have problem. > > > > > I have been reading the patch > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/kernel?id=ab4720ec76b756e1f8705e207a7b392b0453afd6 > > > > > > > > > > > > > > > > > > > > + wait_for_completion(&rcu_barrier_completion); > > > > > > > > > > How this guarantees all completes to be done ? > > > > > I learn one wait_for_completion corresponds to one x->done++ once a time > > > > > > > > 2005! That takes me back a bit! > > > > > > > > Adding the rcu email list on CC to archive this and for others to > > > > weigh in. > > > > > > > > The trick is that rcu_barrier_callback() is an RCU callback that executes > > > > on each CPU (see the on_each_cpu() in the rcu_barrier() function.) > > > > > > > > This RCU callback function is queued using call_rcu(), which queues > > > > that callback at the end of the CPU's callback list. Thus, all > > > > RCU callback functions that were already queued on that CPU will > > > > be invoked before rcu_barrier_callback() in invoked. > > > > > > > > The rcu_barrier_callback() does an atomic_dec_and_test() operation on the > > > > rcu_barrier_cpu_count global variable, and only when this variable becomes > > > > zero does it invoke complete(). This atomic_dec_and_test() operation is > > > > fully ordered, and thus ensures that all the earlier atomic_dec_and_test() > > > > operations on this variable are globally seen to happen before the last > > > > such operation (the one that decrements rcu_barrier_cpu_count to zero). > > > > > > > > This last rcu_barrier_callback() will then invoke complete(). This will > > > > ensure that the wakeup in wait_for_completion() happens only after all > > > > previously queued RCU callbacks are invoked. > > > > > > > > Almost, anyway. > > > > > > > > There are rare but real race-condition bugs in this ancient version > > > > of rcu_barrier(). Can you tell me what they are? > > > > > > > > Thanx, Paul