From mboxrd@z Thu Jan 1 00:00:00 1970 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 ECC56CCD1BB for ; Wed, 22 Oct 2025 13:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:References:Content-Type: Content-Transfer-Encoding:In-Reply-To:Cc:To:From:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uVOoyF07iVYQ24dFE2kJcX0p9ox+bw4w5ywwtjuXGNM=; b=jsk7cVJBuGnviijCGoQTlC37Za xQivjqbSg9XQ9J4qCDnhXJnxjGHFYYZwUhx6DZTNlRtHGB/gy+JmN/jKYbJ/2v/VjVwarTAoNUddK vyZr6LatoV6vQ8gAv0hCPkhWYcis7c+4ORzGDNIwullS6nyKKK6EQds17hVNtI/ZFim4qtWmm5/8g dDIjdMHvs9Dp2gZfwgAi++vgXzo2hmc61NVo5usev49xYVdYc+wdOA9+rSXDCDoCzPc87/9U1l+JU VaEHRAWshLL14OVT7bfcOgX4EQyhgbuIK9UzSfXp/ceXbrlU/unGhhn3G210SdrW9iUER6/F3A4Cb 7tyQkAKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vBZ9V-000000034HM-0UrV; Wed, 22 Oct 2025 13:45:21 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vBZ9Q-000000034Ej-0ymc for linux-arm-kernel@lists.infradead.org; Wed, 22 Oct 2025 13:45:20 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20251022134510euoutp023c9b4287aff8aae76e3a6dd3f172718b~w1CUbf8SJ1123511235euoutp02c for ; Wed, 22 Oct 2025 13:45:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20251022134510euoutp023c9b4287aff8aae76e3a6dd3f172718b~w1CUbf8SJ1123511235euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1761140710; bh=uVOoyF07iVYQ24dFE2kJcX0p9ox+bw4w5ywwtjuXGNM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CZryngLgbYRbGFm/ihPNVB9ukl/429AnUUsVxxCUcbjSI/Lu1diT/A7KiU7IzeeG6 coz4p5Uhslnv5JVHPlOadDhREbFd5sVox2JbdDYoJu+XDDJr8pNc9UWrpteHVZRPAo bYBObZC5/v+zcbjyxqZ0qdHqps6WOfHuAXkKc8Ns= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20251022134509eucas1p1789fd89e07d10b550b7f21decd862d52~w1CT44nK50583205832eucas1p1W; Wed, 22 Oct 2025 13:45:09 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20251022134508eusmtip2d638eeea6ab8ba407c25e72a5591ac57~w1CS6lJHO0945309453eusmtip2K; Wed, 22 Oct 2025 13:45:08 +0000 (GMT) Message-ID: <5c19e4ef-c4fd-4bf5-88b3-46c86751b14e@samsung.com> Date: Wed, 22 Oct 2025 15:45:07 +0200 MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH v3 06/10] pmdomain: samsung: convert to regmap_read_poll_timeout() From: Marek Szyprowski To: =?UTF-8?Q?Andr=C3=A9_Draszik?= , Krzysztof Kozlowski , Alim Akhtar , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Ulf Hansson Cc: Peter Griffin , Tudor Ambarus , Will McVicker , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Content-Language: en-US In-Reply-To: <2e38e6c2-0548-432f-ae34-daf3972877ac@samsung.com> Content-Transfer-Encoding: 8bit X-CMS-MailID: 20251022134509eucas1p1789fd89e07d10b550b7f21decd862d52 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20251016155855eucas1p2ccc516861548e963761133fc52fc560e X-EPHeader: CA X-CMS-RootMailID: 20251016155855eucas1p2ccc516861548e963761133fc52fc560e References: <20251016-gs101-pd-v3-0-7b30797396e7@linaro.org> <20251016-gs101-pd-v3-6-7b30797396e7@linaro.org> <2e38e6c2-0548-432f-ae34-daf3972877ac@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251022_064516_860831_0F7FFE09 X-CRM114-Status: GOOD ( 26.81 ) 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 On 21.10.2025 22:38, Marek Szyprowski wrote: > On 16.10.2025 17:58, André Draszik wrote: >> Replace the open-coded PD status polling with >> regmap_read_poll_timeout(). This change simplifies the code without >> altering functionality. >> >> Signed-off-by: André Draszik >> --- >>   drivers/pmdomain/samsung/exynos-pm-domains.c | 29 >> ++++++++-------------------- >>   1 file changed, 8 insertions(+), 21 deletions(-) >> >> diff --git a/drivers/pmdomain/samsung/exynos-pm-domains.c >> b/drivers/pmdomain/samsung/exynos-pm-domains.c >> index >> 383126245811cb8e4dbae3b99ced3f06d3093f35..431548ad9a7e40c0a77ac6672081b600c90ddd4e >> 100644 >> --- a/drivers/pmdomain/samsung/exynos-pm-domains.c >> +++ b/drivers/pmdomain/samsung/exynos-pm-domains.c >> @@ -13,7 +13,6 @@ >>   #include >>   #include >>   #include >> -#include >>   #include >>   #include >>   #include >> @@ -35,7 +34,8 @@ struct exynos_pm_domain { >>   static int exynos_pd_power(struct generic_pm_domain *domain, bool >> power_on) >>   { >>       struct exynos_pm_domain *pd; >> -    u32 timeout, pwr; >> +    unsigned int val; >> +    u32 pwr; >>       int err; >>         pd = container_of(domain, struct exynos_pm_domain, pd); >> @@ -45,25 +45,12 @@ static int exynos_pd_power(struct >> generic_pm_domain *domain, bool power_on) >>       if (err) >>           return err; >>   -    /* Wait max 1ms */ >> -    timeout = 10; >> -    while (timeout-- > 0) { >> -        unsigned int val; >> - >> -        err = regmap_read(pd->regmap, 0x4, &val); >> -        if (err || ((val & pd->local_pwr_cfg) != pwr)) { >> -            cpu_relax(); >> -            usleep_range(80, 100); >> -            continue; >> -        } >> - >> -        return 0; >> -    } >> - >> -    if (!err) >> -        err = -ETIMEDOUT; >> -    pr_err("Power domain %s %sable failed: %d\n", domain->name, >> -           power_on ? "en" : "dis", err); >> +    err = regmap_read_poll_timeout(pd->regmap, 0x4, val, >> +                       (val & pd->local_pwr_cfg) == pwr, >> +                       100, 1 * USEC_PER_MSEC); >> +    if (err) >> +        pr_err("Power domain %s %sable failed: %d (%#.2x)\n", >> +               domain->name, power_on ? "en" : "dis", err, val); > > I've posted my 'tested-by' tag for this patchset, but in meantime I > found that this patch causes regression from time to time on old > Exynos SoCs (especially when all debugs are disabled). It looks that > there are some subtle differences between reading the status register > up to 10 times with cpu_relax()+usleep_range() and the > regmap_read_poll_timeout(). I will try to analyze this a bit more and > provide details, but I suspect that the old loop might take a bit > longer than the 1ms from the comment above this code. It looks that during the early boot all calls to regmap_read_poll_timeout() lasts exactly 10ms (measured with ktime_get() and ktime_to_ms()), what means that timekeeping source doesn't provide resolution high enough for the 1ms timeout. This in turn results in premature end of regmap_read_poll_timeout() loop after only one cycle of read+wait+read, what is not always enough for power domain to turn on/off. According to the commit 7349a69cf312 ("iopoll: Do not use timekeeping in read_poll_timeout_atomic()"), ktime_get(), which is used also by regmap_read_poll_timeout(), is not reliable in all contexts, so I think that this patch should be dropped as there is no easy way to fix this. The alternative would be to use regmap_read_poll_timeout_atomic(), which need to be fixed the same way as regmap_read_poll_timeout_atomic() by the mentioned commit, but in such case we would effectively switch from usleep to udelay. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland