[PATCH 3/5] CPUFREQ: Cleanup governor struct, remove userspace specific set_speed functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The store/show _setspeed functions in the general cpufreq governor struct are
only used by the userspace governor.

- Remove them from the struct
- Move the sysfs set_speed store/show functions from
  cpufreq.c to cpufreq_userspace.c
- Create and destroy /sys/../cpuX/cpufreq/scaling_setspeed inside the
  userspace governor instead of always setting it up in the cpufreq core

This will result in a slightly modified sysfs behavior:
Before, the scaling_setspeed always existed in the /sys/../cpuX/cpufreq
directory. If the userspace governor was not active, reads resulted in
<unsupported> output and writes failed with -EINVAL.

Goal: Cleanup interface, make the governors core independent.

Signed-off-by: Thomas Renninger <trenn@xxxxxxx>
---
 drivers/cpufreq/cpufreq.c           |   30 ------------------------------
 drivers/cpufreq/cpufreq_userspace.c |   34 ++++++++++++++++++++++++++++++++--
 include/linux/cpufreq.h             |    4 ----
 3 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 5f37022..4f5207a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -619,32 +619,6 @@ static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
 	return show_cpus(policy->cpus, buf);
 }
 
-static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
-					const char *buf, size_t count)
-{
-	unsigned int freq = 0;
-	unsigned int ret;
-
-	if (!policy->governor || !policy->governor->store_setspeed)
-		return -EINVAL;
-
-	ret = sscanf(buf, "%u", &freq);
-	if (ret != 1)
-		return -EINVAL;
-
-	policy->governor->store_setspeed(policy, freq);
-
-	return count;
-}
-
-static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
-{
-	if (!policy->governor || !policy->governor->show_setspeed)
-		return sprintf(buf, "<unsupported>\n");
-
-	return policy->governor->show_setspeed(policy, buf);
-}
-
 #define define_one_ro(_name) \
 static struct freq_attr _name = \
 __ATTR(_name, 0444, show_##_name, NULL)
@@ -669,7 +643,6 @@ define_one_ro(affected_cpus);
 define_one_rw(scaling_min_freq);
 define_one_rw(scaling_max_freq);
 define_one_rw(scaling_governor);
-define_one_rw(scaling_setspeed);
 
 static struct attribute *default_attrs[] = {
 	&cpuinfo_min_freq.attr,
@@ -682,7 +655,6 @@ static struct attribute *default_attrs[] = {
 	&scaling_governor.attr,
 	&scaling_driver.attr,
 	&scaling_available_governors.attr,
-	&scaling_setspeed.attr,
 	NULL
 };
 
@@ -1639,7 +1611,6 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
 	return ret;
 }
 
-
 int cpufreq_register_governor(struct cpufreq_governor *governor)
 {
 	int err;
@@ -1674,7 +1645,6 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
 EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
 
 
-
 /*********************************************************************
  *                          POLICY INTERFACE                         *
  *********************************************************************/
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 66d2d1d..b41f1a6 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -40,6 +40,33 @@ static int cpus_using_userspace_governor;
 #define dprintk(msg...) \
 	cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
 
+static ssize_t show_speed(struct cpufreq_policy *policy, char *buf);
+static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq);
+
+static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
+					const char *buf, size_t count)
+{
+	unsigned int freq = 0;
+	unsigned int ret;
+
+	ret = sscanf(buf, "%u", &freq);
+	if (ret != 1)
+		return -EINVAL;
+
+	cpufreq_set(policy, freq);
+
+	return count;
+}
+
+static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
+{
+	return show_speed(policy, buf);
+}
+
+static struct freq_attr scaling_setspeed =
+	__ATTR(scaling_setspeed, 0644, show_scaling_setspeed,
+	       store_scaling_setspeed);
+
 /* keep track of frequency transitions */
 static int
 userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
@@ -120,6 +147,10 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
 		if (!cpu_online(cpu))
 			return -EINVAL;
 		BUG_ON(!policy->cur);
+		rc = sysfs_create_file(&policy->kobj, &scaling_setspeed.attr);
+		if (rc)
+			return rc;
+
 		mutex_lock(&userspace_mutex);
 
 		if (cpus_using_userspace_governor == 0) {
@@ -144,6 +175,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
 		mutex_unlock(&userspace_mutex);
 		break;
 	case CPUFREQ_GOV_STOP:
+		sysfs_remove_file(&policy->kobj, &scaling_setspeed.attr);
 		mutex_lock(&userspace_mutex);
 		cpus_using_userspace_governor--;
 		if (cpus_using_userspace_governor == 0) {
@@ -193,8 +225,6 @@ static
 struct cpufreq_governor cpufreq_gov_userspace = {
 	.name		= "userspace",
 	.governor	= cpufreq_governor_userspace,
-	.store_setspeed	= cpufreq_set,
-	.show_setspeed	= show_speed,
 	.owner		= THIS_MODULE,
 };
 
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 1610427..642141a 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -166,10 +166,6 @@ struct cpufreq_governor {
 	char	name[CPUFREQ_NAME_LEN];
 	int 	(*governor)	(struct cpufreq_policy *policy,
 				 unsigned int event);
-	ssize_t	(*show_setspeed)	(struct cpufreq_policy *policy,
-					 char *buf);
-	int 	(*store_setspeed)	(struct cpufreq_policy *policy,
-					 unsigned int freq);
 	unsigned int max_transition_latency; /* HW must be able to switch to
 			next freq faster than this value in nano secs or we
 			will fallback to performance governor */
-- 
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe cpufreq" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Devel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Forum]     [Linux SCSI]

  Powered by Linux