Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp728049lqc; Fri, 8 Mar 2024 09:54:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV7lYmcmj46s0CLM9X2T9E7wqmdx+XnrmDzr2FLpL997gD+raFgKJHRHb3Y9vrLdcbcwIlDnROy0kqFgVUZ9moZuU4pCuGjR55XwwJ8EA== X-Google-Smtp-Source: AGHT+IG7qK5M6f6EW1nLNQLnU6DcInAFEVN8rZ6VNeR8UqQFXpY8Q9Jc4R7SdHogiDJ/EoRQY3SJ X-Received: by 2002:a05:6a00:2e26:b0:6e4:f32a:4612 with SMTP id fc38-20020a056a002e2600b006e4f32a4612mr23988279pfb.16.1709920491903; Fri, 08 Mar 2024 09:54:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709920491; cv=pass; d=google.com; s=arc-20160816; b=V/tkJtN0v0h5wV84PTOqJJx50IM66AERrrOHnFsW+u7lyaolR/BMs92I4auPF//Xdf Y/r8KyOUUuZpzNG6DDjpXzH4oOlsXbVEyMQgTUvbwHf2YOJHlEYeIu37oiCzDmf78d+9 UavoscviL0c4oK55V0tRw1L7CGXC9TpSEJNpk/Dr5+1JEsnSZYGwJ1nU28uaXvS4hK0k Y05bvfoC3OD5qTo/nk1LT1EJ05w6/uF6mBvsVXQiVN4ArQOimz96ddeH4tYnynfo5UUl RUkoZ1mSlJ6A4uIM6pF0ZIc5wUF9RcIqt1Qla0v3YuwtrNDZIaznqQvEkLhQz7IOvpFs yzRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=4kXI0veK3zovqADurCTXCV6ODXqE2SkXGgISmSermwU=; fh=vclOy54vrc4go6iMECrcor6hAewGQ03f2X+1SnH2p10=; b=ioJDrcJMDSfEeXCTem56V4psQm9Eqre9iTpMtWzFQxOyc+q/y6vBl05gUykHgg1Eso Z5i6w4XRC7OQOfTmA4K6T6u00pl2p9nxmOf51vu3y4881kUD/6k8RGae9dAnc5d+vg2B D41/OaRZoafqIOj9SN3Xm81zjKtL6GRtEd1I/VsqIpxpH7x8TZhwEHHcB8Sb88w4xbbS NvVfK6l2kZCWo5c9WrXzeC4yH8jWFitEvtojEx9RSK71I5mhHGXb9Fhh6A8cuDE97WSX YdccxONeEbAEJ6/w80Q68udqXd/iRxqKSiEwIuYu683iOr9lKANyLEOhxsShMWdBn0AR +SSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-97421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx36-20020a056a02052400b005e2b17cb799si17689875pgb.267.2024.03.08.09.54.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 09:54:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-97421-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 94174284E25 for ; Fri, 8 Mar 2024 17:54:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 867BA40873; Fri, 8 Mar 2024 17:54:46 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id 9275C36D for ; Fri, 8 Mar 2024 17:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.131.102.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709920486; cv=none; b=smpsid6inEvT6mbrHJ/lCYhwZxvuopwqNW4A6VdjuyDNHqj4bmR6+2KcUTNBcVpjPJOs/xzgOqcISaQwfY0y4x2iXNKWHWmtK/QOcRea5Pur6HoXdgQtTPTSrBd5PaVU3AR/GAX9e673ffmIIUYSnJA0QK9QBKHrOCrIb2luHWg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709920486; c=relaxed/simple; bh=/H8WjFvFPxyLsZIPjl4/bakKUkVA3AKPXdEEQ/B6xns=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zdw+YDCnqyC6uCvbLmGtUZU+KgLNhFyRovMcfbzBodleUmLhSjOUbn3EpF5M0CSTTOXYhYpEy2cOcWKE0ZPQ2s8Vk8qYdR7ijcizcKcRfykfaeYFWDRSSFhYuangBpSyjiJSjh6dh9wpFAwCDTGlaTJHLUnVA0ltoK8tAiBrEzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu; spf=pass smtp.mailfrom=netrider.rowland.org; arc=none smtp.client-ip=192.131.102.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netrider.rowland.org Received: (qmail 266266 invoked by uid 1000); 8 Mar 2024 12:54:42 -0500 Date: Fri, 8 Mar 2024 12:54:42 -0500 From: Alan Stern To: Andrea Parri Cc: Kenneth-Lee-2012@foxmail.com, linux-kernel@vger.kernel.org, paulmck@kernel.org Subject: Re: Question about PB rule of LKMM Message-ID: <198f16f6-1d61-4868-b522-1bc5d34bf7af@rowland.harvard.edu> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Mar 07, 2024 at 10:06:08PM +0100, Andrea Parri wrote: > > > C test > > > > > > {} > > > > > > P0(int *x) > > > { > > > *x = 1; > > > } > > > > > > P1(int *x) > > > { > > > *x = 2; > > > } > > > > Ah, but you see, any time you run this program one of those statements > > will execute before the other. Which will go first is indeterminate, > > but the chance of them executing at _exactly_ the same moment is zero. > > TBH, I don't. But I trust you know your memory controller. ;-) I can't tell which aspect of this bothers you more: the fact that the text uses an argument by contradiction, or the fact that it ignores the possibility of two instructions executing at the same time. If it's the latter, consider this: Although the text doesn't say so, the reasoning it gives also covers the case where F executes at the same time as E. You can still deduce that W must have propagated to E's CPU before E executed, because W must propagate to every CPU before F executes. > > The way you put it also relies on argument by contradiction. This > > just wasn't visible, because you omitted a lot of intermediate steps in > > the reasoning. > > > > If you want to see this in detail, try explaining why it is that "W is > > coherence-later than E" implies "E must execute before W propagates to > > E's CPU" in the operational model. > > But that's all over in explanation.txt?? FWIW, a quick search returned > (wrt fre): > > R ->fre W means that W overwrites the value which R reads, but it > doesn't mean that W has to execute after R. All that's necessary > is for the memory subsystem not to propagate W to R's CPU until > after R has executed (In fact, that sentence isn't entirely accurate. It should say "... not to propagate W (or a co-later store)...".) Let's consider coe instead of fre. The description of how the operational model manages the coherence order of stores is found in section 13 (AN OPERATIONAL MODEL): When CPU C executes a store instruction, it tells the memory subsystem to store a certain value at a certain location. The memory subsystem propagates the store to all the other CPUs as well as to RAM. (As a special case, we say that the store propagates to its own CPU at the time it is executed.) The memory subsystem also determines where the store falls in the location's coherence order. In particular, it must arrange for the store to be co-later than (i.e., to overwrite) any other store to the same location which has already propagated to CPU C. So now if E is a store and is co-before W, how do we know that W didn't propagate to E's CPU before E executed? It's clear from the last sentence of the text above: If W had propagated to E's CPU before E executed then the memory subsystem would have arranged for E to be co-later than W. That's an argument by contradiction, and there's no way to avoid it here. Alan