Skip to contentSkip to conversation

cpufreq on-demand governor up_treshold?

PATCH New Jan De Luyck 6 participants 13 messages Mar 14, 2005 – May 17, 2005 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

Hello lists,

(please cc me from cpufreq list)

I've since yesterday started using the ondemand governor. Seems to work fine, tho I can't seem to find a reason why it keeps scaling my processor speed upwards tho the processor use never exceeds 30% (been watching top -d 1).

I've been using the powernowd daemon and the userspace governor previously, which doesn't seem to have this problem, even if i set it at the same sampling rates as the ondemand governor.

The settings in /sys/.../ondemand are default.

Any hints?

Thanks.

Signature · 2 lines
Women aren't as mere as they used to be.
  -- Pogo
#1 lore raw
Quoted 5 lines · Jan De Luyck

Hello lists,

(please cc me from cpufreq list)

I've since yesterday started using the ondemand governor. Seems to work fine, tho I can't seem to find a reason why it keeps scaling my processor speed upwards tho the processor use never exceeds 30% (been watching top -d 1).

:
:

Quoted 1 line

Any hints?

You can try the three attached patches in the order :
ondemand-cleanup-factorise-idle-measurement-2.6.11.patch ondemand-save-idle-up-for-all-cpu-2.6.11.patch ondemand-automatic-downscaling-2.6.11-accepted.patch

They are available on the cpufreq list but as it's difficult to access it I'm sending them again, all together. These are the last things that Venki and I have been working on. It should solve your problem (actually, only the last patch, but it depends on the two previous patches). Please, let me know if it works.

BTW, DaveJ, Dominik, I couldn't find them in the daily-snapshot available at codemonkey.org.uk. Should I worry, or is it just due to some latency between your private trees and the public one?

Eric

drivers/cpufreq/cpufreq_ondemand.c +22 -51
diff -purN linux-2.6.11/drivers/cpufreq/cpufreq_ondemand.c linux-2.6.11-new/drivers/cpufreq/cpufreq_ondemand.c
@@ -34,13 +34,9 @@
  */
 
 #define DEF_FREQUENCY_UP_THRESHOLD		(80)
-#define MIN_FREQUENCY_UP_THRESHOLD		(0)
+#define MIN_FREQUENCY_UP_THRESHOLD		(10)
 #define MAX_FREQUENCY_UP_THRESHOLD		(100)
 
-#define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
-#define MIN_FREQUENCY_DOWN_THRESHOLD		(0)
-#define MAX_FREQUENCY_DOWN_THRESHOLD		(100)
-
 /* 
  * The polling frequency of this governor depends on the capability of 
  * the processor. Default polling frequency is 1000 times the transition
@@ -78,12 +74,10 @@ struct dbs_tuners {
 	unsigned int 		sampling_rate;
 	unsigned int		sampling_down_factor;
 	unsigned int		up_threshold;
-	unsigned int		down_threshold;
 };
 
 static struct dbs_tuners dbs_tuners_ins = {
 	.up_threshold 		= DEF_FREQUENCY_UP_THRESHOLD,
-	.down_threshold 	= DEF_FREQUENCY_DOWN_THRESHOLD,
 	.sampling_down_factor 	= DEF_SAMPLING_DOWN_FACTOR,
 };
 
@@ -115,7 +109,6 @@ static ssize_t show_##file_name						\
 show_one(sampling_rate, sampling_rate);
 show_one(sampling_down_factor, sampling_down_factor);
 show_one(up_threshold, up_threshold);
-show_one(down_threshold, down_threshold);
 
 static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, 
 		const char *buf, size_t count)
@@ -161,8 +154,7 @@ static ssize_t store_up_threshold(struct
 
 	down(&dbs_sem);
 	if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 
-			input < MIN_FREQUENCY_UP_THRESHOLD ||
-			input <= dbs_tuners_ins.down_threshold) {
+			input < MIN_FREQUENCY_UP_THRESHOLD) {
 		up(&dbs_sem);
 		return -EINVAL;
 	}
@@ -173,26 +165,6 @@ static ssize_t store_up_threshold(struct
 	return count;
 }
 
-static ssize_t store_down_threshold(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 || input > MAX_FREQUENCY_DOWN_THRESHOLD || 
-			input < MIN_FREQUENCY_DOWN_THRESHOLD ||
-			input >= dbs_tuners_ins.up_threshold) {
-		up(&dbs_sem);
-		return -EINVAL;
-	}
-
-	dbs_tuners_ins.down_threshold = input;
-	up(&dbs_sem);
-
-	return count;
-}
 
 #define define_one_rw(_name) \
 static struct freq_attr _name = \
@@ -201,7 +173,6 @@ __ATTR(_name, 0644, show_##_name, store_
 define_one_rw(sampling_rate);
 define_one_rw(sampling_down_factor);
 define_one_rw(up_threshold);
-define_one_rw(down_threshold);
 
 static struct attribute * dbs_attributes[] = {
 	&sampling_rate_max.attr,
@@ -209,7 +180,6 @@ static struct attribute * dbs_attributes
 	&sampling_rate.attr,
 	&sampling_down_factor.attr,
 	&up_threshold.attr,
-	&down_threshold.attr,
 	NULL
 };
 
@@ -222,8 +192,8 @@ static struct attribute_group dbs_attr_g
 
 static void dbs_check_cpu(int cpu)
 {
-	unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
-	unsigned int freq_down_step;
+	unsigned int idle_ticks, up_idle_ticks, total_ticks;
+	unsigned int freq_next;
 	unsigned int freq_down_sampling_rate;
 	static int down_skip[NR_CPUS];
 	struct cpu_dbs_info_s *this_dbs_info;
@@ -290,7 +260,12 @@ static void dbs_check_cpu(int cpu)
 	down_skip[cpu]++;
 	if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
 		return;
+	down_skip[cpu] = 0;
 
+	/* don't try to decrease the frequency if it's already the min */
+	if (policy->cur == policy->min)
+		return;
+	
 	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
 		unsigned int tmp_idle_ticks, total_idle_ticks;
@@ -308,27 +283,23 @@ static void dbs_check_cpu(int cpu)
 			idle_ticks = tmp_idle_ticks;
 	}
 
-	/* Scale idle ticks by 100 and compare with up and down ticks */
-	idle_ticks *= 100;
-	down_skip[cpu] = 0;
-
+	/* Compute how many ticks there are between two measurements */
 	freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
 		dbs_tuners_ins.sampling_down_factor;
-	down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
-			sampling_rate_in_HZ(freq_down_sampling_rate);
-
-	if (idle_ticks > down_idle_ticks) {
-		freq_down_step = (5 * policy->max) / 100;
-
-		/* max freq cannot be less than 100. But who knows.... */
-		if (unlikely(freq_down_step == 0))
-			freq_down_step = 5;
+	total_ticks = sampling_rate_in_HZ(freq_down_sampling_rate);
+	
+	/* 
+	 * The optimal frequency is the frequency that is the lowest that
+	 * can support the current CPU usage without triggering 
+	 * the up policy. To be safe, we focus 10 points under the threshold.
+	 */
+	freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks;
+	freq_next = freq_next * policy->cur / (dbs_tuners_ins.up_threshold-10);
 
+	if (freq_next <= ((policy->cur * 95) / 100))
 		__cpufreq_driver_target(policy,
-			policy->cur - freq_down_step, 
-			CPUFREQ_RELATION_H);
-		return;
-	}
+			freq_next, 
+			CPUFREQ_RELATION_L);
 }
 
 static void do_dbs_timer(void *data)
drivers/cpufreq/cpufreq_ondemand.c renamed from drivers/cpufreq/cpufreq_ondemand.c.bak +6 -24
@@ -223,7 +223,6 @@ static struct attribute_group dbs_attr_g
 static void dbs_check_cpu(int cpu)
 {
 	unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
-	unsigned int total_idle_ticks;
 	unsigned int freq_down_step;
 	unsigned int freq_down_sampling_rate;
 	static int down_skip[NR_CPUS];
@@ -252,20 +251,11 @@ static void dbs_check_cpu(int cpu)
 	 */
 
 	/* Check for frequency increase */
-	total_idle_ticks = kstat_cpu(cpu).cpustat.idle +
-		kstat_cpu(cpu).cpustat.iowait;
-	idle_ticks = total_idle_ticks -
-		this_dbs_info->prev_cpu_idle_up;
-	this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
-	
-
+	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
-		unsigned int tmp_idle_ticks;
+		unsigned int tmp_idle_ticks, total_idle_ticks;
 		struct cpu_dbs_info_s *j_dbs_info;
 
-		if (j == cpu)
-			continue;
-
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
 		total_idle_ticks = kstat_cpu(j).cpustat.idle +
@@ -287,7 +277,7 @@ static void dbs_check_cpu(int cpu)
 		__cpufreq_driver_target(policy, policy->max, 
 			CPUFREQ_RELATION_H);
 		down_skip[cpu] = 0;
-		this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
+		this_dbs_info->prev_cpu_idle_down = this_dbs_info->prev_cpu_idle_up;
 		return;
 	}
 
@@ -296,19 +286,11 @@ static void dbs_check_cpu(int cpu)
 	if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
 		return;
 
-	total_idle_ticks = kstat_cpu(cpu).cpustat.idle +
-		kstat_cpu(cpu).cpustat.iowait;
-	idle_ticks = total_idle_ticks -
-		this_dbs_info->prev_cpu_idle_down;
-	this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
-
+	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
-		unsigned int tmp_idle_ticks;
+		unsigned int tmp_idle_ticks, total_idle_ticks;
 		struct cpu_dbs_info_s *j_dbs_info;
 
-		if (j == cpu)
-			continue;
-
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
 		total_idle_ticks = kstat_cpu(j).cpustat.idle +
@@ -330,7 +312,7 @@ static void dbs_check_cpu(int cpu)
 	down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
 			sampling_rate_in_HZ(freq_down_sampling_rate);
 
-	if (idle_ticks > down_idle_ticks ) {
+	if (idle_ticks > down_idle_ticks) {
 		freq_down_step = (5 * policy->max) / 100;
 
 		/* max freq cannot be less than 100. But who knows.... */
drivers/cpufreq/cpufreq_ondemand.c renamed from drivers/cpufreq/cpufreq_ondemand.c.clean2 +6 -1
@@ -277,7 +277,12 @@
 		__cpufreq_driver_target(policy, policy->max, 
 			CPUFREQ_RELATION_H);
 		down_skip[cpu] = 0;
-		this_dbs_info->prev_cpu_idle_down = this_dbs_info->prev_cpu_idle_up;
+		for_each_cpu_mask(j, policy->cpus) {
+			struct cpu_dbs_info_s *j_dbs_info;
+
+			j_dbs_info = &per_cpu(cpu_dbs_info, j);
+			j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up;
+		}
 		return;
 	}
 

_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq

#2 lore raw
Quoted 4 lines · Eric Piel

BTW, DaveJ, Dominik, I couldn't find them in the daily-snapshot available at codemonkey.org.uk. Should I worry, or is it just due to some latency between your private trees and the public one?

This happens those days only when I upgrade the LINUX_2_4 branch (and only because its easier for me to diff between HEAD and LINUX_2_4).

Signature · 4 lines
Bruno Ducrot

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#3 lore raw
In reply to Eric Piel
Quoted 18 lines · Eric Piel
Quoted 11 lines · Jan De Luyck

Hello lists,

(please cc me from cpufreq list)

I've since yesterday started using the ondemand governor. Seems to work fine, tho I can't seem to find a reason why it keeps scaling my processor speed upwards tho the processor use never exceeds 30% (been watching top -d 1).

Any hints?

You can try the three attached patches in the order :
ondemand-cleanup-factorise-idle-measurement-2.6.11.patch ondemand-save-idle-up-for-all-cpu-2.6.11.patch ondemand-automatic-downscaling-2.6.11-accepted.patch

Quoted 5 lines

They are available on the cpufreq list but as it's difficult to access it I'm sending them again, all together. These are the last things that Venki and I have been working on. It should solve your problem (actually, only the last patch, but it depends on the two previous patches). Please, let me know if it works.

Okay, now the behaviour of the ondemand governor looks more 'sane'. Thanks, it looks like a huge improvement :)

Jan

Signature · 2 lines
Snow and adolescence are the only problems that disappear if you ignore
them long enough.
#4 lore raw
In reply to Eric Piel
Quoted 3 lines · Eric Piel

BTW, DaveJ, Dominik, I couldn't find them in the daily-snapshot available at codemonkey.org.uk. Should I worry, or is it just due to some latency between your private trees and the public one?

/me has no official position wrt cpufreq core [except userspace cpufrequtils, but I intend to hand this over to somebody else in the next few months].

Dave, as maintainer of cpufreq, has a cpufreq bitkeeper tree [http interface at http://linux-dj.bkbits.net/ ] which is exported as plain diff daily at
http://www.codemonkey.org.uk/projects/cpufreq/daily-snapshots/ . This does not contain your patches yet, probably because he's still busy with other stuff.

Thanks,
Dominik

#5 lore raw
In reply to Eric Piel
Quoted 23 lines · Eric Piel
Quoted 8 lines · Jan De Luyck

Hello lists,

(please cc me from cpufreq list)

I've since yesterday started using the ondemand governor. Seems to work fine, tho I can't seem to find a reason why it keeps scaling my processor speed upwards tho the processor use never exceeds 30% (been watching top -d 1).

:
:

Quoted 1 line

Any hints?

You can try the three attached patches in the order :
ondemand-cleanup-factorise-idle-measurement-2.6.11.patch ondemand-save-idle-up-for-all-cpu-2.6.11.patch ondemand-automatic-downscaling-2.6.11-accepted.patch

They are available on the cpufreq list but as it's difficult to access it I'm sending them again, all together. These are the last things that Venki and I have been working on. It should solve your problem (actually, only the last patch, but it depends on the two previous patches). Please, let me know if it works.

Quoted 3 lines

BTW, DaveJ, Dominik, I couldn't find them in the daily-snapshot available at codemonkey.org.uk. Should I worry, or is it just due to some latency between your private trees and the public one?

I'm preparing the first cpufreq->linus sync right now. Can you write up some descriptions & signed-off-by: lines for these three please ?

Thanks,
Dave

#6 lore raw
Quoted 24 lines · Dave Jones
Quoted 23 lines · Eric Piel
Quoted 8 lines · Jan De Luyck

Hello lists,

(please cc me from cpufreq list)

I've since yesterday started using the ondemand governor. Seems to work fine, tho I can't seem to find a reason why it keeps scaling my processor speed upwards tho the processor use never exceeds 30% (been watching top -d 1).

:
:

Quoted 1 line

Any hints?

You can try the three attached patches in the order :
ondemand-cleanup-factorise-idle-measurement-2.6.11.patch ondemand-save-idle-up-for-all-cpu-2.6.11.patch ondemand-automatic-downscaling-2.6.11-accepted.patch

They are available on the cpufreq list but as it's difficult to access it I'm sending them again, all together. These are the last things that Venki and I have been working on. It should solve your problem (actually, only the last patch, but it depends on the two previous patches). Please, let me know if it works.

Quoted 7 lines
Quoted 3 lines

BTW, DaveJ, Dominik, I couldn't find them in the daily-snapshot available at codemonkey.org.uk. Should I worry, or is it just due to some latency between your private trees and the public one?

I'm preparing the first cpufreq->linus sync right now. Can you write up some descriptions & signed-off-by: lines for these three please ?

Additionally, it'll need tweaking to diff on top of whats currently in the pending queue. looks like the patch at
http://www.codemonkey.org.uk/projects/cpufreq/pending-patches/CPUFREQ-04-ondemand-cleanups.patch
upsets yours a little.

Thanks,

Dave

#7 lore raw
Quoted 11 lines · Dave Jones
Quoted 4 lines · Dave Jones

I'm preparing the first cpufreq->linus sync right now. Can you write up some descriptions & signed-off-by: lines for these three please ?

Additionally, it'll need tweaking to diff on top of whats currently in the pending queue. looks like the patch at
http://www.codemonkey.org.uk/projects/cpufreq/pending-patches/CPUFREQ-04-ondemand-cleanups.patch
upsets yours a little.

Here follows the three patches, updated for the last snapshot of cpufreq. I knew there was a conflict (CPUFREQ-04 is also a patch I wrote ;-) ) but was too lasy to resend them. Here you are!

Eric

#8 lore raw

PATCH 1/3 ondemand governor clean-up

Ondemand governor clean-up, it factorises the idle ticks measurement.

--

drivers/cpufreq/cpufreq_ondemand.c renamed from drivers/cpufreq/cpufreq_ondemand.c.cpufreq-20050501 +6 -24
@@ -222,7 +222,6 @@ static struct attribute_group dbs_attr_g
 static void dbs_check_cpu(int cpu)
 {
 	unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
-	unsigned int total_idle_ticks;
 	unsigned int freq_down_step;
 	unsigned int freq_down_sampling_rate;
 	static int down_skip[NR_CPUS];
@@ -251,20 +250,11 @@ static void dbs_check_cpu(int cpu)
 	 */
 
 	/* Check for frequency increase */
-	total_idle_ticks = kstat_cpu(cpu).cpustat.idle +
-		kstat_cpu(cpu).cpustat.iowait;
-	idle_ticks = total_idle_ticks -
-		this_dbs_info->prev_cpu_idle_up;
-	this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
-	
-
+	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
-		unsigned int tmp_idle_ticks;
+		unsigned int tmp_idle_ticks, total_idle_ticks;
 		struct cpu_dbs_info_s *j_dbs_info;
 
-		if (j == cpu)
-			continue;
-
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
 		total_idle_ticks = kstat_cpu(j).cpustat.idle +
@@ -286,7 +276,7 @@ static void dbs_check_cpu(int cpu)
 		__cpufreq_driver_target(policy, policy->max, 
 			CPUFREQ_RELATION_H);
 		down_skip[cpu] = 0;
-		this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
+		this_dbs_info->prev_cpu_idle_down = this_dbs_info->prev_cpu_idle_up;
 		return;
 	}
 
@@ -295,19 +285,11 @@ static void dbs_check_cpu(int cpu)
 	if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
 		return;
 
-	total_idle_ticks = kstat_cpu(cpu).cpustat.idle +
-		kstat_cpu(cpu).cpustat.iowait;
-	idle_ticks = total_idle_ticks -
-		this_dbs_info->prev_cpu_idle_down;
-	this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
-
+	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
-		unsigned int tmp_idle_ticks;
+		unsigned int tmp_idle_ticks, total_idle_ticks;
 		struct cpu_dbs_info_s *j_dbs_info;
 
-		if (j == cpu)
-			continue;
-
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
 		total_idle_ticks = kstat_cpu(j).cpustat.idle +
@@ -329,7 +311,7 @@ static void dbs_check_cpu(int cpu)
 	down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
 			usecs_to_jiffies(freq_down_sampling_rate);
 
-	if (idle_ticks > down_idle_ticks ) {
+	if (idle_ticks > down_idle_ticks) {
 		freq_down_step = (5 * policy->max) / 100;
 
 		/* max freq cannot be less than 100. But who knows.... */

_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq

#9 lore raw

PATCH 2/3 ondemand governor store the idle ticks for all cpus

In reply to Eric Piel

Ondemand governor did not store prev_cpu_idle_up into prev_cpu_idle_down for other CPUs than the current CPU.

--

drivers/cpufreq/cpufreq_ondemand.c renamed from drivers/cpufreq/cpufreq_ondemand.c.cpufreq-20050501-1 +6 -1
@@ -276,7 +276,12 @@ static void dbs_check_cpu(int cpu)
 		__cpufreq_driver_target(policy, policy->max, 
 			CPUFREQ_RELATION_H);
 		down_skip[cpu] = 0;
-		this_dbs_info->prev_cpu_idle_down = this_dbs_info->prev_cpu_idle_up;
+		for_each_cpu_mask(j, policy->cpus) {
+			struct cpu_dbs_info_s *j_dbs_info;
+
+			j_dbs_info = &per_cpu(cpu_dbs_info, j);
+			j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up;
+		}
 		return;
 	}
 

_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq

#10 lore raw

PATCH 3/3 ondemand governor automatic downscaling

In reply to Eric Piel

This patch has been redone for latest snapshot. Very little differences from before, use the usecs_to_jiffies() instead of the old sampling_rate_in_HZ() and comments updated.

Eric

--
Here is a new policy for the ondemand governor. The modification concerns the frequency downscaling. Instead of decreasing to a lower frequency when the CPU usage is under 20%, this new policy automatically scales to the optimal frequency. The optimal frequency being the lowest frequency which provides enough power to not trigger the upscaling policy.

--

drivers/cpufreq/cpufreq_ondemand.c renamed from drivers/cpufreq/cpufreq_ondemand.c.cpufreq-20050501-2 +27 -58
@@ -34,13 +34,9 @@
  */
 
 #define DEF_FREQUENCY_UP_THRESHOLD		(80)
-#define MIN_FREQUENCY_UP_THRESHOLD		(0)
+#define MIN_FREQUENCY_UP_THRESHOLD		(10)
 #define MAX_FREQUENCY_UP_THRESHOLD		(100)
 
-#define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
-#define MIN_FREQUENCY_DOWN_THRESHOLD		(0)
-#define MAX_FREQUENCY_DOWN_THRESHOLD		(100)
-
 /* 
  * The polling frequency of this governor depends on the capability of 
  * the processor. Default polling frequency is 1000 times the transition
@@ -77,12 +73,10 @@ struct dbs_tuners {
 	unsigned int 		sampling_rate;
 	unsigned int		sampling_down_factor;
 	unsigned int		up_threshold;
-	unsigned int		down_threshold;
 };
 
 static struct dbs_tuners dbs_tuners_ins = {
 	.up_threshold 		= DEF_FREQUENCY_UP_THRESHOLD,
-	.down_threshold 	= DEF_FREQUENCY_DOWN_THRESHOLD,
 	.sampling_down_factor 	= DEF_SAMPLING_DOWN_FACTOR,
 };
 
@@ -114,7 +108,6 @@ static ssize_t show_##file_name						\
 show_one(sampling_rate, sampling_rate);
 show_one(sampling_down_factor, sampling_down_factor);
 show_one(up_threshold, up_threshold);
-show_one(down_threshold, down_threshold);
 
 static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, 
 		const char *buf, size_t count)
@@ -160,8 +153,7 @@ static ssize_t store_up_threshold(struct
 
 	down(&dbs_sem);
 	if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 
-			input < MIN_FREQUENCY_UP_THRESHOLD ||
-			input <= dbs_tuners_ins.down_threshold) {
+			input < MIN_FREQUENCY_UP_THRESHOLD) {
 		up(&dbs_sem);
 		return -EINVAL;
 	}
@@ -172,26 +164,6 @@ static ssize_t store_up_threshold(struct
 	return count;
 }
 
-static ssize_t store_down_threshold(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 || input > MAX_FREQUENCY_DOWN_THRESHOLD || 
-			input < MIN_FREQUENCY_DOWN_THRESHOLD ||
-			input >= dbs_tuners_ins.up_threshold) {
-		up(&dbs_sem);
-		return -EINVAL;
-	}
-
-	dbs_tuners_ins.down_threshold = input;
-	up(&dbs_sem);
-
-	return count;
-}
 
 #define define_one_rw(_name) \
 static struct freq_attr _name = \
@@ -200,7 +172,6 @@ __ATTR(_name, 0644, show_##_name, store_
 define_one_rw(sampling_rate);
 define_one_rw(sampling_down_factor);
 define_one_rw(up_threshold);
-define_one_rw(down_threshold);
 
 static struct attribute * dbs_attributes[] = {
 	&sampling_rate_max.attr,
@@ -208,7 +179,6 @@ static struct attribute * dbs_attributes
 	&sampling_rate.attr,
 	&sampling_down_factor.attr,
 	&up_threshold.attr,
-	&down_threshold.attr,
 	NULL
 };
 
@@ -221,8 +191,8 @@ static struct attribute_group dbs_attr_g
 
 static void dbs_check_cpu(int cpu)
 {
-	unsigned int idle_ticks, up_idle_ticks, down_idle_ticks;
-	unsigned int freq_down_step;
+	unsigned int idle_ticks, up_idle_ticks, total_ticks;
+	unsigned int freq_next;
 	unsigned int freq_down_sampling_rate;
 	static int down_skip[NR_CPUS];
 	struct cpu_dbs_info_s *this_dbs_info;
@@ -240,13 +210,13 @@ static void dbs_check_cpu(int cpu)
 	 * Every sampling_rate, we check
 	 * 	- If current idle time is less than 20%, then we try to 
 	 * 	  increase frequency
-	 * Every sampling_rate*sampling_down_factor, we check
-	 * 	- If current idle time is more than 80%, then we try to
-	 * 	  decrease frequency
+	 * Every sampling_rate*sampling_down_factor, we look for a the lowest
+	 * frequency which can sustain the load while keeping idle time over
+	 * 30%. If such a frequency exist, we try to decrease to this frequency.
 	 *
 	 * Any frequency increase takes it to the maximum frequency. 
-	 * Frequency reduction happens at minimum steps of 
-	 * 5% of max_frequency 
+	 * Frequency reduction happens at minimum steps of 5% of current 
+	 * frequency. 
 	 */
 
 	/* Check for frequency increase */
@@ -289,7 +259,12 @@ static void dbs_check_cpu(int cpu)
 	down_skip[cpu]++;
 	if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
 		return;
+	down_skip[cpu] = 0;
 
+	/* don't try to decrease the frequency if it's already the min */
+	if (policy->cur == policy->min)
+		return;
+	
 	idle_ticks = UINT_MAX;
 	for_each_cpu_mask(j, policy->cpus) {
 		unsigned int tmp_idle_ticks, total_idle_ticks;
@@ -307,27 +282,21 @@ static void dbs_check_cpu(int cpu)
 			idle_ticks = tmp_idle_ticks;
 	}
 
-	/* Scale idle ticks by 100 and compare with up and down ticks */
-	idle_ticks *= 100;
-	down_skip[cpu] = 0;
-
+ 	/* Compute how many ticks there are between two measurements */
 	freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
 		dbs_tuners_ins.sampling_down_factor;
-	down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
-			usecs_to_jiffies(freq_down_sampling_rate);
-
-	if (idle_ticks > down_idle_ticks) {
-		freq_down_step = (5 * policy->max) / 100;
-
-		/* max freq cannot be less than 100. But who knows.... */
-		if (unlikely(freq_down_step == 0))
-			freq_down_step = 5;
-
-		__cpufreq_driver_target(policy,
-			policy->cur - freq_down_step, 
-			CPUFREQ_RELATION_H);
-		return;
-	}
+ 	total_ticks = usecs_to_jiffies(freq_down_sampling_rate);
+ 	
+ 	/* 
+ 	 * The optimal frequency is the frequency that is the lowest that
+ 	 * can support the current CPU usage without triggering 
+ 	 * the up policy. To be safe, we focus 10 points under the threshold.
+ 	 */
+ 	freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks;
+ 	freq_next = (freq_next * policy->cur) / (dbs_tuners_ins.up_threshold - 10);
+ 
+ 	if (freq_next <= ((policy->cur * 95) / 100))
+ 		__cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L);
 }
 
 static void do_dbs_timer(void *data)

_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq

#11 lore raw
In reply to Eric Piel
Quoted 7 lines · Eric Piel
Quoted 5 lines · Dave Jones
Quoted 3 lines · Dave Jones
Quoted 1 line

I'm preparing the first cpufreq->linus sync right now.

Can you write up some descriptions & signed-off-by: lines for these three please ?

Quoted 8 lines
Quoted 6 lines

Additionally, it'll need tweaking to diff on top of whats currently in the pending queue. looks like the patch at
http://www.codemonkey.org.uk/projects/cpufreq/pending-patches/CPUFREQ-04-ondemand-cleanups.patch

upsets yours a little.

Here follows the three patches, updated for the last snapshot of cpufreq. I knew there was a conflict (CPUFREQ-04 is also a patch I wrote ;-) ) but was too lasy to resend them. Here you are!

Hi Dave,

I've just noticed that while I was rediffiing the patches, you had integrated the 3 patches of Alexander for the ondemand governor... which conflict with mine!

Concerning CPUFREQ-17-ondemand-ignore-nice.patch, it'll just require rediffing again my patches, that's easy.

CPUFREQ-18-ondemand-check-rate-and-break-out.patch is in part also available in "automatic-downscaling". I hadn't integrated the break if the cpu frequency is max because it seemed that resetting the values for down frequency is necessary all the time (maybe Venki can confirm?). So I would recommand discarding it and just using "automatic-downscaling".

Finally, CPUFREQ-19-ondemand-sys_freq_step.patch brings a feature which is probably not needed anymore if you use the "automatic downscaling" (this can be argued though). I'd discard it too.

Please, let me know what you are planning to do. If you agree I can simply send you my 3 patches against the 20050511 tree minus CPUFREQ-18 and CPUFREQ-19. IMHO, this would put the ondemand governor in the best shape.

Eric

#12 lore raw

PATCH 1/1 ondemand,conservative minor bug-fix and cleanup

Quoted 8 lines

Hi Dave,

I've just noticed that while I was rediffiing the patches, you had integrated the 3 patches of Alexander for the ondemand governor... which conflict with mine!

Quoted 7 lines

Please, let me know what you are planning to do. If you agree I can simply send you my 3 patches against the 20050511 tree minus CPUFREQ-18 and CPUFREQ-19. IMHO, this would put the ondemand governor in the best shape.

Eric

Looks like all the Alexander's changes have made it to the mm (2.6.12-rc4-mm2) tree and Eric's changes hasn't.

Attached patch fixes some minor issues with Alexander's patch and related cleanup in both ondemand and conservative governor.

I will follow this up with Eric's patches rebased with latest base kernel in a day or two.

Please Apply.

Thanks,
Venki

With addition of ignore-nice, there were some minor bugs in ondemand and conservative governor. Attached patch fixes it and also does some minor cleanup related to idle time calculation.

drivers/cpufreq/cpufreq_conservative.c +18 -35
diff -purN linux-2.6.12-rc4-mm2/drivers/cpufreq/cpufreq_conservative.c linux-2.6.12-rc4-mm2-ondemand/drivers/cpufreq/cpufreq_conservative.c
@@ -89,6 +89,15 @@ static struct dbs_tuners dbs_tuners_ins 
 	.sampling_down_factor 	= DEF_SAMPLING_DOWN_FACTOR,
 };
 
+static inline unsigned int get_cpu_idle_time(unsigned int cpu)
+{
+	return	kstat_cpu(cpu).cpustat.idle +
+		kstat_cpu(cpu).cpustat.iowait +
+		( !dbs_tuners_ins.ignore_nice ? 
+		  kstat_cpu(cpu).cpustat.nice :
+		  0);
+}
+
 /************************** sysfs interface ************************/
 static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf)
 {
@@ -221,16 +230,10 @@ static ssize_t store_ignore_nice(struct 
 	dbs_tuners_ins.ignore_nice = input;
 
 	/* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */
-	for_each_cpu_mask(j, policy->cpus) {
+	for_each_online_cpu(j) {
 		struct cpu_dbs_info_s *j_dbs_info;
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
-		j_dbs_info->cur_policy = policy;
-
-		j_dbs_info->prev_cpu_idle_up =
-			kstat_cpu(j).cpustat.idle +
-			kstat_cpu(j).cpustat.iowait +
-			( !dbs_tuners_ins.ignore_nice
-			  ? kstat_cpu(j).cpustat.nice : 0 );
+		j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j);
 		j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up;
 	}
 	up(&dbs_sem);
@@ -335,11 +338,7 @@ static void dbs_check_cpu(int cpu)
 	 */
 
 	/* 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;
+	total_idle_ticks = get_cpu_idle_time(cpu);
 	idle_ticks = total_idle_ticks -
 		this_dbs_info->prev_cpu_idle_up;
 	this_dbs_info->prev_cpu_idle_up = total_idle_ticks;
@@ -354,11 +353,7 @@ static void dbs_check_cpu(int cpu)
 
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
-		total_idle_ticks = kstat_cpu(j).cpustat.idle +
-			kstat_cpu(j).cpustat.iowait;
-		  /* consider 'nice' too? */
-		  if (dbs_tuners_ins.ignore_nice == 0)
-			   total_idle_ticks += kstat_cpu(j).cpustat.nice;
+		total_idle_ticks = get_cpu_idle_time(j);
 		tmp_idle_ticks = total_idle_ticks -
 			j_dbs_info->prev_cpu_idle_up;
 		j_dbs_info->prev_cpu_idle_up = total_idle_ticks;
@@ -373,6 +368,8 @@ static void dbs_check_cpu(int cpu)
 		usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
 
 	if (idle_ticks < up_idle_ticks) {
+		down_skip[cpu] = 0;
+		this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
 		/* if we are already at full speed then break out early */
 		if (requested_freq[cpu] == policy->max)
 			return;
@@ -389,8 +386,6 @@ static void dbs_check_cpu(int cpu)
 
 		__cpufreq_driver_target(policy, requested_freq[cpu], 
 			CPUFREQ_RELATION_H);
-		down_skip[cpu] = 0;
-		this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
 		return;
 	}
 
@@ -399,11 +394,7 @@ static void dbs_check_cpu(int cpu)
 	if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
 		return;
 
-	total_idle_ticks = kstat_cpu(cpu).cpustat.idle +
-		kstat_cpu(cpu).cpustat.iowait;
-	  /* consider 'nice' too? */
-	  if (dbs_tuners_ins.ignore_nice == 0)
-		  total_idle_ticks += kstat_cpu(cpu).cpustat.nice;
+	total_idle_ticks = this_dbs_info->prev_cpu_idle_up;
 	idle_ticks = total_idle_ticks -
 		this_dbs_info->prev_cpu_idle_down;
 	this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
@@ -417,11 +408,7 @@ static void dbs_check_cpu(int cpu)
 
 		j_dbs_info = &per_cpu(cpu_dbs_info, j);
 		/* Check for frequency increase */
-		total_idle_ticks = kstat_cpu(j).cpustat.idle +
-			kstat_cpu(j).cpustat.iowait;
-		  /* consider 'nice' too? */
-		  if (dbs_tuners_ins.ignore_nice == 0)
-			total_idle_ticks += kstat_cpu(j).cpustat.nice;
+		total_idle_ticks = j_dbs_info->prev_cpu_idle_up;
 		tmp_idle_ticks = total_idle_ticks -
 			j_dbs_info->prev_cpu_idle_down;
 		j_dbs_info->prev_cpu_idle_down = total_idle_ticks;
@@ -516,11 +503,7 @@ static int cpufreq_governor_dbs(struct c
 			j_dbs_info = &per_cpu(cpu_dbs_info, j);
 			j_dbs_info->cur_policy = policy;
 		
-			j_dbs_info->prev_cpu_idle_up = 
-				kstat_cpu(j).cpustat.idle +
-				kstat_cpu(j).cpustat.iowait +
-				( !dbs_tuners_ins.ignore_nice
-				  ? kstat_cpu(j).cpustat.nice : 0 );
+			j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j);
 			j_dbs_info->prev_cpu_idle_down
 				= j_dbs_info->prev_cpu_idle_up;
 		}
drivers/cpufreq/cpufreq_ondemand.c +20 -38

123 lines not on this page · raw message