diff options
Diffstat (limited to 'drivers/cpufreq/cpufreq_governor.h')
-rw-r--r-- | drivers/cpufreq/cpufreq_governor.h | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h new file mode 100644 index 000000000000..34e14adfc3f9 --- /dev/null +++ b/drivers/cpufreq/cpufreq_governor.h | |||
@@ -0,0 +1,177 @@ | |||
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 | |||
17 | #ifndef _CPUFREQ_GOVERNER_H | ||
18 | #define _CPUFREQ_GOVERNER_H | ||
19 | |||
20 | #include <asm/cputime.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <linux/kobject.h> | ||
23 | #include <linux/mutex.h> | ||
24 | #include <linux/workqueue.h> | ||
25 | #include <linux/sysfs.h> | ||
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 | ||
30 | * governor will work on any processor with transition latency <= 10mS, using | ||
31 | * appropriate sampling rate. | ||
32 | * | ||
33 | * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL) | ||
34 | * this governor will not work. All times here are in uS. | ||
35 | */ | ||
36 | #define MIN_SAMPLING_RATE_RATIO (2) | ||
37 | #define LATENCY_MULTIPLIER (1000) | ||
38 | #define MIN_LATENCY_MULTIPLIER (100) | ||
39 | #define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) | ||
40 | |||
41 | /* Ondemand Sampling types */ | ||
42 | enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE}; | ||
43 | |||
44 | /* Macro creating sysfs show routines */ | ||
45 | #define show_one(_gov, file_name, object) \ | ||
46 | static ssize_t show_##file_name \ | ||
47 | (struct kobject *kobj, struct attribute *attr, char *buf) \ | ||
48 | { \ | ||
49 | return sprintf(buf, "%u\n", _gov##_tuners.object); \ | ||
50 | } | ||
51 | |||
52 | #define define_get_cpu_dbs_routines(_dbs_info) \ | ||
53 | static struct cpu_dbs_common_info *get_cpu_cdbs(int cpu) \ | ||
54 | { \ | ||
55 | return &per_cpu(_dbs_info, cpu).cdbs; \ | ||
56 | } \ | ||
57 | \ | ||
58 | static void *get_cpu_dbs_info_s(int cpu) \ | ||
59 | { \ | ||
60 | return &per_cpu(_dbs_info, cpu); \ | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * Abbreviations: | ||
65 | * dbs: used as a shortform for demand based switching It helps to keep variable | ||
66 | * names smaller, simpler | ||
67 | * cdbs: common dbs | ||
68 | * on_*: On-demand governor | ||
69 | * cs_*: Conservative governor | ||
70 | */ | ||
71 | |||
72 | /* Per cpu structures */ | ||
73 | struct cpu_dbs_common_info { | ||
74 | int cpu; | ||
75 | cputime64_t prev_cpu_idle; | ||
76 | cputime64_t prev_cpu_wall; | ||
77 | cputime64_t prev_cpu_nice; | ||
78 | struct cpufreq_policy *cur_policy; | ||
79 | struct delayed_work work; | ||
80 | /* | ||
81 | * percpu mutex that serializes governor limit change with gov_dbs_timer | ||
82 | * invocation. We do not want gov_dbs_timer to run when user is changing | ||
83 | * the governor or limits. | ||
84 | */ | ||
85 | struct mutex timer_mutex; | ||
86 | }; | ||
87 | |||
88 | struct od_cpu_dbs_info_s { | ||
89 | struct cpu_dbs_common_info cdbs; | ||
90 | cputime64_t prev_cpu_iowait; | ||
91 | struct cpufreq_frequency_table *freq_table; | ||
92 | unsigned int freq_lo; | ||
93 | unsigned int freq_lo_jiffies; | ||
94 | unsigned int freq_hi_jiffies; | ||
95 | unsigned int rate_mult; | ||
96 | unsigned int sample_type:1; | ||
97 | }; | ||
98 | |||
99 | struct cs_cpu_dbs_info_s { | ||
100 | struct cpu_dbs_common_info cdbs; | ||
101 | unsigned int down_skip; | ||
102 | unsigned int requested_freq; | ||
103 | unsigned int enable:1; | ||
104 | }; | ||
105 | |||
106 | /* Governers sysfs tunables */ | ||
107 | struct od_dbs_tuners { | ||
108 | unsigned int ignore_nice; | ||
109 | unsigned int sampling_rate; | ||
110 | unsigned int sampling_down_factor; | ||
111 | unsigned int up_threshold; | ||
112 | unsigned int down_differential; | ||
113 | unsigned int powersave_bias; | ||
114 | unsigned int io_is_busy; | ||
115 | }; | ||
116 | |||
117 | struct cs_dbs_tuners { | ||
118 | unsigned int ignore_nice; | ||
119 | unsigned int sampling_rate; | ||
120 | unsigned int sampling_down_factor; | ||
121 | unsigned int up_threshold; | ||
122 | unsigned int down_threshold; | ||
123 | unsigned int freq_step; | ||
124 | }; | ||
125 | |||
126 | /* Per Governer data */ | ||
127 | struct dbs_data { | ||
128 | /* Common across governors */ | ||
129 | #define GOV_ONDEMAND 0 | ||
130 | #define GOV_CONSERVATIVE 1 | ||
131 | int governor; | ||
132 | unsigned int min_sampling_rate; | ||
133 | unsigned int enable; /* number of CPUs using this policy */ | ||
134 | struct attribute_group *attr_group; | ||
135 | void *tuners; | ||
136 | |||
137 | /* dbs_mutex protects dbs_enable in governor start/stop */ | ||
138 | struct mutex mutex; | ||
139 | |||
140 | struct cpu_dbs_common_info *(*get_cpu_cdbs)(int cpu); | ||
141 | void *(*get_cpu_dbs_info_s)(int cpu); | ||
142 | void (*gov_dbs_timer)(struct work_struct *work); | ||
143 | void (*gov_check_cpu)(int cpu, unsigned int load); | ||
144 | |||
145 | /* Governor specific ops, see below */ | ||
146 | void *gov_ops; | ||
147 | }; | ||
148 | |||
149 | /* Governor specific ops, will be passed to dbs_data->gov_ops */ | ||
150 | struct od_ops { | ||
151 | int (*io_busy)(void); | ||
152 | void (*powersave_bias_init_cpu)(int cpu); | ||
153 | unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy, | ||
154 | unsigned int freq_next, unsigned int relation); | ||
155 | void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq); | ||
156 | }; | ||
157 | |||
158 | struct cs_ops { | ||
159 | struct notifier_block *notifier_block; | ||
160 | }; | ||
161 | |||
162 | static inline int delay_for_sampling_rate(unsigned int sampling_rate) | ||
163 | { | ||
164 | int delay = usecs_to_jiffies(sampling_rate); | ||
165 | |||
166 | /* We want all CPUs to do sampling nearly on same jiffy */ | ||
167 | if (num_online_cpus() > 1) | ||
168 | delay -= jiffies % delay; | ||
169 | |||
170 | return delay; | ||
171 | } | ||
172 | |||
173 | cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall); | ||
174 | void dbs_check_cpu(struct dbs_data *dbs_data, int cpu); | ||
175 | int cpufreq_governor_dbs(struct dbs_data *dbs_data, | ||
176 | struct cpufreq_policy *policy, unsigned int event); | ||
177 | #endif /* _CPUFREQ_GOVERNER_H */ | ||