diff options
-rw-r--r-- | Documentation/cpu-freq/governors.txt | 14 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_conservative.c | 28 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 28 |
3 files changed, 49 insertions, 21 deletions
diff --git a/Documentation/cpu-freq/governors.txt b/Documentation/cpu-freq/governors.txt index 9b1851297d4e..ce73f3eb5ddb 100644 --- a/Documentation/cpu-freq/governors.txt +++ b/Documentation/cpu-freq/governors.txt | |||
@@ -117,7 +117,19 @@ accessible parameters: | |||
117 | sampling_rate: measured in uS (10^-6 seconds), this is how often you | 117 | sampling_rate: measured in uS (10^-6 seconds), this is how often you |
118 | want the kernel to look at the CPU usage and to make decisions on | 118 | want the kernel to look at the CPU usage and to make decisions on |
119 | what to do about the frequency. Typically this is set to values of | 119 | what to do about the frequency. Typically this is set to values of |
120 | around '10000' or more. | 120 | around '10000' or more. It's default value is (cmp. with users-guide.txt): |
121 | transition_latency * 1000 | ||
122 | The lowest value you can set is: | ||
123 | transition_latency * 100 or it may get restricted to a value where it | ||
124 | makes not sense for the kernel anymore to poll that often which depends | ||
125 | on your HZ config variable (HZ=1000: max=20000us, HZ=250: max=5000). | ||
126 | Be aware that transition latency is in ns and sampling_rate is in us, so you | ||
127 | get the same sysfs value by default. | ||
128 | Sampling rate should always get adjusted considering the transition latency | ||
129 | To set the sampling rate 750 times as high as the transition latency | ||
130 | in the bash (as said, 1000 is default), do: | ||
131 | echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) \ | ||
132 | >ondemand/sampling_rate | ||
121 | 133 | ||
122 | show_sampling_rate_(min|max): THIS INTERFACE IS DEPRECATED, DON'T USE IT. | 134 | show_sampling_rate_(min|max): THIS INTERFACE IS DEPRECATED, DON'T USE IT. |
123 | You can use wider ranges now and the general | 135 | You can use wider ranges now and the general |
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 | */ | ||
63 | static 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 | */ | ||
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 | } |