Commit d7a27323 authored by Dave Jones's avatar Dave Jones Committed by Linus Torvalds

[CPUFREQ] fix userspace governor.

Let's put the sysfs file exported by the cpufreq userspace governor also
into the cpufreq/ - subdirectory of /sys/devices/sys/cpu0/.
parent f1ffad72
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sysfs.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -465,23 +466,14 @@ static inline void cpufreq_sysctl_exit(void) ...@@ -465,23 +466,14 @@ static inline void cpufreq_sysctl_exit(void)
/************************** sysfs interface ************************/ /************************** sysfs interface ************************/
static inline int to_cpu_nr (struct device *dev) static ssize_t show_speed (struct cpufreq_policy *policy, char *buf)
{ {
struct sys_device * cpu_sys_dev = container_of(dev, struct sys_device, dev); return sprintf (buf, "%u\n", cpu_cur_freq[policy->cpu]);
return (cpu_sys_dev->id);
}
static ssize_t show_speed (struct device *dev, char *buf)
{
unsigned int cpu = to_cpu_nr(dev);
return sprintf (buf, "%u\n", cpu_cur_freq[cpu]);
} }
static ssize_t static ssize_t
store_speed (struct device *dev, const char *buf, size_t count) store_speed (struct cpufreq_policy *policy, const char *buf, size_t count)
{ {
unsigned int cpu = to_cpu_nr(dev);
unsigned int freq = 0; unsigned int freq = 0;
unsigned int ret; unsigned int ret;
...@@ -489,13 +481,16 @@ store_speed (struct device *dev, const char *buf, size_t count) ...@@ -489,13 +481,16 @@ store_speed (struct device *dev, const char *buf, size_t count)
if (ret != 1) if (ret != 1)
return -EINVAL; return -EINVAL;
cpufreq_set(freq, cpu); cpufreq_set(freq, policy->cpu);
return count; return count;
} }
static DEVICE_ATTR(scaling_setspeed, (S_IRUGO | S_IWUSR), show_speed, store_speed); static struct freq_attr freq_attr_scaling_setspeed = {
.attr = { .name = "scaling_setspeed", .mode = 0644 },
.show = show_speed,
.store = store_speed,
};
static int cpufreq_governor_userspace(struct cpufreq_policy *policy, static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
unsigned int event) unsigned int event)
...@@ -511,7 +506,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ...@@ -511,7 +506,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
cpu_min_freq[cpu] = policy->min; cpu_min_freq[cpu] = policy->min;
cpu_max_freq[cpu] = policy->max; cpu_max_freq[cpu] = policy->max;
cpu_cur_freq[cpu] = policy->cur; cpu_cur_freq[cpu] = policy->cur;
device_create_file (policy->dev, &dev_attr_scaling_setspeed); sysfs_create_file (&policy->kobj, &freq_attr_scaling_setspeed.attr);
memcpy (&current_policy[cpu], policy, sizeof(struct cpufreq_policy)); memcpy (&current_policy[cpu], policy, sizeof(struct cpufreq_policy));
up(&userspace_sem); up(&userspace_sem);
break; break;
...@@ -520,7 +515,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, ...@@ -520,7 +515,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
cpu_is_managed[cpu] = 0; cpu_is_managed[cpu] = 0;
cpu_min_freq[cpu] = 0; cpu_min_freq[cpu] = 0;
cpu_max_freq[cpu] = 0; cpu_max_freq[cpu] = 0;
device_remove_file (policy->dev, &dev_attr_scaling_setspeed); sysfs_remove_file (&policy->kobj, &freq_attr_scaling_setspeed.attr);
up(&userspace_sem); up(&userspace_sem);
module_put(THIS_MODULE); module_put(THIS_MODULE);
break; break;
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/threads.h> #include <linux/threads.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#define CPUFREQ_NAME_LEN 16 #define CPUFREQ_NAME_LEN 16
...@@ -194,6 +195,13 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, u ...@@ -194,6 +195,13 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, u
return; return;
} }
struct freq_attr {
struct attribute attr;
ssize_t (*show)(struct cpufreq_policy *, char *);
ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
};
/********************************************************************* /*********************************************************************
* CPUFREQ 2.6. INTERFACE * * CPUFREQ 2.6. INTERFACE *
*********************************************************************/ *********************************************************************/
......
...@@ -256,12 +256,6 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy * policy, ...@@ -256,12 +256,6 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy * policy,
} }
struct freq_attr {
struct attribute attr;
ssize_t (*show)(struct cpufreq_policy *, char *);
ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
};
#define define_one_ro(_name) \ #define define_one_ro(_name) \
struct freq_attr _name = { \ struct freq_attr _name = { \
.attr = { .name = __stringify(_name), .mode = 0444 }, \ .attr = { .name = __stringify(_name), .mode = 0444 }, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment