From patchwork Thu Jan 26 10:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13116887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD10EC54EAA for ; Thu, 26 Jan 2023 10:47:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=g58xo4xwZKhQ4xdCGKUMGjCYaiYW0ZFOHn46W5PJBVw=; b=GUqhU7KmVTh2hI 9DNMyedll1zfks/ySQS1nvMO3OF2y7uY1WJoUl/1gXe2XdYL/MLNpDd/cf3F4AJWNm72m9XZmegx4 zbZW1FuAjFMEpqwrw25nyrk+9oLYsHzd0DOlLl7sML1nkhFL9DGBdyZoPRFfdd/xqoiGgRzT1vwSB OuSFJTmBR06yKeBmE5KiOU/01Qcg+olj4T8XHdT/SAfXoSvDSib5sKcMlgT5rIni9KdQcEoUVFNJR y6ouDRfDf5Nt91zH1k4+OUWRpjc1mjiMlz3ltjvpjOEQzY4/lRA2U+9l6tB0uXhohxXddXwRNpcBV P2s8g+gNK5AlY8pCb4jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKzlc-00AXw6-2N; Thu, 26 Jan 2023 10:46:04 +0000 Received: from albert.telenet-ops.be ([2a02:1800:110:4::f00:1a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKzlW-00AXr8-Kx for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 10:46:01 +0000 Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed50:735b:e883:8069:427]) by albert.telenet-ops.be with bizsmtp id DNle2900V4pY4D906NlfsF; Thu, 26 Jan 2023 11:45:50 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1pKzl1-007R9r-V2; Thu, 26 Jan 2023 11:45:38 +0100 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1pKzlC-003tYg-Pt; Thu, 26 Jan 2023 11:45:38 +0100 From: Geert Uytterhoeven To: Stephen Boyd , Krzysztof Kozlowski , Tomasz Figa , Sylwester Nawrocki , Will Deacon , Arnd Bergmann , Wolfram Sang , Dejin Zheng , Kai-Heng Feng , Nicholas Piggin , Heiko Carstens , Peter Zijlstra , Russell King Cc: linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH resend] iopoll: Call cpu_relax() in busy loops Date: Thu, 26 Jan 2023 11:45:37 +0100 Message-Id: <8d492ee4a391bd089a01c218b0b4e05cf8ea593c.1674729407.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_024558_879332_0C7FA892 X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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. - 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. Signed-off-by: Geert Uytterhoeven Acked-by: Peter Zijlstra (Intel) Acked-by: Arnd Bergmann --- Resent with a larger audience due to lack of comments. This has been discussed before, but I am not aware of any patches moving forward: - "Re: [PATCH 6/7] clk: renesas: rcar-gen3: Add custom clock for PLLs" https://lore.kernel.org/all/CAMuHMdWUEhs=nwP+a0vO2jOzkq-7FEOqcJ+SsxAGNXX1PQ2KMA@mail.gmail.com/ - "Re: [PATCH v2] clk: samsung: Prevent potential endless loop in the PLL set_rate ops" https://lore.kernel.org/all/20200811164628.GA7958@kozik-lap --- include/linux/iopoll.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 2c8860e406bd8cae..73132721d1891a2e 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -53,6 +53,8 @@ } \ if (__sleep_us) \ usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + else \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) @@ -95,6 +97,7 @@ } \ if (__delay_us) \ udelay(__delay_us); \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ })