1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef _CPUFREQ_GOVERNOR_H
18#define _CPUFREQ_GOVERNOR_H
19
20#include <linux/cpufreq.h>
21#include <linux/kobject.h>
22#include <linux/mutex.h>
23#include <linux/workqueue.h>
24#include <linux/sysfs.h>
25
26
27
28
29
30
31
32
33
34
35#define MIN_SAMPLING_RATE_RATIO (2)
36#define LATENCY_MULTIPLIER (1000)
37#define MIN_LATENCY_MULTIPLIER (100)
38#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
39
40
41enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};
42
43
44#define show_one(_gov, file_name, object) \
45static ssize_t show_##file_name \
46(struct kobject *kobj, struct attribute *attr, char *buf) \
47{ \
48 return sprintf(buf, "%u\n", _gov##_tuners.object); \
49}
50
51#define define_get_cpu_dbs_routines(_dbs_info) \
52static struct cpu_dbs_common_info *get_cpu_cdbs(int cpu) \
53{ \
54 return &per_cpu(_dbs_info, cpu).cdbs; \
55} \
56 \
57static void *get_cpu_dbs_info_s(int cpu) \
58{ \
59 return &per_cpu(_dbs_info, cpu); \
60}
61
62
63
64
65
66
67
68
69
70
71
72struct cpu_dbs_common_info {
73 int cpu;
74 u64 prev_cpu_idle;
75 u64 prev_cpu_wall;
76 u64 prev_cpu_nice;
77 struct cpufreq_policy *cur_policy;
78 struct delayed_work work;
79
80
81
82
83
84 struct mutex timer_mutex;
85 ktime_t time_stamp;
86};
87
88struct od_cpu_dbs_info_s {
89 struct cpu_dbs_common_info cdbs;
90 u64 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
99struct 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
107struct 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 adj_up_threshold;
113 unsigned int powersave_bias;
114 unsigned int io_is_busy;
115};
116
117struct 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
127struct dbs_data {
128
129 #define GOV_ONDEMAND 0
130 #define GOV_CONSERVATIVE 1
131 int governor;
132 unsigned int min_sampling_rate;
133 struct attribute_group *attr_group;
134 void *tuners;
135
136
137 struct mutex mutex;
138
139 struct cpu_dbs_common_info *(*get_cpu_cdbs)(int cpu);
140 void *(*get_cpu_dbs_info_s)(int cpu);
141 void (*gov_dbs_timer)(struct work_struct *work);
142 void (*gov_check_cpu)(int cpu, unsigned int load);
143
144
145 void *gov_ops;
146};
147
148
149struct od_ops {
150 int (*io_busy)(void);
151 void (*powersave_bias_init_cpu)(int cpu);
152 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
153 unsigned int freq_next, unsigned int relation);
154 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
155};
156
157struct cs_ops {
158 struct notifier_block *notifier_block;
159};
160
161static inline int delay_for_sampling_rate(unsigned int sampling_rate)
162{
163 int delay = usecs_to_jiffies(sampling_rate);
164
165
166 if (num_online_cpus() > 1)
167 delay -= jiffies % delay;
168
169 return delay;
170}
171
172u64 get_cpu_idle_time(unsigned int cpu, u64 *wall);
173void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
174bool need_load_eval(struct cpu_dbs_common_info *cdbs,
175 unsigned int sampling_rate);
176int cpufreq_governor_dbs(struct dbs_data *dbs_data,
177 struct cpufreq_policy *policy, unsigned int event);
178#endif
179