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 X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E7A6C4363A for ; Mon, 5 Oct 2020 18:43:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BAE9D20853 for ; Mon, 5 Oct 2020 18:43:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="K8lCnJhu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="BlKiMMCf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAE9D20853 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3ow858aYeOsNDn09L38iPtWp+UFN0wQbQV5uBoH1goI=; b=K8lCnJhuJcr0MfSjW7Bt4MAiy SkbQQb2nZggEWWTmWP7MfqxH9BKFHKxClwtwnI6n60IAOApkGyVOvLNIl1Sfk84ZZ27+3d5CAwZx1 B3OOfN9+vLAvKbPuf/ZSM9H437i/xSOJQqmQyn3zjEnddFl+jLMqZP7gN8BlMUA/zNusD4YIJZCHt jSw+w25hplzcAqtdYVbQ1J/niR/RtBMZRZbRG0WA8sfyCwLjTzEsr/fbULrgnXARmP+AQnF9gDIIW 97QZnUctx5uZMFMGkO04in1vHMqPXaGHvOUlqyhqXdK0ALCKRirRef3ZACHkQ9h3KWkXmadQEPgIx CQmrMMBmw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPVQW-0002Wz-Pf; Mon, 05 Oct 2020 18:41:36 +0000 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPVQU-0002VR-7q for linux-arm-kernel@lists.infradead.org; Mon, 05 Oct 2020 18:41:35 +0000 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Mon, 05 Oct 2020 11:41:13 -0700 Received: from [10.24.37.103] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 5 Oct 2020 18:40:18 +0000 Subject: Re: [Patch 1/2] cpufreq: tegra194: get consistent cpuinfo_cur_freq To: Viresh Kumar References: <1600276277-7290-1-git-send-email-sumitg@nvidia.com> <1600276277-7290-2-git-send-email-sumitg@nvidia.com> <20201005044621.t3stylpbsvzhxtyr@vireshk-i7> From: Sumit Gupta Message-ID: <69929ea0-0304-3bbe-fd33-40f50791a0ec@nvidia.com> Date: Tue, 6 Oct 2020 00:10:15 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20201005044621.t3stylpbsvzhxtyr@vireshk-i7> Content-Language: en-US X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1601923278; bh=0bk80uFfUoVDAgV24Vm7g3jBPiC3DpODVsAsPneRk0I=; h=Subject:To:CC:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; b=BlKiMMCfdVZvY4zvTG3b6mgy+4VEJiAX3cwTK/w+ge8PXBtO1JETAEbthi8KM4gOj AVtpHjlyhmm8wezrva1/F4tUr8f8GRYAH68hz/Rhqmge1TNNivS98ZWkS2DgU6NCU8 ADX0PqhOOfx7kAcDYbN2RHRuXoheVTwP/FIbMQzprZluAm0Y2a4RFHLahAlrrTZ01t gAB+is+mLv0IJAyznUT4hG2LZrwPlRS4ke74k77BH0YbROc+DmMKcrzgf5B1y4Ab8B +0rKc1DOGZ1RpQMnSJXMMDVCqi7FKMRcg2u9kdLva+enT0aZwfHSJy4yb/fHEv9ORP EyKvSOsKruXvA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201005_144134_347072_362FFF22 X-CRM114-Status: GOOD ( 24.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bbasu@nvidia.com, linux-pm@vger.kernel.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, jonathanh@nvidia.com, ksitaraman@nvidia.com, thierry.reding@gmail.com, linux-tegra@vger.kernel.org, Sumit Gupta , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org >> Frequency returned by 'cpuinfo_cur_freq' using counters is not fixed >> and keeps changing slightly. This change returns a consistent value >> from freq_table. If the reconstructed frequency has acceptable delta >> from the last written value, then return the frequency corresponding >> to the last written ndiv value from freq_table. Otherwise, print a >> warning and return the reconstructed freq. >> >> Signed-off-by: Sumit Gupta >> --- >> drivers/cpufreq/tegra194-cpufreq.c | 66 ++++++++++++++++++++++++++++++++------ >> 1 file changed, 57 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c >> index e1d931c..d5b608d 100644 >> --- a/drivers/cpufreq/tegra194-cpufreq.c >> +++ b/drivers/cpufreq/tegra194-cpufreq.c >> @@ -180,9 +180,65 @@ static unsigned int tegra194_get_speed_common(u32 cpu, u32 delay) >> return (rate_mhz * KHZ); /* in KHz */ >> } >> >> +static void get_cpu_ndiv(void *ndiv) >> +{ >> + u64 ndiv_val; >> + >> + asm volatile("mrs %0, s3_0_c15_c0_4" : "=r" (ndiv_val) : ); >> + >> + *(u64 *)ndiv = ndiv_val; >> +} >> + >> +static void set_cpu_ndiv(void *data) >> +{ >> + struct cpufreq_frequency_table *tbl = data; >> + u64 ndiv_val = (u64)tbl->driver_data; >> + >> + asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val)); >> +} >> + >> static unsigned int tegra194_get_speed(u32 cpu) >> { >> - return tegra194_get_speed_common(cpu, US_DELAY); >> + struct cpufreq_frequency_table *table, *pos; >> + struct cpufreq_policy policy; >> + unsigned int rate; >> + u64 ndiv; >> + int err; >> + >> + cpufreq_get_policy(&policy, cpu); >> + table = policy.freq_table; > > Maybe getting freq-table from cluster specific data would be better/faster. > will do the change in next patch version. >> + >> + /* reconstruct actual cpu freq using counters*/ >> + rate = tegra194_get_speed_common(cpu, US_DELAY); >> + >> + /* get last written ndiv value*/ >> + err = smp_call_function_single(cpu, get_cpu_ndiv, &ndiv, true); >> + if (err) { >> + pr_err("cpufreq: Failed to get ndiv for CPU%d, ret:%d\n", >> + cpu, err); >> + return rate; >> + } >> + >> + /* if the reconstructed frequency has acceptable delta from > > Both have got the multi-line comments wrong. Format is wrong and every sentence > needs to start with a capital letter. > will correct. >> + * the last written value, then return freq corresponding >> + * to the last written ndiv value from freq_table. This is >> + * done to return consistent value. >> + */ >> + cpufreq_for_each_valid_entry(pos, table) { >> + if (pos->driver_data != ndiv) >> + continue; >> + >> + if (abs(pos->frequency - rate) > 115200) { >> + pr_warn("cpufreq: high delta (%d) on CPU%d\n", >> + abs(pos->frequency - rate), cpu); >> + pr_warn("cpufreq: cur:%u, set:%u, set ndiv:%llu\n", >> + rate, pos->frequency, ndiv); > > Both of these can be merged in a single line I think. There is no need to print > delta as you already print both the frequencies. > Will do this also in next patch version. >> + } else { >> + rate = pos->frequency; >> + } >> + break; >> + } >> + return rate; >> } >> >> static int tegra194_cpufreq_init(struct cpufreq_policy *policy) >> @@ -209,14 +265,6 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy) >> return 0; >> } >> >> -static void set_cpu_ndiv(void *data) >> -{ >> - struct cpufreq_frequency_table *tbl = data; >> - u64 ndiv_val = (u64)tbl->driver_data; >> - >> - asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val)); >> -} >> - >> static int tegra194_cpufreq_set_target(struct cpufreq_policy *policy, >> unsigned int index) >> { >> -- >> 2.7.4 > > -- > viresh > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel