cpufreq: allow user to specify voltage
Hi!
This allows user to specify voltage manually. This gives me 40 extra minutes (1h50m -> 2h30m) on HP omnibook which appears to have broken bios tables. Please apply,
Pavel
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +10 -2
@@ -210,7 +210,7 @@ } -static void change_speed (unsigned int index) +static void change_speed (unsigned int index,unsigned int voltage) {u8 fid, vid;struct cpufreq_freqs freqs;
@@ -226,6 +226,14 @@ fid = powernow_table[index].index &0xFF ; vid = (powernow_table[index].index &0xFF00 ) >>8 ; +if (voltage) { +int i; +for (i=0 ; i<32 ; i++) +if (mobile_vid_table[i] == voltage) + vid = i; +printk ("Voltage overriden to %d mV, index 0x%x\n" , voltage, vid); + } + freqs.cpu =0 ;rdmsrl (MSR_K7_FID_VID_STATUS , fidvidstatus.val);
@@ -338,7 +346,7 @@if (cpufreq_frequency_table_target (policy, powernow_table, target_freq, relation, &newstate))return -EINVAL ; -change_speed (newstate); +change_speed (newstate, policy->voltage);return 0 ; }
drivers/cpufreq/proc_intf.c +16 -0
@@ -28,6 +28,7 @@unsigned int min =0 ;unsigned int max =0 ;unsigned int cpu =0 ; +unsigned int voltage =0 ;char str_governor[16 ];struct cpufreq_policy current_policy;unsigned int result = -EFAULT ;
@@ -37,9 +38,24 @@ policy->min =0 ; policy->max =0 ; + policy->voltage =0 ; policy->policy =0 ; policy->cpu =CPUFREQ_ALL_CPUS ; +if (sscanf (input_string,"%d:%d:%d:%15s" , &cpu, &min, &voltage, str_governor) ==4 ) + { +if (!strcmp (str_governor,"mVforce" )) { +printk ("Have request to go to %d mV\n" , voltage); + policy->min = min; + policy->max = min; + policy->voltage = voltage; + policy->cpu = cpu; + result =0 ; + policy->policy =CPUFREQ_POLICY_PERFORMANCE ; +return 0 ; + } + } +if (sscanf (input_string,"%d:%d:%d:%15s" , &cpu, &min, &max, str_governor) ==4 ) { policy->min = min;
include/linux/cpufreq.h +1 -0
@@ -63,6 +63,7 @@unsigned int min;/* in kHz */ unsigned int max;/* in kHz */ unsigned int policy;/* see above */ +unsigned int voltage;/* in mV, 0 == trust bios */ struct cpufreq_governor *governor;/* see below */ struct cpufreq_cpuinfo cpuinfo;/* see above */ struct intf_data intf;/* interface data */
kernel/cpufreq.c +1 -0
@@ -1103,11 +1103,12 @@ cpufreq_driver->policy[policy->cpu].min = policy->min; cpufreq_driver->policy[policy->cpu].max = policy->max; + cpufreq_driver->policy[policy->cpu].voltage= policy->voltage;#ifdef CONFIG_CPU_FREQ_24_API cpu_cur_freq[policy->cpu] = policy->max;#endif if (cpufreq_driver->setpolicy) { cpufreq_driver->policy[policy->cpu].policy = policy->policy; ret = cpufreq_driver->setpolicy (policy);
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Hi Pavel, Hi Linus,
Quoted 7 lines
Hi!
This allows user to specify voltage manually. This gives me 40 extra minutes (1h50m -> 2h30m) on HP omnibook which appears to have broken bios tables. Please apply,
Pavel
Please don't apply this patch -- for the following reasons:
- it only uses the deprecated, overloaded cpufreq proc_intf
- selecting the voltage within the policy (minimum and maximum frequency, mode of operation) is not where it should be done: you may want a different voltage at min-speed as at max-speed. So the frequency tables, or -even better- the amd-k7-specific table may be a better choice for this.
- selecting the voltage manually is something which is only valid for some very few drivers - so let's only export one sysfs file[*] for these drivers.
Dominik
[*] sysfs is the _only_ recommended way to access cpufreq these days.
Hi!
Quoted 11 lines
Quoted 3 lines
This allows user to specify voltage manually. This gives me 40 extra minutes (1h50m -> 2h30m) on HP omnibook which appears to have broken bios tables. Please apply,
Please don't apply this patch -- for the following reasons:
- it only uses the deprecated, overloaded cpufreqproc_intf
- selecting the voltage within the policy (minimum and maximum frequency, mode of operation) is not where it should be done: you may want a different voltage at min-speed as at max-speed. So the frequency tables, or -even better- the amd-k7-specific table may be a better choice for this.
Well, look again; if you use mVforce, it forces *just one* frequency (min=max=freq you specified), so it is actually okay.
But I agree that hacking proc_intf is not the right thing to do. I did not see that sysfs access. Where is it?
Quoted 3 lines
- selecting the voltage manually is something which is only valid for some very few drivers - so let's only export one sysfs file[*] for these drivers.
Very few drivers? It should be common for at least Intel and AMD, no?
Pavel
Signature · 2 lines
Horseback riding is like software... ...vgf orggre jura vgf serr.
Hi!
Quoted 4 lines · Pavel Machek
Hi!
Well, look again; if you use mVforce, it forces *just one* frequency (min=max=freq you specified), so it is actually okay.
But min=max=freq is awful... I know, I reccommended it sometimes, but with the appearance of the userspace governor (already available on the cpufreq homepage, http://www.brodo.de/cpufreq/advanced.html , will be submitted soon) min=max=freq is deprecated.
Quoted 2 lines
But I agree that hacking
proc_intfis not the right thing to do. I did not see that sysfs access. Where is it?
kernel/cpufreq.c
Quoted 5 lines
Quoted 3 lines
- selecting the voltage manually is something which is only valid for some very few drivers - so let's only export one sysfs file[*] for these drivers.
Very few drivers? It should be common for at least Intel and AMD, no?
No. Intel doesn't let you select the exact voltage. IIRC, only vew VIA/Cyrix-longhaul-capable processors and, of course, powernow-k7 are vaild targets for such a patch.
Dominik
Hi!
Quoted 4 lines
Quoted 2 lines
But I agree that hacking
proc_intfis not the right thing to do. I did not see that sysfs access. Where is it?
kernel/cpufreq.c
Okay, I see.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
- selecting the voltage manually is something which is only valid for some very few drivers - so let's only export one sysfs file[*] for these drivers.
Very few drivers? It should be common for at least Intel and AMD, no?
No. Intel doesn't let you select the exact voltage. IIRC, only vew VIA/Cyrix-longhaul-capable processors and, of course, powernow-k7 are vaild targets for such a patch.
So I guess adding /sys/bus/system/devices/cpu0/voltage? Should code to do that be in kernel/cpufreq.c or is it possible to do sysfs from powernow-k7 [it does not seem easy]?
Pavel
Signature · 2 lines
Horseback riding is like software... ...vgf orggre jura vgf serr.
Quoted 13 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 2 lines
But I agree that hacking
proc_intfis not the right thing to do. I did not see that sysfs access. Where is it?
kernel/cpufreq.cOkay, I see.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
- selecting the voltage manually is something which is only valid for some very few drivers - so let's only export one sysfs file[*] for these drivers.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Very few drivers? It should be common for at least Intel and AMD, no?
No. Intel doesn't let you select the exact voltage. IIRC, only vew VIA/Cyrix-longhaul-capable processors and, of course, powernow-k7 are vaild targets for such a patch.
So I guess adding
/sys/bus/system/devices/cpu0/voltage? Should code to do that be inkernel/cpufreq.cor is it possible to do sysfs from powernow-k7 [it does not seem easy]?
Pavel
I agree, there shoul dbe a way to add sysfs files from a cpufreq driver module. I told dave I was looking into overriding the powernow tables, but I can't seem to get enough time away from my day job right now.
for the powernow driver, and the userspace governor, I'd like to export a file "current_setting" or something that contains:
<frequency> <voltage> <fsb? maybe for other drivers>
A write to this file of one, two, or three values would result in changing the frequency to the closest standard table match we have. Unless, the user specifies an "override" flag as a module parameter. If the override flag is set, then writing to that file will set the speed and voltage to exactly what you specify (within the min/max hardware limits), and basically ignore the standard BIOS table.
simple, elegant, gives standard default behavior....but allows one to override the tables if they -swear- they know better. But it's really tough to do without a way to add sysfs files from the driver itself.
john.c
Signature · 3 lines
John Clemens http://www.deater.net/john [email protected] ICQ: 7175925, IM: PianoManO8 "I Hate Quotes" -- Samuel L. Clemens
Hi!
Quoted 11 lines
Quoted 3 lines
So I guess adding
/sys/bus/system/devices/cpu0/voltage? Should code to do that be inkernel/cpufreq.cor is it possible to do sysfs from powernow-k7 [it does not seem easy]?Pavel
I agree, there shoul dbe a way to add sysfs files from a cpufreq driver module. I told dave I was looking into overriding the powernow tables, but I can't seem to get enough time away from my day job right now.for the powernow driver, and the userspace governor, I'd like to export a file "
current_setting" or something that contains:
Quoted 8 lines
<frequency> <voltage> <fsb? maybe for other drivers>
A write to this file of one, two, or three values would result in changing the frequency to the closest standard table match we have. Unless, the user specifies an "override" flag as a module parameter. If the override flag is set, then writing to that file will set the speed and voltage to exactly what you specify (within the min/max hardware limits), and basically ignore the standard BIOS table.
Actually I think sysfs is trying to get it into one-file-per-value...
...which is going to be problem for writing because it will not be able to atomically update different values at once...
Oh and forget module parameter :-).
Pavel
Signature · 2 lines
Horseback riding is like software... ...vgf orggre jura vgf serr.
Here's my suggestion, (partly) based on something Patrick Mochel suggested for the passing of attribute files of cpufreq drivers to the cpufreq core:
a NULL-terminated list of device_attributes *attr is passed to the core. And if attr itself is NULL, no attribute is passed, of course. Using this approach, this patch against cpufreq-CVS-HEAD adds a file
/sys/devices/sys/cpu0/scaling_available_freqs (something Carl Thompson
asked for)
for the powernow-k7.c and the p4-clockmod.c drivers (other frequency table based drivers can be added at will -- Carl, please don't realy _solely_ on this file: some drivers don't use frequency tables but still might want to use your great userspace scaling program!)
And for powernow-k7.c , the file
/sys/devices/sys/cpu0/scaling_setvoltage
should show the current voltage for the current speed (scaling_setspeed). "echoing" a different value (must be lower than the current voltage) changes the voltage for this frequency only. However, this override is "static" so that if you switch to a different frequency in the meantime but get back to the one you wanted to override the voltage setting for, the new user-specified value is remembered.
This is untested (don't have a powernow-k7-capable notebook), so handle with care.
Comments most welcome,
Dominik
arch/i386/kernel/cpu/cpufreq/p4-clockmod.c +4 -0
@@ -214,6 +214,7 @@else p4clockmod_table[i].frequency = (stock_freq * i)/8 ; } +cpufreq_frequency_table_get_attr (p4clockmod_table, policy->cpu);/* cpuinfo and default policy values */ policy->policy =CPUFREQ_POLICY_PERFORMANCE ;
@@ -226,6 +227,7 @@static int cpufreq_p4_cpu_exit (struct cpufreq_policy *policy) { +cpufreq_frequency_table_put_attr (policy->cpu);return cpufreq_p4_setdc (policy->cpu,DC_DISABLE ); }
@@ -236,6 +238,8 @@ .init = cpufreq_p4_cpu_init, .exit = cpufreq_p4_cpu_exit, .name = "p4-clockmod", + .attr = {&dev_attr_scaling_available_freqs, + NULL}, };
arch/i386/kernel/cpu/cpufreq/powernow-k7.c +96 -0
126 lines not on this page · raw message
drivers/cpufreq/freq_table.c +47 -0
53 lines not on this page · raw message
include/linux/cpufreq.h +11 -0
@@ -166,8 +166,11 @@/* optional, for the moment */ int (*init) (struct cpufreq_policy *policy);int (*exit) (struct cpufreq_policy *policy); +struct device_attribute *attr[]; }; +inline int to_cpu_nr (struct device *dev); +int cpufreq_register_driver (struct cpufreq_driver *driver_data);int cpufreq_unregister_driver (struct cpufreq_driver *driver_data);/* deprecated */
@@ -298,6 +301,14 @@unsigned int relation, unsigned int *index); +/* the following are really really optional */ +extern struct device_attribute dev_attr_scaling_available_freqs; + +void cpufreq_frequency_table_get_attr (struct cpufreq_frequency_table *table, +unsigned int cpu); + +void cpufreq_frequency_table_put_attr (unsigned int cpu); +#endif /* CONFIG_CPU_FREQ_TABLE */ #endif /* _LINUX_CPUFREQ_H */
kernel/cpufreq.c +15 -1
@@ -102,7 +102,7 @@ .devnum = 0, }; -static inline int to_cpu_nr (struct device *dev) +inline int to_cpu_nr (struct device *dev) { struct sys_device * cpu_sys_dev = container_of(dev, struct sys_device, dev);return (cpu_sys_dev->id);
@@ -312,6 +312,7 @@unsigned int cpu =to_cpu_nr (dev);int ret =0 ;struct cpufreq_policy policy; +struct device_attribute ** drv_attr;down (&cpufreq_driver_sem);if (!cpufreq_driver) {
@@ -369,6 +370,12 @@device_create_file (dev, &dev_attr_scaling_driver);device_create_file (dev, &dev_attr_available_scaling_governors); + drv_attr = cpufreq_driver->attr; +while ((drv_attr) && (*drv_attr)) { +device_create_file (dev, *drv_attr); + drv_attr++; + } +up (&cpufreq_driver_sem);return ret; }
@@ -384,6 +391,7 @@ {struct device * dev = intf->dev;unsigned int cpu =to_cpu_nr (dev); +struct device_attribute ** drv_attr;if (cpufreq_driver->target)cpufreq_governor (cpu,CPUFREQ_GOV_STOP );
@@ -399,6 +407,12 @@device_remove_file (dev, &dev_attr_scaling_driver);device_remove_file (dev, &dev_attr_available_scaling_governors); + drv_attr = cpufreq_driver->attr; +while ((drv_attr) && (*drv_attr)) { +device_remove_file (dev, *drv_attr); + drv_attr++; + } +return 0 ; }
Hi!
Quoted 8 lines
Here's my suggestion, (partly) based on something Patrick Mochel suggested for the passing of attribute files of cpufreq drivers to the cpufreq core:
a NULL-terminated list ofdevice_attributes*attr is passed to the core. And if attr itself is NULL, no attribute is passed, of course. Using this approach, this patch against cpufreq-CVS-HEAD adds a file
/sys/devices/sys/cpu0/scaling_available_freqs(something Carl Thompson
asked for)
Strange, I need
include/linux/cpufreq.h line 169
Quoted 5 lines
include/linux/cpufreq.h +1
-0@@ -166,8 +166,11 @@/* optional, for the moment */ int (*init) (struct cpufreq_policy *policy);int (*exit) (struct cpufreq_policy *policy); +struct device_attribute *attr[];
to change this to *attr[99] if I want it to compile...
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Hi!
Quoted 25 lines
Here's my suggestion, (partly) based on something Patrick Mochel suggested for the passing of attribute files of cpufreq drivers to the cpufreq core:
a NULL-terminated list ofdevice_attributes*attr is passed to the core. And if attr itself is NULL, no attribute is passed, of course. Using this approach, this patch against cpufreq-CVS-HEAD adds a file
/sys/devices/sys/cpu0/scaling_available_freqs(something Carl Thompson
asked for)for the
powernow-k7.cand thep4-clockmod.cdrivers (other frequency table based drivers can be added at will -- Carl, please don't realy _solely_ on this file: some drivers don't use frequency tables but still might want to use your great userspace scaling program!)And for
powernow-k7.c, the file
/sys/devices/sys/cpu0/scaling_setvoltageshould show the current voltage for the current speed (
scaling_setspeed). "echoing" a different value (must be lower than the current voltage) changes the voltage for this frequency only. However, this override is "static" so that if you switch to a different frequency in the meantime but get back to the one you wanted to override the voltage setting for, the new user-specified value is remembered.
Quoted 2 lines
This is untested (don't have a powernow-k7-capable notebook), so handle with care.
It seems to work. I'll crash my machine now (and go to sleep ;-). So if you don't get another mail within 30 minutes of this, it worked.
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Hi!
Quoted 11 lines
And for
powernow-k7.c, the file
/sys/devices/sys/cpu0/scaling_setvoltageshould show the current voltage for the current speed (
scaling_setspeed). "echoing" a different value (must be lower than the current voltage) changes the voltage for this frequency only. However, this override is "static" so that if you switch to a different frequency in the meantime but get back to the one you wanted to override the voltage setting for, the new user-specified value is remembered.
Quoted 2 lines
This is untested (don't have a powernow-k7-capable notebook), so handle with care.
Thanx, it works. I'd drop "can't set higher voltage" limitation [hardware protects you, anyway, and if you make it so low your system is unstable you can no longer fix it without reboot], but that's minor.
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]