From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZK4xU-00063V-QK for qemu-devel@nongnu.org; Tue, 28 Jul 2015 09:30:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZK4xP-0001da-6V for qemu-devel@nongnu.org; Tue, 28 Jul 2015 09:30:16 -0400 Received: from mail-pd0-x233.google.com ([2607:f8b0:400e:c02::233]:35107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZK4xP-0001bw-0B for qemu-devel@nongnu.org; Tue, 28 Jul 2015 09:30:11 -0400 Received: by pdrg1 with SMTP id g1so71002359pdr.2 for ; Tue, 28 Jul 2015 06:30:08 -0700 (PDT) Message-ID: <55B783D6.3020102@gmail.com> Date: Tue, 28 Jul 2015 21:29:58 +0800 From: Wen Congyang MIME-Version: 1.0 References: <55B6E854.9090600@cn.fujitsu.com> <55B75278.80909@redhat.com> <55B7532D.9010506@cn.fujitsu.com> <55B756D8.9090503@redhat.com> <55B75A70.8080203@cn.fujitsu.com> <55B76BA3.4080804@redhat.com> In-Reply-To: <55B76BA3.4080804@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 for-2.5] rcu: Allow calling rcu_(un)register_thread() during synchronize_rcu() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Wen Congyang , qemu-devl At 2015/7/28 19:46, Paolo Bonzini Wrote: > > > On 28/07/2015 12:33, Wen Congyang wrote: >> On 07/28/2015 06:18 PM, Paolo Bonzini wrote: >>> >>> >>> On 28/07/2015 12:02, Wen Congyang wrote: >>>> I have a question about rcu: while do we call wait_for_readers() >>>> twice for 32-bit host? >>> >>> Because there is a very small but non-zero probability of the counter >>> going up by exactly 2^31 periods (periods are stored in bits 1-31 so you >>> lose one bit) while the thread is sleeping. This detail of the >>> implementation comes from URCU. >> >> Yes, so you use rcu_gp_ctr ^ RCU_GP_CTR to instead of rcu_gp_ctr + RCU_GP_CTR. >> The initial value is 1, so rcu_gp_ctr is: 1, 3, 1, 3, ... >> The rcu_gp_ctr will never be 0. I think calling wait_for_readers() once is >> enough. >> >> Do I miss something? > > If you call it just once, you have the same problem as before. In fact, > it's worse because instead of having an overflow every 2^31 periods, you > have one every 2 periods. Instead, by checking that rcu_reader went > through 1 _and_ 3 (or that it was at least once 0, i.e. the thread was > quiescent), you are sure that the thread went through _at least one_ > grace period. The overflow is acceptable. We only compare if rcu_reader.ctr is equal than rcu_gp_ctr. If not, we should wait that thread to call rcu_read_unlock(). We don't care which is bigger. If no threads calls sync_rcu(), all threads rcu_read.ctr is 0 or rcu_gp_ctr. If one thread calls sync_rcu(), all threads rcu_read.ctr is 0, old_rcu_gp_ctr, or new_rcu_gp_ctr. We only wait the thread that's rcu_read.ctr is old_rcu_gp_ctr. Thanks Wen Congyang > > Paolo > >