From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88C1AC433F5 for ; Fri, 15 Apr 2022 06:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350438AbiDOGbg (ORCPT ); Fri, 15 Apr 2022 02:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236018AbiDOGbg (ORCPT ); Fri, 15 Apr 2022 02:31:36 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA1E50456; Thu, 14 Apr 2022 23:29:08 -0700 (PDT) X-UUID: b225d94715c9430390a03777fc3720d7-20220415 X-UUID: b225d94715c9430390a03777fc3720d7-20220415 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 113088385; Fri, 15 Apr 2022 14:29:05 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Fri, 15 Apr 2022 14:29:04 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkexhb02.mediatek.inc (172.21.101.103) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 15 Apr 2022 14:29:03 +0800 Received: from mtksdccf07 (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 15 Apr 2022 14:29:03 +0800 Message-ID: Subject: Re: [PATCH V3 10/15] cpufreq: mediatek: Add counter to prevent infinite loop when tracking voltage From: Rex-BC Chen To: Hsin-Yi Wang CC: , Viresh Kumar , Rob Herring , , Matthias Brugger , Tim Chang , , Kevin Hilman , , , , , , , Date: Fri, 15 Apr 2022 14:29:03 +0800 In-Reply-To: References: <20220415055916.28350-1-rex-bc.chen@mediatek.com> <20220415055916.28350-11-rex-bc.chen@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Fri, 2022-04-15 at 14:14 +0800, Hsin-Yi Wang wrote: > On Fri, Apr 15, 2022 at 1:59 PM Rex-BC Chen > wrote: > > > > To prevent infinite loop when tracking voltage, we calculate the > > maximum > > value for each platform data. > > We assume min voltage is 0 and tracking target voltage using > > min_volt_shift for each iteration. > > The retry_max is 3 times of expeted iteration count. > > > > Signed-off-by: Rex-BC Chen > > --- > > drivers/cpufreq/mediatek-cpufreq.c | 16 ++++++++++++++++ > > 1 file changed, 16 insertions(+) > > > > diff --git a/drivers/cpufreq/mediatek-cpufreq.c > > b/drivers/cpufreq/mediatek-cpufreq.c > > index cc44a7a9427a..d4c00237e862 100644 > > --- a/drivers/cpufreq/mediatek-cpufreq.c > > +++ b/drivers/cpufreq/mediatek-cpufreq.c > > @@ -86,6 +86,16 @@ static int mtk_cpufreq_voltage_tracking(struct > > mtk_cpu_dvfs_info *info, > > struct regulator *proc_reg = info->proc_reg; > > struct regulator *sram_reg = info->sram_reg; > > int pre_vproc, pre_vsram, new_vsram, vsram, vproc, ret; > > + int retry_max; > > + > > + /* > > + * We assume min voltage is 0 and tracking target voltage > > using > > + * min_volt_shift for each iteration. > > + * The retry_max is 3 times of expeted iteration count. > > + */ > > + retry_max = 3 * DIV_ROUND_UP(max(info->soc_data- > > >sram_max_volt, > > + info->soc_data- > > >proc_max_volt), > > + info->soc_data- > > >min_volt_shift); > > mtk_cpufreq_voltage_tracking() will be called very frequently. > retry_max is the same every time mtk_cpufreq_voltage_tracking() is > called. Is it better to calculate before and store in > mtk_cpu_dvfs_info? > Hello Hsin-Yi, Thanks for your reviwew. I will do this in next version. BRs, Rex > > > > pre_vproc = regulator_get_voltage(proc_reg); > > if (pre_vproc < 0) { > > @@ -151,6 +161,12 @@ static int mtk_cpufreq_voltage_tracking(struct > > mtk_cpu_dvfs_info *info, > > > > pre_vproc = vproc; > > pre_vsram = vsram; > > + > > + if (--retry_max < 0) { > > + dev_err(info->cpu_dev, > > + "over loop count, failed to set > > voltage\n"); > > + return -EINVAL; > > + } > > } while (vproc != new_vproc || vsram != new_vsram); > > > > return 0; > > -- > > 2.18.0 > >