Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5111037pxb; Thu, 14 Oct 2021 19:46:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/4nlBRaGa8vPEsSnk/j0lxH8/y6FcXiZ9kJ+eIDQ3tKhp3Jscn0YPRQ0qcqIq+xXsLcfG X-Received: by 2002:aa7:9563:0:b0:44c:9261:3d86 with SMTP id x3-20020aa79563000000b0044c92613d86mr8791645pfq.44.1634265991784; Thu, 14 Oct 2021 19:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634265991; cv=none; d=google.com; s=arc-20160816; b=lWIqxUZd/VP3exFNXLixZdDCEaPyEm4cmRx7o2XIeHhHWNfUyF+aSld/nXUhopkbmo 1AszgPWVaDHwAdHBa84vRiuNYnquQErJAMPsfLFZ/qxRlqLXR2kbZljc/mdc/2OThhd2 VUyCXHskVlp0rCQkiX8+M+F087rblNundXzvyZQH+o0bSxu/wrCHDYCj/paC+3zmwnXE imLLXDfykK27XkQupLrrO7h4UAvDvJQnSptmYUi9KfT0mdM0udM696yhWw4oIyXz4t4n 7wyXzDdvpG3PjbEp8R/C3jl22f1j4u6ENMniZFutBkS+1snmxFc0luRskoG1Lcg4dMUn TaPQ== 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-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=mBELhcGVhUrunadfH0/0KGAeTeHalHofQMZ42KCtU/8=; b=p4lkmTuwRWiE4H1Bgm3fGdmAHwSbvCHIt3p/w1V7LcdkE0eVU08T89qpXPbUASxA2Z ZoxLcimbZQ8+s7ODC+lNMmXjsGmPQtGxnpTukJwwVekYn/s+XKvvHHJ8iluI41bFgkEz 9sVGSdyMV7KHzB7j/G0J0B0kHS96SLBcqY0Ap/hHxB4drIZOVQd54vOrIfAnDG2Gy+Lt Vum4k5UkfgunszDyoxGzLqn0aiQdWlCeH3d3K5c51z3LdTyZIh1M9u8nM7ZFbW0NV1cE gMnXF2L5lotgfaGuIEj7I55f7aHdi3wcvIHUjkPoZwZJ7XS30KD9a/E8qMoHHJZqmRRa kZhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=saRPFvZy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oc11si18568118pjb.39.2021.10.14.19.46.08; Thu, 14 Oct 2021 19:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=saRPFvZy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233002AbhJNVMF (ORCPT + 99 others); Thu, 14 Oct 2021 17:12:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbhJNVMF (ORCPT ); Thu, 14 Oct 2021 17:12:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB03C610A0; Thu, 14 Oct 2021 21:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634245799; bh=4TYiyp4sVKUskNtzVyTQ21gmDtCxwEMzXP/fy+9w4VU=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=saRPFvZyUX8osI9aDVpT1HWcp+O69VRT+9TTbndX2ttphpDwHsY091dNrI6USNSLa onbLmrUJhpOXG55N3GNFTn94HZoW48gP+//eG6pQN9sl+LUIXUILq+Agf052RPBFgB cAXdLAyoYcwRfZ5KCgZZKIw7f3b6JVHlmvvFt+H/E1T6XISRkWTZpP3XE8aMDGg7e7 HN3XJ9skYETzs4R4gWAN3lhiH4C3eJFD7seztDVDbXhSdAIrtgpqJwdL9HCMCqwSQU Mp/W31JzwHxKF1nIZUrCbyS9eJL7IRQoy+96nJ93SREmq8hZxUl+u/LZf1CrHnOdFn cL7nEqBhIKAOw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 7831A5C0A6E; Thu, 14 Oct 2021 14:09:59 -0700 (PDT) Date: Thu, 14 Oct 2021 14:09:59 -0700 From: "Paul E. McKenney" To: Florian Weimer Cc: Linus Torvalds , Mathieu Desnoyers , Segher Boessenkool , Will Deacon , Peter Zijlstra , linux-kernel , Alan Stern , Andrea Parri , Boqun Feng , Nicholas Piggin , David Howells , j alglave , luc maranget , akiyks , linux-toolchains , linux-arch Subject: Re: [RFC PATCH] LKMM: Add ctrl_dep() macro for control dependency Message-ID: <20211014210959.GJ880162@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <87lf3f7eh6.fsf@oldenburg.str.redhat.com> <20210929174146.GF22689@gate.crashing.org> <2088260319.47978.1633104808220.JavaMail.zimbra@efficios.com> <871r54ww2k.fsf@oldenburg.str.redhat.com> <87y271yo4l.fsf@mid.deneb.enyo.de> <20211014000104.GX880162@paulmck-ThinkPad-P17-Gen-1> <87lf2v61k7.fsf@mid.deneb.enyo.de> <20211014162311.GD880162@paulmck-ThinkPad-P17-Gen-1> <87o87r4gfp.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o87r4gfp.fsf@mid.deneb.enyo.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021 at 08:19:54PM +0200, Florian Weimer wrote: > * Paul E. McKenney: > > >> > Yes, I know, we for sure have conflicting constraints on "reasonable" > >> > on copy on this email. What else is new? ;-) > >> > > >> > I could imagine a tag of some sort on the load and store, linking the > >> > operations that needed to be ordered. You would also want that same > >> > tag on any conditional operators along the way? Or would the presence > >> > of the tags on the load and store suffice? > >> > >> If the load is assigned to a local variable whose address is not taken > >> and which is only assigned this once, it could be used to label the > >> store. Then the compiler checks if all paths from the load to the > >> store feature a condition that depends on the local variable (where > >> qualifying conditions probably depend on the architecture). If it > >> can't prove that is the case, it emits a fake no-op condition that > >> triggers the hardware barrier. This formulation has the advantage > >> that it does not add side effects to operators like <. It even > >> generalizes to different barrier-implying instructions besides > >> conditional branches. > > > > So something like this? > > > > tagvar = READ_ONCE(a); > > if (tagvar) > > WRITE_ONCE_COND(b, 1, tagvar); > > Yes, something like that. The syntax only makes sense if tagvar is > assigned only once (statically). > > > (This seems to me to be an eminently reasonable syntax.) > > > > Or did I miss a turn in there somewhere? > > The important bit is that the compiler emits the extra condition when > necessary, and the information in the snippet above seems to provide > enough information to optimize it away in principle, when it's safe. > This assumes that we can actually come up with a concrete model what > triggers the hardware barrier, of course. For example, if tagvar is > spilled to the stack, is it still possible to apply an effective > condition to it after it is loaded from the stack? If not, then the > compiler would have to put in a barrier before spilling tagvar if it > is used in any WRITE_ONCE_COND statement. In all the weakly ordered architectures I am aware of, spilling to the stack and reloading preserves the ordering. The ordering from the initial load to the spill is an assembly-language data dependency, the ordering from the spill to the reload is single-variable SC, and the ordering beyond that is the original control dependency. Thanx, Paul