Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4114389rwj; Tue, 20 Dec 2022 06:19:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf74rwPRkSf8n0kD2gSfIfYIt/85dxxiw8dlrq7smj5AvMEbc/vHo7SgzGBn9ucaAdqyVtTT X-Received: by 2002:a17:902:a60c:b0:189:f990:24af with SMTP id u12-20020a170902a60c00b00189f99024afmr45411900plq.20.1671545945634; Tue, 20 Dec 2022 06:19:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671545945; cv=none; d=google.com; s=arc-20160816; b=UOza2MfsYlrIESUvrm/zROb+8uRM8GjhKL8AoT0WKnwtSsoLWeLFVtZKyTTehk7kh2 xcEsBdOS4ySVqhRcQR7CZHE+zMgdBhkZQ6i65hZ6xyOV/Usu7aJSkomRccrPGGtM4M7y 1h8LzjkwyNdMoz6WOte5NP95jAbGjY4f8wzw7RI/x0YnSLIvs1CJfNKCQPnyVG/Ni6Md NElQDwv7EeZcx7oTjZ5R/Umd2z+cv0qge/HcCuAgFSK3o5H/vzd1B/4Nrh831RfDW9m1 UdN+BJbtj5l2iFRgZQOUYjs0XHYAXPdSs7guNId7cxmiagQk3fqcP6i9OFWHRN48pE4D j50Q== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=5uUh0xY9CELsk794mD9Gi2eyzbftMJwF75PMvM8KZ+M=; b=moneAMYBlWy7+MPD2dHj3wxR6a0t0XPwxeM/H7pCO5h7KIfbQ9zDGTicfbfhH4FNAI cLeQet6AuSWc/SEZqXjriwCWVomL7QwDgUeOSf078+5VfhA2A1yvU0yTQTqnbzS4k1C2 +5SyIlQ6pLSiFnQXb2MFzjtYXHHFB94Dyi2RnFnG9zpafIyFA1mAX/hkWR3Kf+JVLUY2 QB1glYliope/Y8pY2HhdTlgKWQjg5W84+NfK7eUBzCxIHSvooHPw+JfEH6V1HzC6LeRj mBAb2S+r3Ku9edTYKdd3uwtZcWUY9OSJOYBjLuJL8AVG1koHN0+CLaMS4ibXYWjIFPbM AxBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bEBs1w7W; 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 p8-20020a631e48000000b0049148558228si368786pgm.90.2022.12.20.06.18.55; Tue, 20 Dec 2022 06:19:05 -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=bEBs1w7W; 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 S232513AbiLTOH0 (ORCPT + 70 others); Tue, 20 Dec 2022 09:07:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbiLTOHS (ORCPT ); Tue, 20 Dec 2022 09:07:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DDCDF95; Tue, 20 Dec 2022 06:07:18 -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 E87EE61468; Tue, 20 Dec 2022 14:07:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFCE5C433EF; Tue, 20 Dec 2022 14:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671545237; bh=kjxsA1RKba1sAwK7HkKMsn1Ci5sL+fSF3MvywZYYKxo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bEBs1w7WNlsh7yDburfMLoIzQ5V2rqciIrYUzki1SZHyoAydD6E0iyjn559MuR0x/ TIM5Z/KtR0YkQagzYRs2UshkbwS/CCNptGIYNEoDGZlhHLQYEYv9Cl7ZqcHz8NT+Y0 D+JYfXdrR+LcqxHalVQI73Ow94IS1aIvmFV0qtglqHunk73e7+mz2ln99fEpxaFb6U FQRDfCTUVeNdFbIuRlKGQgCrtrecDbjm5sbjb2z0Oo0upnOlJOvCxOV+5JJeKzkIGN B9ZfuOGdtCrL8ThvXOHVDTMJCxmIpD9ewWqK18dgb82sotvAkZUjX43q4z+pcTTVGK 9bwSbkuQxt9MA== Date: Tue, 20 Dec 2022 15:07:14 +0100 From: Frederic Weisbecker To: Joel Fernandes Cc: linux-kernel@vger.kernel.org, Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , "Paul E. McKenney" , rcu@vger.kernel.org, Steven Rostedt Subject: Re: [RFC 0/2] srcu: Remove pre-flip memory barrier Message-ID: <20221220140714.GB22763@lothringen> References: <20221220124033.GA22763@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Tue, Dec 20, 2022 at 08:44:40AM -0500, Joel Fernandes wrote: > > C w-depend-r > > > > { > > PLOCK=LOCK0; > > } > > > > // updater > > P0(int *LOCK1, int **PLOCK) > > { > > int lock1; > > > > lock1 = READ_ONCE(*LOCK1); // READ from inactive idx > > smp_mb(); > > WRITE_ONCE(*PLOCK, LOCK1); // Flip idx > > } > > > > // reader > > P1(int **PLOCK) > > { > > int *plock; > > > > plock = READ_ONCE(*PLOCK); // Read active idx > > WRITE_ONCE(*plock, 1); // Write to active idx > > I am a bit lost here, why would the reader want to write to the active idx? > The reader does not update the idx, only the lock count. So &ssp->sda->srcu_lock_count is the base address and idx is the offset, right? The write is then displayed that way: this_cpu_inc(ssp->sda->srcu_lock_count[idx].counter); But things could be also thought the other way around with idx being the base address and ssp->sda->srcu_lock_count being the offset. this_cpu_inc(idx[ssp->sda->srcu_lock_count].counter); That would require to change some high level types but the result would be the same from the memory point of view (and even from the ASM point of view). In the end we are dealing with the same address and access. Now ssp->sda->srcu_lock_count is a constant address value. It doesn't change. So it can be zero for example. Then the above increment becomes: this_cpu_inc(idx.counter); And then it can be modelized as in the above litmus test. I had to play that trick because litmus doesn't support arrays but I believe it stands. Now of course I may well have got something wrong since I've always been terrible at maths... > > Further, the comment does not talk about implicit memory ordering, it’s talking about explicit ordering due to B+C on one side, and E on the other. Not arguing I'm also still confused by the comment... Thanks.