Commit 5b0c0b16d48d20e26859907df4dd449e3b3c7f4c
Committed by
Rafael J. Wysocki
1 parent
22d0628a22
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
cpufreq: Introduce new relation for freq selection
Introduce CPUFREQ_RELATION_C for frequency selection. It selects the frequency with the minimum euclidean distance to target. In case of equal distance between 2 frequencies, it will select the greater frequency. Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Showing 2 changed files with 12 additions and 1 deletions Side-by-side Diff
drivers/cpufreq/freq_table.c
... | ... | @@ -117,7 +117,7 @@ |
117 | 117 | .frequency = 0, |
118 | 118 | }; |
119 | 119 | struct cpufreq_frequency_table *pos; |
120 | - unsigned int freq, i = 0; | |
120 | + unsigned int freq, diff, i = 0; | |
121 | 121 | |
122 | 122 | pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", |
123 | 123 | target_freq, relation, policy->cpu); |
... | ... | @@ -127,6 +127,7 @@ |
127 | 127 | suboptimal.frequency = ~0; |
128 | 128 | break; |
129 | 129 | case CPUFREQ_RELATION_L: |
130 | + case CPUFREQ_RELATION_C: | |
130 | 131 | optimal.frequency = ~0; |
131 | 132 | break; |
132 | 133 | } |
... | ... | @@ -166,6 +167,15 @@ |
166 | 167 | suboptimal.frequency = freq; |
167 | 168 | suboptimal.driver_data = i; |
168 | 169 | } |
170 | + } | |
171 | + break; | |
172 | + case CPUFREQ_RELATION_C: | |
173 | + diff = abs(freq - target_freq); | |
174 | + if (diff < optimal.frequency || | |
175 | + (diff == optimal.frequency && | |
176 | + freq > table[optimal.driver_data].frequency)) { | |
177 | + optimal.frequency = diff; | |
178 | + optimal.driver_data = i; | |
169 | 179 | } |
170 | 180 | break; |
171 | 181 | } |
include/linux/cpufreq.h
... | ... | @@ -176,6 +176,7 @@ |
176 | 176 | |
177 | 177 | #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */ |
178 | 178 | #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */ |
179 | +#define CPUFREQ_RELATION_C 2 /* closest frequency to target */ | |
179 | 180 | |
180 | 181 | struct freq_attr { |
181 | 182 | struct attribute attr; |