All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Michael Turquette <mturquette@baylibre.com>,
	Yang Xiwen <forbidden405@outlook.com>,
	Yang Xiwen via B4 Relay
	<devnull+forbidden405.outlook.com@kernel.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] clk: set initial best mux parent to current parent when determining rate
Date: Thu, 29 Feb 2024 17:42:25 -0800	[thread overview]
Message-ID: <97787cc46d663b08b2e571841fb1bd6b.sboyd@kernel.org> (raw)
In-Reply-To: <SEZPR06MB69598A991B4CCF633E764CE7965F2@SEZPR06MB6959.apcprd06.prod.outlook.com>

Quoting Yang Xiwen (2024-02-28 18:33:11)
> On 2/29/2024 10:25 AM, Stephen Boyd wrote:
> >>>
> >>> Is the problem that we're not using abs_diff()?
> >>
> >>
> >> No, i think. It has nothing to do with the code here. It's because of
> >> the initial best_parent/best_parent_rate.
> > 
> > Alright.

I will have to fix this as well in a different patch.

> > 
> >>
> >>>
> >>> ----8<----
> >>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> >>> index a3bc7fb90d0f..91023345595f 100644
> >>> --- a/drivers/clk/clk.c
> >>> +++ b/drivers/clk/clk.c
> >>> @@ -542,7 +542,7 @@ static bool mux_is_better_rate(unsigned long rate, unsigned long now,
> >>>                          unsigned long best, unsigned long flags)
> >>>  {
> >>>       if (flags & CLK_MUX_ROUND_CLOSEST)
> >>> -             return abs(now - rate) < abs(best - rate);
> >>> +             return abs_diff(now, rate) < abs_diff(best, rate);
> >>
> >> Without this patch, the initial `best` rate would be always 0. This is
> >> wrong for most cases, 0Hz might (usually) be unavailable. We should use
> >> a valid rate(i.e. current rate) initially.
> > 
> > Ok. But you set best to the parent rate. So why not use 'core->rate'
> > directly as 'best'?
> 
> 
> I can't remember exactly. I just add this piece of code and found it's
> working. Is this field already filled prior to setting rate? Anyway,
> your suggestion is very reasonable. Maybe dear clk maintainers can fix
> it as i'm not familiar with clk core code.

Yes the 'struct clk_rate_request' is pre-filled with many details,
including the rate of the clk and the current parent rate and parent hw
pointer. I'm pretty sure you're trying to fix this fixme from clk_test.c

static const struct clk_ops clk_dummy_single_parent_ops = {
	/*
	 * FIXME: Even though we should probably be able to use
	 * __clk_mux_determine_rate() here, if we use it and call
	 * clk_round_rate() or clk_set_rate() with a rate lower than
	 * what all the parents can provide, it will return -EINVAL.
	 *
	 * This is due to the fact that it has the undocumented
	 * behaviour to always pick up the closest rate higher than the
	 * requested rate. If we get something lower, it thus considers
	 * that it's not acceptable and will return an error.
	 *
	 * It's somewhat inconsistent and creates a weird threshold
	 * between rates above the parent rate which would be rounded to
	 * what the parent can provide, but rates below will simply
	 * return an error.
	 */

  reply	other threads:[~2024-03-01  1:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 17:18 [PATCH RESEND] clk: set initial best mux parent to current parent when determining rate Yang Xiwen
2024-02-23 17:18 ` Yang Xiwen via B4 Relay
2024-02-29  1:58 ` Stephen Boyd
2024-02-29  2:13   ` Yang Xiwen
2024-02-29  2:25     ` Stephen Boyd
2024-02-29  2:33       ` Yang Xiwen
2024-03-01  1:42         ` Stephen Boyd [this message]
2024-03-01  1:58           ` Yang Xiwen
  -- strict thread matches above, loose matches on Subject: below --
2024-02-19 19:59 Yang Xiwen
2024-02-19 19:59 ` Yang Xiwen via B4 Relay

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=97787cc46d663b08b2e571841fb1bd6b.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=devnull+forbidden405.outlook.com@kernel.org \
    --cc=forbidden405@outlook.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.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 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.