From 50df5832acea15cbc768e5ee502e4af45c6663c7 Mon Sep 17 00:00:00 2001 From: Daeyeong Lee Date: Tue, 27 Mar 2018 18:46:50 +0900 Subject: [PATCH] [COMMON] sched: ems: New function to check whether task make cpu overutilize The lbt_bring_overutilize function checks whether the CPU will be overutilized at all levels when a task is added to the CPU. Change-Id: Idbeb0f06f65ab7a807d85f4e76fc1fb8931d12f7 Signed-off-by: Daeyeong Lee --- kernel/sched/ems/ems.h | 1 + kernel/sched/ems/lbt.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/kernel/sched/ems/ems.h b/kernel/sched/ems/ems.h index a3cf41e19253..9cf27e760746 100644 --- a/kernel/sched/ems/ems.h +++ b/kernel/sched/ems/ems.h @@ -19,6 +19,7 @@ extern struct kobject *ems_kobj; extern int ontime_task_wakeup(struct task_struct *p); extern int global_boosting(struct task_struct *p); +extern bool lbt_bring_overutilize(int cpu, struct task_struct *p); #ifdef CONFIG_SCHED_TUNE extern int prefer_perf_cpu(struct task_struct *p); diff --git a/kernel/sched/ems/lbt.c b/kernel/sched/ems/lbt.c index 359f51794e21..a2f65f0c1afc 100644 --- a/kernel/sched/ems/lbt.c +++ b/kernel/sched/ems/lbt.c @@ -67,6 +67,30 @@ static inline int get_last_level(struct lbt_overutil *ou) return -1; } +static inline unsigned long task_util(struct task_struct *p) +{ + return p->se.avg.util_avg; +} + +static inline int check_migration_task(struct task_struct *p) +{ + return !p->se.avg.last_update_time; +} + +static inline unsigned long cpu_util_wake(int cpu, struct task_struct *p) +{ + unsigned long util, capacity; + + /* Task has no contribution or is new */ + if (cpu != task_cpu(p) || check_migration_task(p)) + return cpu_util(cpu); + + capacity = capacity_orig_of(cpu); + util = max_t(long, cpu_util(cpu) - task_util(p), 0); + + return (util >= capacity) ? capacity : util; +} + /****************************************************************/ /* External APIs */ /****************************************************************/ @@ -87,6 +111,23 @@ bool lbt_overutilized(int cpu, int level) return overutilized; } +bool lbt_bring_overutilize(int cpu, struct task_struct *p) +{ + struct sched_domain *sd; + struct lbt_overutil *ou = per_cpu(lbt_overutil, cpu); + unsigned long util_sum = cpu_util_wake(cpu, p) + task_util(p); + + if (!ou) + return false; + + for_each_domain(cpu, sd) { + if (util_sum > ou[sd->level].capacity) + return true; + } + + return false; +} + void update_lbt_overutil(int cpu, unsigned long capacity) { struct lbt_overutil *ou = per_cpu(lbt_overutil, cpu); -- 2.20.1