[v3] clk: expand clk_ignore_unused mechanism to keep only a few clks on

Message ID 20221026151812.1042052-1-u.kleine-koenig@pengutronix.de
State New
Headers
Series [v3] clk: expand clk_ignore_unused mechanism to keep only a few clks on |

Commit Message

Uwe Kleine-König Oct. 26, 2022, 3:18 p.m. UTC
  Allow to pass an integer n that results in only keeping n unused clocks
enabled.

This helps to debug the problem if you only know that clk_ignore_unused
helps but you have no clue yet which clock is the culprit.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

compared to v2 sent in August 2021 this is a trivial rebase on top of
v6.1-rc1. I pinged that one repeatedly, I'm now trying with resending
and calling the rebased patch v3 to maybe get some feedback. :-\

Best regards
Uwe

 Documentation/driver-api/clk.rst |  4 +++-
 drivers/clk/clk.c                | 33 ++++++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 9 deletions(-)
  

Comments

Uwe Kleine-König March 13, 2023, 6:27 p.m. UTC | #1
Hello,

On Wed, Oct 26, 2022 at 05:18:12PM +0200, Uwe Kleine-König wrote:
> Allow to pass an integer n that results in only keeping n unused clocks
> enabled.
> 
> This helps to debug the problem if you only know that clk_ignore_unused
> helps but you have no clue yet which clock is the culprit.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> compared to v2 sent in August 2021 this is a trivial rebase on top of
> v6.1-rc1. I pinged that one repeatedly, I'm now trying with resending
> and calling the rebased patch v3 to maybe get some feedback. :-\

I didn't get any feedback on this patch and still consider it useful.

Any insights from your side?

Best regards
Uwe
  
Stephen Boyd March 29, 2023, 7:49 p.m. UTC | #2
Quoting Uwe Kleine-König (2022-10-26 08:18:12)
> Allow to pass an integer n that results in only keeping n unused clocks
> enabled.
> 
> This helps to debug the problem if you only know that clk_ignore_unused
> helps but you have no clue yet which clock is the culprit.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> compared to v2 sent in August 2021 this is a trivial rebase on top of
> v6.1-rc1. I pinged that one repeatedly, I'm now trying with resending
> and calling the rebased patch v3 to maybe get some feedback. :-\
> 
> Best regards
> Uwe
> 
>  Documentation/driver-api/clk.rst |  4 +++-

No update to Documentation/admin-guide/kernel-parameters.txt?

>  drivers/clk/clk.c                | 33 ++++++++++++++++++++++++--------
>  2 files changed, 28 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index c3c3f8c07258..356119a7e5fe 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1322,6 +1322,8 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)
>         clk_pm_runtime_put(core);
>  }
>  
> +static unsigned clk_unused_keep_on __initdata;
> +
>  static void __init clk_disable_unused_subtree(struct clk_core *core)
>  {
>         struct clk_core *child;
> @@ -1352,12 +1354,17 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
>          * back to .disable
>          */
>         if (clk_core_is_enabled(core)) {
> -               trace_clk_disable(core);
> -               if (core->ops->disable_unused)
> -                       core->ops->disable_unused(core->hw);
> -               else if (core->ops->disable)
> -                       core->ops->disable(core->hw);
> -               trace_clk_disable_complete(core);
> +               if (clk_unused_keep_on) {
> +                       pr_warn("Keep unused clk \"%s\" on\n", core->name);
> +                       clk_unused_keep_on -= 1;
> +               } else {
> +                       trace_clk_disable(core);

We have trace_clk_disable() here. Can you have this tracepoint print to
the kernel log and watch over serial console? That would be faster than
bisecting.

> +                       if (core->ops->disable_unused)
> +                               core->ops->disable_unused(core->hw);
> +                       else if (core->ops->disable)
> +                               core->ops->disable(core->hw);
> +                       trace_clk_disable_complete(core);
> +               }
>         }
>  
>  unlock_out:
> @@ -1369,9 +1376,17 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
>  }
>  
>  static bool clk_ignore_unused __initdata;
> -static int __init clk_ignore_unused_setup(char *__unused)
> +static int __init clk_ignore_unused_setup(char *keep)
>  {
> -       clk_ignore_unused = true;
> +       if (*keep == '=') {
> +               int ret;
> +
> +               ret = kstrtouint(keep + 1, 0, &clk_unused_keep_on);
> +               if (ret < 0)

Could omit 'ret' and just have if (kstrtouint(..))

> +                       pr_err("Warning: failed to parse clk_ignore_unused parameter, ignoring");

Missing newline on printk.

> +       } else {
> +               clk_ignore_unused = true;
> +       }
>         return 1;
>  }
>  __setup("clk_ignore_unused", clk_ignore_unused_setup);
  

Patch

diff --git a/Documentation/driver-api/clk.rst b/Documentation/driver-api/clk.rst
index 3cad45d14187..65ae7c3e2b33 100644
--- a/Documentation/driver-api/clk.rst
+++ b/Documentation/driver-api/clk.rst
@@ -259,7 +259,9 @@  the disabling means that the driver will remain functional while the issues
 are sorted out.
 
 To bypass this disabling, include "clk_ignore_unused" in the bootargs to the
-kernel.
+kernel. If you pass "clk_ignore_unused=n" (where n is an integer) the first n
+found clocks are not disabled which can be useful for bisecting over the unused
+clks if you don't know yet which of them is reponsible for your problem.
 
 Locking
 =======
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c3c3f8c07258..356119a7e5fe 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1322,6 +1322,8 @@  static void __init clk_unprepare_unused_subtree(struct clk_core *core)
 	clk_pm_runtime_put(core);
 }
 
+static unsigned clk_unused_keep_on __initdata;
+
 static void __init clk_disable_unused_subtree(struct clk_core *core)
 {
 	struct clk_core *child;
@@ -1352,12 +1354,17 @@  static void __init clk_disable_unused_subtree(struct clk_core *core)
 	 * back to .disable
 	 */
 	if (clk_core_is_enabled(core)) {
-		trace_clk_disable(core);
-		if (core->ops->disable_unused)
-			core->ops->disable_unused(core->hw);
-		else if (core->ops->disable)
-			core->ops->disable(core->hw);
-		trace_clk_disable_complete(core);
+		if (clk_unused_keep_on) {
+			pr_warn("Keep unused clk \"%s\" on\n", core->name);
+			clk_unused_keep_on -= 1;
+		} else {
+			trace_clk_disable(core);
+			if (core->ops->disable_unused)
+				core->ops->disable_unused(core->hw);
+			else if (core->ops->disable)
+				core->ops->disable(core->hw);
+			trace_clk_disable_complete(core);
+		}
 	}
 
 unlock_out:
@@ -1369,9 +1376,17 @@  static void __init clk_disable_unused_subtree(struct clk_core *core)
 }
 
 static bool clk_ignore_unused __initdata;
-static int __init clk_ignore_unused_setup(char *__unused)
+static int __init clk_ignore_unused_setup(char *keep)
 {
-	clk_ignore_unused = true;
+	if (*keep == '=') {
+		int ret;
+
+		ret = kstrtouint(keep + 1, 0, &clk_unused_keep_on);
+		if (ret < 0)
+			pr_err("Warning: failed to parse clk_ignore_unused parameter, ignoring");
+	} else {
+		clk_ignore_unused = true;
+	}
 	return 1;
 }
 __setup("clk_ignore_unused", clk_ignore_unused_setup);
@@ -1383,6 +1398,8 @@  static int __init clk_disable_unused(void)
 	if (clk_ignore_unused) {
 		pr_warn("clk: Not disabling unused clocks\n");
 		return 0;
+	} else if (clk_unused_keep_on) {
+		pr_warn("clk: Not disabling %u unused clocks\n", clk_unused_keep_on);
 	}
 
 	clk_prepare_lock();