Commit | Line | Data |
---|---|---|
4471a34f VK |
1 | /* |
2 | * drivers/cpufreq/cpufreq_governor.h | |
3 | * | |
4 | * Header file for CPUFreq governors common code | |
5 | * | |
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 | * | |
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 | ||
beb0ff39 BP |
17 | #ifndef _CPUFREQ_GOVERNOR_H |
18 | #define _CPUFREQ_GOVERNOR_H | |
4471a34f | 19 | |
2dd3e724 | 20 | #include <linux/atomic.h> |
9be4fd2c | 21 | #include <linux/irq_work.h> |
4471a34f | 22 | #include <linux/cpufreq.h> |
5ff0a268 VK |
23 | #include <linux/kernel_stat.h> |
24 | #include <linux/module.h> | |
4471a34f | 25 | #include <linux/mutex.h> |
4471a34f VK |
26 | |
27 | /* | |
28 | * The polling frequency depends on the capability of the processor. Default | |
29 | * polling frequency is 1000 times the transition latency of the processor. The | |
c4afc410 | 30 | * governor will work on any processor with transition latency <= 10ms, using |
4471a34f VK |
31 | * appropriate sampling rate. |
32 | * | |
c4afc410 SK |
33 | * For CPUs with transition latency > 10ms (mostly drivers with CPUFREQ_ETERNAL) |
34 | * this governor will not work. All times here are in us (micro seconds). | |
4471a34f VK |
35 | */ |
36 | #define MIN_SAMPLING_RATE_RATIO (2) | |
37 | #define LATENCY_MULTIPLIER (1000) | |
98104ee2 | 38 | #define MIN_LATENCY_MULTIPLIER (20) |
4471a34f VK |
39 | #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) |
40 | ||
41 | /* Ondemand Sampling types */ | |
42 | enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE}; | |
43 | ||
4471a34f VK |
44 | /* |
45 | * Abbreviations: | |
46 | * dbs: used as a shortform for demand based switching It helps to keep variable | |
47 | * names smaller, simpler | |
48 | * cdbs: common dbs | |
e5dde92c | 49 | * od_*: On-demand governor |
4471a34f VK |
50 | * cs_*: Conservative governor |
51 | */ | |
52 | ||
bc505475 RW |
53 | /* Governor demand based switching data (per-policy or global). */ |
54 | struct dbs_data { | |
0dd3c1d6 | 55 | struct gov_attr_set attr_set; |
bc505475 | 56 | void *tuners; |
ff4b1789 VK |
57 | unsigned int min_sampling_rate; |
58 | unsigned int ignore_nice_load; | |
59 | unsigned int sampling_rate; | |
60 | unsigned int sampling_down_factor; | |
61 | unsigned int up_threshold; | |
8847e038 | 62 | unsigned int io_is_busy; |
c4435630 VK |
63 | }; |
64 | ||
0dd3c1d6 RW |
65 | static inline struct dbs_data *to_dbs_data(struct gov_attr_set *attr_set) |
66 | { | |
67 | return container_of(attr_set, struct dbs_data, attr_set); | |
68 | } | |
69 | ||
c4435630 VK |
70 | #define gov_show_one(_gov, file_name) \ |
71 | static ssize_t show_##file_name \ | |
0dd3c1d6 | 72 | (struct gov_attr_set *attr_set, char *buf) \ |
c4435630 | 73 | { \ |
0dd3c1d6 | 74 | struct dbs_data *dbs_data = to_dbs_data(attr_set); \ |
c4435630 VK |
75 | struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \ |
76 | return sprintf(buf, "%u\n", tuners->file_name); \ | |
77 | } | |
78 | ||
79 | #define gov_show_one_common(file_name) \ | |
80 | static ssize_t show_##file_name \ | |
0dd3c1d6 | 81 | (struct gov_attr_set *attr_set, char *buf) \ |
c4435630 | 82 | { \ |
0dd3c1d6 | 83 | struct dbs_data *dbs_data = to_dbs_data(attr_set); \ |
c4435630 VK |
84 | return sprintf(buf, "%u\n", dbs_data->file_name); \ |
85 | } | |
86 | ||
87 | #define gov_attr_ro(_name) \ | |
88 | static struct governor_attr _name = \ | |
89 | __ATTR(_name, 0444, show_##_name, NULL) | |
90 | ||
91 | #define gov_attr_rw(_name) \ | |
92 | static struct governor_attr _name = \ | |
93 | __ATTR(_name, 0644, show_##_name, store_##_name) | |
94 | ||
44152cb8 | 95 | /* Common to all CPUs of a policy */ |
e40e7b25 | 96 | struct policy_dbs_info { |
44152cb8 VK |
97 | struct cpufreq_policy *policy; |
98 | /* | |
70f43e5e VK |
99 | * Per policy mutex that serializes load evaluation from limit-change |
100 | * and work-handler. | |
44152cb8 VK |
101 | */ |
102 | struct mutex timer_mutex; | |
70f43e5e | 103 | |
9be4fd2c RW |
104 | u64 last_sample_time; |
105 | s64 sample_delay_ns; | |
686cc637 | 106 | atomic_t work_count; |
9be4fd2c | 107 | struct irq_work irq_work; |
70f43e5e | 108 | struct work_struct work; |
bc505475 RW |
109 | /* dbs_data may be shared between multiple policy objects */ |
110 | struct dbs_data *dbs_data; | |
c54df071 | 111 | struct list_head list; |
57dc3bcd RW |
112 | /* Multiplier for increasing sample delay temporarily. */ |
113 | unsigned int rate_mult; | |
e4db2813 RW |
114 | /* Status indicators */ |
115 | bool is_shared; /* This object is used by multiple CPUs */ | |
116 | bool work_in_progress; /* Work is being queued up or in progress */ | |
44152cb8 VK |
117 | }; |
118 | ||
e40e7b25 | 119 | static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs, |
9be4fd2c RW |
120 | unsigned int delay_us) |
121 | { | |
e40e7b25 | 122 | policy_dbs->sample_delay_ns = delay_us * NSEC_PER_USEC; |
9be4fd2c RW |
123 | } |
124 | ||
4471a34f | 125 | /* Per cpu structures */ |
875b8508 | 126 | struct cpu_dbs_info { |
1e7586a1 VK |
127 | u64 prev_cpu_idle; |
128 | u64 prev_cpu_wall; | |
129 | u64 prev_cpu_nice; | |
18b46abd | 130 | /* |
c8ae481b VK |
131 | * Used to keep track of load in the previous interval. However, when |
132 | * explicitly set to zero, it is used as a flag to ensure that we copy | |
133 | * the previous load to the current interval only once, upon the first | |
134 | * wake-up from idle. | |
18b46abd | 135 | */ |
c8ae481b | 136 | unsigned int prev_load; |
9be4fd2c | 137 | struct update_util_data update_util; |
e40e7b25 | 138 | struct policy_dbs_info *policy_dbs; |
4471a34f VK |
139 | }; |
140 | ||
c4afc410 | 141 | /* Common Governor data across policies */ |
7bdad34d | 142 | struct dbs_governor { |
af926185 | 143 | struct cpufreq_governor gov; |
c4435630 | 144 | struct kobj_type kobj_type; |
4471a34f | 145 | |
0b981e70 VK |
146 | /* |
147 | * Common data for platforms that don't set | |
148 | * CPUFREQ_HAVE_GOVERNOR_PER_POLICY | |
149 | */ | |
4d5dcc42 | 150 | struct dbs_data *gdbs_data; |
4471a34f | 151 | |
9be4fd2c | 152 | unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy); |
7d5a9956 RW |
153 | struct policy_dbs_info *(*alloc)(void); |
154 | void (*free)(struct policy_dbs_info *policy_dbs); | |
8e0484d2 VK |
155 | int (*init)(struct dbs_data *dbs_data, bool notify); |
156 | void (*exit)(struct dbs_data *dbs_data, bool notify); | |
702c9e54 | 157 | void (*start)(struct cpufreq_policy *policy); |
4471a34f VK |
158 | }; |
159 | ||
ea59ee0d RW |
160 | static inline struct dbs_governor *dbs_governor_of(struct cpufreq_policy *policy) |
161 | { | |
162 | return container_of(policy->governor, struct dbs_governor, gov); | |
163 | } | |
164 | ||
8434dadb | 165 | /* Governor specific operations */ |
4471a34f | 166 | struct od_ops { |
4471a34f VK |
167 | unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy, |
168 | unsigned int freq_next, unsigned int relation); | |
4471a34f VK |
169 | }; |
170 | ||
4cccf755 | 171 | unsigned int dbs_update(struct cpufreq_policy *policy); |
906a6e5a | 172 | int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event); |
fb30809e JS |
173 | void od_register_powersave_bias_handler(unsigned int (*f) |
174 | (struct cpufreq_policy *, unsigned int, unsigned int), | |
175 | unsigned int powersave_bias); | |
176 | void od_unregister_powersave_bias_handler(void); | |
0dd3c1d6 | 177 | ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf, |
aded387b | 178 | size_t count); |
8c8f77fd | 179 | void gov_update_cpu_data(struct dbs_data *dbs_data); |
beb0ff39 | 180 | #endif /* _CPUFREQ_GOVERNOR_H */ |