]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Thomas Renninger <trenn@suse.de> |
2 | Subject: CPUFREQ: ondemand/conservative: sanitize sampling_rate restrictions | |
3 | References: bnc#464461 | |
4 | Patch-Mainline: not yet | |
5 | ||
6 | Limit sampling rate to transition_latency * 100 or kernel limits. | |
7 | If sampling_rate is tried to be set too low, set the lowest allowed value. | |
8 | ||
9 | Signed-off-by: Thomas Renninger <trenn@suse.de> | |
10 | ||
11 | --- | |
12 | Documentation/cpu-freq/governors.txt | 14 +++++++++++++- | |
13 | drivers/cpufreq/cpufreq_conservative.c | 19 ++++++++++++++++--- | |
14 | drivers/cpufreq/cpufreq_ondemand.c | 19 +++++++++++++++---- | |
15 | 3 files changed, 44 insertions(+), 8 deletions(-) | |
16 | ||
17 | Index: linux-2.6.27/Documentation/cpu-freq/governors.txt | |
18 | =================================================================== | |
19 | --- linux-2.6.27.orig/Documentation/cpu-freq/governors.txt | |
20 | +++ linux-2.6.27/Documentation/cpu-freq/governors.txt | |
21 | @@ -117,7 +117,19 @@ accessible parameters: | |
22 | sampling_rate: measured in uS (10^-6 seconds), this is how often you | |
23 | want the kernel to look at the CPU usage and to make decisions on | |
24 | what to do about the frequency. Typically this is set to values of | |
25 | -around '10000' or more. | |
26 | +around '10000' or more. It's default value is (cmp. with users-guide.txt): | |
27 | +transition_latency * 1000 | |
28 | +The lowest value you can set is: | |
29 | +transition_latency * 100 or it may get restricted to a value where it | |
30 | +makes not sense for the kernel anymore to poll that often which depends | |
31 | +on your HZ config variable (HZ=1000: max=20000us, HZ=250: max=5000). | |
32 | +Be aware that transition latency is in ns and sampling_rate is in us, so you | |
33 | +get the same sysfs value by default. | |
34 | +Sampling rate should always get adjusted considering the transition latency | |
35 | +To set the sampling rate 750 times as high as the transition latency | |
36 | +in the bash (as said, 1000 is default), do: | |
37 | +echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) \ | |
38 | + >ondemand/sampling_rate | |
39 | ||
40 | show_sampling_rate_(min|max): the minimum and maximum sampling rates | |
41 | available that you may set 'sampling_rate' to. | |
42 | Index: linux-2.6.27/drivers/cpufreq/cpufreq_conservative.c | |
43 | =================================================================== | |
44 | --- linux-2.6.27.orig/drivers/cpufreq/cpufreq_conservative.c | |
45 | +++ linux-2.6.27/drivers/cpufreq/cpufreq_conservative.c | |
46 | @@ -54,7 +54,18 @@ static unsigned int def_sampling_rate; | |
47 | (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) | |
48 | #define MIN_SAMPLING_RATE \ | |
49 | (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) | |
50 | +/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon | |
51 | + * Define the minimal settable sampling rate to the greater of: | |
52 | + * - "HW transition latency" * 100 (same as default sampling / 10) | |
53 | + * - MIN_STAT_SAMPLING_RATE | |
54 | + * To avoid that userspace shoots itself. | |
55 | +*/ | |
56 | +#define MINIMUM_SAMPLING_RATE \ | |
57 | + ((def_sampling_rate / 10) < MIN_STAT_SAMPLING_RATE \ | |
58 | + ? MIN_STAT_SAMPLING_RATE : (def_sampling_rate / 10)) | |
59 | +/* This will also vanish soon with removing sampling_rate_max */ | |
60 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | |
61 | + | |
62 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) | |
63 | #define DEF_SAMPLING_DOWN_FACTOR (1) | |
64 | #define MAX_SAMPLING_DOWN_FACTOR (10) | |
65 | @@ -193,12 +204,14 @@ static ssize_t store_sampling_rate(struc | |
66 | ret = sscanf (buf, "%u", &input); | |
67 | ||
68 | mutex_lock(&dbs_mutex); | |
69 | - if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) { | |
70 | + if (ret != 1) { | |
71 | mutex_unlock(&dbs_mutex); | |
72 | return -EINVAL; | |
73 | } | |
74 | - | |
75 | - dbs_tuners_ins.sampling_rate = input; | |
76 | + if (input < MINIMUM_SAMPLING_RATE) | |
77 | + dbs_tuners_ins.sampling_rate = MINIMUM_SAMPLING_RATE; | |
78 | + else | |
79 | + dbs_tuners_ins.sampling_rate = input; | |
80 | mutex_unlock(&dbs_mutex); | |
81 | ||
82 | return count; | |
83 | Index: linux-2.6.27/drivers/cpufreq/cpufreq_ondemand.c | |
84 | =================================================================== | |
85 | --- linux-2.6.27.orig/drivers/cpufreq/cpufreq_ondemand.c | |
86 | +++ linux-2.6.27/drivers/cpufreq/cpufreq_ondemand.c | |
87 | @@ -45,6 +45,16 @@ static unsigned int def_sampling_rate; | |
88 | (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) | |
89 | #define MIN_SAMPLING_RATE \ | |
90 | (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) | |
91 | +/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon | |
92 | + * Define the minimal settable sampling rate to the greater of: | |
93 | + * - "HW transition latency" * 100 (same as default sampling / 10) | |
94 | + * - MIN_STAT_SAMPLING_RATE | |
95 | + * To avoid that userspace shoots itself. | |
96 | +*/ | |
97 | +#define MINIMUM_SAMPLING_RATE \ | |
98 | + ((def_sampling_rate / 10) < MIN_STAT_SAMPLING_RATE \ | |
99 | + ? MIN_STAT_SAMPLING_RATE : (def_sampling_rate / 10)) | |
100 | +/* This will also vanish soon with removing sampling_rate_max */ | |
101 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | |
102 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) | |
103 | #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) | |
104 | @@ -219,13 +229,14 @@ static ssize_t store_sampling_rate(struc | |
105 | ret = sscanf(buf, "%u", &input); | |
106 | ||
107 | mutex_lock(&dbs_mutex); | |
108 | - if (ret != 1 || input > MAX_SAMPLING_RATE | |
109 | - || input < MIN_SAMPLING_RATE) { | |
110 | + if (ret != 1) { | |
111 | mutex_unlock(&dbs_mutex); | |
112 | return -EINVAL; | |
113 | } | |
114 | - | |
115 | - dbs_tuners_ins.sampling_rate = input; | |
116 | + if (input < MINIMUM_SAMPLING_RATE) | |
117 | + dbs_tuners_ins.sampling_rate = MINIMUM_SAMPLING_RATE; | |
118 | + else | |
119 | + dbs_tuners_ins.sampling_rate = input; | |
120 | mutex_unlock(&dbs_mutex); | |
121 | ||
122 | return count; |