Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp395959lqt; Thu, 6 Jun 2024 06:59:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8kCU99ssBWclk108lMI9WpKRGgFjg9z6KCnX3CgV9bRWDeDeBgGwE28xmb0ujRwuLtdnQAeba2HAvfelADaoOwo3BLFrgwxFpz1GCOw== X-Google-Smtp-Source: AGHT+IFJxluAmCAcjxkNXh9y+8+kBDUxbOYQYTdPO6RQB37TbXKUzPrmsWgNL6CqfrjDqZEw3y4I X-Received: by 2002:a05:6214:5349:b0:6ae:1a96:efde with SMTP id 6a1803df08f44-6b030a5bf95mr65816806d6.40.1717682349701; Thu, 06 Jun 2024 06:59:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717682349; cv=pass; d=google.com; s=arc-20160816; b=vyT1KAZNC8wprCMPNSJ1NgcCcaP7ZTndO21wcWpAJdnvY2PAnH9sh+yDKBIy/uuD1L jJCj4IpRQa6Y64uaCBWY2pFXiOCzODr7BJCy+EnN7Bhg3OOebwEgDzHTu6gX9TWi1Nws 5ju96czkLl+vNvryhevN4ArGNQLqR/xEn0peL33pqL4VKOea4pZhZrf2Wpoi+cZDu1r2 4a1TFfKxPfbctB4oVuhtu88OBeclWT72S5WTH/zmU69xyTZoufnEyAngEKiw40mYJDWE 4gFU5DEvYqiwdYdx71jOWAmA9Sf8rxQD6oRLsXL1IxBHdloSnJujRiPq60LjOhBYAYAO SjMg== 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=tmt4arY+7Spw+wiT8Doph0BUmW9r2oixN9iuax46uqM=; fh=0zCIpKUUfXNR4vgEGKRVdryXrgfIVE1T7Yen7VUJyhA=; b=IR9BiZJaexzLsBoJBCUbogZwZ08Wc1DzXR9NSD/36nlV67QXrD1+MgAqCDY9DhLbwq dd6zf0XARE+zG8l3OC7W+RxQlh6ka1Sy8gX3FAEAvHpf7tJWh0SbpxVTfiNO4BH9UHmb ChKd86xlyqlMdmVO5szf1hu9VazHCG3uNl/0v0uBVMPhDxT+BqvaEdYq5282WAdJG/C+ nmUZIpU2zGQFdfN9XlcDDsdMkC4bL5NJCKElSfp2Lr2dTrwhQjAea9uUFcckJseDZefu NeeofBd6i/WxZgMCC+bYY/C0L7cKaUkDX1XA/sJuRpFdqI+Ru/9V+B9at++y+an78gsB v/ww==; 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-204403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b04fa45b48si12651766d6.591.2024.06.06.06.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 06:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=netrider.rowland.org); spf=pass (google.com: domain of linux-kernel+bounces-204403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204403-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6BAD31C2288E for ; Thu, 6 Jun 2024 13:59:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB7CD19645B; Thu, 6 Jun 2024 13:59:04 +0000 (UTC) Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id D2B03196442 for ; Thu, 6 Jun 2024 13:59:02 +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=1717682344; cv=none; b=SeSTr9MlkBaQqHn5E9k8C1cETfUtRJCXF04z8ZFUiiKHOO6dExn6hkI+HRWIkV34P3icXddUeNLEZsykh38IkNyPhDnEuyhh1rx+JtD3t72kMJy8aw752tIQbh8oFDTmadrmLTFx6deuR91v7xQk7gHB2Sr/2L3RtTezBPye930= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717682344; c=relaxed/simple; bh=oEB3iQ7W0LF4mrGeU/QllrcvNYC47ASB9Gkcuve3NnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=diyOjNGiN12MgTY4pgDHNsc4Ef4DkibaXxA+XGLHjxdc9iNrt8/cjDN6asS1r/rej5wvneQXQztpXy8X3OvGAKlsiOVEgOlv12Xp/9Fw5YpCbUpsmooZ0GDsD4vjIsnSkaXcIzCMquXyd6t56SVLq8joPpSSgDCADwAwTxYN+6U= 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 231206 invoked by uid 1000); 6 Jun 2024 09:59:01 -0400 Date: Thu, 6 Jun 2024 09:59:01 -0400 From: Alan Stern To: "Paul E. McKenney" Cc: Andrea Parri , 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, akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org, linux-kernel@vger.kernel.org, hernan.poncedeleon@huaweicloud.com, jonas.oberhauser@huaweicloud.com Subject: [PATCH 2/2] tools/memory-model: Code reorganization in lock.cat Message-ID: <6211154e-7db9-4129-b0d4-26ff69e2398c@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: Code reorganization for the lock.cat file in tools/memory-model: Improve the efficiency by ruling out right at the start RU events (spin_is_locked() calls that return False) inside a critical section for the same lock. Improve the organization of the code for handling LF and RU events by pulling the definitions of the pair-to-relation macro out from two different complicated compound expressions, using a single standalone definition instead. Rewrite the calculations of the rf relation for LF and RU events, for greater clarity. Signed-off-by: Alan Stern --- tools/memory-model/lock.cat | 56 +++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 21 deletions(-) Index: usb-devel/tools/memory-model/lock.cat =================================================================== --- usb-devel.orig/tools/memory-model/lock.cat +++ usb-devel/tools/memory-model/lock.cat @@ -54,6 +54,12 @@ flag ~empty LKR \ domain(lk-rmw) as unpa *) empty ([LKW] ; po-loc ; [LKR]) \ (po-loc ; [UL] ; po-loc) as lock-nest +(* + * In the same way, spin_is_locked() inside a critical section must always + * return True (no RU events can be in a critical section for the same lock). + *) +empty ([LKW] ; po-loc ; [RU]) \ (po-loc ; [UL] ; po-loc) as nested-is-locked + (* The final value of a spinlock should not be tested *) flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final @@ -79,39 +85,47 @@ empty ([UNMATCHED-LKW] ; loc ; [UNMATCHE (* rfi for LF events: link each LKW to the LF events in its critical section *) let rfi-lf = ([LKW] ; po-loc ; [LF]) \ ([LKW] ; po-loc ; [UL] ; po-loc) -(* rfe for LF events *) +(* Utility macro to convert a single pair to a single-edge relation *) +let pair-to-relation p = p ++ 0 + +(* + * If a given LF event e is outside a critical section, it cannot read + * internally but it may read from an LKW event in another thread. + * Compute the relation containing these possible edges. + *) +let possible-rfe-noncrit-lf e = (LKW * {e}) & loc & ext + +(* Compute set of sets of possible rfe edges for LF events *) let all-possible-rfe-lf = (* - * Given an LF event r, compute the possible rfe edges for that event - * (all those starting from LKW events in other threads), - * and then convert that relation to a set of single-edge relations. + * Convert the possible-rfe-noncrit-lf relation for e + * to a set of single edges *) - let possible-rfe-lf r = - let pair-to-relation p = p ++ 0 - in map pair-to-relation ((LKW * {r}) & loc & ext) - (* Do this for each LF event r that isn't in rfi-lf *) - in map possible-rfe-lf (LF \ range(rfi-lf)) + let set-of-singleton-rfe-lf e = + map pair-to-relation (possible-rfe-noncrit-lf e) + (* Do this for each LF event e that isn't in rfi-lf *) + in map set-of-singleton-rfe-lf (LF \ range(rfi-lf)) (* Generate all rf relations for LF events *) with rfe-lf from cross(all-possible-rfe-lf) let rf-lf = rfe-lf | rfi-lf (* - * RU, i.e., spin_is_locked() returning False, is slightly different. - * We rely on the memory model to rule out cases where spin_is_locked() - * within one of the lock's critical sections returns False. + * A given RU event e may read internally from the last po-previous UL, + * or it may read from a UL event in another thread or the initial write. + * Compute the relation containing these possible edges. *) +let possible-rf-ru e = (((UL * {e}) & po-loc) \ + ([UL] ; po-loc ; [UL] ; po-loc)) | + (((UL | IW) * {e}) & loc & ext) -(* - * rf for RU events: an RU may read from an external UL or the initial write, - * or from the last po-previous UL - *) +(* Compute set of sets of possible rf edges for RU events *) let all-possible-rf-ru = - let possible-rf-ru r = - let pair-to-relation p = p ++ 0 - in map pair-to-relation ((((UL | IW) * {r}) & loc & ext) | - (((UL * {r}) & po-loc) \ ([UL] ; po-loc ; [LKW] ; po-loc))) - in map possible-rf-ru RU + (* Convert the possible-rf-ru relation for e to a set of single edges *) + let set-of-singleton-rf-ru e = + map pair-to-relation (possible-rf-ru e) + (* Do this for each RU event e *) + in map set-of-singleton-rf-ru RU (* Generate all rf relations for RU events *) with rf-ru from cross(all-possible-rf-ru)