linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: Stephen Boyd <sboyd@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Mike Turquette <mturquette@baylibre.com>,
	linux-clk@vger.kernel.org, Jerome Brunet <jbrunet@baylibre.com>,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
	Alexander Stein <alexander.stein@ew.tq-group.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Yassine Oudjana <y.oudjana@protonmail.com>,
	Tony Lindgren <tony@atomide.com>
Subject: Re: [PATCH v9 13/25] clk: Set req_rate on reparenting
Date: Mon, 10 Oct 2022 16:52:56 +0200	[thread overview]
Message-ID: <20221010145256.7zikxmkhjgor6esx@houat> (raw)
In-Reply-To: <20221010095608.ak6pnxslmvzhayce@houat>

[-- Attachment #1: Type: text/plain, Size: 3654 bytes --]

Replying to my own questions after some time working on this.

On Mon, Oct 10, 2022 at 11:56:08AM +0200, Maxime Ripard wrote:
> > > > +/*
> > > > + * Update the orphan rate and req_rate of @core and all its children.
> > > > + */
> > > > +static void clk_core_update_orphan_child_rates(struct clk_core *core)
> > > > +{
> > > > +     struct clk_core *child;
> > > > +     unsigned long parent_rate = 0;
> > > > +
> > > > +     if (core->parent)
> > > > +             parent_rate = core->parent->rate;
> > > > +
> > > > +     core->rate = core->req_rate = clk_recalc(core, parent_rate);
> > > > +
> > > > +     hlist_for_each_entry(child, &core->children, child_node)
> > > > +             clk_core_update_orphan_child_rates(child);
> > > > +}
> > > > +
> > > >   static void clk_reparent(struct clk_core *core, struct clk_core *new_parent)
> > > >   {
> > > >       bool was_orphan = core->orphan;
> > > > @@ -2506,6 +2527,7 @@ static void clk_core_reparent(struct clk_core *core,
> > > >                                 struct clk_core *new_parent)
> > > >   {
> > > >       clk_reparent(core, new_parent);
> > > > +     clk_core_update_orphan_child_rates(core);
> > > >       __clk_recalc_accuracies(core);
> > > >       __clk_recalc_rates(core, POST_RATE_CHANGE);
> > 
> > I see a problem. __clk_recalc_rates() uses 'core->rate' as "old rate"
> > but we'll have already destroyed that by calling
> > clk_core_update_orphan_child_rates() and assigning 'core->rate' to the
> > recalc_rate. Are clk notifiers being used? If so, it will probably be
> > confused because the notifier will see the same rate as what was set
> > instead of the old rate. cpufreq is probably the biggest user of clk
> > notifiers.
> 
> That's a very good point... Which raises another one. Would it be ok to
> notify users on a reparenting? It would make sense to me, since the rate
> could be affected, but it's not been done so far so I'm not sure what
> the implications might be

Turns out it's already done, and the rates were indeed off like you
pointed out.

> > We should add a test for that so when a clk is reparented the old rate
> > is still what we expected it to be when the notifier is called.
> 
> I can do it, but I'm not sure what you want to test exactly. Let's
> assume we have a mux with a given rate, we change the parent of that
> mux, the rate is likely to be changed as well and we should put in the
> notifier that the old_rate is the first parent's, and the new rate the
> one of the new parent?

I implemented this, and this catches the issue you pointed out, so it
looks like a decent test :)

> > Also, clk_core_update_orphan_child_rates() is poorly named. It doesn't
> > care at all that the clk is an orphan. It seems like another
> > __clk_recalc_rates() without the notifier. I have no idea why we need
> > another recalc rates.
> 
> You're right, the only difference between the two (aside from the
> notifiers) is that req_rate is also updated in
> clk_core_update_orphan_child_rates().
> 
> > Possibly setting the req_rate in __clk_recalc_rates() is sufficient.
> > Or maybe we should bail out if the clk doesn't have the orphan bit
> > set.
> 
> Either way makes sense to me, the latter is probably less intrusive, but
> the former allows to consolidate __clk_recalc_rates() and
> clk_core_update_orphan_child_rates(). Which one would you prefer?

I ended up removing clk_core_update_orphan_child_rates() entirely,
adding the test, and submitting it here:
https://lore.kernel.org/linux-clk/20221010-rpi-clk-fixes-again-v1-0-d87ba82ac404@cerno.tech/

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2022-10-10 14:53 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16 11:25 [PATCH v9 00/25] clk: More clock rate fixes and tests Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 01/25] clk: test: Switch to clk_hw_get_clk Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 02/25] clk: Drop the rate range on clk_put() Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 03/25] clk: Skip clamping when rounding if there's no boundaries Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 04/25] clk: Mention that .recalc_rate can return 0 on error Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 05/25] clk: Clarify clk_get_rate() expectations Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 06/25] clk: tests: Add test suites description Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 07/25] clk: tests: Add reference to the orphan mux bug report Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 08/25] clk: tests: Add tests for uncached clock Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 09/25] clk: tests: Add tests for single parent mux Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 10/25] clk: tests: Add tests for mux with multiple parents Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 11/25] clk: tests: Add some tests for orphan " Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 12/25] clk: Take into account uncached clocks in clk_set_rate_range() Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 13/25] clk: Set req_rate on reparenting Maxime Ripard
2022-10-03  9:59   ` Marek Szyprowski
2022-10-04 20:59     ` Stephen Boyd
2022-10-10  9:56       ` Maxime Ripard
2022-10-10 14:52         ` Maxime Ripard [this message]
2022-10-11  1:15           ` Stephen Boyd
2022-08-16 11:25 ` [PATCH v9 14/25] clk: Change clk_core_init_rate_req prototype Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 15/25] clk: Move clk_core_init_rate_req() from clk_core_round_rate_nolock() to its caller Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 16/25] clk: Introduce clk_hw_init_rate_request() Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 17/25] clk: Add our request boundaries in clk_core_init_rate_req Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 18/25] clk: Switch from __clk_determine_rate to clk_core_round_rate_nolock Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 19/25] clk: Introduce clk_core_has_parent() Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 20/25] clk: Constify clk_has_parent() Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 21/25] clk: Stop forwarding clk_rate_requests to the parent Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 22/25] clk: Zero the clk_rate_request structure Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 23/25] clk: Introduce the clk_hw_get_rate_range function Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 24/25] clk: qcom: clk-rcg2: Take clock boundaries into consideration for gfx3d Maxime Ripard
2022-08-16 11:25 ` [PATCH v9 25/25] clk: tests: Add missing test case for ranges Maxime Ripard
2022-08-16 14:07 ` [PATCH v9 00/25] clk: More clock rate fixes and tests Alexander Stein
2022-08-18  6:44 ` Naresh Kamboju
2022-09-02 14:53 ` Maxime Ripard
2022-09-17  8:31   ` Stephen Boyd
2022-09-20 12:35     ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010145256.7zikxmkhjgor6esx@houat \
    --to=maxime@cerno.tech \
    --cc=alexander.stein@ew.tq-group.com \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=jbrunet@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mturquette@baylibre.com \
    --cc=naresh.kamboju@linaro.org \
    --cc=narmstrong@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=tony@atomide.com \
    --cc=y.oudjana@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).