tizen 2.3 release
[framework/system/deviced.git] / src / pass / pass.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #ifndef __PASS__
21 #define __PASS__
22
23 #include <Ecore.h>
24 #include "pass-util.h"
25
26 /******************************************************
27  *                   PASS Governors                   *
28  ******************************************************/
29 #define PASS_NAME_LEN           128
30 #define PASS_LEVEL_COND_MAX     3
31 #define PASS_CPU_STATS_DEFAULT  20
32 #define PASS_MIN_GOV_TIMEOUT    0.2
33
34 #define PASS_CONF_PATH          "/etc/deviced/pass.conf"
35
36 struct pass_policy;
37
38 /*
39  * PASS state
40  */
41 enum pass_state {
42         PASS_UNUSED = -1,
43         PASS_OFF = 0,
44         PASS_ON = 1,
45 };
46
47 /*
48  * PASS Governor type
49  */
50 enum pass_gov_type {
51         PASS_GOV_STEP,
52         PASS_GOV_RADIATION,
53
54         PASS_GOV_END,
55 };
56
57 enum pass_gov_state {
58         PASS_GOV_NONE = 0,
59         PASS_GOV_START,
60         PASS_GOV_STOP,
61 };
62
63 /*
64  * PASS cpu state
65  */
66 enum pass_cpu_state {
67         PASS_CPU_DOWN = 0,
68         PASS_CPU_UP,
69 };
70
71 /*
72  * struct pass_governor
73  */
74 struct pass_governor {
75         char name[PASS_NAME_LEN];
76         int (*init)(struct pass_policy *);
77         int (*exit)(struct pass_policy *);
78         int (*update)(struct pass_policy *, enum pass_gov_state state);
79         int (*governor)(struct pass_policy *);
80         Ecore_Timer *gov_timer_id;
81         double gov_timeout;
82 };
83
84 /******************************************************
85  *                   PASS basic data                  *
86  ******************************************************/
87
88 /*
89  * struct pass_cpu_stats
90  *
91  * @time: current time
92  * @freq: current cpu frequency
93  * @freq: new cpu frequency
94  * @nr_runnings: the average number of running threads
95  * @nr_running[]: current number of running threads of each core
96  * @runnable_load[]: the runnable load of each core
97  * @busy_cpu: the number of busy cpu
98  * @avg_load: the average load of all CPUs
99  * @avg_runnable_load: the average runnable load of all CPUs
100  * @avg_thread_load: the Per-thread load
101  * @avg_thread_runnable_load: the Per-thread runnable load
102  */
103 struct pass_cpu_stats {
104         int64_t time;
105         unsigned int freq;
106         unsigned int freq_new;
107         unsigned int nr_runnings;
108
109         unsigned int *load;
110         unsigned int *nr_running;
111         unsigned int *runnable_load;
112
113         unsigned int num_busy_cpu;
114         unsigned int avg_load;
115         unsigned int avg_runnable_load;
116         unsigned int avg_thread_load;
117         unsigned int avg_thread_runnable_load;
118 };
119
120 /******************************************************
121  *                   PASS interface             *
122  ******************************************************/
123 struct pass_level_condition {
124         int freq;
125         int nr_running;
126         int busy_cpu;
127         int avg_load;
128 };
129
130 struct pass_table {
131         /* Constraints condition for powersaving */
132         int limit_max_freq;
133         int limit_max_cpu;
134
135         /* Governor timer's timeout for each pass level */
136         double gov_timeout;
137
138         /* Condition to determine up/down of pass level */
139         struct pass_level_condition comm_cond;
140         struct pass_level_condition up_cond[PASS_LEVEL_COND_MAX];
141         struct pass_level_condition down_cond[PASS_LEVEL_COND_MAX];
142         struct pass_level_condition left_cond[PASS_LEVEL_COND_MAX];
143         struct pass_level_condition right_cond[PASS_LEVEL_COND_MAX];
144         int num_up_cond;
145         int num_down_cond;
146         int num_left_cond;
147         int num_right_cond;
148 };
149
150 /*
151  * struct pass_hotplug - store information of cpu hotplug
152  * @max_online: the possible maximum number of online cpu
153  * @online: the current number of online cpu
154  * @sequence: the sequence to turn on/off cpu
155  */
156 struct pass_hotplug {
157         char name[PASS_NAME_LEN];
158         unsigned int max_online;
159         unsigned int online;
160         unsigned int *sequence;
161         int (*governor)(struct pass_policy *);
162 };
163
164
165 struct pass_cpufreq_policy {
166         unsigned int max_freq;
167         unsigned int num_nr_cpus;
168         unsigned int sampling_rate;
169         unsigned int up_threshold;
170 };
171
172 struct pass_busfreq_policy {
173         /* TODO */
174 };
175
176 struct pass_gpufreq_policy {
177         /* TODO */
178 };
179
180 struct pass_scenario {
181         char name[PASS_NAME_LEN];
182         enum pass_state state;
183         enum pass_state locked;
184         int64_t locked_time;
185
186         unsigned int cpufreq_min_level;
187         unsigned int cpufreq_max_level;
188
189         unsigned int busfreq_min_level;
190         unsigned int busfreq_max_level;
191
192         unsigned int gpufreq_min_level;
193         unsigned int gpufreq_max_level;
194 };
195
196 struct pass_scenario_policy {
197         enum pass_state state;
198         unsigned int num_scenarios;
199
200         struct pass_scenario *list;
201 };
202
203 /*
204  * struct pass_policy
205  */
206 struct pass_policy {
207         enum pass_state state;
208         enum pass_gov_type gov_type;
209         enum pass_gov_state gov_state;
210         unsigned int pass_cpu_threshold;
211         unsigned int up_threshold;
212         unsigned int down_threshold;
213
214         unsigned int init_level;
215         unsigned int prev_level;
216         unsigned int curr_level;
217         unsigned int min_level;
218         unsigned int max_level;
219
220         unsigned int default_min_level;
221         unsigned int default_max_level;
222
223         unsigned int num_levels;
224         unsigned int level_up_threshold;
225
226         struct pass_cpufreq_policy cpufreq;
227         struct pass_busfreq_policy busfreq;
228         struct pass_gpufreq_policy gpufreq;
229         struct pass_scenario_policy scenario;
230
231         struct pass_table *pass_table;
232         struct pass_cpu_stats *pass_cpu_stats;
233         int num_pass_cpu_stats;
234
235         struct pass_governor *governor;
236         double gov_timeout;
237         struct pass_hotplug *hotplug;
238 };
239 #endif /* __pass__ */