Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4348288imm; Mon, 18 Jun 2018 13:23:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIFuz0fIRxSjUa4wcFk2HAvaKK2vuqYuAp4MiGmutDjZXk+Z/3RWMzMjCB3zI6TNb2JqA4W X-Received: by 2002:a17:902:343:: with SMTP id 61-v6mr15546982pld.344.1529353430147; Mon, 18 Jun 2018 13:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529353430; cv=none; d=google.com; s=arc-20160816; b=YqpC2qPFMwe5qoO7m/18t8tHQ6TSYQsatBoEj9/8gkMQi+wD2Farx3wDyOz2jxGGJq B7JtUnJahEVFxdyn0WwkPeaQheGc92HrgR3n7rp23fh5tNkVCHtxm2ipmNDYVz9icCiz 6qz+KVghliOJgzbB3fjeq0QZcplnaXgSlmFsZ5DuK2eN3+dZBpLX8gfrmjFAH7bBq83J Bih/xl49DCfSI9FNq6KRAXxfsgsk0yqXyClSusVzIouF3d17W5RjfnzFJaJXHybnuBgn PU4+5p4sLtg55b/a07acKWjsEsQAkSVlxLAtIpBpwvs9mbzDQL8DxpUiSWfxrzS6eLk0 layw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=2nEp0d44C4qYEPuwIYSNjVXd5QcsbKX/uCLl9ZDB3Bc=; b=pTPr1A6qtfG/xBkqpohe4Hec/ScHZEYPeeUGlmQmc4A4aOgPoiq0PCqKFUk+uGSdof 9lNrYh/ez2L+j0v4JEoCPP066nV1N0xKAweiAM4GZ2hC+hn2EBNfThvF3d5kviYJwnXc YLHsgJtxL1Tv4vJz1QgAUU50FJJ8m72HC9LwhCdTReaeYcChB+c0vgrJ/Jbhe0eVaal/ 05g+zg60HxkB/h+30Yx2u5aMWekuwlalG47bxwr9K/d/qgwCalHRF1tSHKQ9TroU25Py g9Fg/FJCpGjaCbpozf4QIgynpRUWifEHe+J7dzlFjFfcM1h+ZJ+rSaAdFS7yxeCSoTVT q0aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=aLz2z4tW; dkim=pass header.i=@codeaurora.org header.s=default header.b=YcbzGKMG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si15884116plz.479.2018.06.18.13.23.36; Mon, 18 Jun 2018 13:23:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=aLz2z4tW; dkim=pass header.i=@codeaurora.org header.s=default header.b=YcbzGKMG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935727AbeFRUVz (ORCPT + 99 others); Mon, 18 Jun 2018 16:21:55 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:37896 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933834AbeFRUVx (ORCPT ); Mon, 18 Jun 2018 16:21:53 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4B4AB60B11; Mon, 18 Jun 2018 20:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529353313; bh=/v2ySN9trXowUfxWwirp1WpGhHakkJ4/U1vlsd8fwPk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=aLz2z4tWQ+QmBNKttcc/54U/e8EPhRaNahqRqiasHpe4tTVrMx/2UnsWyE4Ja7GCT 3ukcky8QpVXFdvHDo8bH+We3ZHIk5MpMk7p/SoKC0iBxroXXd6M2Z+zSOx24Jh8gzA LCizeNQqaOGDW/ok4WL8iuDrEguLMFKlt5SNp9YU= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.226.58.143] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pprakash@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 503E0602FC; Mon, 18 Jun 2018 20:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529353312; bh=/v2ySN9trXowUfxWwirp1WpGhHakkJ4/U1vlsd8fwPk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=YcbzGKMGK5XULLniPvAQjTOp6cc8Ukdh+TNGqmAucHvG4skzl4RptrvMlKqCZov/l 3OodrcQWDD7layJL5cQrueObcPIe/TRHNwkCBSHjJ4/WF3BgN9Cscmj5qA/RN8VkDe 5pKG989cWMKxClWBqwt3RSLNBLf/sWAqA6kHu540= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 503E0602FC Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=pprakash@codeaurora.org Subject: Re: [PATCH v2] cpufreq / CPPC: Add cpuinfo_cur_freq support for CPPC To: George Cherian , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: viresh.kumar@linaro.org, rjw@rjwysocki.net References: <1529056995-122792-1-git-send-email-george.cherian@cavium.com> From: "Prakash, Prashanth" Message-ID: <67822500-0c9d-ac24-71bc-2717831ab29d@codeaurora.org> Date: Mon, 18 Jun 2018 14:21:51 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1529056995-122792-1-git-send-email-george.cherian@cavium.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi George, On 6/15/2018 4:03 AM, George Cherian wrote: > Per Section 8.4.7.1.3 of ACPI 6.2, The platform provides performance > feedback via set of performance counters. To determine the actual > performance level delivered over time, OSPM may read a set of > performance counters from the Reference Performance Counter Register > and the Delivered Performance Counter Register. > > OSPM calculates the delivered performance over a given time period by > taking a beginning and ending snapshot of both the reference and > delivered performance counters, and calculating: > > delivered_perf = reference_perf X (delta of delivered_perf counter / delta of reference_perf counter). > > Implement the above and hook this to the cpufreq->get method. > > Signed-off-by: George Cherian > Acked-by: Viresh Kumar > --- > drivers/cpufreq/cppc_cpufreq.c | 71 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 71 insertions(+) > > diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c > index 3464580..3fe7625 100644 > --- a/drivers/cpufreq/cppc_cpufreq.c > +++ b/drivers/cpufreq/cppc_cpufreq.c > @@ -296,10 +296,81 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) > return ret; > } > > +static int cppc_get_rate_from_fbctrs(struct cppc_cpudata *cpu, > + struct cppc_perf_fb_ctrs fb_ctrs_t0, > + struct cppc_perf_fb_ctrs fb_ctrs_t1) > +{ > + u64 delta_reference, delta_delivered; > + u64 reference_perf, delivered_perf; > + > + reference_perf = fb_ctrs_t0.reference_perf; > + if (fb_ctrs_t1.reference > fb_ctrs_t0.reference) { > + delta_reference = fb_ctrs_t1.reference - fb_ctrs_t0.reference; > + } else { There should be another if () here to check if the reference counters are equal. We cannot assume, there was a overflow when the counters are equal. As I mentioned on last patch, the counters *may* pause in idle states. > + /* > + * Counters would have wrapped-around > + * We also need to find whether the low level fw > + * maintains 32 bit or 64 bit counters, to calculate > + * the correct delta. > + */ > + if (fb_ctrs_t0.reference > (~(u32)0)) > + delta_reference = (~((u64)0) - fb_ctrs_t0.reference) + > + fb_ctrs_t1.reference; > + else > + delta_reference = (~((u32)0) - fb_ctrs_t0.reference) + > + fb_ctrs_t1.reference; > + } > + > + if (fb_ctrs_t1.delivered > fb_ctrs_t0.delivered) { > + delta_delivered = fb_ctrs_t1.delivered - fb_ctrs_t0.delivered; > + } else { > + /* > + * Counters would have wrapped-around > + * We also need to find whether the low level fw > + * maintains 32 bit or 64 bit counters, to calculate > + * the correct delta. > + */ > + if (fb_ctrs_t0.delivered > (~(u32)0)) > + delta_delivered = (~((u64)0) - fb_ctrs_t0.delivered) + > + fb_ctrs_t1.delivered; > + else > + delta_delivered = (~((u32)0) - fb_ctrs_t0.delivered) + > + fb_ctrs_t1.delivered; > + } > + > + if (delta_reference) /* Check to avoid divide-by zero */ > + delivered_perf = (reference_perf * delta_delivered) / > + delta_reference; > + else > + delivered_perf = reference_perf; If we cannot compute delivered performance then we should return desired/requested perf and not reference_perf. > + > + return cppc_cpufreq_perf_to_khz(cpu, delivered_perf); > +} > + > +static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) > +{ > + struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; > + struct cppc_cpudata *cpu = all_cpu_data[cpunum]; > + int ret; > + > + ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t0); > + if (ret) > + return ret; > + > + udelay(2); /* 2usec delay between sampling */ > + > + ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t1); > + if (ret) > + return ret; > + > + return cppc_get_rate_from_fbctrs(cpu, fb_ctrs_t0, fb_ctrs_t1); > +} > + > static struct cpufreq_driver cppc_cpufreq_driver = { > .flags = CPUFREQ_CONST_LOOPS, > .verify = cppc_verify_policy, > .target = cppc_cpufreq_set_target, > + .get = cppc_cpufreq_get_rate, > .init = cppc_cpufreq_cpu_init, > .stop_cpu = cppc_cpufreq_stop_cpu, > .name = "cppc_cpufreq", Thanks, Prashanth