Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp233534rwb; Wed, 18 Jan 2023 16:58:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXudieDiZwcu9z1HRAd2ZgKKArAqv2GJqkSrWCE9zqmqtapuUvjid50gw+KpsGZtyJbAEGfx X-Received: by 2002:a05:6a00:1a15:b0:581:73c4:f0bb with SMTP id g21-20020a056a001a1500b0058173c4f0bbmr11522369pfv.2.1674089931684; Wed, 18 Jan 2023 16:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674089931; cv=none; d=google.com; s=arc-20160816; b=JBMOFgeROQ6bcwNZNAWf5sRKTQRLCOBlM4uSpFOktcqQHvTTDNxpBqHob1NMUzLANg 9VDx7s0UgziOQikHkLeUp2OaqroF3VPrig0d+gqcQE6ctyBKlPLmupb1Yh3Yu9FeJzEg 2ZbaMFpXv3F+JSi433D9h8i40MPaYuduwE6+xftEwFqONJHVbRbhbSFw8BDaE8TJO89g atTVgZjdtE3IuIEvgxmItbf4G4oFnUEdjevqormqjjbbVQs7Flw1sCcK1XkOQxLko3CL B9dxrGjv5yLdqlvH50UgGBN5mTo3BpylvfUrPw7/EI9e6GW5n2AIf1vBFkjM06dgKrYF McGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=L4o83sKpve866q+smKBsklHHnSkUOR5gjJCWoQP3nNQ=; b=eqYUVqlvFmxNvc20Q3zV5mLuxDhYAzdP6wXCX1sNFQ98OyV2ZhwPetrjGNVUUFPy9B Egnea3QVcgl3Vc4I7ftB09tiw2YbswLLhe6+H9XZyxYSyE8W+xKj/23MMPrEUq5s8e6E f66ZNfp0prG9VO2+qrXg556e2HsPRhVZApaug+YpSqFxKmhThiececSyZGGeEEl0gw80 9HycKWmg2blB7JYT627CcPWHmuUgUugC5PrZZ/pqElexB+XFmBbDm/s2bUcajWKkc2+O VD1GYsRaFIp+eU5WAELHMUBp8tI8vvbZYab2SybqvVk59vFlBqnNrVV+LkzCzLLSpGy/ vLmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XMPcHDaf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a056a0022ce00b0058de5bb613csi3548229pfj.29.2023.01.18.16.58.46; Wed, 18 Jan 2023 16:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XMPcHDaf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbjASALx (ORCPT + 44 others); Wed, 18 Jan 2023 19:11:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbjASALu (ORCPT ); Wed, 18 Jan 2023 19:11:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8913E08D for ; Wed, 18 Jan 2023 16:11:48 -0800 (PST) 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 7495A61ACE for ; Thu, 19 Jan 2023 00:11:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0AC4C433EF; Thu, 19 Jan 2023 00:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674087107; bh=+vKp94IjqzCbXRJhpm9qWbaAwtlskkDfxJvECB2O8Cg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=XMPcHDafOjV3lqL10kIOWaonP8nwSJUMQSFkK1BI687PKqamkb1uzQ5HJsNQ3tUmg aEtZ2DaMklzQXi3WymD3740MllCOL5SrKsZ+zolOSVxzw5b1E1LjgkAQiguDWSOJGN NxXEz12zyqRnOS/Z4dxjDPbA/RwcpEENSRyuZK6KRMg6QmBeUyLfGUYes0+HtjKRUj PdlIWEi74SQJqb5PY+qJ6kONGOS+GkmQowJ2+l3Fs80oRnY49WNiBavcaS86uFutpb DjmKzgmDVlFsGu8zosxzwv423LFeKc21MvUm7Y02bWuzz4VQnnW6pJHyb5Yl8sS+LW 9UZbmh8Ss6jqg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 768C55C0A1A; Wed, 18 Jan 2023 16:11:47 -0800 (PST) Date: Wed, 18 Jan 2023 16:11:47 -0800 From: "Paul E. McKenney" To: Jonas Oberhauser Cc: Alan Stern , Andrea Parri , Jonas Oberhauser , Peter Zijlstra , will , "boqun.feng" , npiggin , dhowells , "j.alglave" , "luc.maranget" , akiyks , dlustig , joel , urezki , quic_neeraju , frederic , Kernel development list Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test) Message-ID: <20230119001147.GN2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230117174308.GK2948950@paulmck-ThinkPad-P17-Gen-1> <20230118035041.GQ2948950@paulmck-ThinkPad-P17-Gen-1> <3dabbcfb-858c-6aa0-6824-05b8cc8e9cdb@gmail.com> <20230118201918.GI2948950@paulmck-ThinkPad-P17-Gen-1> <20230118211201.GL2948950@paulmck-ThinkPad-P17-Gen-1> <09f084d2-6128-7f83-b2a5-cbe236b1678d@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <09f084d2-6128-7f83-b2a5-cbe236b1678d@huaweicloud.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 18, 2023 at 10:24:50PM +0100, Jonas Oberhauser wrote: > > > On 1/18/2023 10:12 PM, Paul E. McKenney wrote: > > > The only difference between srcu_read_lock() and srcu_read_unlock() > > on the one hand and srcu_down_read() and srcu_up_read() on the other > > is that a matching pair of srcu_read_lock() and srcu_read_unlock() > > must be running on the same task. In contrast, srcu_down_read() and > > srcu_up_read() are not subject to this constraint. > > > > > What I was suggesting below is how to redefine "match" between read_down and > > > read_up that work more like a cross-thread semaphore. > > Understood, but what I don't understand is why not simply this: > > > > let srcu-rscs-down = ([Srcu-down] ; (data | rf)* ; [Srcu-up]) & loc > > Oh, I had thought that it should be more like a semaphore rather than just a > cross-cpu mutex. > > Here's an example of how what you are describing would be used: > > P0{ > ?? idx = srcu_down(&ss); > ?? store_release(done,1); > } > > P1{ > ??? while (! load_acquire(done)); > ??? srcu_up(&ss,idx) > } Exactly!!! > What I was thinking of is more something like this: > > P0{ > ?? idx1 = srcu_down(&ss); > ?? srcu_up(&ss,idx1); > } > > P1{ > ??? idx2 = srcu_down(&ss); > ??? srcu_up(&ss,idx2) > } And srcu_read_lock() and srcu_read_unlock() already do this. > where the big difference to srcu_lock/unlock would be that if P0 and P1 > happened to get the same index -- which you could very well check or > synchronize on -- that you would be guaranteed that the grace period only > ends once *all* threads that are using this index have called up. (note that > I believe that your implementation has this property, and some users may > come to rely on it if they find out!) They are permitted and encouraged to rely on the fact that synchronize_srcu() waits until all pre-existing SRCU read-side critical sections have completed, which I believe is quite close to what you are saying. But if they want to look at the return values from either srcu_read_lock() or srcu_down_read(), they would be better off using either get_state_synchronize_srcu() or start_poll_synchronize_srcu(). Huh. I need to add a NUM_ACTIVE_SRCU_POLL_OLDSTATE, don't I? I first need to figure out what its value would be. > If you want this latter kind of guarantee, then you need to do so something > along the lines of what Alan or I wrote. > > If all you need is the ability to use the first scenario, without any > guarantee that if the index happened to be the same (or providing an API > where you can do the down with a fixed index provided by P0) the grace > period will extend, then what you propose should be right. > > But from Alan's comments I had misunderstood that that wouldn't be the case. "What do you need?" "Well, what can be provided?" ;-) Thanx, Paul