Blame view
drivers/cpufreq/cpufreq_userspace.c
3.06 KB
c06728601
|
1 |
|
1da177e4c
|
2 3 4 5 6 7 8 9 10 11 12 |
/* * linux/drivers/cpufreq/cpufreq_userspace.c * * Copyright (C) 2001 Russell King * (C) 2002 - 2004 Dominik Brodowski <linux@brodo.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ |
db7011516
|
13 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4c
|
14 |
#include <linux/cpufreq.h> |
d1922f025
|
15 16 |
#include <linux/init.h> #include <linux/module.h> |
3fc54d37a
|
17 |
#include <linux/mutex.h> |
1da177e4c
|
18 |
|
b38868aab
|
19 |
static DEFINE_PER_CPU(unsigned int, cpu_is_managed); |
1bceb8d13
|
20 |
static DEFINE_MUTEX(userspace_mutex); |
1da177e4c
|
21 |
|
32ee8c3e4
|
22 |
/** |
1da177e4c
|
23 |
* cpufreq_set - set the CPU frequency |
9e76988e9
|
24 |
* @policy: pointer to policy struct where freq is being set |
1da177e4c
|
25 |
* @freq: target frequency in kHz |
1da177e4c
|
26 27 28 |
* * Sets the CPU frequency to freq. */ |
9e76988e9
|
29 |
static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) |
1da177e4c
|
30 31 |
{ int ret = -EINVAL; |
2d06d8c49
|
32 33 |
pr_debug("cpufreq_set for cpu %u, freq %u kHz ", policy->cpu, freq); |
1da177e4c
|
34 |
|
3fc54d37a
|
35 |
mutex_lock(&userspace_mutex); |
b38868aab
|
36 |
if (!per_cpu(cpu_is_managed, policy->cpu)) |
1da177e4c
|
37 |
goto err; |
c06728601
|
38 |
ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L); |
1da177e4c
|
39 |
err: |
3fc54d37a
|
40 |
mutex_unlock(&userspace_mutex); |
1da177e4c
|
41 42 |
return ret; } |
9e76988e9
|
43 |
static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) |
1da177e4c
|
44 |
{ |
d1922f025
|
45 46 |
return sprintf(buf, "%u ", policy->cur); |
1da177e4c
|
47 |
} |
1da177e4c
|
48 49 50 51 |
static int cpufreq_governor_userspace(struct cpufreq_policy *policy, unsigned int event) { unsigned int cpu = policy->cpu; |
914f7c31b
|
52 |
int rc = 0; |
1da177e4c
|
53 54 |
switch (event) { case CPUFREQ_GOV_START: |
1da177e4c
|
55 |
BUG_ON(!policy->cur); |
d1922f025
|
56 57 |
pr_debug("started managing cpu %u ", cpu); |
c7f652e04
|
58 |
|
d1922f025
|
59 |
mutex_lock(&userspace_mutex); |
b38868aab
|
60 |
per_cpu(cpu_is_managed, cpu) = 1; |
3fc54d37a
|
61 |
mutex_unlock(&userspace_mutex); |
1da177e4c
|
62 63 |
break; case CPUFREQ_GOV_STOP: |
d1922f025
|
64 65 |
pr_debug("managing cpu %u stopped ", cpu); |
c7f652e04
|
66 |
|
d1922f025
|
67 |
mutex_lock(&userspace_mutex); |
b38868aab
|
68 |
per_cpu(cpu_is_managed, cpu) = 0; |
3fc54d37a
|
69 |
mutex_unlock(&userspace_mutex); |
1da177e4c
|
70 71 |
break; case CPUFREQ_GOV_LIMITS: |
3fc54d37a
|
72 |
mutex_lock(&userspace_mutex); |
d1922f025
|
73 74 |
pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz ", |
c06728601
|
75 |
cpu, policy->min, policy->max, |
d1922f025
|
76 77 78 |
policy->cur); if (policy->max < policy->cur) |
c06728601
|
79 80 |
__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H); |
d1922f025
|
81 |
else if (policy->min > policy->cur) |
c06728601
|
82 83 |
__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L); |
3fc54d37a
|
84 |
mutex_unlock(&userspace_mutex); |
1da177e4c
|
85 86 |
break; } |
914f7c31b
|
87 |
return rc; |
1da177e4c
|
88 |
} |
c4d14bc0b
|
89 90 91 |
#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE static #endif |
1da177e4c
|
92 93 94 |
struct cpufreq_governor cpufreq_gov_userspace = { .name = "userspace", .governor = cpufreq_governor_userspace, |
9e76988e9
|
95 96 |
.store_setspeed = cpufreq_set, .show_setspeed = show_speed, |
1da177e4c
|
97 98 |
.owner = THIS_MODULE, }; |
1da177e4c
|
99 100 101 |
static int __init cpufreq_gov_userspace_init(void) { |
1da177e4c
|
102 103 |
return cpufreq_register_governor(&cpufreq_gov_userspace); } |
1da177e4c
|
104 105 106 |
static void __exit cpufreq_gov_userspace_exit(void) { cpufreq_unregister_governor(&cpufreq_gov_userspace); |
1da177e4c
|
107 |
} |
1bceb8d13
|
108 109 110 111 |
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, " "Russell King <rmk@arm.linux.org.uk>"); MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'"); MODULE_LICENSE("GPL"); |
1da177e4c
|
112 |
|
6915719b3
|
113 |
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE |
1da177e4c
|
114 |
fs_initcall(cpufreq_gov_userspace_init); |
6915719b3
|
115 116 117 |
#else module_init(cpufreq_gov_userspace_init); #endif |
1da177e4c
|
118 |
module_exit(cpufreq_gov_userspace_exit); |