public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@codeaurora.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Subject: Re: [PATCH v1 1/1] clk: fractional-divider: eliminate while-loop
Date: Thu, 19 Mar 2015 23:34:58 -0700	[thread overview]
Message-ID: <20150320063458.GA6677@codeaurora.org> (raw)
In-Reply-To: <1426791260-15910-1-git-send-email-andriy.shevchenko@linux.intel.com>

On 03/19, Andy Shevchenko wrote:
> We may do a calculation of the rounded rate based on (*prate / div) value in
> case it is not 0. It's as much higher as power of two of nearest value to
> (*prate / div / maxn). Thus, the patch replaces while-loop by direct
> calculations.
> 
> While here, fix off-by-one error. maxn is the maximum value that can be hold by
> a register which means all ones in it.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/clk/clk-fractional-divider.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
> index 6aa72d9..4c0541b 100644
> --- a/drivers/clk/clk-fractional-divider.c
> +++ b/drivers/clk/clk-fractional-divider.c
> @@ -14,6 +14,7 @@
>  #include <linux/device.h>
>  #include <linux/slab.h>
>  #include <linux/gcd.h>
> +#include <linux/log2.h>
>  
>  #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
>  
> @@ -49,18 +50,16 @@ static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate,
>  			      unsigned long *prate)
>  {
>  	struct clk_fractional_divider *fd = to_clk_fd(hw);
> -	unsigned maxn = (fd->nmask >> fd->nshift) + 1;
> -	unsigned div;
> +	unsigned maxn = fd->nmask >> fd->nshift;
> +	unsigned long div, n;
>  
>  	if (!rate || rate >= *prate)
>  		return *prate;
>  
>  	div = gcd(*prate, rate);
> -
> -	while ((*prate / div) > maxn) {
> -		div <<= 1;
> -		rate <<= 1;
> -	}
> +	n = *prate / div;
> +	if (n > maxn)
> +		return rate * roundup_pow_of_two(n / maxn);
>  
>  	return rate;
>  }

Is there any reason why this code isn't using
rational_best_approximation() and mult_frac()? 

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2015-03-20  6:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19 18:54 [PATCH v1 1/1] clk: fractional-divider: eliminate while-loop Andy Shevchenko
2015-03-20  6:34 ` Stephen Boyd [this message]
2015-03-20 13:03   ` 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=20150320063458.GA6677@codeaurora.org \
    --to=sboyd@codeaurora.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.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