From patchwork Wed Jan 29 16:24:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime COQUELIN X-Patchwork-Id: 23880 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C1084202FA for ; Wed, 29 Jan 2014 16:25:48 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id k19sf7414751igc.3 for ; Wed, 29 Jan 2014 08:25:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=x+cE8C84Qlm2S33muESnIOgykKdiiZeoAo0RYqK6hfI=; b=KJ7r/DI7sjYJBFbdmRSw0jVYWGV6ZC8aD1PcHRtBLWZkxie+nEk6w/JnrQfOJ/9Pjg PQv81X2yHjg+HVAGKoX/lSCvCwyeW+IFy7Ql6uqvwPLkiZ+rfhr9VMDdKKxPlt+AvCw0 kynII2oPEICC7/MrDkZNkoTX3jHJyYk7+bqY90lKMpzVu8OFWnVyTZQHffyJOF5BVMGy nnzO3dlMtsh568zft4U7BPcN1VDsfAxXylcUTQF73X7+I7EXOE/DILzdiYTtqyWB5xiU z4qnJqgPhHPwD/aCfK5NsLcanRAdXAMhYQ5G3KKLtuzU3lqJ5ZzyqA/i1D84XMEQ0VvQ 8k3w== X-Gm-Message-State: ALoCoQmLQ5rnXq5mB7Dyouxs/nZcACR5vf5IG+x+LTmZQTwZTkZJezSncwX2M9ddkUGvmZcM7uc2 X-Received: by 10.182.213.5 with SMTP id no5mr3192342obc.15.1391012748048; Wed, 29 Jan 2014 08:25:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.28.6 with SMTP id 6ls173874qgy.16.gmail; Wed, 29 Jan 2014 08:25:47 -0800 (PST) X-Received: by 10.58.181.165 with SMTP id dx5mr7046400vec.19.1391012747763; Wed, 29 Jan 2014 08:25:47 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id tj7si934583vdc.111.2014.01.29.08.25.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Jan 2014 08:25:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id jz11so1327831veb.22 for ; Wed, 29 Jan 2014 08:25:47 -0800 (PST) X-Received: by 10.52.164.39 with SMTP id yn7mr2665736vdb.25.1391012747605; Wed, 29 Jan 2014 08:25:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp126023vcz; Wed, 29 Jan 2014 08:25:46 -0800 (PST) X-Received: by 10.180.149.206 with SMTP id uc14mr18329019wib.44.1391012746421; Wed, 29 Jan 2014 08:25:46 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id u4si1454520wjq.117.2014.01.29.08.25.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jan 2014 08:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8Xx0-0001k1-MT; Wed, 29 Jan 2014 16:25:18 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8Xwy-0000ar-6W; Wed, 29 Jan 2014 16:25:16 +0000 Received: from eu1sys200aog111.obsmtp.com ([207.126.144.131]) by merlin.infradead.org with smtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8Xwu-0000ZQ-1c for linux-arm-kernel@lists.infradead.org; Wed, 29 Jan 2014 16:25:13 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob111.postini.com ([207.126.147.11]) with SMTP ID DSNKUukrTUHEYGSGknIejea++9D0c+2CxIc9@postini.com; Wed, 29 Jan 2014 16:25:11 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9C84BED; Wed, 29 Jan 2014 16:23:34 +0000 (GMT) Received: from mail7.sgp.st.com (unknown [164.129.223.81]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7FB292C670; Wed, 29 Jan 2014 16:24:22 +0000 (GMT) Received: from lmenx29l.st.com (lmenx29l.lme.st.com [10.201.23.80]) by mail7.sgp.st.com (MOS 4.3.3-GA) with ESMTP id BWY31352 (AUTH lme00137); Wed, 29 Jan 2014 17:24:23 +0100 From: Maxime COQUELIN To: Mike Turquette , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] clk: divider: Optimize clk_divider_bestdiv loop Date: Wed, 29 Jan 2014 17:24:08 +0100 Message-Id: <1391012648-12481-4-git-send-email-maxime.coquelin@st.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1391012648-12481-1-git-send-email-maxime.coquelin@st.com> References: <1391012648-12481-1-git-send-email-maxime.coquelin@st.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140129_112512_298493_B115AF61 X-CRM114-Status: GOOD ( 14.35 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.126.144.131 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: kernel@stlinux.com, maxime.coquelin@st.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxime.coquelin@st.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Currently, the for-loop used to try all the different dividers to find the one that best fit tries all the values from 1 to max_div, incrementing by one. In case of power-of-two, or table based divider, the loop isn't optimal. Instead of incrementing by one, this patch provides directly the next divider. Signed-off-by: Maxime Coquelin --- drivers/clk/clk-divider.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 1eaa5d8..4aabf4f 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -240,6 +240,18 @@ static bool _is_best_div(struct clk_divider *divider, return now <= rate && now > best; } +static int _next_div(struct clk_divider *divider, int div) +{ + div++; + + if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) + return __roundup_pow_of_two(div); + if (divider->table) + return _round_up_table(divider->table, div); + + return div; +} + static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, unsigned long *best_parent_rate) { @@ -267,7 +279,7 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate, */ maxdiv = min(ULONG_MAX / rate, maxdiv); - for (i = 1; i <= maxdiv; i++) { + for (i = 1; i <= maxdiv; i = _next_div(divider, i)) { if (!_is_valid_div(divider, i)) continue; if (rate * i == parent_rate_saved) {