cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
[deliverable/linux.git] / drivers / cpufreq / cpufreq_governor.c
CommitLineData
2aacdfff 1/*
2 * drivers/cpufreq/cpufreq_governor.c
3 *
4 * CPUFREQ governors common code
5 *
4471a34f
VK
6 * Copyright (C) 2001 Russell King
7 * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
8 * (C) 2003 Jun Nakajima <jun.nakajima@intel.com>
9 * (C) 2009 Alexander Clouter <alex@digriz.org.uk>
10 * (c) 2012 Viresh Kumar <viresh.kumar@linaro.org>
11 *
2aacdfff 12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
4471a34f
VK
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
2aacdfff 19#include <linux/export.h>
20#include <linux/kernel_stat.h>
4d5dcc42 21#include <linux/slab.h>
4471a34f
VK
22
23#include "cpufreq_governor.h"
24
2bb8d94f
RW
25DEFINE_MUTEX(dbs_data_mutex);
26EXPORT_SYMBOL_GPL(dbs_data_mutex);
27
4d5dcc42
VK
28static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
29{
30 if (have_governor_per_policy())
31 return dbs_data->cdata->attr_group_gov_pol;
32 else
33 return dbs_data->cdata->attr_group_gov_sys;
34}
35
4471a34f
VK
36void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
37{
875b8508 38 struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
4471a34f
VK
39 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
40 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
44152cb8 41 struct cpufreq_policy *policy = cdbs->shared->policy;
18b46abd 42 unsigned int sampling_rate;
4471a34f
VK
43 unsigned int max_load = 0;
44 unsigned int ignore_nice;
45 unsigned int j;
46
18b46abd
SB
47 if (dbs_data->cdata->governor == GOV_ONDEMAND) {
48 struct od_cpu_dbs_info_s *od_dbs_info =
49 dbs_data->cdata->get_cpu_dbs_info_s(cpu);
50
51 /*
52 * Sometimes, the ondemand governor uses an additional
53 * multiplier to give long delays. So apply this multiplier to
54 * the 'sampling_rate', so as to keep the wake-up-from-idle
55 * detection logic a bit conservative.
56 */
57 sampling_rate = od_tuners->sampling_rate;
58 sampling_rate *= od_dbs_info->rate_mult;
59
6c4640c3 60 ignore_nice = od_tuners->ignore_nice_load;
18b46abd
SB
61 } else {
62 sampling_rate = cs_tuners->sampling_rate;
6c4640c3 63 ignore_nice = cs_tuners->ignore_nice_load;
18b46abd 64 }
4471a34f 65
dfa5bb62 66 /* Get Absolute Load */
4471a34f 67 for_each_cpu(j, policy->cpus) {
875b8508 68 struct cpu_dbs_info *j_cdbs;
9366d840
SK
69 u64 cur_wall_time, cur_idle_time;
70 unsigned int idle_time, wall_time;
4471a34f 71 unsigned int load;
9366d840 72 int io_busy = 0;
4471a34f 73
4d5dcc42 74 j_cdbs = dbs_data->cdata->get_cpu_cdbs(j);
4471a34f 75
9366d840
SK
76 /*
77 * For the purpose of ondemand, waiting for disk IO is
78 * an indication that you're performance critical, and
79 * not that the system is actually idle. So do not add
80 * the iowait time to the cpu idle time.
81 */
82 if (dbs_data->cdata->governor == GOV_ONDEMAND)
83 io_busy = od_tuners->io_is_busy;
84 cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);
4471a34f
VK
85
86 wall_time = (unsigned int)
87 (cur_wall_time - j_cdbs->prev_cpu_wall);
88 j_cdbs->prev_cpu_wall = cur_wall_time;
89
0df35026
CY
90 if (cur_idle_time < j_cdbs->prev_cpu_idle)
91 cur_idle_time = j_cdbs->prev_cpu_idle;
92
4471a34f
VK
93 idle_time = (unsigned int)
94 (cur_idle_time - j_cdbs->prev_cpu_idle);
95 j_cdbs->prev_cpu_idle = cur_idle_time;
96
97 if (ignore_nice) {
98 u64 cur_nice;
99 unsigned long cur_nice_jiffies;
100
101 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE] -
102 cdbs->prev_cpu_nice;
103 /*
104 * Assumption: nice time between sampling periods will
105 * be less than 2^32 jiffies for 32 bit sys
106 */
107 cur_nice_jiffies = (unsigned long)
108 cputime64_to_jiffies64(cur_nice);
109
110 cdbs->prev_cpu_nice =
111 kcpustat_cpu(j).cpustat[CPUTIME_NICE];
112 idle_time += jiffies_to_usecs(cur_nice_jiffies);
113 }
114
4471a34f
VK
115 if (unlikely(!wall_time || wall_time < idle_time))
116 continue;
117
18b46abd
SB
118 /*
119 * If the CPU had gone completely idle, and a task just woke up
120 * on this CPU now, it would be unfair to calculate 'load' the
121 * usual way for this elapsed time-window, because it will show
122 * near-zero load, irrespective of how CPU intensive that task
123 * actually is. This is undesirable for latency-sensitive bursty
124 * workloads.
125 *
126 * To avoid this, we reuse the 'load' from the previous
127 * time-window and give this task a chance to start with a
128 * reasonably high CPU frequency. (However, we shouldn't over-do
129 * this copy, lest we get stuck at a high load (high frequency)
130 * for too long, even when the current system load has actually
131 * dropped down. So we perform the copy only once, upon the
132 * first wake-up from idle.)
133 *
9be4fd2c
RW
134 * Detecting this situation is easy: the governor's utilization
135 * update handler would not have run during CPU-idle periods.
136 * Hence, an unusually large 'wall_time' (as compared to the
137 * sampling rate) indicates this scenario.
c8ae481b
VK
138 *
139 * prev_load can be zero in two cases and we must recalculate it
140 * for both cases:
141 * - during long idle intervals
142 * - explicitly set to zero
18b46abd 143 */
c8ae481b
VK
144 if (unlikely(wall_time > (2 * sampling_rate) &&
145 j_cdbs->prev_load)) {
18b46abd 146 load = j_cdbs->prev_load;
c8ae481b
VK
147
148 /*
149 * Perform a destructive copy, to ensure that we copy
150 * the previous load only once, upon the first wake-up
151 * from idle.
152 */
153 j_cdbs->prev_load = 0;
18b46abd
SB
154 } else {
155 load = 100 * (wall_time - idle_time) / wall_time;
156 j_cdbs->prev_load = load;
18b46abd 157 }
4471a34f 158
4471a34f
VK
159 if (load > max_load)
160 max_load = load;
161 }
162
4d5dcc42 163 dbs_data->cdata->gov_check_cpu(cpu, max_load);
4471a34f
VK
164}
165EXPORT_SYMBOL_GPL(dbs_check_cpu);
166
9be4fd2c
RW
167void gov_set_update_util(struct cpu_common_dbs_info *shared,
168 unsigned int delay_us)
4471a34f 169{
9be4fd2c 170 struct cpufreq_policy *policy = shared->policy;
70f43e5e 171 struct dbs_data *dbs_data = policy->governor_data;
70f43e5e 172 int cpu;
031299b3 173
9be4fd2c
RW
174 gov_update_sample_delay(shared, delay_us);
175 shared->last_sample_time = 0;
176
70f43e5e 177 for_each_cpu(cpu, policy->cpus) {
9be4fd2c
RW
178 struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
179
180 cpufreq_set_update_util_data(cpu, &cdbs->update_util);
031299b3
VK
181 }
182}
9be4fd2c 183EXPORT_SYMBOL_GPL(gov_set_update_util);
031299b3 184
9be4fd2c 185static inline void gov_clear_update_util(struct cpufreq_policy *policy)
031299b3 186{
031299b3 187 int i;
58ddcead 188
9be4fd2c
RW
189 for_each_cpu(i, policy->cpus)
190 cpufreq_set_update_util_data(i, NULL);
191
192 synchronize_rcu();
4471a34f
VK
193}
194
9be4fd2c 195static void gov_cancel_work(struct cpu_common_dbs_info *shared)
70f43e5e 196{
9be4fd2c 197 /* Tell dbs_update_util_handler() to skip queuing up work items. */
2dd3e724 198 atomic_inc(&shared->skip_work);
70f43e5e 199 /*
9be4fd2c
RW
200 * If dbs_update_util_handler() is already running, it may not notice
201 * the incremented skip_work, so wait for it to complete to prevent its
202 * work item from being queued up after the cancel_work_sync() below.
70f43e5e 203 */
9be4fd2c
RW
204 gov_clear_update_util(shared->policy);
205 irq_work_sync(&shared->irq_work);
70f43e5e 206 cancel_work_sync(&shared->work);
2dd3e724 207 atomic_set(&shared->skip_work, 0);
70f43e5e 208}
43e0ee36 209
70f43e5e 210static void dbs_work_handler(struct work_struct *work)
43e0ee36 211{
70f43e5e
VK
212 struct cpu_common_dbs_info *shared = container_of(work, struct
213 cpu_common_dbs_info, work);
3a91b069
VK
214 struct cpufreq_policy *policy;
215 struct dbs_data *dbs_data;
9be4fd2c 216 unsigned int delay;
43e0ee36 217
3a91b069 218 policy = shared->policy;
3a91b069
VK
219 dbs_data = policy->governor_data;
220
70f43e5e 221 /*
9be4fd2c
RW
222 * Make sure cpufreq_governor_limits() isn't evaluating load or the
223 * ondemand governor isn't updating the sampling rate in parallel.
70f43e5e
VK
224 */
225 mutex_lock(&shared->timer_mutex);
9be4fd2c
RW
226 delay = dbs_data->cdata->gov_dbs_timer(policy);
227 shared->sample_delay_ns = jiffies_to_nsecs(delay);
43e0ee36 228 mutex_unlock(&shared->timer_mutex);
70f43e5e 229
9be4fd2c
RW
230 /*
231 * If the atomic operation below is reordered with respect to the
232 * sample delay modification, the utilization update handler may end
233 * up using a stale sample delay value.
234 */
235 smp_mb__before_atomic();
2dd3e724 236 atomic_dec(&shared->skip_work);
9be4fd2c
RW
237}
238
239static void dbs_irq_work(struct irq_work *irq_work)
240{
241 struct cpu_common_dbs_info *shared;
70f43e5e 242
9be4fd2c
RW
243 shared = container_of(irq_work, struct cpu_common_dbs_info, irq_work);
244 schedule_work(&shared->work);
70f43e5e
VK
245}
246
9be4fd2c 247static inline void gov_queue_irq_work(struct cpu_common_dbs_info *shared)
70f43e5e 248{
9be4fd2c
RW
249#ifdef CONFIG_SMP
250 irq_work_queue_on(&shared->irq_work, smp_processor_id());
251#else
252 irq_work_queue(&shared->irq_work);
253#endif
254}
255
256static void dbs_update_util_handler(struct update_util_data *data, u64 time,
257 unsigned long util, unsigned long max)
258{
259 struct cpu_dbs_info *cdbs = container_of(data, struct cpu_dbs_info, update_util);
70f43e5e 260 struct cpu_common_dbs_info *shared = cdbs->shared;
70f43e5e
VK
261
262 /*
9be4fd2c
RW
263 * The work may not be allowed to be queued up right now.
264 * Possible reasons:
265 * - Work has already been queued up or is in progress.
266 * - The governor is being stopped.
267 * - It is too early (too little time from the previous sample).
70f43e5e 268 */
9be4fd2c
RW
269 if (atomic_inc_return(&shared->skip_work) == 1) {
270 u64 delta_ns;
271
272 delta_ns = time - shared->last_sample_time;
273 if ((s64)delta_ns >= shared->sample_delay_ns) {
274 shared->last_sample_time = time;
275 gov_queue_irq_work(shared);
276 return;
277 }
278 }
279 atomic_dec(&shared->skip_work);
43e0ee36 280}
4447266b 281
4d5dcc42
VK
282static void set_sampling_rate(struct dbs_data *dbs_data,
283 unsigned int sampling_rate)
284{
285 if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
286 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
287 cs_tuners->sampling_rate = sampling_rate;
288 } else {
289 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
290 od_tuners->sampling_rate = sampling_rate;
291 }
292}
293
44152cb8
VK
294static int alloc_common_dbs_info(struct cpufreq_policy *policy,
295 struct common_dbs_data *cdata)
296{
297 struct cpu_common_dbs_info *shared;
298 int j;
299
300 /* Allocate memory for the common information for policy->cpus */
301 shared = kzalloc(sizeof(*shared), GFP_KERNEL);
302 if (!shared)
303 return -ENOMEM;
304
305 /* Set shared for all CPUs, online+offline */
306 for_each_cpu(j, policy->related_cpus)
307 cdata->get_cpu_cdbs(j)->shared = shared;
308
5e4500d8 309 mutex_init(&shared->timer_mutex);
2dd3e724 310 atomic_set(&shared->skip_work, 0);
9be4fd2c 311 init_irq_work(&shared->irq_work, dbs_irq_work);
70f43e5e 312 INIT_WORK(&shared->work, dbs_work_handler);
44152cb8
VK
313 return 0;
314}
315
316static void free_common_dbs_info(struct cpufreq_policy *policy,
317 struct common_dbs_data *cdata)
318{
319 struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
320 struct cpu_common_dbs_info *shared = cdbs->shared;
321 int j;
322
5e4500d8
VK
323 mutex_destroy(&shared->timer_mutex);
324
44152cb8
VK
325 for_each_cpu(j, policy->cpus)
326 cdata->get_cpu_cdbs(j)->shared = NULL;
327
328 kfree(shared);
329}
330
714a2d9c 331static int cpufreq_governor_init(struct cpufreq_policy *policy,
714a2d9c 332 struct common_dbs_data *cdata)
4471a34f 333{
5da3dd1e 334 struct dbs_data *dbs_data = cdata->gdbs_data;
714a2d9c
VK
335 unsigned int latency;
336 int ret;
4471a34f 337
a72c4959
VK
338 /* State should be equivalent to EXIT */
339 if (policy->governor_data)
340 return -EBUSY;
341
714a2d9c
VK
342 if (dbs_data) {
343 if (WARN_ON(have_governor_per_policy()))
344 return -EINVAL;
44152cb8
VK
345
346 ret = alloc_common_dbs_info(policy, cdata);
347 if (ret)
348 return ret;
349
714a2d9c
VK
350 dbs_data->usage_count++;
351 policy->governor_data = dbs_data;
352 return 0;
353 }
4d5dcc42 354
714a2d9c
VK
355 dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL);
356 if (!dbs_data)
357 return -ENOMEM;
4d5dcc42 358
44152cb8
VK
359 ret = alloc_common_dbs_info(policy, cdata);
360 if (ret)
361 goto free_dbs_data;
362
714a2d9c
VK
363 dbs_data->cdata = cdata;
364 dbs_data->usage_count = 1;
4d5dcc42 365
714a2d9c
VK
366 ret = cdata->init(dbs_data, !policy->governor->initialized);
367 if (ret)
44152cb8 368 goto free_common_dbs_info;
4d5dcc42 369
714a2d9c
VK
370 /* policy latency is in ns. Convert it to us first */
371 latency = policy->cpuinfo.transition_latency / 1000;
372 if (latency == 0)
373 latency = 1;
4d5dcc42 374
714a2d9c
VK
375 /* Bring kernel and HW constraints together */
376 dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate,
377 MIN_LATENCY_MULTIPLIER * latency);
378 set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate,
379 latency * LATENCY_MULTIPLIER));
2361be23 380
8eec1020 381 if (!have_governor_per_policy())
714a2d9c 382 cdata->gdbs_data = dbs_data;
4d5dcc42 383
e4b133cc
VK
384 policy->governor_data = dbs_data;
385
714a2d9c
VK
386 ret = sysfs_create_group(get_governor_parent_kobj(policy),
387 get_sysfs_attr(dbs_data));
388 if (ret)
8eec1020 389 goto reset_gdbs_data;
4d5dcc42 390
714a2d9c 391 return 0;
4d5dcc42 392
8eec1020 393reset_gdbs_data:
e4b133cc
VK
394 policy->governor_data = NULL;
395
8eec1020 396 if (!have_governor_per_policy())
714a2d9c 397 cdata->gdbs_data = NULL;
714a2d9c 398 cdata->exit(dbs_data, !policy->governor->initialized);
44152cb8
VK
399free_common_dbs_info:
400 free_common_dbs_info(policy, cdata);
714a2d9c
VK
401free_dbs_data:
402 kfree(dbs_data);
403 return ret;
404}
4d5dcc42 405
5da3dd1e 406static int cpufreq_governor_exit(struct cpufreq_policy *policy)
714a2d9c 407{
5da3dd1e 408 struct dbs_data *dbs_data = policy->governor_data;
714a2d9c 409 struct common_dbs_data *cdata = dbs_data->cdata;
a72c4959
VK
410 struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
411
412 /* State should be equivalent to INIT */
413 if (!cdbs->shared || cdbs->shared->policy)
414 return -EBUSY;
4d5dcc42 415
714a2d9c
VK
416 if (!--dbs_data->usage_count) {
417 sysfs_remove_group(get_governor_parent_kobj(policy),
418 get_sysfs_attr(dbs_data));
2361be23 419
e4b133cc
VK
420 policy->governor_data = NULL;
421
8eec1020 422 if (!have_governor_per_policy())
4d5dcc42 423 cdata->gdbs_data = NULL;
4471a34f 424
714a2d9c
VK
425 cdata->exit(dbs_data, policy->governor->initialized == 1);
426 kfree(dbs_data);
e4b133cc
VK
427 } else {
428 policy->governor_data = NULL;
4d5dcc42 429 }
44152cb8
VK
430
431 free_common_dbs_info(policy, cdata);
a72c4959 432 return 0;
714a2d9c 433}
4d5dcc42 434
5da3dd1e 435static int cpufreq_governor_start(struct cpufreq_policy *policy)
714a2d9c 436{
5da3dd1e 437 struct dbs_data *dbs_data = policy->governor_data;
714a2d9c
VK
438 struct common_dbs_data *cdata = dbs_data->cdata;
439 unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
49a9a40c 440 struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
44152cb8 441 struct cpu_common_dbs_info *shared = cdbs->shared;
714a2d9c
VK
442 int io_busy = 0;
443
444 if (!policy->cur)
445 return -EINVAL;
446
a72c4959
VK
447 /* State should be equivalent to INIT */
448 if (!shared || shared->policy)
449 return -EBUSY;
450
714a2d9c
VK
451 if (cdata->governor == GOV_CONSERVATIVE) {
452 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
4d5dcc42 453
4d5dcc42 454 sampling_rate = cs_tuners->sampling_rate;
6c4640c3 455 ignore_nice = cs_tuners->ignore_nice_load;
4471a34f 456 } else {
714a2d9c
VK
457 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
458
4d5dcc42 459 sampling_rate = od_tuners->sampling_rate;
6c4640c3 460 ignore_nice = od_tuners->ignore_nice_load;
9366d840 461 io_busy = od_tuners->io_is_busy;
4471a34f
VK
462 }
463
714a2d9c 464 for_each_cpu(j, policy->cpus) {
875b8508 465 struct cpu_dbs_info *j_cdbs = cdata->get_cpu_cdbs(j);
714a2d9c 466 unsigned int prev_load;
4471a34f 467
714a2d9c
VK
468 j_cdbs->prev_cpu_idle =
469 get_cpu_idle_time(j, &j_cdbs->prev_cpu_wall, io_busy);
4471a34f 470
714a2d9c
VK
471 prev_load = (unsigned int)(j_cdbs->prev_cpu_wall -
472 j_cdbs->prev_cpu_idle);
473 j_cdbs->prev_load = 100 * prev_load /
474 (unsigned int)j_cdbs->prev_cpu_wall;
18b46abd 475
714a2d9c
VK
476 if (ignore_nice)
477 j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
18b46abd 478
9be4fd2c 479 j_cdbs->update_util.func = dbs_update_util_handler;
714a2d9c 480 }
9be4fd2c 481 shared->policy = policy;
2abfa876 482
714a2d9c
VK
483 if (cdata->governor == GOV_CONSERVATIVE) {
484 struct cs_cpu_dbs_info_s *cs_dbs_info =
485 cdata->get_cpu_dbs_info_s(cpu);
4471a34f 486
714a2d9c 487 cs_dbs_info->down_skip = 0;
714a2d9c
VK
488 cs_dbs_info->requested_freq = policy->cur;
489 } else {
490 struct od_ops *od_ops = cdata->gov_ops;
491 struct od_cpu_dbs_info_s *od_dbs_info = cdata->get_cpu_dbs_info_s(cpu);
4471a34f 492
714a2d9c
VK
493 od_dbs_info->rate_mult = 1;
494 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
495 od_ops->powersave_bias_init_cpu(cpu);
496 }
4471a34f 497
9be4fd2c 498 gov_set_update_util(shared, sampling_rate);
714a2d9c
VK
499 return 0;
500}
501
5da3dd1e 502static int cpufreq_governor_stop(struct cpufreq_policy *policy)
714a2d9c 503{
5da3dd1e 504 struct dbs_data *dbs_data = policy->governor_data;
03d5eec0 505 struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
44152cb8
VK
506 struct cpu_common_dbs_info *shared = cdbs->shared;
507
a72c4959
VK
508 /* State should be equivalent to START */
509 if (!shared || !shared->policy)
510 return -EBUSY;
511
70f43e5e 512 gov_cancel_work(shared);
3a91b069 513 shared->policy = NULL;
3a91b069 514
a72c4959 515 return 0;
714a2d9c 516}
4471a34f 517
5da3dd1e 518static int cpufreq_governor_limits(struct cpufreq_policy *policy)
714a2d9c 519{
5da3dd1e 520 struct dbs_data *dbs_data = policy->governor_data;
714a2d9c
VK
521 struct common_dbs_data *cdata = dbs_data->cdata;
522 unsigned int cpu = policy->cpu;
49a9a40c 523 struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
8eeed095 524
a72c4959 525 /* State should be equivalent to START */
44152cb8 526 if (!cdbs->shared || !cdbs->shared->policy)
a72c4959 527 return -EBUSY;
4471a34f 528
44152cb8
VK
529 mutex_lock(&cdbs->shared->timer_mutex);
530 if (policy->max < cdbs->shared->policy->cur)
531 __cpufreq_driver_target(cdbs->shared->policy, policy->max,
714a2d9c 532 CPUFREQ_RELATION_H);
44152cb8
VK
533 else if (policy->min > cdbs->shared->policy->cur)
534 __cpufreq_driver_target(cdbs->shared->policy, policy->min,
714a2d9c
VK
535 CPUFREQ_RELATION_L);
536 dbs_check_cpu(dbs_data, cpu);
44152cb8 537 mutex_unlock(&cdbs->shared->timer_mutex);
a72c4959
VK
538
539 return 0;
714a2d9c 540}
4471a34f 541
714a2d9c
VK
542int cpufreq_governor_dbs(struct cpufreq_policy *policy,
543 struct common_dbs_data *cdata, unsigned int event)
544{
5da3dd1e 545 int ret = -EINVAL;
714a2d9c 546
732b6d61 547 /* Lock governor to block concurrent initialization of governor */
2bb8d94f 548 mutex_lock(&dbs_data_mutex);
732b6d61 549
5da3dd1e
RW
550 if (event == CPUFREQ_GOV_POLICY_INIT) {
551 ret = cpufreq_governor_init(policy, cdata);
552 } else if (policy->governor_data) {
553 switch (event) {
554 case CPUFREQ_GOV_POLICY_EXIT:
555 ret = cpufreq_governor_exit(policy);
556 break;
557 case CPUFREQ_GOV_START:
558 ret = cpufreq_governor_start(policy);
559 break;
560 case CPUFREQ_GOV_STOP:
561 ret = cpufreq_governor_stop(policy);
562 break;
563 case CPUFREQ_GOV_LIMITS:
564 ret = cpufreq_governor_limits(policy);
565 break;
566 }
4471a34f 567 }
714a2d9c 568
2bb8d94f 569 mutex_unlock(&dbs_data_mutex);
714a2d9c 570 return ret;
4471a34f
VK
571}
572EXPORT_SYMBOL_GPL(cpufreq_governor_dbs);
This page took 0.179492 seconds and 5 git commands to generate.