From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbbCTNDT (ORCPT ); Fri, 20 Mar 2015 09:03:19 -0400 Received: from mga09.intel.com ([134.134.136.24]:54922 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751034AbbCTNDS (ORCPT ); Fri, 20 Mar 2015 09:03:18 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,436,1422950400"; d="scan'208";a="701652214" Message-ID: <1426856584.14897.381.camel@linux.intel.com> Subject: Re: [PATCH v1 1/1] clk: fractional-divider: eliminate while-loop From: Andy Shevchenko To: Stephen Boyd Cc: linux-kernel@vger.kernel.org, Heikki Krogerus Date: Fri, 20 Mar 2015 15:03:04 +0200 In-Reply-To: <20150320063458.GA6677@codeaurora.org> References: <1426791260-15910-1-git-send-email-andriy.shevchenko@linux.intel.com> <20150320063458.GA6677@codeaurora.org> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2015-03-19 at 23:34 -0700, Stephen Boyd wrote: > 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 > > --- > > 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 > > #include > > #include > > +#include > > > > #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()? For fist glance it should be faster that rational_best_approximation(), though less precise. I could switch to them. -- Andy Shevchenko Intel Finland Oy