diff options
author | Thomas Renninger <trenn@suse.de> | 2009-02-04 05:55:12 -0500 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2009-02-24 22:47:31 -0500 |
commit | 112124ab0a9f507a0d7fdbb1e1ed2b9a24f8c4ea (patch) | |
tree | 15512b608d8f8f58817c1053d22a39d8f45e8b6d /drivers/cpufreq/cpufreq_ondemand.c | |
parent | 9411b4ef7fcb534fe1582fe02738254e398dd931 (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_ondemand.c')
-rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 28 |
1 files changed, 18 insertions, 10 deletions
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 | */ | ||
61 | static 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 | ||
59 | static void do_dbs_timer(struct work_struct *work); | 71 | static 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 | } |