Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2215240imu; Fri, 14 Dec 2018 07:33:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vkzo/Ete0Kk1vf1oSK5eqiGtNmjAyJDJ6I3GQI9/byt/KrzxzRWZuOVVd2zA7H/Xmki3y5 X-Received: by 2002:a17:902:820f:: with SMTP id x15mr3161049pln.224.1544801615228; Fri, 14 Dec 2018 07:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544801615; cv=none; d=google.com; s=arc-20160816; b=Z3476/T3FaHIngHrn7kWHhjhYT3ZCOnUexz60WFW6FZyLGPwUz2g+2MdJjBo0Qo9bK pVQ9hZ9SQwBzPB1MmQz+0UIHGudgdbftmovKRteWgAsWuRHd/AKhVRBb8xYXUAxh6EEI 5lUa9gwyVlVYIOSld6q+csm7vWKedRKJ88mF+rZO0P/id8Csg0bnptzSxjgAuz9CzrGR bga9894Mciry334dDLJpW8Ghx6cMTd/UAnSe5A+QG37CMyTMAgGtWB/5W0Hdp6Gi/Z0F Cly6cl1BhDdEfaDI0pCWEMCPDtlkkGOXBmugio1tgQ1GMVEi4mIlRWjioQGYSjlUQ5lN ACMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=eTbEJUJh5GP92Kan+0TOJ2ZpwRufKaTs3fg9xJN7KLQ=; b=01hG0aQjT8cvWfkEtMSh22Cwy2H0WDSVlEilKfs/LMHRRwZ0umFcbPkx4KLzNkrGtZ yxYw9Gg9O0TPxQYNBM1VWjDpgfJ2CxnvoWg50NKi+dFf23Qr1dWqUeUin/vJPxJUgrSC x4HruV2BKlFZGYnKo7PXR3TBedTrEf5lA4ifbjAs2uEIca2rYRs9F1aOH7n3eiTF+c5E XL7R0j8GfVJC4HEmTtRCtLJ6HsetcCXARJUSwIPudt3u1adsz5ztAacDtXV67kwS0KMX CWHhw/tMWksehz3ES0gTBHlWNKo7H1lLUO/PoEN/sh/gPoEJ53DoPIc6eWFYT9sHpv5w n2mA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si4342057pgi.531.2018.12.14.07.33.09; Fri, 14 Dec 2018 07:33:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729409AbeLNPbx (ORCPT + 99 others); Fri, 14 Dec 2018 10:31:53 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:59498 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727361AbeLNPbw (ORCPT ); Fri, 14 Dec 2018 10:31:52 -0500 Received: (qmail 3022 invoked by uid 2102); 14 Dec 2018 10:31:51 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 14 Dec 2018 10:31:51 -0500 Date: Fri, 14 Dec 2018 10:31:51 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Paul E. McKenney" cc: David Goldblatt , , Florian Weimer , , , , , , , , , , , , , , Subject: Re: [PATCH] Linux: Implement membarrier function In-Reply-To: <20181214002043.GP4170@linux.ibm.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Dec 2018, Paul E. McKenney wrote: > > > I guess that I still haven't gotten over being a bit surprised that the > > > RCU counting rule also applies to sys_membarrier(). ;-) > > > > Why not? They are both synchronization mechanisms with heavy-weight > > write sides and light-weight read sides, and most importantly, they > > provide the same Guarantee. > > True, but I do feel the need to poke at it. > > The zero-size sys_membarrier() read-side critical sections do make > things act a bit differently, for example, interchanging the accesses > in an RCU read-side critical section has no effect, while doing so in > a sys_membarrier() reader can cause the result to be allowed. One key > point is that everything before the end of a read-side critical section > of any type is ordered before any later grace period of that same type, > and vice versa. > > This is why reordering accesses matters for sys_membarrier() readers but > not for RCU and SRCU readers -- in the case of RCU and SRCU readers, > the accesses are inside the read-side critical section, while for > sys_membarrier() readers, the read-side critical sections don't have > an inside. So yes, ordering also matters in the case of SRCU and > RCU readers for accesses outside of the read-side critical sections. > The reason sys_membarrier() seems surprising to me isn't because it is > any different in theoretical structure, but rather because the practice > is to put RCU and SRCU read-side accesses inside a read-side critical > sections, which is impossible for sys_membarrier(). RCU and sys_membarrier are more similar than you might think at first. For one thing, if there were primitives for blocking and unblocking reception of IPIs, those primitives would delimit critical sections for sys_membarrier. (Maybe such things do exist; I wouldn't know.) For another, the way we model RCU isn't fully accurate for the Linux kernel, as you know. Since individual instructions cannot be preempted, each instruction is a tiny read-side critical section. Thus, litmus tests like this one: P0 P1 Wa=1 Wb=1 synchronize_rcu() Ra=0 Rb=0 actually are forbidden in the kernel (provided P1 isn't part of the idle loop!), even though the LKMM allows them. However, it wouldn't be forbidden if the accesses in P1 were swapped -- just like with sys_membarrier. Put these two observations together and you see that sys_membarrier is almost exactly the same as RCU without explicit read-side critical sections. Perhaps this isn't surprising, given that the initial implementation of sys_membarrier() was pretty much the same as synchronize_rcu(). > The other thing that took some time to get used to is the possibility > of long delays during sys_membarrier() execution, allowing significant > execution and reordering between different CPUs' IPIs. This was key > to my understanding of the six-process example, and probably needs to > be clearly called out, including in an example or two. In all the examples I'm aware of, no more than one of the IPIs generated by each sys_membarrier call really matters. (Of course, there's no way to know in advance which one it will be, so you have to send an IPI to every CPU.) The execution delays and reordering between different CPUs' IPIs don't appear to be significant. > The interleaving restrictions are straightforward for me, but the > fixed-time approach does have some interesting cross-talk potential > between sys_membarrier() and RCU read-side critical sections whose > accesses have been reversed. I don't believe that it is possible to > leverage this "order the other guy's read-side critical sections" effect > in the general case, but I could be missing something. I regard the fixed-time approach as nothing more than a heuristic aid. It's not an accurate explaination of what's really going on. > If you are claiming that I am worrying unnecessarily, you are probably > right. But if I didn't worry unnecessarily, RCU wouldn't work at all! ;-) Alan