Skip to contentSkip to conversation

watchdog: rti_wdt: Drop RPM count when unused

PATCH In review Vignesh Raghavendra 3 participants 4 messages Nov 22, 2023 – Dec 13, 2023 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 watchdog: rti_wdt: Drop RPM count when unused

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")

---

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/[email protected]

 drivers/watchdog/rti_wdt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/watchdog/rti_wdt.c +12 -1
index 8e1be7ba0103..9215793a1c81 100644
@@ -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);
 }
 
Signature · 1 line
2.42.0
Tested-by on v2 1/1
#1 lore raw

Hi Vignesh,

Quoted 50 lines · Vignesh Raghavendra

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")

---

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/[email protected]

 drivers/watchdog/rti_wdt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/watchdog/rti_wdt.c +8 -0
index 8e1be7ba0103..9215793a1c81 100644
@@ -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);

drivers/watchdog/rti_wdt.c static void rti_wdt_remove(struct platform_device *pdev) · line 374

Quoted 10 lines
drivers/watchdog/rti_wdt.c +4 -1
 
 	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

Regards,
Manorit

Quoted 8 lines
Signature · 7 lines
2.42.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Vignesh Raghavendra
Quoted 10 lines · Vignesh Raghavendra

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")

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

Guenter

#3 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 10 lines · Vignesh Raghavendra

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")
Quoted 9 lines

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

Quoted 2 lines

Thanks!

Quoted 2 lines

Guenter

Signature · 2 lines
Regards
Vignesh