/*
 * Copyright (c) 2018 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 "../sched-pelt.h"

#define cpu_selected(cpu)	(cpu >= 0)
#define tsk_cpus_allowed(tsk)	(&(tsk)->cpus_allowed)

extern struct kobject *ems_kobj;

extern int select_service_cpu(struct task_struct *p);
extern int ontime_task_wakeup(struct task_struct *p, int sync);
extern int select_perf_cpu(struct task_struct *p);
extern int global_boosting(struct task_struct *p);
extern int global_boosted(void);
extern int select_energy_cpu(struct task_struct *p, int prev_cpu, int sd_flag, int sync);
extern unsigned int calculate_energy(struct task_struct *p, int target_cpu);
extern int band_play_cpu(struct task_struct *p);
extern int ontime_can_migration(struct task_struct *p, int dst_cpu);

#ifdef CONFIG_SCHED_TUNE
extern int prefer_perf_cpu(struct task_struct *p);
extern int prefer_idle_cpu(struct task_struct *p);
extern int group_balancing(struct task_struct *p);
#else
static inline int prefer_perf_cpu(struct task_struct *p) { return -1; }
static inline int prefer_idle_cpu(struct task_struct *p) { return -1; }
#endif

extern unsigned long cpu_util(int cpu);
extern unsigned long task_util(struct task_struct *p);
extern int cpu_util_wake(int cpu, struct task_struct *p);
extern unsigned long task_util_est(struct task_struct *p);
extern unsigned int get_cpu_mips(unsigned int cpu);
extern unsigned int get_cpu_max_capacity(unsigned int cpu);

extern unsigned long boosted_task_util(struct task_struct *p);

static inline struct task_struct *task_of(struct sched_entity *se)
{
	return container_of(se, struct task_struct, se);
}
