Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2019543lqb; Mon, 27 May 2024 05:31:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmZejSqAuw9WWgYs/dLZ05AHEuXq0uD+8jybORLD0qXzPXQJpC3Tt6XbsYPdV6aPagV6AXjEGBHTx/rfuZFMJ4mpN6s1CWglNRci7Lfg== X-Google-Smtp-Source: AGHT+IFXEkxqXA9blnoNpP2DxgaCS2ngCDfkMZAeYndgQdBIikVEXu8mZ9pAVSC1nwplWbmgZ4Jh X-Received: by 2002:a05:6a00:1f12:b0:6f6:7c6a:2c14 with SMTP id d2e1a72fcca58-6f8f2c56e53mr9492081b3a.4.1716813069344; Mon, 27 May 2024 05:31:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716813069; cv=pass; d=google.com; s=arc-20160816; b=tB6ES+0t9Yd1VYIMpW2shKBH4LTjyNFltA4Ytpc51fxoibK7xFhpZogwl1sl/vqssH GHAMfaWaJzs6UykdmevNzutBQi6PBEHzrXusBslA9KzJZgSWt8k4It/ozqJDpQ57u8RE WdDVaXOULUBASnx5aCLuPYDKjkwLSw7igzfTmQsdTFnxyFpL2ehYfl+evE1CH/9xH0m/ 3yEsDaAHr3Q+3TBvh5V6UhrAN5VLXx83H3n2kXQtNIYql1Hg8XrUOJ0x3hjLYskP1+bQ XLtmtXR79lZjoaCF+hRLIxlVRSfVRsbPwOOyEgAsnyFVYrlfy88SsN1gnkjkjdmIVHDL SOkQ== 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:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=dkTzWROR4bXp+ugDMFMrQiuwvR0VxPcZMDrgVH1CjZg=; fh=dq4FhjzUuIpWwad8kwywSU2C+En0EZ9hE+DKQZ0Q1nM=; b=wukWiX0QeyEFVG4qQEFVYWkIxYCpPP5z2sZRnWGxTMb1fMayJDvBgUjw98Klo0E2jo 37iGiz0ssx40xforZ3yPE00diapmDxMx0GkIujxropMeawA/CmKPNjg8az+XwRhkvD7a P05INHi99jG1pcSj7Jc61I7JtUYcVaGY9NVrRTt2W5VGByqLf3TtX6wflTdSRht/1MoB V/OuLoP3V3T9adkMv0joFsbZqs7Bd5nPgm730bBK4aUa9mVsxYUiRPtImUpz7nHyXI9q fXlXoHqJglfv2JdO1bAyN27uy7UC4DlTmjKixIvWiqWvQ1DyI9yOi9Wm5e51WOWiMOKi znVA==; 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-190573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190573-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 d2e1a72fcca58-6f8fd4d1658si3581255b3a.252.2024.05.27.05.31.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190573-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-190573-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190573-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 67557B24400 for ; Mon, 27 May 2024 12:23:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E905815E5A2; Mon, 27 May 2024 12:23:14 +0000 (UTC) Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) (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 9FFC43C463; Mon, 27 May 2024 12:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716812594; cv=none; b=crvWafTi045foNSzNHAiYGWDEzSFUGx+sO3X36zfVnFnR1VADXNz+BqMzQ0vV8i88CL2rQ5fkqDKQGEKsZ+u3cSl+7ix0AUqJ8hQnd/KUeBXPWZ/f+dVo6YwurPm40x+eYe/DGr2HzDUZyDHUSxoy+qUvSrzju69Z184sqecELA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716812594; c=relaxed/simple; bh=g+274Zd16a/afuTgix5rR0iNpzqwOmfPQ4ggj7SGsRQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IV/96fbmme+SfgESMdzIFc0hEycWg+D2Eg2X3TUpTtdBuPDnHlDGvENeaIg5nBSPnnDk4bwu4a2zm7a+b5pDO9IyFzIlHkyw201dDxPqs9aE0S8NUBPN5VmUjSJyXHjPpPNhHS0dRxgDkQhb/Q6bPaj/DegWXNs+QgPuM0dbirg= 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.46 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.51]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4VnvVd0hshz9v7J2; Mon, 27 May 2024 20:05:45 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id 1AABA1400D5; Mon, 27 May 2024 20:23:02 +0800 (CST) Received: from [10.221.98.131] (unknown [10.221.98.131]) by APP2 (Coremail) with SMTP id GxC2BwBHgCQZe1RmtJIACQ--.46068S2; Mon, 27 May 2024 13:23:01 +0100 (CET) Message-ID: <1a3c892c-903e-8fd3-24a6-2454c2a55302@huaweicloud.com> Date: Mon, 27 May 2024 14:22:47 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] tools/memory-model: Document herd7 (internal) representation To: Andrea Parri , stern@rowland.harvard.edu, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, 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 Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, jonas.oberhauser@huaweicloud.com References: <20240524151356.236071-1-parri.andrea@gmail.com> Content-Language: en-US From: Hernan Ponce de Leon In-Reply-To: <20240524151356.236071-1-parri.andrea@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:GxC2BwBHgCQZe1RmtJIACQ--.46068S2 X-Coremail-Antispam: 1UD129KBjvJXoWxtr1ftw1kJF4xKFyUZFWxtFb_yoW7CFWxpr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rea Parri wrote: > tools/memory-model/ and herdtool7 are closely linked: the latter is > responsible for (pre)processing each C-like macro of a litmus test, > and for providing the LKMM with a set of events, or "representation", > corresponding to the given macro. Provide herd-representation.txt > to document the representation of synchronization macros, following > their "classification" in Documentation/atomic_t.txt. > > Suggested-by: Hernan Ponce de Leon > Signed-off-by: Andrea Parri > --- > - Leaving srcu_{up,down}_read() and smp_mb__after_srcu_read_unlock() for > the next version. > > - Limiting to "add" and "and" ops (skipping similar/same representations > for "sub", "inc", "dec", "or", "xor", "andnot"). > > - While preparing this submission, I recalled that atomic_add_unless() > is not listed in the .def file. I can't remember the reason for this > omission though. > > - While checking the information below using herd7, I've observed some > "strange" behavior with spin_is_locked() (perhaps, unsurprisingly...); > IAC, that's also excluded from this table/submission. > > > .../Documentation/herd-representation.txt | 81 +++++++++++++++++++ > 1 file changed, 81 insertions(+) > create mode 100644 tools/memory-model/Documentation/herd-representation.txt > > diff --git a/tools/memory-model/Documentation/herd-representation.txt b/tools/memory-model/Documentation/herd-representation.txt > new file mode 100644 > index 0000000000000..94d0d0a9eee50 > --- /dev/null > +++ b/tools/memory-model/Documentation/herd-representation.txt > @@ -0,0 +1,81 @@ > + --------------------------------------------------------------------------- > + | C macro | Events | > + --------------------------------------------------------------------------- > + | Non-RMW ops | | > + --------------------------------------------------------------------------- > + | READ_ONCE | R[once] | > + | atomic_read | (as in the previous row) | > + | WRITE_ONCE | W[once] | > + | atomic_set | | > + | smp_load_acquire | R[acquire] | > + | atomic_read_acquire | | > + | smp_store_release | W[release] | > + | atomic_set_release | | > + | smp_store_mb | W[once] ->po F[mb] | I expect this one to be hard-coded in herd7 source code, but I cannot find it. Can you give me a pointer? In fact, dartagnan uses W[Mb] ... another clear example of the need for documentation as this one. > + | smp_mb | F[mb] | > + | smp_rmb | F[rmb] | > + | smp_wmb | F[wmb] | > + | smp_mb__before_atomic | F[before-atomic] | > + | smp_mb__after_atomic | F[after-atomic] | > + | spin_unlock | UL | > + | smp_mb__after_spinlock | F[after-spinlock] | > + | smp_mb__after_unlock_lock | F[after-unlock-lock] | > + | rcu_read_lock | F[rcu-lock] | > + | rcu_read_unlock | F[rcu-unlock] | > + | synchronize_rcu | F[sync-rcu] | > + | rcu_dereference | R[once] | > + | rcu_assign_pointer | W[release] | > + | srcu_read_lock | R[srcu-lock] | > + | srcu_read_unlock | W[srcu-unlock] | > + | synchronize_srcu | SRCU[sync-srcu] | > + --------------------------------------------------------------------------- > + | RMW ops w/o return value | | > + --------------------------------------------------------------------------- > + | atomic_add | R*[noreturn] ->rmw W*[once] | > + | atomic_and | | > + | spin_lock | LKR ->lk-rmw LKW | What about spin_unlock? > + --------------------------------------------------------------------------- > + | RMW ops w/ return value | | > + --------------------------------------------------------------------------- > + | atomic_add_return | F[mb] ->po R*[once] | > + | | ->rmw W*[once] ->po F[mb] | > + | atomic_fetch_add | | > + | atomic_fetch_and | | > + | atomic_xchg | | > + | xchg | | > + | atomic_add_negative | | > + | atomic_add_return_relaxed | R*[once] ->rmw W*[once] | > + | atomic_fetch_add_relaxed | | > + | atomic_fetch_and_relaxed | | > + | atomic_xchg_relaxed | | > + | xchg_relaxed | | > + | atomic_add_negative_relaxed | | > + | atomic_add_return_acquire | R*[acquire] ->rmw W*[once] | > + | atomic_fetch_add_acquire | | > + | atomic_fetch_and_acquire | | > + | atomic_xchg_acquire | | > + | xchg_acquire | | > + | atomic_add_negative_acquire | | > + | atomic_add_return_release | R*[once] ->rmw W*[release] | > + | atomic_fetch_add_release | | > + | atomic_fetch_and_release | | > + | atomic_xchg_release | | > + | xchg_release | | > + | atomic_add_negative_release | | > + --------------------------------------------------------------------------- > + | Conditional RMW ops | | > + --------------------------------------------------------------------------- > + | atomic_cmpxchg | On success: F[mb] ->po R*[once] | > + | | ->rmw W*[once] ->po F[mb] | > + | | On failure: R*[once] | > + | cmpxchg | | > + | atomic_add_unless | | > + | atomic_cmpxchg_relaxed | On success: R*[once] ->rmw W*[once] | > + | | On failure: R*[once] | > + | atomic_cmpxchg_acquire | On success: R*[acquire] ->rmw W*[once] | > + | | On failure: R*[once] | > + | atomic_cmpxchg_release | On success: R*[once] ->rmw W*[release] | > + | | On failure: R*[once] | > + | spin_trylock | On success: LKR ->lk-rmw LKW | > + | | On failure: LF | > + --------------------------------------------------------------------------- I found the extra spaces in the failure case very hard to read. Any particular reason why you went with this format? Hernan