Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754965AbbG1Det (ORCPT ); Mon, 27 Jul 2015 23:34:49 -0400 Received: from mga11.intel.com ([192.55.52.93]:16319 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753934AbbG1Der (ORCPT ); Mon, 27 Jul 2015 23:34:47 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,560,1432623600"; d="scan'208";a="531396378" Message-ID: <55B6F7C3.8040405@intel.com> Date: Tue, 28 Jul 2015 11:32:19 +0800 From: Pan Xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" CC: "rjw@rjwysocki.net" , Viresh Kumar , "mnipxh@163.com" , "yanmin_zhang@linux.intel.com" Subject: [PATCH] cpufreq: Add scaling frequency range support Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2638 Lines: 80 From: Pan Xinhui Userspace at most time do cpufreq tests very much inconveniently. Currently they have to echo min and max cpu freq separately like below: echo 480000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq echo 2240000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq Add scaling_freq_range cpufreq attr to support userspace's demand. Therefore it's easier for testers to write readable scripts like below: echo 480000-2240000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_freq_range Signed-off-by: Pan Xinhui --- drivers/cpufreq/cpufreq.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 26063af..6424e05 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -812,6 +812,35 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); } +static ssize_t store_scaling_freq_range(struct cpufreq_policy *policy, + char *buf, size_t count) +{ + int ret, temp_min, temp_max; + struct cpufreq_policy new_policy; + + ret = cpufreq_get_policy(&new_policy, policy->cpu); + if (ret) + return -EINVAL; + + ret = sscanf(buf, "%u-%u", &new_policy.min, &new_policy.max); + if (ret != 2) + return -EINVAL; + + temp_min = new_policy.min; + temp_max = new_policy.max; + ret = cpufreq_set_policy(policy, &new_policy); + if (!ret) { + policy->user_policy.min = temp_min; + policy->user_policy.max = temp_max; + } + return ret ? ret : count; +} + +static ssize_t show_scaling_freq_range(struct cpufreq_policy *policy, char *buf) +{ + return sprintf(buf, "%u-%u\n", policy->min, policy->max); +} + cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400); cpufreq_freq_attr_ro(cpuinfo_min_freq); cpufreq_freq_attr_ro(cpuinfo_max_freq); @@ -826,6 +855,7 @@ cpufreq_freq_attr_rw(scaling_min_freq); cpufreq_freq_attr_rw(scaling_max_freq); cpufreq_freq_attr_rw(scaling_governor); cpufreq_freq_attr_rw(scaling_setspeed); +cpufreq_freq_attr_rw(scaling_freq_range); static struct attribute *default_attrs[] = { &cpuinfo_min_freq.attr, @@ -839,6 +869,7 @@ static struct attribute *default_attrs[] = { &scaling_driver.attr, &scaling_available_governors.attr, &scaling_setspeed.attr, + &scaling_freq_range.attr, NULL }; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/