cpufreq_(ondemand|conservative) (round three)
PATCH 1/1 cpufreq_(ondemand|conservative) (round three)
Evening All,
Well again I received more suggestions (thanks), a few tweaks have been added and it was asked of me to produce diff's for 2.6.10-rc1-mm3 which I have; due to changes in the cpufreq code the borked my patches and there is now a different approach being used to return failed /sys changes that I needed to amend for.
All the 2.6.9 patches to ondemand are in the 'ondemand' style of coding, or the best I have managed to keep to. I kept with the 2.6.9 'style' for my 'conservative' patch also.
For 2.6.10-rc1-mm3 I re-wrote the little bits of the patches to fit in with the amended style, but I also included a 'consistency' patch as some of the /sys functions already present in the 'ondemand' governor did not 'look' like the others. Again my 'conservative' governor has been tweaked to match.
What about this time? Still lacking any reports of "Works for Me(tm)" and "Damn Your Code Sucks(tm)" which is a shame.... :)
Cheers all
Alex
Signature · 10 lines
________________________________________
/ Pray to God, but keep rowing to shore. \
| |
\ -- Russian Proverb /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||drivers/cpufreq/cpufreq_ondemand.c +31 -2
@@ -81,6 +81,7 @@unsigned int sampling_down_factor;unsigned int up_threshold;unsigned int down_threshold; +unsigned int ignore_nice; };struct dbs_tuners dbs_tuners_ins = {
@@ -120,6 +121,7 @@show_one (sampling_down_factor, sampling_down_factor);show_one (up_threshold, up_threshold);show_one (down_threshold, down_threshold); +show_one (ignore_nice, ignore_nice);static ssize_t store_sampling_down_factor (struct cpufreq_policy *unused,const char *buf,size_t count)
@@ -189,6 +191,24 @@return count; } +static ssize_t store_ignore_nice (struct cpufreq_policy *unused, +const char *buf,size_t count) +{ +unsigned int input; +int ret; + ret =sscanf (buf,"%u" , &input); +down (&dbs_sem); +if ( ret !=1 ) + goto out; + +if ( input >1 ) + input =1 ; + dbs_tuners_ins.ignore_nice = input; +out: +up (&dbs_sem); +return count; +} +#define define_one_rw (_name) \ static struct freq_attr _name = { \ .attr = { .name = __stringify(_name), .mode = 0644 }, \
@@ -200,6 +220,7 @@define_one_rw (sampling_down_factor);define_one_rw (up_threshold);define_one_rw (down_threshold); +define_one_rw (ignore_nice);static struct attribute * dbs_attributes[] = { &sampling_rate_max.attr,
@@ -208,6 +229,7 @@ &sampling_down_factor.attr, &up_threshold.attr, &down_threshold.attr, + &ignore_nice.attr, NULL };
@@ -247,6 +269,10 @@/* Check for frequency increase */ total_idle_ticks =kstat_cpu (cpu).cpustat.idle +kstat_cpu (cpu).cpustat.iowait; +/* consider 'nice' tasks as 'idle' time too if required */ +if (dbs_tuners_ins.ignore_nice ==0 ) + total_idle_ticks +=kstat_cpu (cpu).cpustat.nice; + idle_ticks = total_idle_ticks - this_dbs_info->prev_cpu_idle_up; this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
@@ -346,10 +372,12 @@ this_dbs_info->prev_cpu_idle_up =kstat_cpu (cpu).cpustat.idle + -kstat_cpu (cpu).cpustat.iowait; +kstat_cpu (cpu).cpustat.iowait + +kstat_cpu (cpu).cpustat.nice; this_dbs_info->prev_cpu_idle_down =kstat_cpu (cpu).cpustat.idle + -kstat_cpu (cpu).cpustat.iowait; +kstat_cpu (cpu).cpustat.iowait + +kstat_cpu (cpu).cpustat.nice; this_dbs_info->enable =1 ;sysfs_create_group (&policy->kobj, &dbs_attr_group); dbs_enable++;
@@ -368,6 +396,7 @@ def_sampling_rate = (latency /1000 ) *DEF_SAMPLING_RATE_LATENCY_MULTIPLIER ; dbs_tuners_ins.sampling_rate = def_sampling_rate; + dbs_tuners_ins.ignore_nice =0 ;dbs_timer_init (); }
drivers/cpufreq/cpufreq_ondemand.c +6 -0
@@ -283,6 +283,9 @@sampling_rate_in_HZ (dbs_tuners_ins.sampling_rate);if (idle_ticks < up_idle_ticks) { +if (this_dbs_info->cur_policy->cur + == this_dbs_info->cur_policy->max) +return ;__cpufreq_driver_target (this_dbs_info->cur_policy, this_dbs_info->cur_policy->max,CPUFREQ_RELATION_H );
@@ -309,6 +312,9 @@sampling_rate_in_HZ (freq_down_sampling_rate);if (idle_ticks > down_idle_ticks ) { +if (this_dbs_info->cur_policy->cur + == this_dbs_info->cur_policy->min) +return ; freq_down_step = (5 * this_dbs_info->cur_policy->max) /100 ;/* max freq cannot be less than 100. But who knows.... */
drivers/cpufreq/cpufreq_ondemand.c +44 -9
109 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +7 -12
@@ -123,6 +123,7 @@unsigned int input;int ret; ret =sscanf (buf,"%u" , &input); +if (ret !=1 )return -EINVAL ;
@@ -140,12 +141,10 @@int ret; ret =sscanf (buf,"%u" , &input); -down (&dbs_sem); -if (ret !=1 || input >MAX_SAMPLING_RATE || input <MIN_SAMPLING_RATE ) { -up (&dbs_sem); +if (ret !=1 || input >MAX_SAMPLING_RATE || input <MIN_SAMPLING_RATE )return -EINVAL ; - } +down (&dbs_sem); dbs_tuners_ins.sampling_rate = input;up (&dbs_sem);
@@ -159,14 +158,12 @@int ret; ret =sscanf (buf,"%u" , &input); -down (&dbs_sem);if (ret !=1 || input >MAX_FREQUENCY_UP_THRESHOLD || input <MIN_FREQUENCY_UP_THRESHOLD || - input <= dbs_tuners_ins.down_threshold) { -up (&dbs_sem); + input <= dbs_tuners_ins.down_threshold)return -EINVAL ; - } +down (&dbs_sem); dbs_tuners_ins.up_threshold = input;up (&dbs_sem);
@@ -180,14 +177,12 @@int ret; ret =sscanf (buf,"%u" , &input); -down (&dbs_sem);if (ret !=1 || input >MAX_FREQUENCY_DOWN_THRESHOLD || input <MIN_FREQUENCY_DOWN_THRESHOLD || - input >= dbs_tuners_ins.up_threshold) { -up (&dbs_sem); + input >= dbs_tuners_ins.up_threshold)return -EINVAL ; - } +down (&dbs_sem); dbs_tuners_ins.down_threshold = input;up (&dbs_sem);
drivers/cpufreq/cpufreq_ondemand.c +33 -2
@@ -79,6 +79,7 @@unsigned int sampling_down_factor;unsigned int up_threshold;unsigned int down_threshold; +unsigned int ignore_nice; };static struct dbs_tuners dbs_tuners_ins = {
@@ -116,6 +117,7 @@show_one (sampling_down_factor, sampling_down_factor);show_one (up_threshold, up_threshold);show_one (down_threshold, down_threshold); +show_one (ignore_nice, ignore_nice);static ssize_t store_sampling_down_factor (struct cpufreq_policy *unused,const char *buf,size_t count)
@@ -189,6 +191,26 @@return count; } +static ssize_t store_ignore_nice (struct cpufreq_policy *unused, +const char *buf,size_t count) +{ +unsigned int input; +int ret; + + ret =sscanf (buf,"%u" , &input); + +if ( ret !=1 ) +return -EINVAL ; + +if ( input >1 ) + input =1 ; +down (&dbs_sem); + dbs_tuners_ins.ignore_nice = input; +up (&dbs_sem); + +return count; +} +#define define_one_rw (_name) \ static struct freq_attr _name = \ __ATTR(_name, 0644, show_##_name, store_##_name)
@@ -197,6 +219,7 @@define_one_rw (sampling_down_factor);define_one_rw (up_threshold);define_one_rw (down_threshold); +define_one_rw (ignore_nice);static struct attribute * dbs_attributes[] = { &sampling_rate_max.attr,
@@ -205,6 +228,7 @@ &sampling_down_factor.attr, &up_threshold.attr, &down_threshold.attr, + &ignore_nice.attr, NULL };
@@ -244,6 +268,10 @@/* Check for frequency increase */ total_idle_ticks =kstat_cpu (cpu).cpustat.idle +kstat_cpu (cpu).cpustat.iowait; +/* consider 'nice' tasks as 'idle' time too if required */ +if (dbs_tuners_ins.ignore_nice ==0 ) + total_idle_ticks +=kstat_cpu (cpu).cpustat.nice; + idle_ticks = total_idle_ticks - this_dbs_info->prev_cpu_idle_up; this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
@@ -343,10 +371,12 @@ this_dbs_info->prev_cpu_idle_up =kstat_cpu (cpu).cpustat.idle + -kstat_cpu (cpu).cpustat.iowait; +kstat_cpu (cpu).cpustat.iowait + +kstat_cpu (cpu).cpustat.nice; this_dbs_info->prev_cpu_idle_down =kstat_cpu (cpu).cpustat.idle + -kstat_cpu (cpu).cpustat.iowait; +kstat_cpu (cpu).cpustat.iowait + +kstat_cpu (cpu).cpustat.nice; this_dbs_info->enable =1 ;sysfs_create_group (&policy->kobj, &dbs_attr_group); dbs_enable++;
@@ -365,6 +395,7 @@ def_sampling_rate = (latency /1000 ) *DEF_SAMPLING_RATE_LATENCY_MULTIPLIER ; dbs_tuners_ins.sampling_rate = def_sampling_rate; + dbs_tuners_ins.ignore_nice =0 ;dbs_timer_init (); }
drivers/cpufreq/cpufreq_ondemand.c +6 -0
@@ -282,6 +282,9 @@sampling_rate_in_HZ (dbs_tuners_ins.sampling_rate);if (idle_ticks < up_idle_ticks) { +if (this_dbs_info->cur_policy->cur + == this_dbs_info->cur_policy->max) +return ;__cpufreq_driver_target (this_dbs_info->cur_policy, this_dbs_info->cur_policy->max,CPUFREQ_RELATION_H );
@@ -308,6 +311,9 @@sampling_rate_in_HZ (freq_down_sampling_rate);if (idle_ticks > down_idle_ticks ) { +if (this_dbs_info->cur_policy->cur + == this_dbs_info->cur_policy->min) +return ; freq_down_step = (5 * this_dbs_info->cur_policy->max) /100 ;/* max freq cannot be less than 100. But who knows.... */
drivers/cpufreq/cpufreq_ondemand.c +45 -9
110 lines not on this page · raw message
drivers/cpufreq/cpufreq_conservative.c +529 -0
529 lines not on this page · raw message
drivers/cpufreq/Kconfig +18 -0
@@ -84,6 +84,24 @@ If in doubt, say N. +config CPU_FREQ_GOV_CONSERVATIVE + tristate "'conservative' cpufreq governor" + depends on CPU_FREQ + help + 'conservative' - this driver is quite identical to the 'ondemand' + governor both in its source code and purpose, the difference is that + it has been designed to be much more suitable in a battery powered + environment. The frequency is gracefully increased and decreased + rather than jumping to 100% when speed is required and dropping back + aggressively. It also polls 100 times fewer times than 'ondemand'. + + For details, take a look at linux/Documentation/cpu-freq. + + If you have a desktop machine then you should consider really the + 'ondemand' governor instead, however if you are using a laptop, PDA or + even an AMD64 based desktop (due to latency issues) you probably will + want to use this governor. If in doubt, say N. + config CPU_FREQ_24_API bool "/proc/sys/cpu/ interface (2.4. / OLD)" depends on CPU_FREQ && SYSCTL && CPU_FREQ_GOV_USERSPACE
drivers/cpufreq/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o +obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o # CPUfreq cross-arch helpers obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o
drivers/cpufreq/cpufreq_conservative.c +532 -0
532 lines not on this page · raw message
drivers/cpufreq/Kconfig +18 -0
@@ -98,6 +98,24 @@ If in doubt, say Y. +config CPU_FREQ_GOV_CONSERVATIVE + tristate "'conservative' cpufreq governor" + depends on CPU_FREQ + help + 'conservative' - this driver is quite identical to the 'ondemand' + governor both in its source code and purpose, the difference is that + it has been designed to be much more suitable in a battery powered + environment. The frequency is gracefully increased and decreased + rather than jumping to 100% when speed is required and dropping back + aggressively. It also polls 100 times fewer times than 'ondemand'. + + For details, take a look at linux/Documentation/cpu-freq. + + If you have a desktop machine then you should consider really the + 'ondemand' governor instead, however if you are using a laptop, PDA or + even an AMD64 based desktop (due to latency issues) you probably will + want to use this governor. If in doubt, say N. + config CPU_FREQ_24_API bool "/proc/sys/cpu/ interface (2.4. / OLD)" depends on CPU_FREQ_GOV_USERSPACE
drivers/cpufreq/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o +obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o # CPUfreq cross-arch helpers obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o
_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq