All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] return error when failing to set minfreq
@ 2006-07-05 21:12 Mattia Dongili
  2006-07-05 21:21 ` Dave Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Mattia Dongili @ 2006-07-05 21:12 UTC (permalink / raw)
  To: CPUFreq Mailing List; +Cc: davej, Dominik Brodowski

[-- Attachment #1: Type: text/plain, Size: 499 bytes --]

Hello,

I'm resending this patch that probably has been lost in deep space.
It got the signed-off by Dominik before:
http://lists.linux.org.uk/mailman/private/cpufreq/2006-June/005916.html
The same message contains a detailed explanation of the problem it
fixes.
Rediffed against 2.6.17-mm6.

Description:
return -EINVAL if trying to increase frequencies starting from
scaling_min_freq and documents the correct ordering of writes.

Signed-off-by: Mattia Dongili <malattia@linux.it>
-- 
mattia
:wq!

[-- Attachment #2: cpufreq_error_when_increasing_minfreq_before_maxfreq.diff --]
[-- Type: text/plain, Size: 1263 bytes --]

diff --git a/Documentation/cpu-freq/user-guide.txt b/Documentation/cpu-freq/user-guide.txt
index 7fedc00..555c8cf 100644
--- a/Documentation/cpu-freq/user-guide.txt
+++ b/Documentation/cpu-freq/user-guide.txt
@@ -153,10 +153,13 @@ scaling_governor,		and by "echoing" the 
 				that some governors won't load - they only
 				work on some specific architectures or
 				processors.
-scaling_min_freq and 
+scaling_min_freq and
 scaling_max_freq		show the current "policy limits" (in
 				kHz). By echoing new values into these
 				files, you can change these limits.
+				NOTE: when setting a policy you need to
+				first set scaling_max_freq, then
+				scaling_min_freq.
 
 
 If you have selected the "userspace" governor which allows you to
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 1ba4039..deea3e0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1348,6 +1348,11 @@ static int __cpufreq_set_policy(struct c
 
 	memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo));
 
+	if (policy->min > data->min && policy->min > policy->max) {
+		ret = -EINVAL;
+		goto error_out;
+	}
+
 	/* verify the cpu speed can be set within this limit */
 	ret = cpufreq_driver->verify(policy);
 	if (ret)

[-- Attachment #3: Type: text/plain, Size: 147 bytes --]

_______________________________________________
Cpufreq mailing list
Cpufreq@lists.linux.org.uk
http://lists.linux.org.uk/mailman/listinfo/cpufreq

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] return error when failing to set minfreq
@ 2006-05-25 22:34 Mattia Dongili
  2006-06-05 18:31 ` Mattia Dongili
  0 siblings, 1 reply; 5+ messages in thread
From: Mattia Dongili @ 2006-05-25 22:34 UTC (permalink / raw)
  To: CPUFreq Mailing List

[-- Attachment #1: Type: text/plain, Size: 1362 bytes --]

Hello,
I just stumbled on this bug/feature, this is how to reproduce it:

# echo 450000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
# echo 450000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
# echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# cpufreq-info -p
450000 450000 powersave
# echo 1800000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq ; echo $?
0
# cpufreq-info -p             
450000 450000 powersave

Here it is. The kernel refuses to set a min_freq higher than the
max_freq but it allows a max_freq lower than min_freq (lowering min_freq
also).

I'm unsure if things could be improved here.  The offending instruction
is in cpufreq_verify_within_limits (cpufreq.h:241):

	if (policy->min > policy->max)
                policy->min = policy->max;

This behaviour is pretty straightforward (but undocumented) and it
doesn't return an error altough failing to accomplish the requested
action (set min_freq).
The problem (IMO) is basically that userspace is not allowed to set a
full policy atomically while the kernel always does that thus it must
enforce an ordering on operations.

The attached patch returns -EINVAL if trying to increase frequencies
starting from scaling_min_freq and documents the correct ordering of
writes.

Signed-off-by: Mattia Dongili <malattia@linux.it>
-- 
mattia
:wq!

[-- Attachment #2: cpufreq_error_when_increasing_minfreq_before_maxfreq.diff --]
[-- Type: text/plain, Size: 1263 bytes --]

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 29b2fa5..a78967f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1349,6 +1349,11 @@ static int __cpufreq_set_policy(struct c
 
 	memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo));
 
+	if (policy->min > data->min && policy->min > policy->max) {
+		ret = -EINVAL;
+		goto error_out;
+	}
+
 	/* verify the cpu speed can be set within this limit */
 	ret = cpufreq_driver->verify(policy);
 	if (ret)
diff --git a/Documentation/cpu-freq/user-guide.txt b/Documentation/cpu-freq/user-guide.txt
index 7fedc00..555c8cf 100644
--- a/Documentation/cpu-freq/user-guide.txt
+++ b/Documentation/cpu-freq/user-guide.txt
@@ -153,10 +153,13 @@ scaling_governor,		and by "echoing" the 
 				that some governors won't load - they only
 				work on some specific architectures or
 				processors.
-scaling_min_freq and 
+scaling_min_freq and
 scaling_max_freq		show the current "policy limits" (in
 				kHz). By echoing new values into these
 				files, you can change these limits.
+				NOTE: when setting a policy you need to
+				first set scaling_max_freq, then
+				scaling_min_freq.
 
 
 If you have selected the "userspace" governor which allows you to

[-- Attachment #3: Type: text/plain, Size: 147 bytes --]

_______________________________________________
Cpufreq mailing list
Cpufreq@lists.linux.org.uk
http://lists.linux.org.uk/mailman/listinfo/cpufreq

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-07-05 21:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-05 21:12 [PATCH] return error when failing to set minfreq Mattia Dongili
2006-07-05 21:21 ` Dave Jones
  -- strict thread matches above, loose matches on Subject: below --
2006-05-25 22:34 Mattia Dongili
2006-06-05 18:31 ` Mattia Dongili
2006-06-06  8:32   ` Dominik Brodowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.