aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
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
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')
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c28
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c28
2 files changed, 36 insertions, 20 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
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 32ddeaa42244..338f428a15b7 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -52,8 +52,20 @@ static unsigned int def_sampling_rate;
52 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) 52 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
53#define MIN_SAMPLING_RATE \ 53#define MIN_SAMPLING_RATE \
54 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) 54 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
55/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon
56 * Define the minimal settable sampling rate to the greater of:
57 * - "HW transition latency" * 100 (same as default sampling / 10)
58 * - MIN_STAT_SAMPLING_RATE
59 * To avoid that userspace shoots itself.
60*/
61static unsigned int minimum_sampling_rate(void)
62{
63 return max(def_sampling_rate / 10, MIN_STAT_SAMPLING_RATE);
64}
65
66/* This will also vanish soon with removing sampling_rate_max */
55#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 67#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
56#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 68#define LATENCY_MULTIPLIER (1000)
57#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) 69#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
58 70
59static void do_dbs_timer(struct work_struct *work); 71static void do_dbs_timer(struct work_struct *work);
@@ -255,13 +267,11 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
255 ret = sscanf(buf, "%u", &input); 267 ret = sscanf(buf, "%u", &input);
256 268
257 mutex_lock(&dbs_mutex); 269 mutex_lock(&dbs_mutex);
258 if (ret != 1 || input > MAX_SAMPLING_RATE 270 if (ret != 1) {
259 || input < MIN_SAMPLING_RATE) {
260 mutex_unlock(&dbs_mutex); 271 mutex_unlock(&dbs_mutex);
261 return -EINVAL; 272 return -EINVAL;
262 } 273 }
263 274 dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate());
264 dbs_tuners_ins.sampling_rate = input;
265 mutex_unlock(&dbs_mutex); 275 mutex_unlock(&dbs_mutex);
266 276
267 return count; 277 return count;
@@ -607,11 +617,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
607 if (latency == 0) 617 if (latency == 0)
608 latency = 1; 618 latency = 1;
609 619
610 def_sampling_rate = latency * 620 def_sampling_rate =
611 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 621 max(latency * LATENCY_MULTIPLIER,
612 622 MIN_STAT_SAMPLING_RATE);
613 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
614 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
615 623
616 dbs_tuners_ins.sampling_rate = def_sampling_rate; 624 dbs_tuners_ins.sampling_rate = def_sampling_rate;
617 } 625 }