Linux Watchdog driver development
 help / color / mirror / Atom feed
* [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused
@ 2023-11-22  4:16 Vignesh Raghavendra
  2023-12-12 10:09 ` Manorit Chawdhry
  2023-12-12 15:27 ` Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Vignesh Raghavendra @ 2023-11-22  4:16 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: Tero Kristo, linux-watchdog, linux-kernel, Vignesh Raghavendra,
	linux-arm-kernel, afd

Do a RPM put if watchdog is not already started during probe and re
enable it in watchdog start.

On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
if the reference count of unused watchdogs aren't dropped, it will lead
to CPU hotplug failures as Device Management firmware won't allow to
turn off the PD due to dangling reference count.

Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---

v2:
* Drop 1/2 (will be posted along with runtime_pm callbacks)
* Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() which
 takes care of err handling

v1: lore.kernel.org/r/20231110100726.2930218-1-vigneshr@ti.com

 drivers/watchdog/rti_wdt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index 8e1be7ba0103..9215793a1c81 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -77,6 +77,11 @@ static int rti_wdt_start(struct watchdog_device *wdd)
 {
 	u32 timer_margin;
 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
+	int ret;
+
+	ret = pm_runtime_resume_and_get(wdd->parent);
+	if (ret)
+		return ret;
 
 	/* set timeout period */
 	timer_margin = (u64)wdd->timeout * wdt->freq;
@@ -343,6 +348,9 @@ static int rti_wdt_probe(struct platform_device *pdev)
 	if (last_ping)
 		watchdog_set_last_hw_keepalive(wdd, last_ping);
 
+	if (!watchdog_hw_running(wdd))
+		pm_runtime_put_sync(&pdev->dev);
+
 	return 0;
 
 err_iomap:
@@ -357,7 +365,10 @@ static void rti_wdt_remove(struct platform_device *pdev)
 	struct rti_wdt_device *wdt = platform_get_drvdata(pdev);
 
 	watchdog_unregister_device(&wdt->wdd);
-	pm_runtime_put(&pdev->dev);
+
+	if (!pm_runtime_suspended(&pdev->dev))
+		pm_runtime_put(&pdev->dev);
+
 	pm_runtime_disable(&pdev->dev);
 }
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused
  2023-11-22  4:16 [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused Vignesh Raghavendra
@ 2023-12-12 10:09 ` Manorit Chawdhry
  2023-12-12 15:27 ` Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Manorit Chawdhry @ 2023-12-12 10:09 UTC (permalink / raw)
  To: Vignesh Raghavendra
  Cc: Wim Van Sebroeck, Guenter Roeck, Tero Kristo, linux-watchdog,
	linux-kernel, linux-arm-kernel, afd

Hi Vignesh,

On 09:46-20231122, Vignesh Raghavendra wrote:
> Do a RPM put if watchdog is not already started during probe and re
> enable it in watchdog start.
> 
> On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
> if the reference count of unused watchdogs aren't dropped, it will lead
> to CPU hotplug failures as Device Management firmware won't allow to
> turn off the PD due to dangling reference count.
> 
> Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> ---
> 
> v2:
> * Drop 1/2 (will be posted along with runtime_pm callbacks)
> * Use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() which
>  takes care of err handling
> 
> v1: lore.kernel.org/r/20231110100726.2930218-1-vigneshr@ti.com
> 
>  drivers/watchdog/rti_wdt.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
> index 8e1be7ba0103..9215793a1c81 100644
> --- a/drivers/watchdog/rti_wdt.c
> +++ b/drivers/watchdog/rti_wdt.c
> @@ -77,6 +77,11 @@ static int rti_wdt_start(struct watchdog_device *wdd)
>  {
>  	u32 timer_margin;
>  	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(wdd->parent);
> +	if (ret)
> +		return ret;
>  
>  	/* set timeout period */
>  	timer_margin = (u64)wdd->timeout * wdt->freq;
> @@ -343,6 +348,9 @@ static int rti_wdt_probe(struct platform_device *pdev)
>  	if (last_ping)
>  		watchdog_set_last_hw_keepalive(wdd, last_ping);
>  
> +	if (!watchdog_hw_running(wdd))
> +		pm_runtime_put_sync(&pdev->dev);
> +
>  	return 0;
>  
>  err_iomap:
> @@ -357,7 +365,10 @@ static void rti_wdt_remove(struct platform_device *pdev)
>  	struct rti_wdt_device *wdt = platform_get_drvdata(pdev);
>  
>  	watchdog_unregister_device(&wdt->wdd);
> -	pm_runtime_put(&pdev->dev);
> +
> +	if (!pm_runtime_suspended(&pdev->dev))
> +		pm_runtime_put(&pdev->dev);
> +
>  	pm_runtime_disable(&pdev->dev);
>  }
>  

Tested the following on j721s2 evm.
https://gist.github.com/manorit2001/05a85582fea670d39cc3cfb2df1e5328

Tested-by: Manorit Chawdhry <m-chawdhry@ti.com>

Regards,
Manorit

> -- 
> 2.42.0
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused
  2023-11-22  4:16 [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused Vignesh Raghavendra
  2023-12-12 10:09 ` Manorit Chawdhry
@ 2023-12-12 15:27 ` Guenter Roeck
  2023-12-13 12:22   ` Vignesh Raghavendra
  1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2023-12-12 15:27 UTC (permalink / raw)
  To: Vignesh Raghavendra, Wim Van Sebroeck
  Cc: Tero Kristo, linux-watchdog, linux-kernel, linux-arm-kernel, afd

On 11/21/23 20:16, Vignesh Raghavendra wrote:
> Do a RPM put if watchdog is not already started during probe and re
> enable it in watchdog start.
> 
> On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
> if the reference count of unused watchdogs aren't dropped, it will lead
> to CPU hotplug failures as Device Management firmware won't allow to
> turn off the PD due to dangling reference count.
> 
> Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>

I always find it amazing that people think everyone would understand the TLAs
(three-letter-acronyms) they use. While those who don't might find it confusing
why a watchdog driver would need or want to drop rotation-per-minute counts,
and what that has to do with police departments, that isn't worth
arguing about

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Guenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused
  2023-12-12 15:27 ` Guenter Roeck
@ 2023-12-13 12:22   ` Vignesh Raghavendra
  0 siblings, 0 replies; 4+ messages in thread
From: Vignesh Raghavendra @ 2023-12-13 12:22 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: Tero Kristo, linux-watchdog, linux-kernel, linux-arm-kernel, afd



On 12/12/23 20:57, Guenter Roeck wrote:
> On 11/21/23 20:16, Vignesh Raghavendra wrote:
>> Do a RPM put if watchdog is not already started during probe and re
>> enable it in watchdog start.
>>
>> On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
>> if the reference count of unused watchdogs aren't dropped, it will lead
>> to CPU hotplug failures as Device Management firmware won't allow to
>> turn off the PD due to dangling reference count.
>>
>> Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
>> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> 
> I always find it amazing that people think everyone would understand the
> TLAs
> (three-letter-acronyms) they use. While those who don't might find it
> confusing
> why a watchdog driver would need or want to drop rotation-per-minute
> counts,
> and what that has to do with police departments, that isn't worth
> arguing about
> 

Oops, my apologies. I will respin with TLAs expanded

> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> 

Thanks!

> Guenter
> 

-- 
Regards
Vignesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-13 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22  4:16 [PATCH v2] watchdog: rti_wdt: Drop RPM count when unused Vignesh Raghavendra
2023-12-12 10:09 ` Manorit Chawdhry
2023-12-12 15:27 ` Guenter Roeck
2023-12-13 12:22   ` Vignesh Raghavendra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox