From patchwork Wed Jul 8 10:37:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 50870 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EEF6722A03 for ; Wed, 8 Jul 2015 10:38:10 +0000 (UTC) Received: by lbko2 with SMTP id o2sf648584lbk.0 for ; Wed, 08 Jul 2015 03:38:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=n1S2NvPRj4mHSsBtdcuk/WRoTvfowVhcq66qvO5GWzQ=; b=UjEq9T4NKn4DbOGUDMJkfdREORuxUvc+q4/0qShKcf338mFT0pcTwZG0dMpKdmao4a M1E7w1WbOlF+0UZqQaITqlzV0xTYHvtGi9hHk4FHb7tiq+EXnFNQGzgFhp/oefYYe1aI fJnI31UKBmb+RKL/F8B9BQY2jldDeWkoErVKFbr/a/lSx4AHmSpeU0Vwk6ka4+eV/436 X7Blx2PHv/JqANVessYPMD5IxWNGIrHQeM2edjkbrV4/wXOTjDNDjCkZe8PEFoFh/yt+ o8IOHu0jjQ1yenvvzbM9GsD2hG6Bz8RzjFDUvsGR1qOY/sctjiemK1aNc22exhbM+S51 ONUQ== X-Gm-Message-State: ALoCoQlXTEPyf0a2T6vzkWcMdcddZoXIkCJnqJwIlK2tOGhS9hKCZ2HG9GSdHmOJkfc0IgfpGtTk X-Received: by 10.180.77.225 with SMTP id v1mr9020074wiw.5.1436351889966; Wed, 08 Jul 2015 03:38:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.6 with SMTP id lc6ls939905lac.80.gmail; Wed, 08 Jul 2015 03:38:09 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr8707487laj.88.1436351889737; Wed, 08 Jul 2015 03:38:09 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id bw8si1536399lbd.146.2015.07.08.03.38.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2015 03:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lagx9 with SMTP id x9so222302054lag.1 for ; Wed, 08 Jul 2015 03:38:09 -0700 (PDT) X-Received: by 10.152.5.228 with SMTP id v4mr1407146lav.36.1436351889610; Wed, 08 Jul 2015 03:38:09 -0700 (PDT) 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.112.108.230 with SMTP id hn6csp2991354lbb; Wed, 8 Jul 2015 03:38:08 -0700 (PDT) X-Received: by 10.66.234.101 with SMTP id ud5mr18932205pac.23.1436351887683; Wed, 08 Jul 2015 03:38:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rt12si3446444pac.104.2015.07.08.03.38.06; Wed, 08 Jul 2015 03:38:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934886AbbGHKh7 (ORCPT + 11 others); Wed, 8 Jul 2015 06:37:59 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:34905 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934875AbbGHKhw (ORCPT ); Wed, 8 Jul 2015 06:37:52 -0400 Received: by pactm7 with SMTP id tm7so129725297pac.2 for ; Wed, 08 Jul 2015 03:37:52 -0700 (PDT) X-Received: by 10.66.63.8 with SMTP id c8mr19522054pas.122.1436351871973; Wed, 08 Jul 2015 03:37:51 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id xv9sm2059439pbc.2.2015.07.08.03.37.49 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 08 Jul 2015 03:37:50 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , linux-kernel@vger.kernel.org (open list) Subject: [RFC] cpufreq: Add ->get_rate() driver callback Date: Wed, 8 Jul 2015 16:07:32 +0530 Message-Id: X-Mailer: git-send-email 2.4.0 Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , CPUFreq drivers today support a ->get(cpu) callback, which returns current rate of a CPU. The problem with ->get() is that it takes a cpu number as parameter and this unnecessarily makes things complex. Firstly the core gets the cpu number by doing operation 'policy->cpu' on the policy and then many drivers need to get the policy back and so do cpufreq_cpu_get(cpu) on the passed cpu. As cpufreq core works on policies, it would be better if we pass them 'policy' directly and drivers can use policy->cpu if that's all they need. Hence, this patch adds in another callback, ->get_rate() which does exactly the same work as ->get(), just that we pass 'policy' as parameter instead of 'cpu'. The plan is to migrate all drivers to this new callback and remove ->get() after that. Signed-off-by: Viresh Kumar --- Hi Rafael, I hope you are fine with this stuff :), once you approve I will get other patches to migrate existing drivers to this interface. drivers/cpufreq/cpufreq.c | 50 ++++++++++++++++++++++++++++++++--------------- include/linux/cpufreq.h | 1 + 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b612411655f9..b66e169601e8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -154,6 +154,20 @@ void disable_cpufreq(void) } static DEFINE_MUTEX(cpufreq_governor_mutex); +/* Operations for ->get() and ->get_rate() operations */ +static inline bool driver_supports_get_rate(void) +{ + return cpufreq_driver->get || cpufreq_driver->get_rate; +} + +static inline unsigned int policy_get_rate(struct cpufreq_policy *policy) +{ + if (cpufreq_driver->get) + return cpufreq_driver->get(policy->cpu); + else + return cpufreq_driver->get_rate(policy); +} + bool have_governor_per_policy(void) { return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); @@ -596,8 +610,9 @@ static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf) { ssize_t ret; - if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) - ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); + if (cpufreq_driver && cpufreq_driver->setpolicy && + driver_supports_get_rate()) + ret = sprintf(buf, "%u\n", policy_get_rate(policy)); else ret = sprintf(buf, "%u\n", policy->cur); return ret; @@ -1032,7 +1047,7 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, return ret; drv_attr++; } - if (cpufreq_driver->get) { + if (driver_supports_get_rate()) { ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); if (ret) return ret; @@ -1313,10 +1328,10 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) write_unlock_irqrestore(&cpufreq_driver_lock, flags); } - if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { - policy->cur = cpufreq_driver->get(policy->cpu); + if (driver_supports_get_rate() && !cpufreq_driver->setpolicy) { + policy->cur = policy_get_rate(policy); if (!policy->cur) { - pr_err("%s: ->get() failed\n", __func__); + pr_err("%s: ->get_rate() failed\n", __func__); goto err_get_freq; } } @@ -1594,14 +1609,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu) struct cpufreq_policy *policy; unsigned int ret_freq = 0; - if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) - return cpufreq_driver->get(cpu); - policy = cpufreq_cpu_get(cpu); - if (policy) { + if (!policy) + return 0; + + if (cpufreq_driver && cpufreq_driver->setpolicy && + driver_supports_get_rate()) + ret_freq = policy_get_rate(policy); + else ret_freq = policy->cur; - cpufreq_cpu_put(policy); - } + + cpufreq_cpu_put(policy); return ret_freq; } @@ -1631,10 +1649,10 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy) { unsigned int ret_freq = 0; - if (!cpufreq_driver->get) + if (!driver_supports_get_rate()) return ret_freq; - ret_freq = cpufreq_driver->get(policy->cpu); + ret_freq = policy_get_rate(policy); /* Updating inactive policies is invalid, so avoid doing that. */ if (unlikely(policy_is_inactive(policy))) @@ -2345,8 +2363,8 @@ int cpufreq_update_policy(unsigned int cpu) * BIOS might change freq behind our back * -> ask driver for current freq and notify governors about a change */ - if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { - new_policy.cur = cpufreq_driver->get(cpu); + if (driver_supports_get_rate() && !cpufreq_driver->setpolicy) { + new_policy.cur = policy_get_rate(policy); if (WARN_ON(!new_policy.cur)) { ret = -EIO; goto unlock; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 29ad97c34fd5..a82049683016 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -263,6 +263,7 @@ struct cpufreq_driver { /* should be defined, if possible */ unsigned int (*get)(unsigned int cpu); + unsigned int (*get_rate)(struct cpufreq_policy *policy); /* optional */ int (*bios_limit)(int cpu, unsigned int *limit);