Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp678439lqb; Wed, 29 May 2024 07:34:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTZZ6stITxNZwsIGZhfuri46/0aUJNBOB5zGwPq3jrqSokMVaNqWwooTp52dUZGjNrs/j/kxbKRzF4W9fOz30uI5HuSBBD9aZheAlttA== X-Google-Smtp-Source: AGHT+IF/SVu9e/ZU1uY90FRFjvtpxuvtfkj+N6TfW2tQo5F6EDCoDcRWvtrgWysTUPqmkdHyDHFQ X-Received: by 2002:a05:6a21:7888:b0:1b2:5baa:7acb with SMTP id adf61e73a8af0-1b25baa7ca4mr2303688637.1.1716993289622; Wed, 29 May 2024 07:34:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716993289; cv=pass; d=google.com; s=arc-20160816; b=s8iCqW/U2m4OpiuJJBi3rUdhLEt9ZuBub8vwfu+aSUBS4YXXY8eJOoOtKMKKb8N8Xu ++SxAIeruY5XEKxiYssN0MxY+2wQGFUWrLS405OLKzfi0TyHgXVBC9mitz4Zw2T7GHMi rQcDt5xyYY93N8leIxfvZDFwDcT3Py9rOx+GyFJ8wqe6TVqMXobuUPXBnaVLyJtkHvfA JmP0kkQLXoHnlhgnCcMV14yTfWK3Q4WVhNhzkciU2ipJEDBPoVyyh/Y7uZJe99rMTnTt RTc235PnsB1QKa6Ritk2a6dl98e5FXYix2tFO9yt1WJYfA/e5sytSoXU0Mg/j4ZJ6ItJ 80PA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=hg+6NyzCP8pSqnuO6Glp41UO00ZucQQw29nuLGQvNac=; fh=zzul11zjYIcEdSK7K3yukRpG9ygf442qxhxjqxJqrGg=; b=dBfNJwhEyvGEMWJ8RCBRGQLH8TnFJeB4N9Jmmel/oacd0Gb0DjmHFwsqdxFtBwokgZ rvB1ZsqSvYcNZM8hsMXF4auDVYtZuj10pjTjeXq9in6cpy5nPyOJrR/+8qPpZYaMuVsc iBDgvG9+PT8gneT4QzQ+ZP+q6I3cUzz7yJqxFiITNHJcDm2vEsBs0E4hTU+UdcisWFRr 2Yeub0Z0R7mdy8eDC3EOmMXfawnx0gAEkm5d/N5ULw5Qoxw8+uvqazDQ3OSkpqPPjxVn i1fFbW3V8AHv9xLThBpv5Nuwx+Hx6xqU+/JIQpRz5e2Pdae5d3nGIlrcuqOD2ukoL8Dt pqyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-194253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194253-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-68229935fa3si10276064a12.602.2024.05.29.07.34.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-194253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194253-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 244D4B22233 for ; Wed, 29 May 2024 14:18:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D08F7156C62; Wed, 29 May 2024 14:18:05 +0000 (UTC) Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABEDA15699E; Wed, 29 May 2024 14:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716992285; cv=none; b=eSwetI9nWjdbq2E8ewyPu3q0AZnQPSnA/r87HRy03eAuObTwiJ4xd7KS1aGOdXLFpwXdMfBYpl0AVwOQj1I3F76RXpzvptamMqhxISonRJsY7+3r1IlHnCIb+P60jPMe7viMYVSmh7hreZY2Z+XXQhJ+kXRuLxfttN0cByi7828= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716992285; c=relaxed/simple; bh=6PIksgA4xVdsgkQ1CqMr62oRdF0wI+oPtaGukJXpTgU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mdlHDbrv926tlY8+BU2BMN/Ja3Zic2Cd4p+MXytL5r+B1JH3R265do1qhtxMAwIoxcRHvbpXBlvLAj7DJQclugYAJUF9SETMsPJEuys7XPGd6NGmgvxeKH4lZfDA6w0Y+9rTTrJiAyUqdNQIQ8jdjRJECr3NQPvnehHARop4Eug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4Vq9rg1MHFz9v7Jk; Wed, 29 May 2024 21:55:47 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id AE3AA140E31; Wed, 29 May 2024 22:17:52 +0800 (CST) Received: from [10.206.134.102] (unknown [10.206.134.102]) by APP2 (Coremail) with SMTP id GxC2BwAnYCQDOVdmC_AiCQ--.56213S2; Wed, 29 May 2024 15:17:52 +0100 (CET) Message-ID: <8c6174c7-a26c-416e-b9b1-2aff2d43dea1@huaweicloud.com> Date: Wed, 29 May 2024 16:17:36 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] tools/memory-model: Document herd7 (internal) representation To: Alan Stern Cc: Boqun Feng , Andrea Parri , Hernan Ponce de Leon , will@kernel.org, peterz@infradead.org, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, paulmck@kernel.org, akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org References: <20240524151356.236071-1-parri.andrea@gmail.com> <1a3c892c-903e-8fd3-24a6-2454c2a55302@huaweicloud.com> <41bc01fa-ce02-4005-a3c2-abfabe1c6927@huaweicloud.com> <7e2963a3-d471-4593-9170-7f59aa1ce038@huaweicloud.com> From: Jonas Oberhauser In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:GxC2BwAnYCQDOVdmC_AiCQ--.56213S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFyxuFykZryrKr4r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stern: > On Wed, May 29, 2024 at 02:37:30PM +0200, Jonas Oberhauser wrote: >> >> >> Am 5/28/2024 um 7:58 PM schrieb Boqun Feng: >>> This may not be trivial. Note that cmpxchg() is an expression (it has a >>> value), so in .def, we want to define it as an expression. However, the >>> C-like multiple-statement expression is not supported by herd parser, in >>> other words we want: >>> >>> { >>> __fence{mb-successful-rmw}; >>> int tmp = __cmpxchg{once}(...); >>> __fence{mb-successful-rmw}; >>> tmp; >>> } >> >> Oh, you're right. Then probably the rule I was violating is that >> value-returning macros can not be defined with {} at all. >> >> Given herd's other syntactic limitations, perhaps the best way would be to >> introduce these macros as >> >> x = cmpxchg(...) { >> __fence{mb-successful-rmw}; >> x = __cmpxchg{once}(...); >> __fence{mb-successful-rmw}; >> } >> >> since I think x = M(...) is the only way we are allowed to use these macros >> anyways. > > If we did this, how would the .cat file know to ignore the fence events > when the cmpxchg() fails? It doesn't look like there's anything to > connect the two of them. > > Adding the MB tag to the cmpxchg itself seems like the only way forward. > > Alan Something along these lines: Mb = Mb | Mb-successful-rmw & (domain((po\(po;po));rmw) | range(rmw;(po\(po;po))) i.e., using the fact that these mb-successful-rmw fences must appear directly next to a possibly failing rmw, and looking for successful rmw directly around them. I suppose we have to distinguish between the before- and after- fences though to make it work for cases like xchg_release(); cmpxchg(); // fails __xchg_release(...); // is an rmw __fence{mb-successful-rmw}; // wrong takes mb semantics x = __cmpxchg{once}(...); // fails __fence{mb-successful-rmw}; So that would leave us with x = cmpxchg(...) { __fence{mb-before-successful-rmw}; x = __cmpxchg{once}(...); __fence{mb-after-successful-rmw}; } and in .cat/.bell: Mb = Mb | Mb-before-successful-rmw & domain((po\(po;po));rmw) | Mb-after-successful-rmw & range(rmw;(po\(po;po))) Best wishes, jonas