Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp424702iog; Wed, 15 Jun 2022 05:14:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy77601c2E2jkAPZlCYIoCnNio9I4zW9s52prSeALFCJHFpmbRwfIoX/h3GNEm+Mky4XXnq X-Received: by 2002:a05:6402:1c91:b0:42d:c9b6:506b with SMTP id cy17-20020a0564021c9100b0042dc9b6506bmr12431422edb.166.1655295272586; Wed, 15 Jun 2022 05:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655295272; cv=none; d=google.com; s=arc-20160816; b=WjbnrsZilxZF4whi1coqw8uT6Z52Qf4dKbmGgjBdtpK6ZD6+K5v464E8JcaBzsT1Va e98B+x96xaDZxSpW8BYb+IfmKHdQ6Uv5xHKwBHOQjFi2yyfG7OnsEOt4+hgMeEGhE2jJ fGH7D7Xs/yzS6QknVivWEprGJrUP6fdJ+3yH3ur1SFfGaOooix4HawZj1dnpL/8AArJR wxwX+c7dKKhoYHeQ4wzQAsJkUDL1TcumtJooHj/eEzTGQI/tOS9v55GLiyVfafMCpEwI CSdHJQ8XRpqbS4Y7Xuq2oYvkj4gkadFkA2r9++9K2GqWVUmWJP+656Lx5gGBAuHQZXeF 5kSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2kjF4oxVy3r0fd0SR9Tiy0/qNbtSE87Bz7BjdDbE1WQ=; b=p0SZoX+0nZ2HSVfJ7tbxZRaSZc4e1IwoJfNme98rb8YE/xTmGSMAUdMDsZ/ubyOFi7 5N3pN6nWYyXBly6xpMn4vMmZJXh5ybevhXLE2GRCFB2NDbxOnWa1GJMvkkhpR/bMF15C 9QmsyvkuSR6nDye6XhCIX2urGtoh62j/rCw6p4fseF7vJlBsm4lD1PDRD1NLaFP8l2gz tYjsSPZVUqBSuHtILM45TMLLYbyyheJx2vpSZQpQzz7rD3JhuFAt6gOjea3C0eELkCOu bbGPzabmEiWdjXkDj0h5dCzZFMHMdCqgmTuU8PrwYpaj0M64kP5opbRZf5ovQJD5CL6B xjjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@in.tum.de header.s=20220209 header.b=NQ3JEMN2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tum.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id es8-20020a056402380800b004352155fc0asi1514376edb.261.2022.06.15.05.14.06; Wed, 15 Jun 2022 05:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@in.tum.de header.s=20220209 header.b=NQ3JEMN2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tum.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347354AbiFOLn6 (ORCPT + 99 others); Wed, 15 Jun 2022 07:43:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347117AbiFOLno (ORCPT ); Wed, 15 Jun 2022 07:43:44 -0400 Received: from mailout3.rbg.tum.de (mailout3.rbg.tum.de [131.159.0.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB5927CF6; Wed, 15 Jun 2022 04:43:43 -0700 (PDT) Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout3.rbg.tum.de (Postfix) with ESMTPS id 3D867100241; Wed, 15 Jun 2022 13:43:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.tum.de; s=20220209; t=1655293421; bh=2kjF4oxVy3r0fd0SR9Tiy0/qNbtSE87Bz7BjdDbE1WQ=; h=From:To:Cc:Subject:Date:From; b=NQ3JEMN2ZHuNO/jk9Av7B/H/0KpYlcVLlKXKDbQyjFUGHSs9eA9lMK8Lb5Slu6MdY HcTOP24C86scrmcGGk01sFNf5waZuYfo0K92v+lEx6j2EFBxU6rqq3RmGOzrcfu0m3 hA/W9Q7JcCktMgWsoA4AP/p4CRaZz1jgznKU8IAd6uN9NTQwaHKiKLXZAoGFXruKg+ 7vbzwsy69l+TbNglfkS+nBbSJPe2tw3NYT13otO1+Ca4Dn6otyByXM0zhnI1rqfS4W kWyMb7r4EliCIh4QwQdEJS00rR1dWRg/4hM1staWVoKKc2EAFsRIF1x0aygVIyunKK pX9cOhuqMCCtw== Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id 3D0B1DD; Wed, 15 Jun 2022 13:43:41 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id 198DED6; Wed, 15 Jun 2022 13:43:41 +0200 (CEST) Received: from mail.in.tum.de (vmrbg426.in.tum.de [131.159.0.73]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id 14250CE; Wed, 15 Jun 2022 13:43:41 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id 087424A0220; Wed, 15 Jun 2022 13:43:41 +0200 (CEST) Received: (Authenticated sender: heidekrp) by mail.in.tum.de (Postfix) with ESMTPSA id A477F4A01E7; Wed, 15 Jun 2022 13:43:40 +0200 (CEST) (Extended-Queue-bit xtech_ko@fff.in.tum.de) From: =?UTF-8?q?Paul=20Heidekr=C3=BCger?= To: llvm@lists.linux.dev, linux-toolchains@vger.kernel.org, Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , Tom Rix , Palmer Dabbelt , =?UTF-8?q?Paul=20Heidekr=C3=BCger?= , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Marco Elver , Charalampos Mainas , Pramod Bhatotia , Soham Chakraborty , Martin Fink Subject: [PATCH RFC] tools/memory-model: Adjust ctrl dependency definition Date: Wed, 15 Jun 2022 11:43:29 +0000 Message-Id: <20220615114330.2573952-1-paul.heidekrueger@in.tum.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, I have been confused by explanation.txt's definition of control dependencies: > Finally, a read event and another memory access event are linked by a > control dependency if the value obtained by the read affects whether > the second event is executed at all. I'll go into the following: ==== 1. "At all", to me, is misleading 1.1 The code which confused me 1.2 The traditional definition via post-dominance doesn't work either 2. Solution ==== 1. "At all", to me, is misleading: "At all" to me suggests a question for which we require a definitive "yes" or "no" answer: given a programme and an input, can a certain piece of code be executed? Can we always answer this this question? Doesn't this sound similar to the halting problem? 1.1 The Example which confused me: For the dependency checker project [1], I've been thinking about tracking dependency chains in code, and I stumbled upon the following edge case, which made me question the "at all" part of the current definition. The below C-code is derived from some optimised kernel code in LLVM intermediate representation (IR) I encountered: > int *x, *y; > > int foo() > { > /* More code */ > > loop: > /* More code */ > > if(READ_ONCE(x)) { > WRITE_ONCE(y, 42); > return 0; > } > > /* More code */ > > goto loop; > > /* More code */ > } Assuming that foo() will return, the READ_ONCE() does not determine whether the WRITE_ONCE() will be executed __at all__, as it will be executed exactly when the function returns, instead, it determines __when__ the WRITE_ONCE() will be executed. 1.2. The definition via post-dominance doesn't work either: I have seen control dependencies being defined in terms of the first basic block that post-dominates the basic block of the if-condition, that is the first basic block control flow must take to reach the function return regardless of what the if condition returned. E.g. [2] defines control dependencies as follows: > A statement y is said to be control dependent on another statement x > if (1) there exists a nontrivial path from x to y such that every > statement z != x in the path is post-dominated by y, and (2) x is not > post-dominated by y. Again, this definition doesn't work for the example above. As the basic block of the if branch trivially post-dominates any other basic block, because it contains the function return. 2. Solution: The definition I came up with instead is the following: > A basic block B is control-dependent on a basic block A if > B is reachable from A, but control flow can take a path through A > which avoids B. The scope of a control dependency ends at the first > basic block where all control flow paths running through A meet. Note that this allows control dependencies to remain "unresolved". I'm happy to submit a patch which covers more of what I mentioned above as part of explanation.txt, but figured that in the spirit of keeping things simple, leaving out "at all" might be enough? What do you think? Many thanks, Paul [1]: https://lore.kernel.org/all/Yk7%2FT8BJITwz+Og1@Pauls-MacBook-Pro.local/T/#u [2]: Optimizing Compilers for Modern Architectures: A Dependence-Based Approach, Randy Allen, Ken Kennedy, 2002, p. 350 Signed-off-by: Paul Heidekrüger Cc: Marco Elver Cc: Charalampos Mainas Cc: Pramod Bhatotia Cc: Soham Chakraborty Cc: Martin Fink --- tools/memory-model/Documentation/explanation.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/memory-model/Documentation/explanation.txt b/tools/memory-model/Documentation/explanation.txt index ee819a402b69..42af7ed91313 100644 --- a/tools/memory-model/Documentation/explanation.txt +++ b/tools/memory-model/Documentation/explanation.txt @@ -466,7 +466,7 @@ pointer. Finally, a read event and another memory access event are linked by a control dependency if the value obtained by the read affects whether -the second event is executed at all. Simple example: +the second event is executed. Simple example: int x, y; -- 2.35.1