Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8380314rwr; Wed, 10 May 2023 23:53:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nBJODIo3rHeLAYML2C8jiiOt9EDcR76DkYAxv/YKtkFVN7gAZ864uhhxyJAmuXs9SSNMs X-Received: by 2002:a05:6a20:12cd:b0:101:7ccd:e197 with SMTP id v13-20020a056a2012cd00b001017ccde197mr9733602pzg.52.1683788004685; Wed, 10 May 2023 23:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683788004; cv=none; d=google.com; s=arc-20160816; b=jGk+J4voP+jBS3TSkIpgzfY1ijyrd+hvEnKCkx/95z/3JEfxLYbcixzGeMmEUCMU7L 6ILdhkRMZXd928vUvbomASd3nxdf8M9Vseq89YZeFLZxky+wuTDf16h3HEq6zgxbD3Vz bYHpEcN0yVrCitJ2haAUb7lwpU4sBLx3elp8iU4iAl121j24B3nnTsNA+jAT1l48dEJj jq86QnobQYunuVqKmbpkzqjCtF/oOMhbCMaHoefYTAPvwebL1Gg2pr6VKSry3Tu82RPD iwhPZiJzTLRdwcOjhmrw86/6aCjS0CVx7PRZV4KJt2k4q/DFmBxWipEWFBhq2KwaQqYZ SdOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/jZNMjSY1fILguplYPqTmlWJ+NOubwScu2vcltfthgA=; b=FTgA4CPXBJMG4xbuRd62J0L3KTfAR9xYI8rGrN6WvvQOiVgXZ4K5oA5CDr+a6cklwv elzAL9eWcc1gUceb2GHlGHew08Ca5xKe2y41fqrjkBOtTwDaz2ugkVLvYqv9NUAzd4/O aM3aFPmL0lXsgszZ7JIn+0GpyVeHjsHqM2+/W3drtMawJ5vA1aMpSp6j2b7hP/4ExFNA bb3ktn5l2QqXnUGGtu2nhTOqQkCM9wyNBqB0Pizimm41ktO3IBiOrBncY8L1HpCZ/3Of pRQubEtdWm6RlPrSHkow+96MXLVKGrGtOTAreZMhI3RGrK2+IDOKFJQq97wlEqtyfgHS qTOw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm18-20020a656e92000000b00524f1f0d021si6258465pgb.371.2023.05.10.23.53.11; Wed, 10 May 2023 23:53:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236884AbjEKGs5 (ORCPT + 99 others); Thu, 11 May 2023 02:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjEKGsm (ORCPT ); Thu, 11 May 2023 02:48:42 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8CA2B173A; Wed, 10 May 2023 23:48:41 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id D98A0807A; Thu, 11 May 2023 06:48:40 +0000 (UTC) Date: Thu, 11 May 2023 09:48:39 +0300 From: Tony Lindgren To: Geert Uytterhoeven Cc: Stephen Boyd , Tomasz Figa , Sylwester Nawrocki , Will Deacon , Arnd Bergmann , Wolfram Sang , Dejin Zheng , Kai-Heng Feng , Nicholas Piggin , Heiko Carstens , Peter Zijlstra , Russell King , John Stultz , Thomas Gleixner , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] iopoll: Call cpu_relax() in busy loops Message-ID: <20230511064839.GG14287@atomide.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 * Geert Uytterhoeven [230510 13:23]: > It is considered good practice to call cpu_relax() in busy loops, see > Documentation/process/volatile-considered-harmful.rst. This can not > only lower CPU power consumption or yield to a hyperthreaded twin > processor, but also allows an architecture to mitigate hardware issues > (e.g. ARM Erratum 754327 for Cortex-A9 prior to r2p0) in the > architecture-specific cpu_relax() implementation. > > In addition, cpu_relax() is also a compiler barrier. It is not > immediately obvious that the @op argument "function" will result in an > actual function call (e.g. in case of inlining). > > Where a function call is a C sequence point, this is lost on inlining. > Therefore, with agressive enough optimization it might be possible for > the compiler to hoist the: > > (val) = op(args); > > "load" out of the loop because it doesn't see the value changing. The > addition of cpu_relax() would inhibit this. > > As the iopoll helpers lack calls to cpu_relax(), people are sometimes > reluctant to use them, and may fall back to open-coded polling loops > (including cpu_relax() calls) instead. > > Fix this by adding calls to cpu_relax() to the iopoll helpers: > - For the non-atomic case, it is sufficient to call cpu_relax() in > case of a zero sleep-between-reads value, as a call to > usleep_range() is a safe barrier otherwise. However, it doesn't > hurt to add the call regardless, for simplicity, and for similarity > with the atomic case below. > - For the atomic case, cpu_relax() must be called regardless of the > sleep-between-reads value, as there is no guarantee all > architecture-specific implementations of udelay() handle this. Reviewed-by: Tony Lindgren