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=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,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 865CDC433DF for ; Mon, 12 Oct 2020 05:23:59 +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 2A83A2076E for ; Mon, 12 Oct 2020 05:23:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="wNjsr2JZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IbqtigIm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A83A2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=43XkRVbcuc/+dOjI4zCL/HIIoYNIACYVgkWEtu9DKQA=; b=wNjsr2JZ7UfHlPki7qsZzKiLp oynvTIgx3fTCQM1SyxFPiE6NLPI74xbnU577ku/419LJHAa2PaCZy8bVWrRdFeRemV1ZfP3QmAv1F DX6pQJkopyYvxJoRr3OQCk7ExcLIOR/S6S1/znP8ladScLGw7iUn0IJnRMi1vxSWQ4amODxSaG5RK X8vW74G5yJGfVaII9R6lrUON49YWj6Hhi00mir0FsilFlwOiku2yeBilgrVulWzijMeG4W/Zksejg /TQZ4jr2p61Nq7wc/4c+7eJl/dxzFQCsZmHFymgXCTWeRjBP1GSBipT3f2V30JcOkNpCE2io+u2dr jpEIIxIvg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRqI8-0007aN-1V; Mon, 12 Oct 2020 05:22:36 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRqI4-0007Zc-E6 for linux-arm-kernel@lists.infradead.org; Mon, 12 Oct 2020 05:22:33 +0000 Received: by mail-pg1-x544.google.com with SMTP id x16so13187618pgj.3 for ; Sun, 11 Oct 2020 22:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qmE6A/EKe0hTQJfNjsT3sfUiMsmf4sO+YlCAtCElHT4=; b=IbqtigImICgHWY7+4MtxnpiWYffaixBuI0p65m8WBT8s7qhDIXWrbGYHkKZjiM28Tx bFYDc9N1MkHT4hxFizyql+D9mXX2HnRLdLSTL5f9lD0RinlMPoDcTXX0mZcIF9ejzQP2 OXnqCfY/Flb/48/k6Iz6aagtF95LbJYC12SFH5u2bQFL27fTMvwjSZw1aJATc4ryp3Qb s5GAKfnrrOWjoM/AXxV1OWpP3ijsH2zZdjcG/exb35au79LUjxNgqD8Vz5AOQclFEeRK oB03PoZ6pHCkCGeDUwzWPJLHA7BLUxtR5Z/u8BIU+m/cqWdykNXR2MvqXHQA6VcCsVou eT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qmE6A/EKe0hTQJfNjsT3sfUiMsmf4sO+YlCAtCElHT4=; b=psG4NxUgX0RJHaupOVsQUsQcKGtVxNyyNniKRVRV9am8ZX9SIlzi9rjehhppAEgFep IKfDWEIlFfgK7zLjdFMcXLqG/c0rwECZenPYV2abYaRMDpPS8obFkIRlrIbY8evXLceu 6TBlBzMmnshyF8uYXlNKS1E4FyZ+H3Ctz4Kba+H0cm5dWGl/RG7JCn3GQ1KUfCdLAdge IQWNbftXhqUrJWq8ots7oiTyMADCEjiUF6iVq7XFhE/VFqoKWzTENjeLFycWbLyePDEk SMUcmjYk7YMl0cLObKstfaVHVhnmQ7JYRYuEcz7Pl0SjeUR1dBL8269P4fJ3gTCW5vkw aBnQ== X-Gm-Message-State: AOAM5328RGGRPLMqjf+K73croG1vEPbDURC7kKM3HQ6JiP8e6qw0vfC8 6Q9PCctX8QwtCzNTqBeAjudmkg== X-Google-Smtp-Source: ABdhPJzKiRNtosO8NGGmlAvudBt+rTXzZbJH1MOqFeWC9h7MElpsoLs64t0rf2Oe+W2vSevTayY3ew== X-Received: by 2002:a17:90b:11d1:: with SMTP id gv17mr15654111pjb.3.1602480150206; Sun, 11 Oct 2020 22:22:30 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id b6sm21266225pjq.42.2020.10.11.22.22.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Oct 2020 22:22:29 -0700 (PDT) Date: Mon, 12 Oct 2020 10:52:27 +0530 From: Viresh Kumar To: Sumit Gupta Subject: Re: [PATCH v2 1/2] cpufreq: tegra194: get consistent cpuinfo_cur_freq Message-ID: <20201012052227.x3bigztr7fit4jdz@vireshk-i7> References: <1602162066-26442-1-git-send-email-sumitg@nvidia.com> <1602162066-26442-2-git-send-email-sumitg@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1602162066-26442-2-git-send-email-sumitg@nvidia.com> User-Agent: NeoMutt/20180716-391-311a52 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201012_012232_746405_C44E9AD5 X-CRM114-Status: GOOD ( 25.74 ) 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, sudeep.holla@arm.com, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 08-10-20, 18:31, Sumit Gupta wrote: > 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 | 71 +++++++++++++++++++++++++++++++++----- > 1 file changed, 62 insertions(+), 9 deletions(-) > > diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c > index e1d931c..d250e49 100644 > --- a/drivers/cpufreq/tegra194-cpufreq.c > +++ b/drivers/cpufreq/tegra194-cpufreq.c > @@ -180,9 +180,70 @@ 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) You weren't required to do this unnecessary change. > +{ > + 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 tegra194_cpufreq_data *data = cpufreq_get_driver_data(); > + struct cpufreq_frequency_table *pos; > + unsigned int rate; > + u64 ndiv; > + int ret; > + u32 cl; > + > + if (!cpu_online(cpu)) This isn't required. The CPU is guaranteed to be online here. > + return -EINVAL; > + > + smp_call_function_single(cpu, get_cpu_cluster, &cl, true); > + > + if (cl >= data->num_clusters) Is it really possible here ? I meant you must have already checked this at cpufreq-init level already. Else mark it unlikely at least. > + return -EINVAL; > + > + /* reconstruct actual cpu freq using counters */ > + rate = tegra194_get_speed_common(cpu, US_DELAY); > + > + /* get last written ndiv value */ > + ret = smp_call_function_single(cpu, get_cpu_ndiv, &ndiv, true); > + if (ret) { What exactly can fail here ? get_cpu_ndiv() can't fail. Do we really need this check ? What about WARN_ON_ONCE() ? > + pr_err("cpufreq: Failed to get ndiv for CPU%d, ret:%d\n", > + cpu, ret); > + return rate; > + } > + > + /* > + * If the reconstructed frequency has acceptable delta from > + * 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, data->tables[cl]) { > + if (pos->driver_data != ndiv) > + continue; > + > + if (abs(pos->frequency - rate) > 115200) { where does this 115200 comes from ? Strange that it matches tty's baud rate :) This is 115 MHz, right ? Isn't that too big of a delta ? > + pr_warn("cpufreq: cpu%d,cur:%u,set:%u,set ndiv:%llu\n", > + cpu, rate, pos->frequency, ndiv); > + } else { > + rate = pos->frequency; > + } > + break; > + } > + return rate; > } -- viresh _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel