Skip to contentSkip to conversation

clk: Use clk_core_unlink_consumer on __clk_put

RFC PATCH In review Abel Vesa 1 participant 5 messages Jul 7, 2022 – Jul 21, 2022

Subsystems (2)
lore
Share & tools
lore

Abel Vesa

author
#0 lore raw

RFC PATCH 1/4 clk: Use clk_core_unlink_consumer on __clk_put

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

---
 drivers/clk/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk.c +1 -1
index 7fc191c15507..e1d8245866b1 100644
@@ -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);
Signature · 1 line
2.34.3
author
#1 lore raw

RFC PATCH 2/4 clk: Add consumers count to core

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.

---
 drivers/clk/clk.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/clk.c +6 -0
index e1d8245866b1..9b54afd2fee8 100644
@@ -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--;
 }
 
 /**
Signature · 1 line
2.34.3
author
#2 lore raw

RFC PATCH 3/4 clk: Add consumers count information to debugfs

In reply to 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.

---
 drivers/clk/clk.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/clk/clk.c +7 -5
index 9b54afd2fee8..e412e83a6e28 100644
@@ -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);
Signature · 1 line
2.34.3
author
#3 lore raw

RFC PATCH 4/4 clk: Skip disabling clocks if they have consumers

In reply to Abel Vesa

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

---
 drivers/clk/clk.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/clk.c +6 -0
index e412e83a6e28..6cce31ea4f72 100644
@@ -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);
 
Signature · 1 line
2.34.3
author
#4 lore raw
In reply to Abel Vesa
Quoted 4 lines · 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.

Gentle ping.

Quoted 20 lines
---
 drivers/clk/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/clk.c +1 -2
index 7fc191c15507..e1d8245866b1 100644
@@ -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