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