All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
@ 2022-08-10  1:40 ` Samuel Holland
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Holland @ 2022-08-10  1:40 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jernej Skrabec
  Cc: Samuel Holland, Michael Turquette, Stephen Boyd,
	linux-arm-kernel, linux-clk, linux-kernel, linux-sunxi

ccu_mp_find_best() already computes a best_rate at the same time as the
best m and p factors. Return it so the caller does not need to duplicate
the division.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi-ng/ccu_mp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/sunxi-ng/ccu_mp.c b/drivers/clk/sunxi-ng/ccu_mp.c
index 57cf2d615148..cc94a694cb67 100644
--- a/drivers/clk/sunxi-ng/ccu_mp.c
+++ b/drivers/clk/sunxi-ng/ccu_mp.c
@@ -10,9 +10,9 @@
 #include "ccu_gate.h"
 #include "ccu_mp.h"
 
-static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
-			     unsigned int max_m, unsigned int max_p,
-			     unsigned int *m, unsigned int *p)
+static unsigned long ccu_mp_find_best(unsigned long parent, unsigned long rate,
+				      unsigned int max_m, unsigned int max_p,
+				      unsigned int *m, unsigned int *p)
 {
 	unsigned long best_rate = 0;
 	unsigned int best_m = 0, best_p = 0;
@@ -35,6 +35,8 @@ static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
 
 	*m = best_m;
 	*p = best_p;
+
+	return best_rate;
 }
 
 static unsigned long ccu_mp_find_best_with_parent_adj(struct clk_hw *hw,
@@ -109,8 +111,7 @@ static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
 	max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);
 
 	if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
-		ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
-		rate = *parent_rate / p / m;
+		rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
 	} else {
 		rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
 							max_m, max_p);
-- 
2.35.1


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

* [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
@ 2022-08-10  1:40 ` Samuel Holland
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Holland @ 2022-08-10  1:40 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jernej Skrabec
  Cc: Samuel Holland, Michael Turquette, Stephen Boyd,
	linux-arm-kernel, linux-clk, linux-kernel, linux-sunxi

ccu_mp_find_best() already computes a best_rate at the same time as the
best m and p factors. Return it so the caller does not need to duplicate
the division.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/clk/sunxi-ng/ccu_mp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/sunxi-ng/ccu_mp.c b/drivers/clk/sunxi-ng/ccu_mp.c
index 57cf2d615148..cc94a694cb67 100644
--- a/drivers/clk/sunxi-ng/ccu_mp.c
+++ b/drivers/clk/sunxi-ng/ccu_mp.c
@@ -10,9 +10,9 @@
 #include "ccu_gate.h"
 #include "ccu_mp.h"
 
-static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
-			     unsigned int max_m, unsigned int max_p,
-			     unsigned int *m, unsigned int *p)
+static unsigned long ccu_mp_find_best(unsigned long parent, unsigned long rate,
+				      unsigned int max_m, unsigned int max_p,
+				      unsigned int *m, unsigned int *p)
 {
 	unsigned long best_rate = 0;
 	unsigned int best_m = 0, best_p = 0;
@@ -35,6 +35,8 @@ static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
 
 	*m = best_m;
 	*p = best_p;
+
+	return best_rate;
 }
 
 static unsigned long ccu_mp_find_best_with_parent_adj(struct clk_hw *hw,
@@ -109,8 +111,7 @@ static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
 	max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);
 
 	if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
-		ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
-		rate = *parent_rate / p / m;
+		rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
 	} else {
 		rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
 							max_m, max_p);
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
  2022-08-10  1:40 ` Samuel Holland
@ 2022-08-14 10:02   ` Jernej Škrabec
  -1 siblings, 0 replies; 8+ messages in thread
From: Jernej Škrabec @ 2022-08-14 10:02 UTC (permalink / raw)
  To: Chen-Yu Tsai, Samuel Holland
  Cc: Samuel Holland, Michael Turquette, Stephen Boyd,
	linux-arm-kernel, linux-clk, linux-kernel, linux-sunxi

Dne sreda, 10. avgust 2022 ob 03:40:24 CEST je Samuel Holland napisal(a):
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Other ccu_*_find_best() functions would also benefit with similar change.

Best regards,
Jernej



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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
@ 2022-08-14 10:02   ` Jernej Škrabec
  0 siblings, 0 replies; 8+ messages in thread
From: Jernej Škrabec @ 2022-08-14 10:02 UTC (permalink / raw)
  To: Chen-Yu Tsai, Samuel Holland
  Cc: Samuel Holland, Michael Turquette, Stephen Boyd,
	linux-arm-kernel, linux-clk, linux-kernel, linux-sunxi

Dne sreda, 10. avgust 2022 ob 03:40:24 CEST je Samuel Holland napisal(a):
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Other ccu_*_find_best() functions would also benefit with similar change.

Best regards,
Jernej



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
  2022-08-10  1:40 ` Samuel Holland
@ 2022-08-15 17:26   ` Stephen Boyd
  -1 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2022-08-15 17:26 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland
  Cc: Samuel Holland, Michael Turquette, linux-arm-kernel, linux-clk,
	linux-kernel, linux-sunxi

Quoting Samuel Holland (2022-08-09 18:40:24)
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.

Did the compiler figure this out and thus this patch makes no difference
to the final object code?

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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
@ 2022-08-15 17:26   ` Stephen Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2022-08-15 17:26 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland
  Cc: Samuel Holland, Michael Turquette, linux-arm-kernel, linux-clk,
	linux-kernel, linux-sunxi

Quoting Samuel Holland (2022-08-09 18:40:24)
> ccu_mp_find_best() already computes a best_rate at the same time as the
> best m and p factors. Return it so the caller does not need to duplicate
> the division.

Did the compiler figure this out and thus this patch makes no difference
to the final object code?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
  2022-08-15 17:26   ` Stephen Boyd
@ 2022-12-31 17:21     ` Samuel Holland
  -1 siblings, 0 replies; 8+ messages in thread
From: Samuel Holland @ 2022-12-31 17:21 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec
  Cc: Michael Turquette, linux-arm-kernel, linux-clk, linux-kernel,
	linux-sunxi

Hi Stephen,

On 8/15/22 12:26, Stephen Boyd wrote:
> Quoting Samuel Holland (2022-08-09 18:40:24)
>> ccu_mp_find_best() already computes a best_rate at the same time as the
>> best m and p factors. Return it so the caller does not need to duplicate
>> the division.
> 
> Did the compiler figure this out and thus this patch makes no difference
> to the final object code?

It makes a difference at least on my gcc version 11.1.0.

Before:
   text    data     bss     dec     hex filename
  18257      12       0   18269    475d drivers/clk/sunxi-ng/sunxi-ccu.o

After:
   text    data     bss     dec     hex filename
  18083      12       0   18095    46af drivers/clk/sunxi-ng/sunxi-ccu.o

I will send a v2 covering all of the CCU clock types.

Regards,
Samuel


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

* Re: [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice
@ 2022-12-31 17:21     ` Samuel Holland
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Holland @ 2022-12-31 17:21 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec
  Cc: Michael Turquette, linux-arm-kernel, linux-clk, linux-kernel,
	linux-sunxi

Hi Stephen,

On 8/15/22 12:26, Stephen Boyd wrote:
> Quoting Samuel Holland (2022-08-09 18:40:24)
>> ccu_mp_find_best() already computes a best_rate at the same time as the
>> best m and p factors. Return it so the caller does not need to duplicate
>> the division.
> 
> Did the compiler figure this out and thus this patch makes no difference
> to the final object code?

It makes a difference at least on my gcc version 11.1.0.

Before:
   text    data     bss     dec     hex filename
  18257      12       0   18269    475d drivers/clk/sunxi-ng/sunxi-ccu.o

After:
   text    data     bss     dec     hex filename
  18083      12       0   18095    46af drivers/clk/sunxi-ng/sunxi-ccu.o

I will send a v2 covering all of the CCU clock types.

Regards,
Samuel


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-12-31 17:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10  1:40 [PATCH] clk: sunxi-ng: mp: Avoid computing the rate twice Samuel Holland
2022-08-10  1:40 ` Samuel Holland
2022-08-14 10:02 ` Jernej Škrabec
2022-08-14 10:02   ` Jernej Škrabec
2022-08-15 17:26 ` Stephen Boyd
2022-08-15 17:26   ` Stephen Boyd
2022-12-31 17:21   ` Samuel Holland
2022-12-31 17:21     ` Samuel Holland

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.