All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pan Xinhui <xinhuix.pan@intel.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Cc: "rjw@rjwysocki.net" <rjw@rjwysocki.net>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	"mnipxh@163.com" <mnipxh@163.com>,
	"yanmin_zhang@linux.intel.com" <yanmin_zhang@linux.intel.com>
Subject: [PATCH V2] cpufreq: Add scaling frequency range support
Date: Tue, 28 Jul 2015 15:02:59 +0800	[thread overview]
Message-ID: <55B72923.7030101@intel.com> (raw)
In-Reply-To: <55B6F7C3.8040405@intel.com>

From: Pan Xinhui <xinhuix.pan@intel.com>

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 <xinhuix.pan@intel.com>
---
Change from V1:
	update cpu-freq documentation.
---
 Documentation/cpu-freq/user-guide.txt |  7 +++++++
 drivers/cpufreq/cpufreq.c             | 31 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Documentation/cpu-freq/user-guide.txt b/Documentation/cpu-freq/user-guide.txt
index 109e97b..ac6dd7b 100644
--- a/Documentation/cpu-freq/user-guide.txt
+++ b/Documentation/cpu-freq/user-guide.txt
@@ -212,6 +212,13 @@ bios_limit :			If the BIOS tells the OS to limit a CPU to
 				which can be detected through the generic
 				thermal driver.
 
+scaling_freq_range :	show the current cpufreq range of policy (in
+				kHz) with format "%u-%u". In other words it shows the
+				scaling_min_freq and scaling_max_freq at same time. By
+				echoing new values with format "%u-%u" into this file,
+				you can change this range. first %u stands for
+				scaling_min_freq, second %u stands for scaling_max_freq.
+
 If you have selected the "userspace" governor which allows you to
 set the CPU operating frequency to a specific value, you can read out
 the current frequency in
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

  parent reply	other threads:[~2015-07-28  7:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28  3:32 [PATCH] cpufreq: Add scaling frequency range support Pan Xinhui
2015-07-28  4:29 ` Viresh Kumar
2015-07-28  4:53   ` Pan Xinhui
2015-07-29  0:18     ` Rafael J. Wysocki
2015-07-29  9:59       ` Pan Xinhui
2015-07-29  9:59         ` Pan Xinhui
2015-07-29 10:04         ` Pan Xinhui
2015-07-29 11:01           ` Viresh Kumar
2015-07-29 22:40         ` Rafael J. Wysocki
2015-07-28  5:20 ` Viresh Kumar
2015-07-28  7:02 ` Pan Xinhui [this message]
2015-07-28  7:09   ` [PATCH V2] " Viresh Kumar
2015-07-29  0:15 ` [PATCH] " Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B72923.7030101@intel.com \
    --to=xinhuix.pan@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mnipxh@163.com \
    --cc=rjw@rjwysocki.net \
    --cc=viresh.kumar@linaro.org \
    --cc=yanmin_zhang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.