All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put
@ 2022-07-07 10:03 Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 2/4] clk: Add consumers count to core Abel Vesa
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Abel Vesa @ 2022-07-07 10:03 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-msm, Abel Vesa

For consistency, use clk_core_unlink_consumer rather then hlist_del
directly, on __clk_put. Prepare lock is already acquired at that point.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/clk/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7fc191c15507..e1d8245866b1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4347,7 +4347,7 @@ void __clk_put(struct clk *clk)
 		clk->exclusive_count = 0;
 	}
 
-	hlist_del(&clk->clks_node);
+	clk_core_unlink_consumer(clk);
 	if (clk->min_rate > clk->core->req_rate ||
 	    clk->max_rate < clk->core->req_rate)
 		clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
-- 
2.34.3


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

* [RFC PATCH 2/4] clk: Add consumers count to core
  2022-07-07 10:03 [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
@ 2022-07-07 10:03 ` Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 3/4] clk: Add consumers count information to debugfs Abel Vesa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Abel Vesa @ 2022-07-07 10:03 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-msm, Abel Vesa

Keep a count of all consumers per clock. One usage of could be to make
core decisions (like disabling unused clocks) based on the number of
consumers a clock has.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/clk/clk.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e1d8245866b1..9b54afd2fee8 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -72,6 +72,7 @@ struct clk_core {
 	unsigned long		flags;
 	bool			orphan;
 	bool			rpm_enabled;
+	unsigned int		consumers_count;
 	unsigned int		enable_count;
 	unsigned int		prepare_count;
 	unsigned int		protect_count;
@@ -3682,6 +3683,9 @@ static int __clk_core_init(struct clk_core *core)
 		core->hw->core = NULL;
 	}
 
+	if (!ret)
+		core->consumers_count = 0;
+
 	clk_prepare_unlock();
 
 	if (!ret)
@@ -3699,6 +3703,7 @@ static void clk_core_link_consumer(struct clk_core *core, struct clk *clk)
 {
 	clk_prepare_lock();
 	hlist_add_head(&clk->clks_node, &core->clks);
+	clk->core->consumers_count++;
 	clk_prepare_unlock();
 }
 
@@ -3710,6 +3715,7 @@ static void clk_core_unlink_consumer(struct clk *clk)
 {
 	lockdep_assert_held(&prepare_lock);
 	hlist_del(&clk->clks_node);
+	clk->core->consumers_count--;
 }
 
 /**
-- 
2.34.3


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

* [RFC PATCH 3/4] clk: Add consumers count information to debugfs
  2022-07-07 10:03 [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 2/4] clk: Add consumers count to core Abel Vesa
@ 2022-07-07 10:03 ` Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 4/4] clk: Skip disabling clocks if they have consumers Abel Vesa
  2022-07-21  8:17 ` [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
  3 siblings, 0 replies; 5+ messages in thread
From: Abel Vesa @ 2022-07-07 10:03 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-msm, Abel Vesa

Lets add consumers count information to debugfs. It could be useful for
identifying which clocks do not have a consumer but are enabled at boot
and should be disabled since they are unused. Also you could tell which
clocks are marked as critical since they do not have consumers, but
their enable_count is non-zero.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/clk/clk.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 9b54afd2fee8..e412e83a6e28 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2955,9 +2955,9 @@ static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
 {
 	int phase;
 
-	seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ",
+	seq_printf(s, "%*s%-*s %7d %7d %8d %8d %11lu %10lu ",
 		   level * 3 + 1, "",
-		   30 - level * 3, c->name,
+		   30 - level * 3, c->name, c->consumers_count,
 		   c->enable_count, c->prepare_count, c->protect_count,
 		   clk_core_get_rate_recalc(c),
 		   clk_core_get_accuracy_recalc(c));
@@ -2996,9 +2996,9 @@ static int clk_summary_show(struct seq_file *s, void *data)
 	struct clk_core *c;
 	struct hlist_head **lists = (struct hlist_head **)s->private;
 
-	seq_puts(s, "                                 enable  prepare  protect                                duty  hardware\n");
-	seq_puts(s, "   clock                          count    count    count        rate   accuracy phase  cycle    enable\n");
-	seq_puts(s, "-------------------------------------------------------------------------------------------------------\n");
+	seq_puts(s, "                                 counsumers  enable  prepare  protect                                duty  hardware\n");
+	seq_puts(s, "   clock                              count   count    count    count        rate   accuracy phase  cycle    enable\n");
+	seq_puts(s, "-------------------------------------------------------------------------------------------------------------------\n");
 
 	clk_prepare_lock();
 
@@ -3021,6 +3021,7 @@ static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
 
 	/* This should be JSON format, i.e. elements separated with a comma */
 	seq_printf(s, "\"%s\": { ", c->name);
+	seq_printf(s, "\"consumers_count\": %d,", c->consumers_count);
 	seq_printf(s, "\"enable_count\": %d,", c->enable_count);
 	seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
 	seq_printf(s, "\"protect_count\": %d,", c->protect_count);
@@ -3330,6 +3331,7 @@ static void clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
 	debugfs_create_u32("clk_phase", 0444, root, &core->phase);
 	debugfs_create_file("clk_flags", 0444, root, core, &clk_flags_fops);
 	debugfs_create_u32("clk_prepare_count", 0444, root, &core->prepare_count);
+	debugfs_create_u32("clk_consumers_count", 0444, root, &core->consumers_count);
 	debugfs_create_u32("clk_enable_count", 0444, root, &core->enable_count);
 	debugfs_create_u32("clk_protect_count", 0444, root, &core->protect_count);
 	debugfs_create_u32("clk_notifier_count", 0444, root, &core->notifier_count);
-- 
2.34.3


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

* [RFC PATCH 4/4] clk: Skip disabling clocks if they have consumers
  2022-07-07 10:03 [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 2/4] clk: Add consumers count to core Abel Vesa
  2022-07-07 10:03 ` [RFC PATCH 3/4] clk: Add consumers count information to debugfs Abel Vesa
@ 2022-07-07 10:03 ` Abel Vesa
  2022-07-21  8:17 ` [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
  3 siblings, 0 replies; 5+ messages in thread
From: Abel Vesa @ 2022-07-07 10:03 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-msm, Abel Vesa

If a clock has already consumers, it should be considered as used.
So clk_disable_unused should leave it as is.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/clk/clk.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e412e83a6e28..6cce31ea4f72 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1228,6 +1228,9 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)
 	hlist_for_each_entry(child, &core->children, child_node)
 		clk_unprepare_unused_subtree(child);
 
+	if (core->consumers_count)
+		return;
+
 	if (core->prepare_count)
 		return;
 
@@ -1259,6 +1262,9 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
 	hlist_for_each_entry(child, &core->children, child_node)
 		clk_disable_unused_subtree(child);
 
+	if (core->consumers_count)
+		return;
+
 	if (core->flags & CLK_OPS_PARENT_ENABLE)
 		clk_core_prepare_enable(core->parent);
 
-- 
2.34.3


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

* Re: [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put
  2022-07-07 10:03 [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
                   ` (2 preceding siblings ...)
  2022-07-07 10:03 ` [RFC PATCH 4/4] clk: Skip disabling clocks if they have consumers Abel Vesa
@ 2022-07-21  8:17 ` Abel Vesa
  3 siblings, 0 replies; 5+ messages in thread
From: Abel Vesa @ 2022-07-21  8:17 UTC (permalink / raw)
  To: Mike Turquette, Stephen Boyd
  Cc: linux-clk, Linux Kernel Mailing List, linux-arm-msm

On 22-07-07 13:03:06, Abel Vesa wrote:
> For consistency, use clk_core_unlink_consumer rather then hlist_del
> directly, on __clk_put. Prepare lock is already acquired at that point.
>
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>

Gentle ping.

> ---
>  drivers/clk/clk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 7fc191c15507..e1d8245866b1 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -4347,7 +4347,7 @@ void __clk_put(struct clk *clk)
>  		clk->exclusive_count = 0;
>  	}
>
> -	hlist_del(&clk->clks_node);
> +	clk_core_unlink_consumer(clk);
>  	if (clk->min_rate > clk->core->req_rate ||
>  	    clk->max_rate < clk->core->req_rate)
>  		clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
> --
> 2.34.3
>

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

end of thread, other threads:[~2022-07-21  8:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 10:03 [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa
2022-07-07 10:03 ` [RFC PATCH 2/4] clk: Add consumers count to core Abel Vesa
2022-07-07 10:03 ` [RFC PATCH 3/4] clk: Add consumers count information to debugfs Abel Vesa
2022-07-07 10:03 ` [RFC PATCH 4/4] clk: Skip disabling clocks if they have consumers Abel Vesa
2022-07-21  8:17 ` [RFC PATCH 1/4] clk: Use clk_core_unlink_consumer on __clk_put Abel Vesa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.