[COMMON] sched: ems: New function to check whether task make cpu overutilize
authorDaeyeong Lee <daeyeong.lee@samsung.com>
Tue, 27 Mar 2018 09:46:50 +0000 (18:46 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:35:26 +0000 (17:35 +0900)
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 <daeyeong.lee@samsung.com>
kernel/sched/ems/ems.h
kernel/sched/ems/lbt.c

index a3cf41e192530ef7e836b67785323f89e66f6189..9cf27e7607460c75d71afdb5e4abc1db5a230c33 100644 (file)
@@ -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);
index 359f51794e216b867ae85df14d2706532579467f..a2f65f0c1afc8cfabe4e67c2bb5018012fb24cfa 100644 (file)
@@ -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);