From patchwork Fri Jun 2 08:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp888858vqr; Fri, 2 Jun 2023 02:05:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lV2FdnaJRBKvCVjzaxpi8R7bIZxtNN1A3nWW9nFQjEMXqx3oOVeTMkLhiGU8Bf1nFSlUN X-Received: by 2002:a17:90a:e50a:b0:250:7347:39d9 with SMTP id t10-20020a17090ae50a00b00250734739d9mr922939pjy.37.1685696720356; Fri, 02 Jun 2023 02:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696720; cv=none; d=google.com; s=arc-20160816; b=ZpZfoJAV90hdcvusbNeunhbWzliDjesf/3EGx+ntSyKIeK5WAmJQyNH2MIxeL+hxno WL/t7YdZcBZR9MN4NhIU05jKCu6hJUbQo2OFm/zsEZyxDJl9Kb7T71Moy+aEzJKiCajc y2zUUsYQHpZhPjav4Z0T2jTj6bQa+tUZu9TPY+yxnurqZ+BgYU5NZABZbzqnKVPE16vo 3FONFw46CQeLd8gQK2hfe81HRYLHfcUsfMsGrWSaF/OG3FRHtGTwyoJ9kEwgLeJS88Qs A8vpIl0OedMyr1EwvloRIx39gghPeWmG+bOagN67Yca/G77lnSP3e09SPC/RTb7vvscH HCUg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UtDc6xTPLw+W0uCTOJiMcfXasxWfpaRoJbMiLb/Ldsw=; b=CqwBxUwIg1mknBi5l8cQonUU9OsHJtwIPAyr/qjG0xvH0Ngbh4996TnyXz0wyu9Xf8 mTPdwGHEOHLdqqqfN3r7ncrOhgqo9OsAM5zrflkol3dC++zfrG1pMIbDz/8al0Z1GTkQ WkXkOyAfeQfY4WRDBGNswBXZItUkD/367sbI+wHPcMbJSXYmE/fCct4CgxnEC1zLzlkw BqHA71+RKVsAx25B+uywGAk8Haiin3a3cdN7e3gMaVCc3RQ9W03I7JzRBPNeq65CEi5/ NY30yuwe1znOJJKwvCoDPMWuXNaFORA8seCAtopzmMbDhdLk6kfU30RS7VQ6JwKU6MzP aUiQ== 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 bs8-20020a632808000000b0053f21272753si695406pgb.9.2023.06.02.02.05.07; Fri, 02 Jun 2023 02:05:20 -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 S235023AbjFBIwq (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234919AbjFBIwA (ORCPT ); Fri, 2 Jun 2023 04:52:00 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A5DD1735 for ; Fri, 2 Jun 2023 01:51:16 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by laurent.telenet-ops.be with bizsmtp id 48qo2A00B1tRZS8018qoyS; Fri, 02 Jun 2023 10:51:14 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhY9-RW; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Uh-00APxS-V7; Fri, 02 Jun 2023 10:50:47 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 1/7] iopoll: Call cpu_relax() in busy loops Date: Fri, 2 Jun 2023 10:50:36 +0200 Message-Id: <45c87bec3397fdd704376807f0eec5cc71be440f.1685692810.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581123738673990?= X-GMAIL-MSGID: =?utf-8?q?1767581123738673990?= 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. Signed-off-by: Geert Uytterhoeven Acked-by: Peter Zijlstra (Intel) Acked-by: Arnd Bergmann Reviewed-by: Tony Lindgren Reviewed-by: Ulf Hansson --- v3: - Add Reviewed-by, v2: - Add Acked-by, - Add compiler barrier and inlining explanation (thanks, Peter!). --- include/linux/iopoll.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 2c8860e406bd8cae..0417360a6db9b0d6 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -53,6 +53,7 @@ } \ if (__sleep_us) \ usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) @@ -95,6 +96,7 @@ } \ if (__delay_us) \ udelay(__delay_us); \ + cpu_relax(); \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) From patchwork Fri Jun 2 08:50: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: 102394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp889253vqr; Fri, 2 Jun 2023 02:06:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55aPGHNmStXUDd5Az8S6eZMPDfA/cYGN88HuhBCTJ2vhXpK05/8sYk8dPmgagBvEdOb/n7 X-Received: by 2002:a17:902:e5c8:b0:1b0:3742:e732 with SMTP id u8-20020a170902e5c800b001b03742e732mr2020837plf.23.1685696763427; Fri, 02 Jun 2023 02:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696763; cv=none; d=google.com; s=arc-20160816; b=nUHDjj5eF2oJOE74vkyGqd5YAmMLKOZGc43LvGqkaOybazK2vi/+/bCUGXa/z4YwdF G2NvF4Jfd1h6MXbs3gvLYEVIkY5O5oIbbJP3bXgjyFQr/J8/jInM2bP/TwNPA8vCQsCG 1xatq8F7rCPhwHiSbTm0ojEAKK29QWErlUiLa9jzuW392EsJPq2qB6LykGwz8QmE9txO kR9jUMOb57vS8vJVIbXxUoaMS4Wk2sHUcGYnmnA5HtMCntpOuApxOtbDVxBeIrvZxAHf AFrucIvpwhPoDibYl5lEPg9lNqRfBmUH9rCVw7vgM5oFFqcjm5sy/mtZQQwtSEqV7A7A Cvkw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PkQBVPUAFZ5XEHFObGUj8TILXcCKIUCwq9u6TMBR4W8=; b=z61247o55ptjtW59TXEg+HHkRh1/7M3mVm0CXezf3xbp5PGsV9fEpDlo/Y0GnmXDfm pVTHC0lpW4T9o5aC3BoFprMnji4yX+sJyyVB69yPmia/j5rC67g89WF4RfCiLPffTmOS gcgn2ElN/oNcNjfF0WR4YVd4b3u+DZXKejw3laMZsYZaXfdERRDXyJ5lbARJwCA7+r3c nOdw9S8VHaz3UnUVje5eJjuIdxiHbg4T2/rCV4b3zQvgdwxrJKYwdsHjSBKgjhYOW5KL AcEU5uAmZ0b5WwjaTDC8bH5mZro877OJT58i3Na1yvqhhoG7Dd4OJEUnlqBsD0luXAzc uxgQ== 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 c1-20020a170903234100b001aff514a8f0si572167plh.534.2023.06.02.02.05.51; Fri, 02 Jun 2023 02:06:03 -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 S234253AbjFBIwW (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234861AbjFBIvv (ORCPT ); Fri, 2 Jun 2023 04:51:51 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7482F1722 for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by xavier.telenet-ops.be with bizsmtp id 48qo2A0041tRZS8018qoDF; Fri, 02 Jun 2023 10:51:12 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYB-SP; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Uh-00APxV-Vr; Fri, 02 Jun 2023 10:50:47 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 2/7] iopoll: Do not use timekeeping in read_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:37 +0200 Message-Id: <3d2a2f4e553489392d871108797c3be08f88300b.1685692810.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581169850862958?= X-GMAIL-MSGID: =?utf-8?q?1767581169850862958?= read_poll_timeout_atomic() uses ktime_get() to implement the timeout feature, just like its non-atomic counterpart. However, there are several issues with this, due to its use in atomic contexts: 1. When called in the s2ram path (as typically done by clock or PM domain drivers), timekeeping may be suspended, triggering the WARN_ON(timekeeping_suspended) in ktime_get(): WARNING: CPU: 0 PID: 654 at kernel/time/timekeeping.c:843 ktime_get+0x28/0x78 Calling ktime_get_mono_fast_ns() instead of ktime_get() would get rid of that warning. However, that would break timeout handling, as (at least on systems with an ARM architectured timer), the time returned by ktime_get_mono_fast_ns() does not advance while timekeeping is suspended. Interestingly, (on the same ARM systems) the time returned by ktime_get() does advance while timekeeping is suspended, despite the warning. 2. Depending on the actual clock source, and especially before a high-resolution clocksource (e.g. the ARM architectured timer) becomes available, time may not advance in atomic contexts, thus breaking timeout handling. Fix this by abandoning the idea that one can rely on timekeeping to implement timeout handling in all atomic contexts, and switch from a global time-based to a locally-estimated timeout handling. In most (all?) cases the timeout condition is exceptional and an error condition, hence any additional delays due to underestimating wall clock time are irrelevant. Signed-off-by: Geert Uytterhoeven Acked-by: Arnd Bergmann Reviewed-by: Tony Lindgren Reviewed-by: Ulf Hansson --- The first issue was seen with the rcar-sysc driver in the BSP, as the BSP contains modifications to the resume sequence of various PM Domains. v3: - Add Acked-by, Reviewed-by, - Add comment about not using timekeeping, and its impact, v2: - New. --- include/linux/iopoll.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 0417360a6db9b0d6..19a7b00baff43595 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -74,6 +74,10 @@ * Returns 0 on success and -ETIMEDOUT upon a timeout. In either * case, the last read value at @args is stored in @val. * + * This macro does not rely on timekeeping. Hence it is safe to call even when + * timekeeping is suspended, at the expense of an underestimation of wall clock + * time, which is rather minimal with a non-zero delay_us. + * * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. */ @@ -81,22 +85,30 @@ delay_before_read, args...) \ ({ \ u64 __timeout_us = (timeout_us); \ + s64 __left_ns = __timeout_us * NSEC_PER_USEC; \ unsigned long __delay_us = (delay_us); \ - ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ - if (delay_before_read && __delay_us) \ + u64 __delay_ns = __delay_us * NSEC_PER_USEC; \ + if (delay_before_read && __delay_us) { \ udelay(__delay_us); \ + if (__timeout_us) \ + __left_ns -= __delay_ns; \ + } \ for (;;) { \ (val) = op(args); \ if (cond) \ break; \ - if (__timeout_us && \ - ktime_compare(ktime_get(), __timeout) > 0) { \ + if (__timeout_us && __left_ns < 0) { \ (val) = op(args); \ break; \ } \ - if (__delay_us) \ + if (__delay_us) { \ udelay(__delay_us); \ + if (__timeout_us) \ + __left_ns -= __delay_ns; \ + } \ cpu_relax(); \ + if (__timeout_us) \ + __left_ns--; \ } \ (cond) ? 0 : -ETIMEDOUT; \ }) From patchwork Fri Jun 2 08:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp888961vqr; Fri, 2 Jun 2023 02:05:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4CmLALuz9X/IOdTp/G2UUpy3y/y3onYkjAeCQ8KTUtCl/yBJdkL63zcghVI2GybkJBj49V X-Received: by 2002:a05:6a20:8f11:b0:10f:8528:38b3 with SMTP id b17-20020a056a208f1100b0010f852838b3mr4319852pzk.20.1685696729947; Fri, 02 Jun 2023 02:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696729; cv=none; d=google.com; s=arc-20160816; b=HX4XOjLnQFSkVmQrrvF1HEQ3yFua3hPzEUoTSxoJ5R03FevW3sZTSwi90/Kjx+dQDA xYxuRJ2Gn9tKWPBod/7nRxKW/DdJAOdBv//YU8HsCYDja2oeUbfMhquAB0ga+G4TVuaB PUqNMUJMiV8Rh04tfQVKSEYse4PM3H6rJDmaohuxOL4Bx/nb8XYV8+UI6zR0x/7ra3Px UIqqxmtqiLO0RPxKzDVweabqL+uFEuWSfc9RokX1Ne3YeEm99WJA7EDFUy1T5vVcy1mi P5VHFl3nHiGUuld13kZVx+ttZtaVxyx6kjtP8cU0/K94su/pJhd59SOH7cEap+5JNIpX 52xg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=j6ocvTJdjX+rnntSrwpofJOK/WbMsQ9EDfz5XZhCCjM=; b=VCjvU2UCfc11JujxqfcGKn07B8JYGZrWYPZoUs2bOk8U568UnTBLl6jxxz2mvTZRoC 3m6OY/KUHCwVYwf33K9SHVnGSR6n6F5WZbAcO6ZYMGsC4oVt2LQL+p6LrXiZ8Ynih9Ph qKI0VoA+f6jlLusV/TY17KwwY3r+PWZbNcaUH6VrDE2GQq1siToKw6lhOdpMAvIXn104 mTNFwSYDR1DqupxMQWOENZgGj17ii0F7qT+ZEYBvaXazp7po8rGLFlZAuSpD9kkPS9Rr X3rDEfwuzc8lY/GJZjWwdWUz2tNHzMjYQhzqSdRAAIlaUFe/HGV1tbBEdRSVn3ZAsh6L 8O1g== 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 p16-20020a639510000000b0053fa4589ce2si668868pgd.601.2023.06.02.02.05.17; Fri, 02 Jun 2023 02:05:29 -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 S234796AbjFBIwY (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234875AbjFBIvw (ORCPT ); Fri, 2 Jun 2023 04:51:52 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707B310DB for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by xavier.telenet-ops.be with bizsmtp id 48qo2A0061tRZS8018qoDG; Fri, 02 Jun 2023 10:51:12 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYG-TJ; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxY-0T; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 3/7] clk: renesas: cpg-mssr: Convert to readl_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:38 +0200 Message-Id: <832d29fd9aa3239ea949535309d2bdb003d40c9e.1685692810.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581134028797926?= X-GMAIL-MSGID: =?utf-8?q?1767581134028797926?= Use readl_poll_timeout_atomic() instead of open-coding the same operation. As typically no retries are needed, 10 µs is a suitable timeout value. Signed-off-by: Geert Uytterhoeven --- Polling measurements done on R-Car M2-W, H3 ES2.0, M3-W, M3-N, E3, and V4H. v3: - New. --- drivers/clk/renesas/renesas-cpg-mssr.c | 31 +++++++++----------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index e9c0e341380e8f55..2772499d20165127 100644 --- a/drivers/clk/renesas/renesas-cpg-mssr.c +++ b/drivers/clk/renesas/renesas-cpg-mssr.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -196,8 +197,8 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) struct device *dev = priv->dev; u32 bitmask = BIT(bit); unsigned long flags; - unsigned int i; u32 value; + int error; dev_dbg(dev, "MSTP %u%02u/%pC %s\n", reg, bit, hw->clk, enable ? "ON" : "OFF"); @@ -228,19 +229,13 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A) return 0; - for (i = 1000; i > 0; --i) { - if (!(readl(priv->base + priv->status_regs[reg]) & bitmask)) - break; - cpu_relax(); - } - - if (!i) { + error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg], + value, !(value & bitmask), 0, 10); + if (error) dev_err(dev, "Failed to enable SMSTP %p[%d]\n", priv->base + priv->control_regs[reg], bit); - return -ETIMEDOUT; - } - return 0; + return error; } static int cpg_mstp_clock_enable(struct clk_hw *hw) @@ -896,8 +891,9 @@ static int cpg_mssr_suspend_noirq(struct device *dev) static int cpg_mssr_resume_noirq(struct device *dev) { struct cpg_mssr_priv *priv = dev_get_drvdata(dev); - unsigned int reg, i; + unsigned int reg; u32 mask, oldval, newval; + int error; /* This is the best we can do to check for the presence of PSCI */ if (!psci_ops.cpu_suspend) @@ -935,14 +931,9 @@ static int cpg_mssr_resume_noirq(struct device *dev) if (!mask) continue; - for (i = 1000; i > 0; --i) { - oldval = readl(priv->base + priv->status_regs[reg]); - if (!(oldval & mask)) - break; - cpu_relax(); - } - - if (!i) + error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg], + oldval, !(oldval & mask), 0, 10); + if (error) dev_warn(dev, "Failed to enable SMSTP%u[0x%x]\n", reg, oldval & mask); } From patchwork Fri Jun 2 08:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp888234vqr; Fri, 2 Jun 2023 02:04:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7v03+vHNUaUOmcfllu3ipIGR0/5RqZslWWSYOKruAEiHgx6d374Y+/+4It6+wJ0KHSn84U X-Received: by 2002:a17:903:22c9:b0:1b0:aec3:ed34 with SMTP id y9-20020a17090322c900b001b0aec3ed34mr1154651plg.52.1685696645655; Fri, 02 Jun 2023 02:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696645; cv=none; d=google.com; s=arc-20160816; b=UA8Or1QnqsjWpLHHe2YCDNEN6oQtOzgr14judyPUkhiR+RVi90Jq+iFXUGattCgAge t6Vgo7HqrzyLFuSfEkZQyS9a8WZlKPF6jhGdpZ79Guc3mXbs4DevdvRp5gJQfEJwrMWy gd2crkVal48MsjXuaVWMdQArle2MeDfGmpLGWAWq+ReHQ3DpqpbnRl/qfJ8lfljAiAtm ZFMwlIjl3b3YoVpPxYD7GVKjv8gDbHRwOk5qlsALI1sRTd54G5dfVA7bu87dCELPf0zx 6nI3sv6i3GsDXhv6Yc7DkcXyT0g3jdHhCEexk6V8JGPXEHSGfWH1bc0NoKptVUSaU9NK 74TA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lZYXvtaHrXVHAnEzOhJR1rFXHYdmga1FwMtY7H6htyk=; b=yRpwmCMl71RgnOpRSB2LXT5REIJAf5kXHzbNTPSSrnSJYKqRsQttDWH0LVA9Q5Xzki Zawofqdji/SBC0WdwTAIDEPzRSGAVodOkV1wY/SbfClA2IrpSz/QXWpZWRAeenvn7G3I FT2hmF4VmRUOaNgYxQF+2yA+K5FfmwrXHB9wjOP+FFo9Z54P4YZAvIMpcjccW0l2eXBD GNtMICmlyBRlhNfThMJ04IYpmB8VsbYoV8PheB4yt+jkDsvbAQC+f25i76HQr+XiWIpS sTwTCmrMlzlhv/RdyOt3nrev83cKx7TpOLlpksNJAaHWHBHbce8pUYFv0IeLIF9TMWKU R3XQ== 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 g12-20020a170902934c00b001b049aae135si570824plp.246.2023.06.02.02.03.52; Fri, 02 Jun 2023 02:04:05 -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 S234570AbjFBIwa (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232404AbjFBIvy (ORCPT ); Fri, 2 Jun 2023 04:51:54 -0400 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DEBC1729 for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by andre.telenet-ops.be with bizsmtp id 48qo2A00F1tRZS8018qoWX; Fri, 02 Jun 2023 10:51:13 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYI-U1; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxd-1F; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 4/7] clk: renesas: mstp: Convert to readl_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:39 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581046025324466?= X-GMAIL-MSGID: =?utf-8?q?1767581046025324466?= Use readl_poll_timeout_atomic() instead of open-coding the same operation. As typically no retries are needed, 10 µs is a suitable timeout value. Signed-off-by: Geert Uytterhoeven --- Polling measurements done on R-Mobile APE6 and A1, R-Car H1, and SH-Mobile AG5. v3: - New. --- drivers/clk/renesas/clk-mstp.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/clk/renesas/clk-mstp.c b/drivers/clk/renesas/clk-mstp.c index 6e3c4a9c16b07ae9..e96457371b4cce88 100644 --- a/drivers/clk/renesas/clk-mstp.c +++ b/drivers/clk/renesas/clk-mstp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -78,8 +79,8 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) struct mstp_clock_group *group = clock->group; u32 bitmask = BIT(clock->bit_index); unsigned long flags; - unsigned int i; u32 value; + int ret; spin_lock_irqsave(&group->lock, flags); @@ -102,19 +103,14 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) if (!enable || !group->mstpsr) return 0; - for (i = 1000; i > 0; --i) { - if (!(cpg_mstp_read(group, group->mstpsr) & bitmask)) - break; - cpu_relax(); - } - - if (!i) { + /* group->width_8bit is always false if group->mstpsr is present */ + ret = readl_poll_timeout_atomic(group->mstpsr, value, + !(value & bitmask), 0, 10); + if (ret) pr_err("%s: failed to enable %p[%d]\n", __func__, group->smstpcr, clock->bit_index); - return -ETIMEDOUT; - } - return 0; + return ret; } static int cpg_mstp_clock_enable(struct clk_hw *hw) From patchwork Fri Jun 2 08:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp889030vqr; Fri, 2 Jun 2023 02:05:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nlzjHJC2lu+rDH5x36T5UJkLvfY3HXRbtEhXx9zuaH5cVfDEXiHvq/UoMPNZYrKya2Y7g X-Received: by 2002:a05:6808:3ba:b0:38b:4214:94f3 with SMTP id n26-20020a05680803ba00b0038b421494f3mr2300508oie.24.1685696738566; Fri, 02 Jun 2023 02:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696738; cv=none; d=google.com; s=arc-20160816; b=0U5XnLVuSg/NTf684TG5h0gYojmVnmTQtH3qt/cyc/VeotvkqOpF1nELkcGY18MQT4 QVzqG6NRDjw6G3sMXcbPEVB9d1ho4PL9s+0slxXeLGA3evj1SnTsL8lYk7inLW+3kkIp s2E3BP1sGxil+v17XLTPEW361sn6CJ6WvQdrYog53OuxTrf4/5tHekUxqiiofD7LglZe S9ZfZCCgvhL+Zt2pC1nySWOOy5Ea4Vsd8ojHAqRfuIwWcfucSxBA9zLhczLJH45W3N+5 6Ak9OnPtTOtxEphxbGDgON+qF+qnDzAq78GKSH7TLUiUwlDeQxuTKqF63AqOe1UOxPQS p4MQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=S84n690ubVJsfenBI9Ro1GEGFtsVaWu5UrTAnwgCPzc=; b=ZvPKLL0TCjDaCjHssr2iuXg1Y6Kw9Fr0MBrQHvV/We0L/eZiN5cHtgEB+59zbvrrlt N6mPpTwO2hnBn+77dz5BSSNADSfQAT4JWQ2aWY9JwLc66/ItHLHG6ftGMjiCuqIv/xhe El36kgBWqi3S53FKMvA9aVHniSzyLUbpCOou3QF0ZdiKNpi9uzxrcGXUPRCSGFStwB06 i+C5dldNQFvuZcUT6m80cP24qUAl9KsiXX5xwl7SaHucbUYTHdNDcxG1ddJyXHKwBvR6 cg7OWX4Faefkg6Alqb9wFXFPBmjk2Ut+fvbnHMwp06yTKYmMMiCJOUz/9051XpoIy35c sX8w== 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 c1-20020a170903234100b001aff514a8f0si572167plh.534.2023.06.02.02.05.25; Fri, 02 Jun 2023 02:05:38 -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 S235006AbjFBIwk (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234904AbjFBIv6 (ORCPT ); Fri, 2 Jun 2023 04:51:58 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F2F1730 for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by michel.telenet-ops.be with bizsmtp id 48qo2A00B1tRZS8068qoZc; Fri, 02 Jun 2023 10:51:13 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYO-Uv; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxh-20; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 5/7] clk: renesas: rzg2l: Convert to readl_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:40 +0200 Message-Id: <900543d4b9abc1004e6aecdb676f23e5508ae96f.1685692810.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581143233166686?= X-GMAIL-MSGID: =?utf-8?q?1767581143233166686?= Use readl_poll_timeout_atomic() instead of open-coding the same operation. As typically no retries are needed, 10 µs is a suitable timeout value. Signed-off-by: Geert Uytterhoeven --- Polling measurements done on RZ/Five. v3: - New. --- drivers/clk/renesas/rzg2l-cpg.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/clk/renesas/rzg2l-cpg.c b/drivers/clk/renesas/rzg2l-cpg.c index ca8b921c77625317..bc623515ad843cf5 100644 --- a/drivers/clk/renesas/rzg2l-cpg.c +++ b/drivers/clk/renesas/rzg2l-cpg.c @@ -903,9 +903,9 @@ static int rzg2l_mod_clock_endisable(struct clk_hw *hw, bool enable) unsigned int reg = clock->off; struct device *dev = priv->dev; unsigned long flags; - unsigned int i; u32 bitmask = BIT(clock->bit); u32 value; + int error; if (!clock->off) { dev_dbg(dev, "%pC does not support ON/OFF\n", hw->clk); @@ -930,19 +930,13 @@ static int rzg2l_mod_clock_endisable(struct clk_hw *hw, bool enable) if (!priv->info->has_clk_mon_regs) return 0; - for (i = 1000; i > 0; --i) { - if (((readl(priv->base + CLK_MON_R(reg))) & bitmask)) - break; - cpu_relax(); - } - - if (!i) { + error = readl_poll_timeout_atomic(priv->base + CLK_MON_R(reg), value, + value & bitmask, 0, 10); + if (error) dev_err(dev, "Failed to enable CLK_ON %p\n", priv->base + CLK_ON_R(reg)); - return -ETIMEDOUT; - } - return 0; + return error; } static int rzg2l_mod_clock_enable(struct clk_hw *hw) From patchwork Fri Jun 2 08:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp885389vqr; Fri, 2 Jun 2023 01:59:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/g9ZEiWLTnhwWcZVlGWg5BqREkEGX+xIWwWladyf3rPmrm15R968QdKWDQMxgG6T1ndHt X-Received: by 2002:a05:6a20:9389:b0:110:873a:a8 with SMTP id x9-20020a056a20938900b00110873a00a8mr13573055pzh.52.1685696361512; Fri, 02 Jun 2023 01:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696361; cv=none; d=google.com; s=arc-20160816; b=Kgc13N32h4xrwvKsL40QjWM3zYg43+pf/z+kSoBTneNtmEOkHv2rkDDZs6gfLa/h2L Lh8oBR4XtwA30AiqmELi6Qf1SLxXh/ZqG9h+h11N4U07CT4LA7F7PGC+rJoiwseK1Pis nh+vETZF9Ipxh2InjeVqanZ5BNUFNDDLFAZJDormFuQ85XQfQ3oCPaGd3pbs7cDrEn9w 4aVySD+3aiIi/aEZ+iYqJWIonXbJNF93VFWSnJcEAmr+phWV7rWDPsYzoVLBxJ5T6zQF tTb3UB510gT39vQ3jGM/QCwf1Ki1+jOZMAUN4/iLj8itcEIa7tsGgifXE/1vF80q8mla /1+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HQDEWTcbGvbpQ/4fpOwDwd869G3YfVM+8tc2uh2GD2Y=; b=W43oll/aW7n4qvXl71qXkuAxaJIZQmyzSgCm4q6yGS9Ok8vCoiR3LKFlRAWoZsNsqz iSehc+a88VE+qpVJ5tvM9y+n0HnoAPIVArIBuob+iEeuHixlx4PVPMg9+ZsnMO0jqr0R u6DVyXbqo1QBuC5/CQYE6Pr3OdELb6rB7WzuFQ9Nx165AaTRrMOzE1ZSc5cHclAtuBs4 pynzcio7X03vEw9aOY+1aq1Q16hBfUo0LN2wykqxtdM0dF3hG5hmqglGF33S6/9DdLzO j54GVdurYEBDP1L2NwVs0yYYj+L0L1a8qAkxxG6Ro3iiEIVN0c3bxS0TX28QZAZq1sFI KnCw== 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 o25-20020a637319000000b0053fec3ed061si638885pgc.718.2023.06.02.01.59.07; Fri, 02 Jun 2023 01:59:21 -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 S234980AbjFBIw0 (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234896AbjFBIvy (ORCPT ); Fri, 2 Jun 2023 04:51:54 -0400 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2231728 for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by andre.telenet-ops.be with bizsmtp id 48qo2A00L1tRZS8018qoWZ; Fri, 02 Jun 2023 10:51:13 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYR-Vj; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxl-2q; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 6/7] soc: renesas: rmobile-sysc: Convert to readl_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:41 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767580748100394631?= X-GMAIL-MSGID: =?utf-8?q?1767580748100394631?= Use readl_poll_timeout_atomic() instead of open-coding the same operation. 1. rmobile_pd_power_down(): as typically less than 20 retries are needed, PSTR_RETRIES (100) µs is a suitable timeout value. 2. __rmobile_pd_power_up(): the old method of first polling some cycles with a 1 µs delay, followed by more polling cycles without any delay didn't make much sense, as the latter was insignificant compared to the former. Furthermore, typically no retries are needed. Hence just retain the polling with delay. Signed-off-by: Geert Uytterhoeven --- Polling measurements done on R-Mobile APE6 and A1, and SH-Mobile AG5. v3: - New. --- drivers/soc/renesas/rmobile-sysc.c | 31 ++++++++++-------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c index 728ebac98e14a5cc..5d621c35fba1116a 100644 --- a/drivers/soc/renesas/rmobile-sysc.c +++ b/drivers/soc/renesas/rmobile-sysc.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -19,8 +21,6 @@ #include #include -#include - /* SYSC */ #define SPDCR 0x08 /* SYS Power Down Control Register */ #define SWUCR 0x14 /* SYS Wakeup Control Register */ @@ -47,6 +47,7 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) { struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd); unsigned int mask = BIT(rmobile_pd->bit_shift); + u32 val; if (rmobile_pd->suspend) { int ret = rmobile_pd->suspend(); @@ -56,14 +57,10 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) } if (readl(rmobile_pd->base + PSTR) & mask) { - unsigned int retry_count; writel(mask, rmobile_pd->base + SPDCR); - for (retry_count = PSTR_RETRIES; retry_count; retry_count--) { - if (!(readl(rmobile_pd->base + SPDCR) & mask)) - break; - cpu_relax(); - } + readl_poll_timeout_atomic(rmobile_pd->base + SPDCR, val, + !(val & mask), 0, PSTR_RETRIES); } pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n", genpd->name, mask, @@ -74,25 +71,17 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd) { - unsigned int mask = BIT(rmobile_pd->bit_shift); - unsigned int retry_count; - int ret = 0; + unsigned int val, mask = BIT(rmobile_pd->bit_shift); + int ret; if (readl(rmobile_pd->base + PSTR) & mask) return ret; writel(mask, rmobile_pd->base + SWUCR); - for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) { - if (!(readl(rmobile_pd->base + SWUCR) & mask)) - break; - if (retry_count > PSTR_RETRIES) - udelay(PSTR_DELAY_US); - else - cpu_relax(); - } - if (!retry_count) - ret = -EIO; + ret = readl_poll_timeout_atomic(rmobile_pd->base + SWUCR, val, + (val & mask), PSTR_DELAY_US, + PSTR_RETRIES * PSTR_DELAY_US); pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n", rmobile_pd->genpd.name, mask, From patchwork Fri Jun 2 08:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp890540vqr; Fri, 2 Jun 2023 02:09:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6cPfYsSJCEj7O3Mff6Cp73CGfRYPNGLy+W8aCJfMlWteP5CNakuAIIWQL4G88F/uinUBeu X-Received: by 2002:a05:6808:14e:b0:398:c4ec:63bc with SMTP id h14-20020a056808014e00b00398c4ec63bcmr1868889oie.43.1685696939854; Fri, 02 Jun 2023 02:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696939; cv=none; d=google.com; s=arc-20160816; b=dpBMuHzV1bqi9psOh7ePDw8l/oYKFgs4/U4DMQwZRsgrrbdmz+CoNk6+02SMJEZHXw SbSQj5+Mtt4UOhBsy3SWnisNbQXOPUZWU1rfjTDRBb0TOIJVMaQZhHsuLZGU6N1Xrd3m 1NXNw6L0laY4g76fcCw3rZrKqIxvXjL+IAEQW3HEODu/Uhk5YRakYq9OKwCQ8JQgrTZX q6Z0fk5ex2hUv9rTChe9zKmOMHR9tLXHop7+SVKD24Qg22k7rxgqJLINsKB5Xt1ETjnj w29hS7SUvQsE1SWHo9l8yNMdxPHxD50NjtJPO6oYJ0W7Lc1IMC+cTn45MnK062WwHlT4 2lHg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=55LrKU5QMRHVfRj7TFz49ZLxEXVnIs/Yp9ekfsZZUM8=; b=SdwY2OFV5cmw1WWAt3Z7W55YCjzvZtfXV5e/wjRaaT7y+Ldld222/JQOzEEfixsCw4 qUUfqZA9BpO7tPZPrhhZ2OGHWUNVY0CWj0CTkLeEE7bqcWPvZqC+hdCFAZeD8cbsl0KE HjvA4Gy/XUsw+dZdW469483RTseBiFrh+1FUIitst3KV3oDHjoGAJfL8vFc/gvutDlPl S90SgxSvBtVn5qGmFZhgDJkXExWNqZQe/rWzn59DykW7JS4YAB/Jy1BjPHyF9KyNBcfQ v/z+YAe2fCH7F56S67Qan8HPcb2luGtb5nUAL2ITV2bx4In/wKM1MB1gAsly4hxsH1gj Salw== 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 x10-20020a170902ec8a00b001a52db202c7si598311plg.382.2023.06.02.02.08.47; Fri, 02 Jun 2023 02:08:59 -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 S235016AbjFBIwn (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234911AbjFBIv7 (ORCPT ); Fri, 2 Jun 2023 04:51:59 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3EE1734 for ; Fri, 2 Jun 2023 01:51:16 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by laurent.telenet-ops.be with bizsmtp id 48qo2A00F1tRZS8018qoyb; Fri, 02 Jun 2023 10:51:14 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UP-00BhYW-0P; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxr-3g; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: 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 , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 7/7] iommu/ipmmu-vmsa: Convert to read_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:42 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767581354417666727?= X-GMAIL-MSGID: =?utf-8?q?1767581354417666727?= Use read_poll_timeout_atomic() instead of open-coding the same operation. Signed-off-by: Geert Uytterhoeven --- v3: - New. --- drivers/iommu/ipmmu-vmsa.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9f64c5c9f5b90ace..3b58a8ea3bdef190 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -253,17 +254,13 @@ static void ipmmu_imuctr_write(struct ipmmu_vmsa_device *mmu, /* Wait for any pending TLB invalidations to complete */ static void ipmmu_tlb_sync(struct ipmmu_vmsa_domain *domain) { - unsigned int count = 0; + u32 val; - while (ipmmu_ctx_read_root(domain, IMCTR) & IMCTR_FLUSH) { - cpu_relax(); - if (++count == TLB_LOOP_TIMEOUT) { - dev_err_ratelimited(domain->mmu->dev, + if (read_poll_timeout_atomic(ipmmu_ctx_read_root, val, + !(val & IMCTR_FLUSH), 1, TLB_LOOP_TIMEOUT, + false, domain, IMCTR)) + dev_err_ratelimited(domain->mmu->dev, "TLB sync timed out -- MMU may be deadlocked\n"); - return; - } - udelay(1); - } } static void ipmmu_tlb_invalidate(struct ipmmu_vmsa_domain *domain)