summaryrefstree
path: root/kernel/include/linux/ems.h
blob: e9f058e704d4f9ae0f4a1ead5bd49f2c0cde70f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/kobject.h>
#include <linux/sched.h>
#include <linux/plist.h>
#include <linux/sched/idle.h>

struct rq;

enum {
	STATES_FREQ = 0,
	STATES_PMQOS,
	NUM_OF_REQUESTS,
};

#ifdef CONFIG_SCHED_EMS
/*
 * core
 */
extern int
exynos_select_task_rq(struct task_struct *p, int prev_cpu, int sd_flag, int sync, int wakeup, int sch);
extern int ems_can_migrate_task(struct task_struct *p, int dst_cpu);
extern void sysbusy_boost(void);
extern void init_ems(void);


/*
 * init util
 */
extern void post_init_entity_multi_load(struct sched_entity *se, u64 now);


/*
 * energy model
 */
extern void init_sched_energy_table(struct cpumask *cpus, int table_size,
				unsigned long *f_table, unsigned int *v_table,
				int max_f, int min_f);
extern void rebuild_sched_energy_table(struct cpumask *cpus, int clipped_freq,
						int max_freq, int type);
extern void update_capacity(int cpu, bool init);

/*
 * multi load
 */
extern void init_multi_load(struct sched_entity *se);

extern void set_task_rq_multi_load(struct sched_entity *se, struct cfs_rq *prev, struct cfs_rq *next);
extern void update_tg_cfs_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq);
extern int update_cfs_rq_multi_load(u64 now, struct cfs_rq *cfs_rq);
extern void attach_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se);
extern void detach_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se);
extern int update_multi_load_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se);
extern void sync_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se);
extern void remove_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se);
extern void init_cfs_rq_multi_load(struct cfs_rq *cfs_rq);
extern void migrate_entity_multi_load(struct sched_entity *se);

extern void util_est_enqueue_multi_load(struct cfs_rq *cfs_rq, struct task_struct *p);
extern void util_est_dequeue_multi_load(struct cfs_rq *cfs_rq, struct task_struct *p, bool task_sleep);
extern void util_est_update(struct task_struct *p, int prev_util_est, int next_util_est);
extern void set_part_period_start(struct rq *rq);
extern void update_cpu_active_ratio(struct rq *rq, struct task_struct *p, int type);
extern void part_cpu_active_ratio(unsigned long *util, unsigned long *max, int cpu);


/*
 * ontime migration
 */
extern void ontime_migration(void);


/*
 * load balance
 */
extern struct list_head *lb_cfs_tasks(struct rq *rq, int sse);
extern void lb_add_cfs_task(struct rq *rq, struct sched_entity *se);
extern int lb_check_priority(int src_cpu, int dst_cpu);
extern struct list_head *lb_prefer_cfs_tasks(int src_cpu, int dst_cpu);
extern int lb_need_active_balance(enum cpu_idle_type idle,
				struct sched_domain *sd, int src_cpu, int dst_cpu);
extern bool lb_sibling_overutilized(int dst_cpu, struct sched_domain *sd,
					struct cpumask *lb_cpus);
extern bool lbt_overutilized(int cpu, int level, enum cpu_idle_type idle);
extern void update_lbt_overutil(int cpu, unsigned long capacity);
extern void lb_update_misfit_status(struct task_struct *p, struct rq *rq, unsigned long task_h_load);
extern bool need_iss_margin(int src_cpu, int dst_cpu);
extern void set_lbt_overutil_with_migov(int enabled);

/*
 * Core sparing
 */
extern void ecs_update(void);
extern int ecs_is_sparing_cpu(int cpu);
#else /* CONFIG_SCHED_EMS */

/*
 * core
 */
static inline int
exynos_select_task_rq(struct task_struct *p, int prev_cpu, int sd_flag, int sync, int wakeup, int sch)
{
	return -1;
}
static inline int ems_can_migrate_task(struct task_struct *p, int dst_cpu) { return 1; }
static inline void sysbusy_boost(void) { }
static inline void init_ems(void) { }


/*
 * init util
 */
static inline void post_init_entity_multi_load(struct sched_entity *se, u64 now) { }


/*
 * energy model
 */
static inline void init_sched_energy_table(struct cpumask *cpus, int table_size,
				unsigned long *f_table, unsigned int *v_table,
				int max_f, int min_f) { }
static inline void rebuild_sched_energy_table(struct cpumask *cpus, int clipped_freq,
						int max_freq, int type) { }
static inline void update_capacity(int cpu, bool init) { }

/*
 * multi load
 */
static inline void init_multi_load(struct sched_entity *se) { }

static inline void set_task_rq_multi_load(struct sched_entity *se, struct cfs_rq *prev, struct cfs_rq *next) { }
static inline void update_tg_cfs_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) { }
static inline int update_cfs_rq_multi_load(u64 now, struct cfs_rq *cfs_rq) { return 0; }
static inline void attach_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se) { }
static inline void detach_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se) { }
static inline int update_multi_load_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se) { return 0; }
static inline void sync_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se) { }
static inline void remove_entity_multi_load(struct cfs_rq *cfs_rq, struct sched_entity *se) { }
static inline void init_cfs_rq_multi_load(struct cfs_rq *cfs_rq) { }
static inline void migrate_entity_multi_load(struct sched_entity *se) { }

static inline void util_est_enqueue_multi_load(struct cfs_rq *cfs_rq, struct task_struct *p) { }
static inline void util_est_dequeue_multi_load(struct cfs_rq *cfs_rq, struct task_struct *p, bool task_sleep) { }
static inline void util_est_update(struct task_struct *p, int prev_util_est, int next_util_est) { }
static inline void set_part_period_start(struct rq *rq) { }
static inline void update_cpu_active_ratio(struct rq *rq, struct task_struct *p, int type) { }
static inline void part_cpu_active_ratio(unsigned long *util, unsigned long *max, int cpu) { }


/*
 * ontime migration
 */
static inline int ontime_can_migrate_task(struct task_struct *p, int dst_cpu) { return 1; }
static inline void ontime_migration(void) { }


/*
 * load balance
 */
static inline void lb_add_cfs_task(struct rq *rq, struct sched_entity *se) { }
static inline int lb_check_priority(int src_cpu, int dst_cpu)
{
	return 0;
}
static inline struct list_head *lb_prefer_cfs_tasks(int src_cpu, int dst_cpu)
{
	return NULL;
}
#ifdef CONFIG_SMP
static inline int lb_need_active_balance(enum cpu_idle_type idle,
				struct sched_domain *sd, int src_cpu, int dst_cpu)
{
	return 0;
}
static inline bool lb_sibling_overutilized(int dst_cpu, struct sched_domain *sd,
					struct cpumask *lb_cpus)
{
	return true;
}
#endif
static inline bool lbt_overutilized(int cpu, int level)
{
	return false;
}
static inline void update_lbt_overutil(int cpu, unsigned long capacity) { }
static inline void lb_update_misfit_status(struct task_struct *p, struct rq *rq, unsigned long task_h_load) { }
static inline void set_lbt_overutil_with_migov(int enabled) { }

/*
 * Core sparing
 */
static inline void ecs_update(void) { }
static inline int ecs_is_sparing_cpu(int cpu) { return 0; }
#endif /* CONFIG_SCHED_EMS */

/*
 * EMS Tune
 */
struct emstune_mode_request {
	struct plist_node node;
	bool active;
	struct delayed_work work; /* for emstune_update_request_timeout */
	char *func;
	unsigned int line;
};

#if defined(CONFIG_SCHED_EMS) && defined (CONFIG_SCHED_TUNE)
extern void emstune_cpu_update(int cpu, u64 now);
extern unsigned long emstune_freq_boost(int cpu, unsigned long util);

#define emstune_add_request(req)	do {				\
	__emstune_add_request(req, (char *)__func__, __LINE__);	\
} while(0);
extern void __emstune_add_request(struct emstune_mode_request *req, char *func, unsigned int line);
extern void emstune_remove_request(struct emstune_mode_request *req);
extern void emstune_update_request(struct emstune_mode_request *req, s32 new_value);
extern void emstune_update_request_timeout(struct emstune_mode_request *req, s32 new_value,
					unsigned long timeout_us);
extern void emstune_boost(struct emstune_mode_request *req, int enable);
extern void emstune_boost_timeout(struct emstune_mode_request *req, unsigned long timeout_us);

extern void emstune_mode_change(int next_mode_idx);
extern int emstune_get_cur_mode(void);

extern int emstune_register_mode_update_notifier(struct notifier_block *nb);
extern int emstune_unregister_mode_update_notifier(struct notifier_block *nb);

extern int emstune_util_est_group(int st_idx);
#else
static inline void emstune_cpu_update(int cpu, u64 now) { };
static inline unsigned long emstune_freq_boost(int cpu, unsigned long util) { return util; };

#define emstune_add_request(req)	do { } while(0);
static inline void __emstune_add_request(struct emstune_mode_request *req, char *func, unsigned int line) { }
static inline void emstune_remove_request(struct emstune_mode_request *req) { }
static inline void emstune_update_request(struct emstune_mode_request *req, s32 new_value) { }
static inline void emstune_update_request_timeout(struct emstune_mode_request *req, s32 new_value,
					unsigned long timeout_us) { }
static inline void emstune_boost(struct emstune_mode_request *req, int enable) { }
static inline void emstune_boost_timeout(struct emstune_mode_request *req, unsigned long timeout_us) { }

static inline void emstune_mode_change(int next_mode_idx) { }

static inline int emstune_register_mode_update_notifier(struct notifier_block *nb) { return 0; }
static inline int emstune_unregister_mode_update_notifier(struct notifier_block *nb) { return 0; }

static inline int emstune_util_est_group(int st_idx) { return 0; }
#endif /* CONFIG_SCHED_EMS && CONFIG_SCHED_TUNE */

/* Exynos Fluid Real Time Scheduler */
extern unsigned int frt_disable_cpufreq;

#ifdef CONFIG_SCHED_USE_FLUID_RT
extern int frt_find_lowest_rq(struct task_struct *task);
extern int frt_update_rt_rq_load_avg(struct rq *rq);
extern void frt_migrate_task_rq_rt(struct task_struct *p, int new_cpu);
extern void frt_update_load_avg(struct rt_rq *rt_rq, struct sched_rt_entity *se, int flags);
extern void frt_task_change_group_rt(struct task_struct *p, int type);
extern void frt_attach_task_rt_rq(struct task_struct *p);
extern void frt_detach_task_rt_rq(struct task_struct *p);
extern void frt_init_rt_rq_load(struct rt_rq *rt_rq);
extern void frt_update_available_cpus(void);
extern void frt_clear_victim_flag(struct task_struct *p);
extern bool frt_test_victim_flag(struct task_struct *p);
extern void frt_task_dead_rt(struct task_struct *p);
extern void frt_set_task_rq_rt(struct sched_rt_entity *se, struct rt_rq *prev, struct rt_rq *next);
extern void frt_init_entity_runnable_average(struct sched_rt_entity *rt_se);
extern void frt_store_sched_avg(struct task_struct *p, struct sched_avg *sa);
extern void frt_sync_sched_avg(struct task_struct *p, struct sched_avg *sa);
#else
static inline int frt_update_rt_rq_load_avg(struct rq *rq) { return 0; };
static inline int frt_find_lowest_rq(struct task_struct *task) { return -1; };
static inline void frt_migrate_task_rq_rt(struct task_struct *p, int nuew_cpu) { };
#ifndef CONFIG_UML
static inline void frt_update_load_avg(struct rt_rq *rt_rq, struct sched_rt_entity *se, int flags) { };
#else
static inline void frt_update_load_avg(void *rt_rq, struct sched_rt_entity *se, int flags) { };
#endif
static inline void frt_task_change_group_rt(struct task_struct *p, int type) { };
static inline void frt_attach_task_rt_rq(struct task_struct *p) { };
static inline void frt_detach_task_rt_rq(struct task_struct *p) { };
#ifndef CONFIG_UML
static inline void frt_init_rt_rq_load(struct rt_rq *rt_rq) { };
#else
static inline void frt_init_rt_rq_load(void *rt_rq) { };
#endif
static inline void frt_update_available_cpus(void) { };
static inline void frt_clear_victim_flag(struct task_struct *p) { };
static inline bool frt_test_victim_flag(struct task_struct *p) { return false; };
static inline void frt_task_dead_rt(struct task_struct *p) { };
#ifndef CONFIG_UML
static inline void frt_set_task_rq_rt(struct sched_rt_entity *se, struct rt_rq *prev, struct rt_rq *next) { };
#else
static inline void frt_set_task_rq_rt(struct sched_rt_entity *se, void *prev, void *next) { };
#endif
static inline void frt_init_entity_runnable_average(struct sched_rt_entity *rt_se) { }
static inline void frt_store_sched_avg(struct task_struct *p, struct sched_avg *sa) { }
static inline void frt_sync_sched_avg(struct task_struct *p, struct sched_avg *sa) { }
#endif

#ifdef CONFIG_SCHED_PMU_CONT
void update_cont_avg(struct rq *rq, struct task_struct *prev, struct task_struct *next);
#else
static inline void update_cont_avg(struct rq *rq, struct task_struct *prev, struct task_struct *next) { };
#endif

#ifdef CONFIG_CPU_FREQ_GOV_ENERGYSTEP
extern int esg_get_migov_boost(int cpu);
extern void esg_set_migov_boost(int cpu, int boost);
#else
static inline void esg_get_migov_boost(int cpu) { return 0; };
static inline int esg_set_migov_boost(int cpu, int boost) { };
#endif