Message ID | d25a332bbb792f4c8d74f7e54bf9ca1d706979d9.1670495642.git.geert+renesas@glider.be |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp187135wrr; Thu, 8 Dec 2022 05:16:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5M2j1xupU8/xQHjLYkm1jXiS1GnNLLJmp0AZlNnUMGG5q4E7+F2XN2YePmgktCIcaC+/21 X-Received: by 2002:a17:906:a083:b0:7b2:b15e:322f with SMTP id q3-20020a170906a08300b007b2b15e322fmr75962462ejy.75.1670505368244; Thu, 08 Dec 2022 05:16:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670505368; cv=none; d=google.com; s=arc-20160816; b=eQlvyzFW6erHZiVFZMiNUpZ3WK3fyeQNxUsNtbza2p+1jj4Pq5xjfAIIs9ftPnfbhJ h4vdUnlAKaMw6XqQjSJlDAasWlUf62yL0ViNfKfJZT7Oq5vQOSBMdtcAISyyjyP1Wf/t fTpFZpzHhzR0YComER0NSORm7Zwa7U4akZVsH9pG1/pd5+XB/D0dPwwRwZl37u3ThdLW s5r4lMQnl5wSJMjKoYP5j4wILjsyPVK1GpYnbh97M0B+BS4RUDyfLKQcAGiIoHjzlVFk Aj2JKH9CvbBJMzI5N0SrMC3wPYlNHtTosChYt8JAWR1Q4mePc01vH3ovbwq5noLFSxh2 78oQ== 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; bh=ftIPt85qIlPMqE/Km7nF62y7P3zrCCHBT4PE20o1TvM=; b=QtK4bnQYLMIlMRba1SsnVRIT4gZPxCRHjiVFjp/biLkXaDM7zU7t6yl8RuF8eL9cfl laMWvoUcX72qngwkiufdjAXTsyAnOQB8lvicUPa0TfWzM+duf0uHpMhKMPdbkOq08hZP v0kYz65yHfi52geYGPHUnCE90tmSianWl3LDEdxqtE+8y01b6wbXKGDD0PODRkgJu5xM lxnU0lSPCVPvKI07EOPL7+vd7QPyzwcKgQkKWG3TwQBQ/grwUd7cv3O5mobYuUGIpm+t TTFN6iuo4TmBQR409xOuoIH0uf1lWoFa0IpiqxWeEFSE7Bah/s0JOX26WND1njPYqCY2 QriA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb10-20020a0564020d0a00b0046c77f0b6bcsi6995550edb.562.2022.12.08.05.15.44; Thu, 08 Dec 2022 05:16:08 -0800 (PST) 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 S230241AbiLHNH6 (ORCPT <rfc822;foxyelen666@gmail.com> + 99 others); Thu, 8 Dec 2022 08:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbiLHNHw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 8 Dec 2022 08:07:52 -0500 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2060C2EF45 for <linux-kernel@vger.kernel.org>; Thu, 8 Dec 2022 05:07:45 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:5574:4fdf:a801:888e]) by albert.telenet-ops.be with bizsmtp id tp7d2800K2deJRf06p7dvV; Thu, 08 Dec 2022 14:07:43 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from <geert@linux-m68k.org>) id 1p3GIF-002tBF-6Q; Thu, 08 Dec 2022 13:46:27 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from <geert@linux-m68k.org>) id 1p3EN6-003gqg-Pz; Thu, 08 Dec 2022 11:43:20 +0100 From: Geert Uytterhoeven <geert+renesas@glider.be> To: Stephen Boyd <sboyd@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>, Tomasz Figa <tomasz.figa@gmail.com>, Sylwester Nawrocki <s.nawrocki@samsung.com>, Will Deacon <will@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Wolfram Sang <wsa+renesas@sang-engineering.com>, Dejin Zheng <zhengdejin5@gmail.com>, Kai-Heng Feng <kai.heng.feng@canonical.com> 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 <geert+renesas@glider.be> Subject: [PATCH] iopoll: Call cpu_relax() in busy loops Date: Thu, 8 Dec 2022 11:43:19 +0100 Message-Id: <d25a332bbb792f4c8d74f7e54bf9ca1d706979d9.1670495642.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751651837095366674?= X-GMAIL-MSGID: =?utf-8?q?1751651837095366674?= |
Series |
iopoll: Call cpu_relax() in busy loops
|
|
Commit Message
Geert Uytterhoeven
Dec. 8, 2022, 10:43 a.m. UTC
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 <geert+renesas@glider.be>
---
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; \ })