From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Liu Ying <victor.liu@nxp.com>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Dong Aisheng <aisheng.dong@nxp.com>,
NXP Linux Team <linux-imx@nxp.com>, Jacky Bai <ping.bai@nxp.com>
Subject: Re: [RFC PATCH] clk: fractional-divider: Correct max_{m,n} handed over to rational_best_approximation()
Date: Wed, 14 Jul 2021 13:38:22 +0300 [thread overview]
Message-ID: <YO6+nkzDlNM/KJio@smile.fi.intel.com> (raw)
In-Reply-To: <1f1b38f9c42093bea5e6a8ccb458bdf799069157.camel@nxp.com>
On Wed, Jul 14, 2021 at 06:10:46PM +0800, Liu Ying wrote:
> On Wed, 2021-07-14 at 12:12 +0300, Andy Shevchenko wrote:
> > On Wed, Jul 14, 2021 at 02:41:29PM +0800, Liu Ying wrote:
...
> > > /*
> > > * Get rate closer to *parent_rate to guarantee there is no overflow
> > > * for m and n. In the result it will be the nearest rate left shifted
> > > * by (scale - fd->nwidth) bits.
> > > */
> >
> > I don't know how to rephrase above comment better.
> >
> > > scale = fls_long(*parent_rate / rate - 1);
> > > if (scale > fd->nwidth)
> > > rate <<= scale - fd->nwidth;
> >
> > This takes an advantage of the numbers be in a form of
> >
> > n = k * 2^m, (1)
> >
> > where m will be scale in the snippet above. Thus, if n can be represented by
> > (1), we opportunistically reduce amount of bits needed for it by shifting right
> > by m bits.
> >
> > Does it make sense?
>
> Thanks for your explaination.
> But, sorry, Jacky and I still don't understand this.
Okay, We have two values in question:
r_o (original rate of the parent clock)
r_u (the rate user asked for)
We have a pre-scaler block which asks for
m (denominator)
n (nominator)
values to be provided to satisfy the (2)
r_u ~= r_o * m / n, (2)
where we try our best to make it "=" instead of "~=".
Now, m and n have the limitation by a range, e.g.
n >= 1, n < N_lim, where N_lim = 2^nlim. (3)
Hence, from (2) and (3), assuming the worst case m = 1,
ln2(r_o / r_u) <= nlim. (4)
The above code tries to satisfy (4).
Have you got it now?
> > The code looks good to me, btw, although I dunno if you need to call the newly
> > introduced function before or after the above mentioned snippet.
>
> Assuming that snippet is fully orthogonal to this patch, then it
> doesn't matter if it's before or after.
Please, double check this. Because you play with limits, while we expect them
to satisfy (3).
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2021-07-14 10:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 6:41 Liu Ying
2021-07-14 9:12 ` Andy Shevchenko
2021-07-14 10:10 ` Liu Ying
2021-07-14 10:38 ` Andy Shevchenko [this message]
2021-07-14 10:46 ` Andy Shevchenko
2021-07-15 5:26 ` Liu Ying
2021-07-15 8:02 ` Andy Shevchenko
2021-07-15 8:14 ` Andy Shevchenko
2021-07-15 8:19 ` Andy Shevchenko
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=YO6+nkzDlNM/KJio@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=aisheng.dong@nxp.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=ping.bai@nxp.com \
--cc=sboyd@kernel.org \
--cc=victor.liu@nxp.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
all inboxes | Powered by JetHome®