Blame view
drivers/cpufreq/cpufreq_governor.c
16.4 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
2aacdfff9 cpufreq: Move com... |
2 3 4 5 6 |
/* * drivers/cpufreq/cpufreq_governor.c * * CPUFREQ governors common code * |
4471a34f9 cpufreq: governor... |
7 8 9 10 11 |
* Copyright (C) 2001 Russell King * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. * (C) 2003 Jun Nakajima <jun.nakajima@intel.com> * (C) 2009 Alexander Clouter <alex@digriz.org.uk> * (c) 2012 Viresh Kumar <viresh.kumar@linaro.org> |
2aacdfff9 cpufreq: Move com... |
12 |
*/ |
4471a34f9 cpufreq: governor... |
13 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
2aacdfff9 cpufreq: Move com... |
14 15 |
#include <linux/export.h> #include <linux/kernel_stat.h> |
4d5dcc421 cpufreq: governor... |
16 |
#include <linux/slab.h> |
4471a34f9 cpufreq: governor... |
17 18 |
#include "cpufreq_governor.h" |
56026645e cpufreq: governor... |
19 |
#define CPUFREQ_DBS_MIN_SAMPLING_INTERVAL (2 * TICK_NSEC / NSEC_PER_USEC) |
8c8f77fd0 cpufreq: governor... |
20 |
static DEFINE_PER_CPU(struct cpu_dbs_info, cpu_dbs); |
1112e9d83 cpufreq: governor... |
21 |
static DEFINE_MUTEX(gov_dbs_data_mutex); |
2bb8d94fb cpufreq: governor... |
22 |
|
aded387b9 cpufreq: conserva... |
23 24 25 26 27 28 29 30 31 32 33 34 35 |
/* Common sysfs tunables */ /** * store_sampling_rate - update sampling rate effective immediately if needed. * * If new rate is smaller than the old, simply updating * dbs.sampling_rate might not be appropriate. For example, if the * original sampling_rate was 1 second and the requested new sampling rate is 10 * ms because the user needs immediate reaction from ondemand governor, but not * sure if higher frequency will be required or not, then, the governor may * change the sampling rate too late; up to 1 second later. Thus, if we are * reducing the sampling rate, we need to make the new value effective * immediately. * |
aded387b9 cpufreq: conserva... |
36 37 38 |
* This must be called with dbs_data->mutex held, otherwise traversing * policy_dbs_list isn't safe. */ |
0dd3c1d67 cpufreq: governor... |
39 |
ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf, |
aded387b9 cpufreq: conserva... |
40 41 |
size_t count) { |
0dd3c1d67 cpufreq: governor... |
42 |
struct dbs_data *dbs_data = to_dbs_data(attr_set); |
aded387b9 cpufreq: conserva... |
43 |
struct policy_dbs_info *policy_dbs; |
56026645e cpufreq: governor... |
44 |
unsigned int sampling_interval; |
aded387b9 cpufreq: conserva... |
45 |
int ret; |
56026645e cpufreq: governor... |
46 47 48 |
ret = sscanf(buf, "%u", &sampling_interval); if (ret != 1 || sampling_interval < CPUFREQ_DBS_MIN_SAMPLING_INTERVAL) |
aded387b9 cpufreq: conserva... |
49 |
return -EINVAL; |
56026645e cpufreq: governor... |
50 |
dbs_data->sampling_rate = sampling_interval; |
aded387b9 cpufreq: conserva... |
51 52 53 54 |
/* * We are operating under dbs_data->mutex and so the list and its * entries can't be freed concurrently. */ |
0dd3c1d67 cpufreq: governor... |
55 |
list_for_each_entry(policy_dbs, &attr_set->policy_list, list) { |
26f0dbc9a cpufreq: governor... |
56 |
mutex_lock(&policy_dbs->update_mutex); |
aded387b9 cpufreq: conserva... |
57 58 59 60 61 62 |
/* * On 32-bit architectures this may race with the * sample_delay_ns read in dbs_update_util_handler(), but that * really doesn't matter. If the read returns a value that's * too big, the sample will be skipped, but the next invocation * of dbs_update_util_handler() (when the update has been |
78347cdb8 cpufreq: governor... |
63 |
* completed) will take a sample. |
aded387b9 cpufreq: conserva... |
64 65 66 |
* * If this runs in parallel with dbs_work_handler(), we may end * up overwriting the sample_delay_ns value that it has just |
78347cdb8 cpufreq: governor... |
67 68 |
* written, but it will be corrected next time a sample is * taken, so it shouldn't be significant. |
aded387b9 cpufreq: conserva... |
69 |
*/ |
78347cdb8 cpufreq: governor... |
70 |
gov_update_sample_delay(policy_dbs, 0); |
26f0dbc9a cpufreq: governor... |
71 |
mutex_unlock(&policy_dbs->update_mutex); |
aded387b9 cpufreq: conserva... |
72 73 74 75 76 |
} return count; } EXPORT_SYMBOL_GPL(store_sampling_rate); |
a33cce1c6 cpufreq: governor... |
77 78 |
/** * gov_update_cpu_data - Update CPU load data. |
a33cce1c6 cpufreq: governor... |
79 80 81 82 83 84 85 86 |
* @dbs_data: Top-level governor data pointer. * * Update CPU load data for all CPUs in the domain governed by @dbs_data * (that may be a single policy or a bunch of them if governor tunables are * system-wide). * * Call under the @dbs_data mutex. */ |
8c8f77fd0 cpufreq: governor... |
87 |
void gov_update_cpu_data(struct dbs_data *dbs_data) |
a33cce1c6 cpufreq: governor... |
88 89 |
{ struct policy_dbs_info *policy_dbs; |
0dd3c1d67 cpufreq: governor... |
90 |
list_for_each_entry(policy_dbs, &dbs_data->attr_set.policy_list, list) { |
a33cce1c6 cpufreq: governor... |
91 92 93 |
unsigned int j; for_each_cpu(j, policy_dbs->policy->cpus) { |
8c8f77fd0 cpufreq: governor... |
94 |
struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); |
a33cce1c6 cpufreq: governor... |
95 |
|
b4f4b4b37 cpufreq: governor... |
96 |
j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time, |
a33cce1c6 cpufreq: governor... |
97 98 99 100 101 102 103 |
dbs_data->io_is_busy); if (dbs_data->ignore_nice_load) j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; } } } EXPORT_SYMBOL_GPL(gov_update_cpu_data); |
4cccf7555 cpufreq: governor... |
104 |
unsigned int dbs_update(struct cpufreq_policy *policy) |
4471a34f9 cpufreq: governor... |
105 |
{ |
bc505475b cpufreq: governor... |
106 107 |
struct policy_dbs_info *policy_dbs = policy->governor_data; struct dbs_data *dbs_data = policy_dbs->dbs_data; |
ff4b17895 cpufreq: governor... |
108 |
unsigned int ignore_nice = dbs_data->ignore_nice_load; |
00bfe0588 cpufreq: conserva... |
109 |
unsigned int max_load = 0, idle_periods = UINT_MAX; |
8847e038c cpufreq: governor... |
110 |
unsigned int sampling_rate, io_busy, j; |
4471a34f9 cpufreq: governor... |
111 |
|
57dc3bcd4 cpufreq: governor... |
112 113 114 115 116 117 118 |
/* * Sometimes governors may use an additional multiplier to increase * sample delays temporarily. Apply that multiplier to sampling_rate * so as to keep the wake-up-from-idle detection logic a bit * conservative. */ sampling_rate = dbs_data->sampling_rate * policy_dbs->rate_mult; |
8847e038c cpufreq: governor... |
119 120 121 122 123 124 |
/* * For the purpose of ondemand, waiting for disk IO is an indication * that you're performance critical, and not that the system is actually * idle, so do not add the iowait time to the CPU idle time then. */ io_busy = dbs_data->io_is_busy; |
4471a34f9 cpufreq: governor... |
125 |
|
dfa5bb622 cpufreq: ondemand... |
126 |
/* Get Absolute Load */ |
4471a34f9 cpufreq: governor... |
127 |
for_each_cpu(j, policy->cpus) { |
8c8f77fd0 cpufreq: governor... |
128 |
struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); |
b4f4b4b37 cpufreq: governor... |
129 130 |
u64 update_time, cur_idle_time; unsigned int idle_time, time_elapsed; |
4471a34f9 cpufreq: governor... |
131 |
unsigned int load; |
b4f4b4b37 cpufreq: governor... |
132 |
cur_idle_time = get_cpu_idle_time(j, &update_time, io_busy); |
4471a34f9 cpufreq: governor... |
133 |
|
b4f4b4b37 cpufreq: governor... |
134 135 |
time_elapsed = update_time - j_cdbs->prev_update_time; j_cdbs->prev_update_time = update_time; |
4471a34f9 cpufreq: governor... |
136 |
|
94862a62d Revert "cpufreq: ... |
137 138 |
idle_time = cur_idle_time - j_cdbs->prev_cpu_idle; j_cdbs->prev_cpu_idle = cur_idle_time; |
4471a34f9 cpufreq: governor... |
139 140 |
if (ignore_nice) { |
679b8fe43 cpufreq: governor... |
141 |
u64 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
7fb1327ee sched/cputime: Co... |
142 |
idle_time += div_u64(cur_nice - j_cdbs->prev_cpu_nice, NSEC_PER_USEC); |
679b8fe43 cpufreq: governor... |
143 |
j_cdbs->prev_cpu_nice = cur_nice; |
4471a34f9 cpufreq: governor... |
144 |
} |
9485e4ca0 cpufreq: governor... |
145 146 147 148 149 150 |
if (unlikely(!time_elapsed)) { /* * That can only happen when this function is called * twice in a row with a very short interval between the * calls, so the previous load value can be used then. */ |
18b46abd0 cpufreq: governor... |
151 |
load = j_cdbs->prev_load; |
759201963 cpufreq: governor... |
152 |
} else if (unlikely((int)idle_time > 2 * sampling_rate && |
9485e4ca0 cpufreq: governor... |
153 |
j_cdbs->prev_load)) { |
c8ae481b9 cpufreq: governor... |
154 |
/* |
9485e4ca0 cpufreq: governor... |
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
* If the CPU had gone completely idle and a task has * just woken up on this CPU now, it would be unfair to * calculate 'load' the usual way for this elapsed * time-window, because it would show near-zero load, * irrespective of how CPU intensive that task actually * was. This is undesirable for latency-sensitive bursty * workloads. * * To avoid this, reuse the 'load' from the previous * time-window and give this task a chance to start with * a reasonably high CPU frequency. However, that * shouldn't be over-done, lest we get stuck at a high * load (high frequency) for too long, even when the * current system load has actually dropped down, so * clear prev_load to guarantee that the load will be * computed again next time. * |
759201963 cpufreq: governor... |
172 173 |
* Detecting this situation is easy: an unusually large * 'idle_time' (as compared to the sampling rate) |
9485e4ca0 cpufreq: governor... |
174 |
* indicates this scenario. |
c8ae481b9 cpufreq: governor... |
175 |
*/ |
9485e4ca0 cpufreq: governor... |
176 |
load = j_cdbs->prev_load; |
c8ae481b9 cpufreq: governor... |
177 |
j_cdbs->prev_load = 0; |
18b46abd0 cpufreq: governor... |
178 |
} else { |
9485e4ca0 cpufreq: governor... |
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
if (time_elapsed >= idle_time) { load = 100 * (time_elapsed - idle_time) / time_elapsed; } else { /* * That can happen if idle_time is returned by * get_cpu_idle_time_jiffy(). In that case * idle_time is roughly equal to the difference * between time_elapsed and "busy time" obtained * from CPU statistics. Then, the "busy time" * can end up being greater than time_elapsed * (for example, if jiffies_64 and the CPU * statistics are updated by different CPUs), * so idle_time may in fact be negative. That * means, though, that the CPU was busy all * the time (on the rough average) during the * last sampling interval and 100 can be * returned as the load. */ load = (int)idle_time < 0 ? 100 : 0; } |
18b46abd0 cpufreq: governor... |
199 |
j_cdbs->prev_load = load; |
18b46abd0 cpufreq: governor... |
200 |
} |
4471a34f9 cpufreq: governor... |
201 |
|
759201963 cpufreq: governor... |
202 203 |
if (unlikely((int)idle_time > 2 * sampling_rate)) { unsigned int periods = idle_time / sampling_rate; |
00bfe0588 cpufreq: conserva... |
204 205 206 207 |
if (periods < idle_periods) idle_periods = periods; } |
4471a34f9 cpufreq: governor... |
208 209 210 |
if (load > max_load) max_load = load; } |
00bfe0588 cpufreq: conserva... |
211 212 |
policy_dbs->idle_periods = idle_periods; |
4cccf7555 cpufreq: governor... |
213 |
return max_load; |
4471a34f9 cpufreq: governor... |
214 |
} |
4cccf7555 cpufreq: governor... |
215 |
EXPORT_SYMBOL_GPL(dbs_update); |
4471a34f9 cpufreq: governor... |
216 |
|
70f43e5e7 cpufreq: governor... |
217 |
static void dbs_work_handler(struct work_struct *work) |
43e0ee361 cpufreq: governor... |
218 |
{ |
e40e7b255 cpufreq: governor... |
219 |
struct policy_dbs_info *policy_dbs; |
3a91b069e cpufreq: governor... |
220 |
struct cpufreq_policy *policy; |
ea59ee0dc cpufreq: governor... |
221 |
struct dbs_governor *gov; |
43e0ee361 cpufreq: governor... |
222 |
|
e40e7b255 cpufreq: governor... |
223 224 |
policy_dbs = container_of(work, struct policy_dbs_info, work); policy = policy_dbs->policy; |
ea59ee0dc cpufreq: governor... |
225 |
gov = dbs_governor_of(policy); |
3a91b069e cpufreq: governor... |
226 |
|
70f43e5e7 cpufreq: governor... |
227 |
/* |
9be4fd2c7 cpufreq: governor... |
228 229 |
* Make sure cpufreq_governor_limits() isn't evaluating load or the * ondemand governor isn't updating the sampling rate in parallel. |
70f43e5e7 cpufreq: governor... |
230 |
*/ |
26f0dbc9a cpufreq: governor... |
231 232 233 |
mutex_lock(&policy_dbs->update_mutex); gov_update_sample_delay(policy_dbs, gov->gov_dbs_update(policy)); mutex_unlock(&policy_dbs->update_mutex); |
70f43e5e7 cpufreq: governor... |
234 |
|
e4db2813d cpufreq: governor... |
235 236 |
/* Allow the utilization update handler to queue up more work. */ atomic_set(&policy_dbs->work_count, 0); |
9be4fd2c7 cpufreq: governor... |
237 |
/* |
e4db2813d cpufreq: governor... |
238 239 240 |
* If the update below is reordered with respect to the sample delay * modification, the utilization update handler may end up using a stale * sample delay value. |
9be4fd2c7 cpufreq: governor... |
241 |
*/ |
e4db2813d cpufreq: governor... |
242 243 |
smp_wmb(); policy_dbs->work_in_progress = false; |
9be4fd2c7 cpufreq: governor... |
244 245 246 247 |
} static void dbs_irq_work(struct irq_work *irq_work) { |
e40e7b255 cpufreq: governor... |
248 |
struct policy_dbs_info *policy_dbs; |
70f43e5e7 cpufreq: governor... |
249 |
|
e40e7b255 cpufreq: governor... |
250 |
policy_dbs = container_of(irq_work, struct policy_dbs_info, irq_work); |
539a4c424 cpufreq: governor... |
251 |
schedule_work_on(smp_processor_id(), &policy_dbs->work); |
70f43e5e7 cpufreq: governor... |
252 |
} |
9be4fd2c7 cpufreq: governor... |
253 |
static void dbs_update_util_handler(struct update_util_data *data, u64 time, |
58919e83c cpufreq / sched: ... |
254 |
unsigned int flags) |
9be4fd2c7 cpufreq: governor... |
255 256 |
{ struct cpu_dbs_info *cdbs = container_of(data, struct cpu_dbs_info, update_util); |
e40e7b255 cpufreq: governor... |
257 |
struct policy_dbs_info *policy_dbs = cdbs->policy_dbs; |
27de34823 cpufreq: governor... |
258 |
u64 delta_ns, lst; |
70f43e5e7 cpufreq: governor... |
259 |
|
036399782 cpufreq: Rename c... |
260 |
if (!cpufreq_this_cpu_can_update(policy_dbs->policy)) |
674e75411 sched: cpufreq: A... |
261 |
return; |
70f43e5e7 cpufreq: governor... |
262 |
/* |
9be4fd2c7 cpufreq: governor... |
263 264 265 |
* The work may not be allowed to be queued up right now. * Possible reasons: * - Work has already been queued up or is in progress. |
9be4fd2c7 cpufreq: governor... |
266 |
* - It is too early (too little time from the previous sample). |
70f43e5e7 cpufreq: governor... |
267 |
*/ |
e4db2813d cpufreq: governor... |
268 269 270 271 272 273 274 275 |
if (policy_dbs->work_in_progress) return; /* * If the reads below are reordered before the check above, the value * of sample_delay_ns used in the computation may be stale. */ smp_rmb(); |
27de34823 cpufreq: governor... |
276 277 |
lst = READ_ONCE(policy_dbs->last_sample_time); delta_ns = time - lst; |
e4db2813d cpufreq: governor... |
278 279 280 281 282 283 284 285 |
if ((s64)delta_ns < policy_dbs->sample_delay_ns) return; /* * If the policy is not shared, the irq_work may be queued up right away * at this point. Otherwise, we need to ensure that only one of the * CPUs sharing the policy will do that. */ |
27de34823 cpufreq: governor... |
286 287 288 289 290 291 292 293 294 295 296 297 298 |
if (policy_dbs->is_shared) { if (!atomic_add_unless(&policy_dbs->work_count, 1, 1)) return; /* * If another CPU updated last_sample_time in the meantime, we * shouldn't be here, so clear the work counter and bail out. */ if (unlikely(lst != READ_ONCE(policy_dbs->last_sample_time))) { atomic_set(&policy_dbs->work_count, 0); return; } } |
e4db2813d cpufreq: governor... |
299 300 301 302 |
policy_dbs->last_sample_time = time; policy_dbs->work_in_progress = true; irq_work_queue(&policy_dbs->irq_work); |
43e0ee361 cpufreq: governor... |
303 |
} |
4447266b8 cpufreq: governor... |
304 |
|
0bed612be cpufreq: sched: H... |
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
static void gov_set_update_util(struct policy_dbs_info *policy_dbs, unsigned int delay_us) { struct cpufreq_policy *policy = policy_dbs->policy; int cpu; gov_update_sample_delay(policy_dbs, delay_us); policy_dbs->last_sample_time = 0; for_each_cpu(cpu, policy->cpus) { struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu); cpufreq_add_update_util_hook(cpu, &cdbs->update_util, dbs_update_util_handler); } } static inline void gov_clear_update_util(struct cpufreq_policy *policy) { int i; for_each_cpu(i, policy->cpus) cpufreq_remove_update_util_hook(i); |
cc69b389f cpufreq/cpufreq_g... |
328 |
synchronize_rcu(); |
0bed612be cpufreq: sched: H... |
329 |
} |
bc505475b cpufreq: governor... |
330 331 |
static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy, struct dbs_governor *gov) |
44152cb82 cpufreq: governor... |
332 |
{ |
e40e7b255 cpufreq: governor... |
333 |
struct policy_dbs_info *policy_dbs; |
44152cb82 cpufreq: governor... |
334 |
int j; |
7d5a9956a cpufreq: governor... |
335 336 |
/* Allocate memory for per-policy governor data. */ policy_dbs = gov->alloc(); |
e40e7b255 cpufreq: governor... |
337 |
if (!policy_dbs) |
bc505475b cpufreq: governor... |
338 |
return NULL; |
44152cb82 cpufreq: governor... |
339 |
|
581c214b2 cpufreq: governor... |
340 |
policy_dbs->policy = policy; |
26f0dbc9a cpufreq: governor... |
341 |
mutex_init(&policy_dbs->update_mutex); |
686cc637c cpufreq: governor... |
342 |
atomic_set(&policy_dbs->work_count, 0); |
e40e7b255 cpufreq: governor... |
343 344 |
init_irq_work(&policy_dbs->irq_work, dbs_irq_work); INIT_WORK(&policy_dbs->work, dbs_work_handler); |
cea6a9e77 cpufreq: governor... |
345 346 347 |
/* Set policy_dbs for all CPUs, online+offline */ for_each_cpu(j, policy->related_cpus) { |
8c8f77fd0 cpufreq: governor... |
348 |
struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); |
cea6a9e77 cpufreq: governor... |
349 350 |
j_cdbs->policy_dbs = policy_dbs; |
cea6a9e77 cpufreq: governor... |
351 |
} |
bc505475b cpufreq: governor... |
352 |
return policy_dbs; |
44152cb82 cpufreq: governor... |
353 |
} |
8c8f77fd0 cpufreq: governor... |
354 |
static void free_policy_dbs_info(struct policy_dbs_info *policy_dbs, |
7bdad34d0 cpufreq: governor... |
355 |
struct dbs_governor *gov) |
44152cb82 cpufreq: governor... |
356 |
{ |
44152cb82 cpufreq: governor... |
357 |
int j; |
26f0dbc9a cpufreq: governor... |
358 |
mutex_destroy(&policy_dbs->update_mutex); |
5e4500d8d cpufreq: governor... |
359 |
|
8c8f77fd0 cpufreq: governor... |
360 361 |
for_each_cpu(j, policy_dbs->policy->related_cpus) { struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); |
44152cb82 cpufreq: governor... |
362 |
|
cea6a9e77 cpufreq: governor... |
363 364 365 |
j_cdbs->policy_dbs = NULL; j_cdbs->update_util.func = NULL; } |
7d5a9956a cpufreq: governor... |
366 |
gov->free(policy_dbs); |
44152cb82 cpufreq: governor... |
367 |
} |
e788892ba cpufreq: governor... |
368 |
int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) |
4471a34f9 cpufreq: governor... |
369 |
{ |
ea59ee0dc cpufreq: governor... |
370 |
struct dbs_governor *gov = dbs_governor_of(policy); |
1112e9d83 cpufreq: governor... |
371 |
struct dbs_data *dbs_data; |
bc505475b cpufreq: governor... |
372 |
struct policy_dbs_info *policy_dbs; |
1112e9d83 cpufreq: governor... |
373 |
int ret = 0; |
4471a34f9 cpufreq: governor... |
374 |
|
a72c49590 cpufreq: governor... |
375 376 377 |
/* State should be equivalent to EXIT */ if (policy->governor_data) return -EBUSY; |
bc505475b cpufreq: governor... |
378 379 380 |
policy_dbs = alloc_policy_dbs_info(policy, gov); if (!policy_dbs) return -ENOMEM; |
44152cb82 cpufreq: governor... |
381 |
|
1112e9d83 cpufreq: governor... |
382 383 384 385 |
/* Protect gov->gdbs_data against concurrent updates. */ mutex_lock(&gov_dbs_data_mutex); dbs_data = gov->gdbs_data; |
bc505475b cpufreq: governor... |
386 387 388 389 390 |
if (dbs_data) { if (WARN_ON(have_governor_per_policy())) { ret = -EINVAL; goto free_policy_dbs_info; } |
bc505475b cpufreq: governor... |
391 392 |
policy_dbs->dbs_data = dbs_data; policy->governor_data = policy_dbs; |
c54df0718 cpufreq: governor... |
393 |
|
0dd3c1d67 cpufreq: governor... |
394 |
gov_attr_set_get(&dbs_data->attr_set, &policy_dbs->list); |
1112e9d83 cpufreq: governor... |
395 |
goto out; |
714a2d9c8 cpufreq: governor... |
396 |
} |
4d5dcc421 cpufreq: governor... |
397 |
|
714a2d9c8 cpufreq: governor... |
398 |
dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL); |
bc505475b cpufreq: governor... |
399 400 401 402 |
if (!dbs_data) { ret = -ENOMEM; goto free_policy_dbs_info; } |
44152cb82 cpufreq: governor... |
403 |
|
0dd3c1d67 cpufreq: governor... |
404 |
gov_attr_set_init(&dbs_data->attr_set, &policy_dbs->list); |
4d5dcc421 cpufreq: governor... |
405 |
|
9a15fb2c7 cpufreq: Drop the... |
406 |
ret = gov->init(dbs_data); |
714a2d9c8 cpufreq: governor... |
407 |
if (ret) |
e40e7b255 cpufreq: governor... |
408 |
goto free_policy_dbs_info; |
4d5dcc421 cpufreq: governor... |
409 |
|
56026645e cpufreq: governor... |
410 411 412 413 414 415 416 417 |
/* * The sampling interval should not be less than the transition latency * of the CPU and it also cannot be too small for dbs_update() to work * correctly. */ dbs_data->sampling_rate = max_t(unsigned int, CPUFREQ_DBS_MIN_SAMPLING_INTERVAL, cpufreq_policy_transition_delay_us(policy)); |
2361be236 cpufreq: Don't cr... |
418 |
|
8eec1020f cpufreq: create c... |
419 |
if (!have_governor_per_policy()) |
7bdad34d0 cpufreq: governor... |
420 |
gov->gdbs_data = dbs_data; |
4d5dcc421 cpufreq: governor... |
421 |
|
c54df0718 cpufreq: governor... |
422 |
policy_dbs->dbs_data = dbs_data; |
0dd3c1d67 cpufreq: governor... |
423 |
policy->governor_data = policy_dbs; |
c54df0718 cpufreq: governor... |
424 |
|
c44356303 cpufreq: governor... |
425 |
gov->kobj_type.sysfs_ops = &governor_sysfs_ops; |
0dd3c1d67 cpufreq: governor... |
426 |
ret = kobject_init_and_add(&dbs_data->attr_set.kobj, &gov->kobj_type, |
c44356303 cpufreq: governor... |
427 428 |
get_governor_parent_kobj(policy), "%s", gov->gov.name); |
fafd5e8ab cpufreq: governor... |
429 |
if (!ret) |
1112e9d83 cpufreq: governor... |
430 |
goto out; |
4d5dcc421 cpufreq: governor... |
431 |
|
fafd5e8ab cpufreq: governor... |
432 |
/* Failure, so roll back. */ |
666f4ccc5 cpufreq: governor... |
433 434 |
pr_err("initialization failed (dbs_data kobject init error %d) ", ret); |
4d5dcc421 cpufreq: governor... |
435 |
|
4ebe36c94 cpufreq: Fix kobj... |
436 |
kobject_put(&dbs_data->attr_set.kobj); |
e4b133cc4 cpufreq: Fix NULL... |
437 |
policy->governor_data = NULL; |
8eec1020f cpufreq: create c... |
438 |
if (!have_governor_per_policy()) |
7bdad34d0 cpufreq: governor... |
439 |
gov->gdbs_data = NULL; |
9a15fb2c7 cpufreq: Drop the... |
440 |
gov->exit(dbs_data); |
bc505475b cpufreq: governor... |
441 |
kfree(dbs_data); |
e40e7b255 cpufreq: governor... |
442 |
free_policy_dbs_info: |
8c8f77fd0 cpufreq: governor... |
443 |
free_policy_dbs_info(policy_dbs, gov); |
1112e9d83 cpufreq: governor... |
444 445 446 |
out: mutex_unlock(&gov_dbs_data_mutex); |
714a2d9c8 cpufreq: governor... |
447 448 |
return ret; } |
e788892ba cpufreq: governor... |
449 |
EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_init); |
4d5dcc421 cpufreq: governor... |
450 |
|
e788892ba cpufreq: governor... |
451 |
void cpufreq_dbs_governor_exit(struct cpufreq_policy *policy) |
714a2d9c8 cpufreq: governor... |
452 |
{ |
ea59ee0dc cpufreq: governor... |
453 |
struct dbs_governor *gov = dbs_governor_of(policy); |
bc505475b cpufreq: governor... |
454 455 |
struct policy_dbs_info *policy_dbs = policy->governor_data; struct dbs_data *dbs_data = policy_dbs->dbs_data; |
0dd3c1d67 cpufreq: governor... |
456 |
unsigned int count; |
a72c49590 cpufreq: governor... |
457 |
|
1112e9d83 cpufreq: governor... |
458 459 |
/* Protect gov->gdbs_data against concurrent updates. */ mutex_lock(&gov_dbs_data_mutex); |
0dd3c1d67 cpufreq: governor... |
460 |
count = gov_attr_set_put(&dbs_data->attr_set, &policy_dbs->list); |
2361be236 cpufreq: Don't cr... |
461 |
|
0dd3c1d67 cpufreq: governor... |
462 |
policy->governor_data = NULL; |
e4b133cc4 cpufreq: Fix NULL... |
463 |
|
0dd3c1d67 cpufreq: governor... |
464 |
if (!count) { |
8eec1020f cpufreq: create c... |
465 |
if (!have_governor_per_policy()) |
7bdad34d0 cpufreq: governor... |
466 |
gov->gdbs_data = NULL; |
4471a34f9 cpufreq: governor... |
467 |
|
9a15fb2c7 cpufreq: Drop the... |
468 |
gov->exit(dbs_data); |
714a2d9c8 cpufreq: governor... |
469 |
kfree(dbs_data); |
4d5dcc421 cpufreq: governor... |
470 |
} |
44152cb82 cpufreq: governor... |
471 |
|
8c8f77fd0 cpufreq: governor... |
472 |
free_policy_dbs_info(policy_dbs, gov); |
1112e9d83 cpufreq: governor... |
473 474 |
mutex_unlock(&gov_dbs_data_mutex); |
714a2d9c8 cpufreq: governor... |
475 |
} |
e788892ba cpufreq: governor... |
476 |
EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_exit); |
4d5dcc421 cpufreq: governor... |
477 |
|
e788892ba cpufreq: governor... |
478 |
int cpufreq_dbs_governor_start(struct cpufreq_policy *policy) |
714a2d9c8 cpufreq: governor... |
479 |
{ |
ea59ee0dc cpufreq: governor... |
480 |
struct dbs_governor *gov = dbs_governor_of(policy); |
bc505475b cpufreq: governor... |
481 482 |
struct policy_dbs_info *policy_dbs = policy->governor_data; struct dbs_data *dbs_data = policy_dbs->dbs_data; |
702c9e542 cpufreq: governor... |
483 |
unsigned int sampling_rate, ignore_nice, j; |
8847e038c cpufreq: governor... |
484 |
unsigned int io_busy; |
714a2d9c8 cpufreq: governor... |
485 486 487 |
if (!policy->cur) return -EINVAL; |
e4db2813d cpufreq: governor... |
488 |
policy_dbs->is_shared = policy_is_shared(policy); |
57dc3bcd4 cpufreq: governor... |
489 |
policy_dbs->rate_mult = 1; |
e4db2813d cpufreq: governor... |
490 |
|
ff4b17895 cpufreq: governor... |
491 492 |
sampling_rate = dbs_data->sampling_rate; ignore_nice = dbs_data->ignore_nice_load; |
8847e038c cpufreq: governor... |
493 |
io_busy = dbs_data->io_is_busy; |
4471a34f9 cpufreq: governor... |
494 |
|
714a2d9c8 cpufreq: governor... |
495 |
for_each_cpu(j, policy->cpus) { |
8c8f77fd0 cpufreq: governor... |
496 |
struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j); |
4471a34f9 cpufreq: governor... |
497 |
|
b4f4b4b37 cpufreq: governor... |
498 |
j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time, io_busy); |
ba1ca654f cpufreq: governor... |
499 500 501 502 |
/* * Make the first invocation of dbs_update() compute the load. */ j_cdbs->prev_load = 0; |
18b46abd0 cpufreq: governor... |
503 |
|
714a2d9c8 cpufreq: governor... |
504 505 |
if (ignore_nice) j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; |
714a2d9c8 cpufreq: governor... |
506 |
} |
2abfa876f cpufreq: handle S... |
507 |
|
702c9e542 cpufreq: governor... |
508 |
gov->start(policy); |
4471a34f9 cpufreq: governor... |
509 |
|
e40e7b255 cpufreq: governor... |
510 |
gov_set_update_util(policy_dbs, sampling_rate); |
714a2d9c8 cpufreq: governor... |
511 512 |
return 0; } |
e788892ba cpufreq: governor... |
513 |
EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_start); |
714a2d9c8 cpufreq: governor... |
514 |
|
e788892ba cpufreq: governor... |
515 |
void cpufreq_dbs_governor_stop(struct cpufreq_policy *policy) |
714a2d9c8 cpufreq: governor... |
516 |
{ |
f6709b8aa cpufreq: governor... |
517 518 519 520 521 522 523 |
struct policy_dbs_info *policy_dbs = policy->governor_data; gov_clear_update_util(policy_dbs->policy); irq_work_sync(&policy_dbs->irq_work); cancel_work_sync(&policy_dbs->work); atomic_set(&policy_dbs->work_count, 0); policy_dbs->work_in_progress = false; |
714a2d9c8 cpufreq: governor... |
524 |
} |
e788892ba cpufreq: governor... |
525 |
EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_stop); |
4471a34f9 cpufreq: governor... |
526 |
|
e788892ba cpufreq: governor... |
527 |
void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy) |
714a2d9c8 cpufreq: governor... |
528 |
{ |
2a3eb51e3 cpufreq: governor... |
529 530 531 532 533 534 535 |
struct policy_dbs_info *policy_dbs; /* Protect gov->gdbs_data against cpufreq_dbs_governor_exit() */ mutex_lock(&gov_dbs_data_mutex); policy_dbs = policy->governor_data; if (!policy_dbs) goto out; |
8eeed0956 cpufreq: governor... |
536 |
|
26f0dbc9a cpufreq: governor... |
537 |
mutex_lock(&policy_dbs->update_mutex); |
bf2be2de8 cpufreq: governor... |
538 |
cpufreq_policy_apply_limits(policy); |
4cccf7555 cpufreq: governor... |
539 |
gov_update_sample_delay(policy_dbs, 0); |
26f0dbc9a cpufreq: governor... |
540 |
mutex_unlock(&policy_dbs->update_mutex); |
2a3eb51e3 cpufreq: governor... |
541 542 543 |
out: mutex_unlock(&gov_dbs_data_mutex); |
4471a34f9 cpufreq: governor... |
544 |
} |
e788892ba cpufreq: governor... |
545 |
EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_limits); |