From: "Vijaya Krishna Nivarthi (Temp) (QUIC)" <quic_vnivarth@quicinc.com>
To: Doug Anderson <dianders@chromium.org>,
"Vijaya Krishna Nivarthi (Temp) (QUIC)"
<quic_vnivarth@quicinc.com>
Cc: Andy Gross <agross@kernel.org>,
"bjorn.andersson@linaro.org" <bjorn.andersson@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-arm-msm <linux-arm-msm@vger.kernel.org>,
"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"Mukesh Savaliya (QUIC)" <quic_msavaliy@quicinc.com>,
Matthias Kaehlcke <mka@chromium.org>,
Stephen Boyd <swboyd@chromium.org>
Subject: RE: [PATCH] tty: serial: qcom-geni-serial: minor fixes to get_clk_div_rate()
Date: Mon, 13 Jun 2022 18:16:34 +0000 [thread overview]
Message-ID: <BYAPR02MB456586D44A034C5933A89CFEFAAB9@BYAPR02MB4565.namprd02.prod.outlook.com> (raw)
In-Reply-To: <CAD=FV=WAEhncR462eT06KYuqmqx6QHb7wkvd1gxbsXqFRA06Ew@mail.gmail.com>
Hi,
> > >
> > > ser_clk = 0;
> > > maxdiv = CLK_DIV_MSK >> CLK_DIV_SHFT;
> > > div = 1;
> > > while (div < maxdiv) {
> >
> >
> > div <= maxdiv ?
>
> Ah, sure.
Thank you.
>
>
> > > mult = (unsigned long long)div * desired_clk;
> > > if (mult != (unsigned long)mult)
> > > break;
> > >
> > > two_percent = mult / 50;
> > >
> > > /*
> > > * Loop requesting (freq - 2%) and possibly (freq).
> > > *
> > > * We'll keep track of the lowest freq inexact match we found
> > > * but always try to find a perfect match. NOTE: this algorithm
> > > * could miss a slightly better freq if there's more than one
> > > * freq between (freq - 2%) and (freq) but (freq) can't be made
> > > * exactly, but that's OK.
> > > *
> > > * This absolutely relies on the fact that the Qualcomm clock
> > > * driver always rounds up.
> > > */
> > > test_freq = mult - two_percent;
> > > while (test_freq <= mult) {
> > > freq = clk_round_rate(clk, test_freq);
> > >
> > > /*
> > > * A dead-on freq is an insta-win. This implicitly
> > > * handles when "freq == mult"
> > > */
> > > if (!(freq % desired_clk)) {
> > > *clk_div = freq / desired_clk;
> > > return freq;
> > > }
> > >
> > > /*
> > > * Only time clock framework doesn't round up is if
> > > * we're past the max clock rate. We're done searching
> > > * if that's the case.
> > > */
> > > if (freq < test_freq)
> > > return ser_clk;
> > >
> > > /* Save the first (lowest freq) within 2% */
> > > if (!ser_clk && freq <= mult + two_percent) {
> > > ser_clk = freq;
> > > *clk_div = div;
> > > }
> >
> > My last concern is with search happening only within 2% tolerance.
> > Do we fail otherwise?
> >
> > This real case has best tolerance of 1.9% and seems close.
> >
> > [ 17.963672] 20220530 desired_clk-51200000
> > [ 21.193550] 20220530 returning ser_clk-52174000, div-1, diff-974000
> >
> > Perhaps we can fallback on 1st clock rate?
>
> I don't feel super comfortable just blindly falling back on the 1st clock rate. It
> could be wildly (more than 5%) wrong, can't it?
>
> IMO:
> * If you're not comfortable with 2%, you could always pick 3% or 4%.
> As I said, my random web search seemed to indicate that up to 5% was
> perhaps OK.
> * It's probably overkill, but you could abstract the whole search out and try
> searching once for 2% and then try 4%?
>
Ok, I will implement a function that searches within an input tolerance.
And have a conditional 2nd call to same with higher tolerance of 5%.
This would mean that we will still run through 2 loops in some cases, but that’s ok.
Thank you.
>
> -Doug
next prev parent reply other threads:[~2022-06-13 19:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 18:17 Vijaya Krishna Nivarthi
2022-05-31 18:28 ` Greg KH
2022-05-31 19:28 ` Doug Anderson
2022-06-01 10:45 ` Vijaya Krishna Nivarthi
2022-06-01 15:33 ` Doug Anderson
2022-06-03 17:43 ` Vijaya Krishna Nivarthi
2022-06-03 18:40 ` Doug Anderson
2022-06-06 18:19 ` Vijaya Krishna Nivarthi
2022-06-06 19:59 ` Doug Anderson
2022-06-07 17:40 ` Vijaya Krishna Nivarthi
2022-06-07 19:25 ` Doug Anderson
2022-06-08 18:33 ` Vijaya Krishna Nivarthi
2022-06-08 22:37 ` Doug Anderson
2022-06-09 17:48 ` Vijaya Krishna Nivarthi
2022-06-09 18:08 ` Vijaya Krishna Nivarthi
2022-06-10 9:33 ` Vijaya Krishna Nivarthi (Temp) (QUIC)
2022-06-10 17:20 ` Doug Anderson
2022-06-13 18:16 ` Vijaya Krishna Nivarthi (Temp) (QUIC) [this message]
2022-06-21 17:58 ` Vijaya Krishna Nivarthi (Temp)
2022-06-23 23:11 ` Doug Anderson
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=BYAPR02MB456586D44A034C5933A89CFEFAAB9@BYAPR02MB4565.namprd02.prod.outlook.com \
--to=quic_vnivarth@quicinc.com \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=mka@chromium.org \
--cc=quic_msavaliy@quicinc.com \
--cc=swboyd@chromium.org \
/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®