aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq_conservative.c
diff options
context:
space:
mode:
authorThomas Renninger <trenn@suse.de>2009-02-04 05:55:12 -0500
committerDave Jones <davej@redhat.com>2009-02-24 22:47:31 -0500
commit112124ab0a9f507a0d7fdbb1e1ed2b9a24f8c4ea (patch)
tree15512b608d8f8f58817c1053d22a39d8f45e8b6d /drivers/cpufreq/cpufreq_conservative.c
parent9411b4ef7fcb534fe1582fe02738254e398dd931 (diff)
[CPUFREQ] ondemand/conservative: sanitize sampling_rate restrictions
Limit sampling rate to transition_latency * 100 or kernel limits. If sampling_rate is tried to be set too low, set the lowest allowed value. Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Dave Jones <davej@redhat.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq_conservative.c')
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 0912d7ca8cd7..8d541c69aec6 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -54,8 +54,20 @@ static unsigned int def_sampling_rate;
54 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) 54 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
55#define MIN_SAMPLING_RATE \ 55#define MIN_SAMPLING_RATE \
56 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) 56 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
57/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon
58 * Define the minimal settable sampling rate to the greater of:
59 * - "HW transition latency" * 100 (same as default sampling / 10)
60 * - MIN_STAT_SAMPLING_RATE
61 * To avoid that userspace shoots itself.
62*/
63static unsigned int minimum_sampling_rate(void)
64{
65 return max(def_sampling_rate / 10, MIN_STAT_SAMPLING_RATE);
66}
67
68/* This will also vanish soon with removing sampling_rate_max */
57#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 69#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
58#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 70#define LATENCY_MULTIPLIER (1000)
59#define DEF_SAMPLING_DOWN_FACTOR (1) 71#define DEF_SAMPLING_DOWN_FACTOR (1)
60#define MAX_SAMPLING_DOWN_FACTOR (10) 72#define MAX_SAMPLING_DOWN_FACTOR (10)
61#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) 73#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
@@ -208,13 +220,11 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
208 ret = sscanf(buf, "%u", &input); 220 ret = sscanf(buf, "%u", &input);
209 221
210 mutex_lock(&dbs_mutex); 222 mutex_lock(&dbs_mutex);
211 if (ret != 1 || input > MAX_SAMPLING_RATE || 223 if (ret != 1) {
212 input < MIN_SAMPLING_RATE) {
213 mutex_unlock(&dbs_mutex); 224 mutex_unlock(&dbs_mutex);
214 return -EINVAL; 225 return -EINVAL;
215 } 226 }
216 227 dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate());
217 dbs_tuners_ins.sampling_rate = input;
218 mutex_unlock(&dbs_mutex); 228 mutex_unlock(&dbs_mutex);
219 229
220 return count; 230 return count;
@@ -540,11 +550,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
540 if (latency == 0) 550 if (latency == 0)
541 latency = 1; 551 latency = 1;
542 552
543 def_sampling_rate = 10 * latency * 553 def_sampling_rate =
544 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 554 max(10 * latency * LATENCY_MULTIPLIER,
545 555 MIN_STAT_SAMPLING_RATE);
546 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
547 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
548 556
549 dbs_tuners_ins.sampling_rate = def_sampling_rate; 557 dbs_tuners_ins.sampling_rate = def_sampling_rate;
550 558