2015-02-06 14:13:48

by Tomeu Vizoso

[permalink] [raw]
Subject: [PATCH] clk: Only recalculate the rate if needed

We don't really need to recalculate the effective rate of a clock when a
per-user clock is removed, if the constraints of the later aren't
limiting the requested rate.

This was causing problems with clocks that never had a rate set before,
as rate_req would be zero. Though this could be considered a bug in the
implementation of those clocks, this should be checked somewhere else.

Cc: Thierry Reding <[email protected]>
Cc: Peter De Schrijver <[email protected]>
Signed-off-by: Tomeu Vizoso <[email protected]>

---

This applies on top of https://lkml.org/lkml/2015/2/5/769
---
drivers/clk/clk.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a7d37c3..4ea2d53 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2664,7 +2664,11 @@ void __clk_put(struct clk *clk)
clk_prepare_lock();

hlist_del(&clk->clks_node);
- clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
+
+ 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);
+
owner = clk->core->owner;
kref_put(&clk->core->ref, __clk_release);

--
1.9.3


2015-02-20 03:29:56

by Mike Turquette

[permalink] [raw]
Subject: Re: [PATCH] clk: Only recalculate the rate if needed

Quoting Tomeu Vizoso (2015-02-06 06:13:01)
> We don't really need to recalculate the effective rate of a clock when a
> per-user clock is removed, if the constraints of the later aren't
> limiting the requested rate.
>
> This was causing problems with clocks that never had a rate set before,
> as rate_req would be zero. Though this could be considered a bug in the
> implementation of those clocks, this should be checked somewhere else.
>
> Cc: Thierry Reding <[email protected]>
> Cc: Peter De Schrijver <[email protected]>
> Signed-off-by: Tomeu Vizoso <[email protected]>

Fixes: 1c8e600440c7 ("clk: Add rate constraints to clocks")

Applied to clk-next. With this fix sunxi no longer vomits WARNs
everywhere due to divide-by-zero in the following path:

of_clk_init -> parent_ready -> __clk_put

Thanks,
Mike

>
> ---
>
> This applies on top of https://lkml.org/lkml/2015/2/5/769
> ---
> drivers/clk/clk.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index a7d37c3..4ea2d53 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -2664,7 +2664,11 @@ void __clk_put(struct clk *clk)
> clk_prepare_lock();
>
> hlist_del(&clk->clks_node);
> - clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
> +
> + 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);
> +
> owner = clk->core->owner;
> kref_put(&clk->core->ref, __clk_release);
>
> --
> 1.9.3
>