[PATCH 08/13] clk: divider: stop early if an optimal divider is found
From: Benjamin Bara
Date: Sun Sep 17 2023 - 18:44:22 EST
From: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>
During finding the best divider, the current implementation asks the
parent for the best rate for all its available dividers. If there are a
lot of supported divider values and the maximum divider is far from the
target rate, this can lead to many iterations. Depending on the parent,
the process of calculating the best fitting rate can be quite complex.
Therefore, return early if an optimal divider has been found.
Signed-off-by: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>
---
drivers/clk/clk-divider.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index a2c2b5203b0a..61b40dfb4e6f 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -332,6 +332,15 @@ static int clk_divider_bestdiv(struct clk_hw *hw, struct clk_hw *parent,
bestdiv = i;
best = now;
*best_parent_rate = parent_rate;
+ if (now == rate)
+ /*
+ * Calculating fitting PLL parameters, which
+ * might be done in parent's round_rate, can be
+ * time-consuming. Therefore, the lowest parent
+ * rate which gives us the exact required rate
+ * is already optimal.
+ */
+ return i;
}
}
--
2.34.1