Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp276105pxv; Wed, 14 Jul 2021 03:48:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV4K2m827UzD3bjT0gtBaBIm8qqlIUwkwVkikn/gRxO5NnnrKGGNag2TCp5QcjfYlMM3Yq X-Received: by 2002:aa7:c98d:: with SMTP id c13mr12380253edt.255.1626259732434; Wed, 14 Jul 2021 03:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626259732; cv=none; d=google.com; s=arc-20160816; b=jHvozcbyCqzKnvZ7h3NLoThmAMuVOgT43IdUtp6/QIXHJwbDrYz4GKHQGCD3YDTl95 mj1w7KpNYwcJn1XMDOlbSwuClarCdDTu/PjUoxTSiMZq+zT0KPNpgKnAhwzX7X+wpv5R VZXMLGbRvlO63fMTPxZ4rdrM3X4Lt28P8dyqWYaqYUQYti4J6ZEaGN0z4bTRMBmLsZMN s6EsxpEYtmJnZSi4hWbVZp+CpTAKvFAg+gy03NJoAnvq1nil6njkSxuWbxX9KN9nuLQL fvlVBhvnPb1svu/wOiLOPfxwBMIEOFHOtwLwxEeqcwlwKt3ihkqQLwUg6/DV/WGXO3yu 030Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=NrYvM4AY3bpOy8/S+dRGG7J+YTPDaYRr+mgZeMAgGIg=; b=A9TxSAOzJ80AU+TgdrW7/8DDi0kN7yKnvq7CZo59YprRDMT07ak3lsGiuxGDl8s5LP oX1G9ZPuwWd07Ax58Bdq/tRxkKAbiCl6qCm7iaIeDHCqaneSpZThjA2ce+/wnbflklRq NSOEEVvhdDCWQbrHD4WBokqUJ9MfOuDgGCmVSNm7+RxIeVNP7l3fPinP/UEZgPWHi7Zq 897DVYvl0m/y7sMsh/+QjhQBYeLBb+Ms3CehdR2amslpetKPTKMIFeITFJyJtuQZz4EE fGuAARp7ED5hQf1NLCxD8o0JSoLBPnYcUqDRZ8ZcaMUYLOZarh7eg9zLn13sxTcdJAuv oTpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si2471575edt.211.2021.07.14.03.48.29; Wed, 14 Jul 2021 03:48:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239193AbhGNKtL (ORCPT + 99 others); Wed, 14 Jul 2021 06:49:11 -0400 Received: from mga03.intel.com ([134.134.136.65]:24002 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237788AbhGNKtK (ORCPT ); Wed, 14 Jul 2021 06:49:10 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10044"; a="210367740" X-IronPort-AV: E=Sophos;i="5.84,238,1620716400"; d="scan'208";a="210367740" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 03:46:18 -0700 X-IronPort-AV: E=Sophos;i="5.84,238,1620716400"; d="scan'208";a="413247577" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 03:46:15 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1m3cP3-00DHKT-Rc; Wed, 14 Jul 2021 13:46:09 +0300 Date: Wed, 14 Jul 2021 13:46:09 +0300 From: Andy Shevchenko To: Liu Ying Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Heikki Krogerus , Michael Turquette , Stephen Boyd , Dong Aisheng , NXP Linux Team , Jacky Bai Subject: Re: [RFC PATCH] clk: fractional-divider: Correct max_{m,n} handed over to rational_best_approximation() Message-ID: References: <20210714064129.1321277-1-victor.liu@nxp.com> <1f1b38f9c42093bea5e6a8ccb458bdf799069157.camel@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 14, 2021 at 01:38:22PM +0300, Andy Shevchenko wrote: > 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. It seems I poorly chose the letters for (1). Let's rewrite above as This takes an advantage of the numbers be in a form of a = k * 2^b, (1) where b will be scale in the snippet above. Thus, if a can be represented by (1), we opportunistically reduce amount of bits needed for it by shifting right by b bits. Also note, "shifting right" here is about the result of n (see below). > 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 > > -- With Best Regards, Andy Shevchenko