sched: Add group_misfit_task load-balance type
authorMorten Rasmussen <morten.rasmussen@arm.com>
Fri, 17 Jul 2015 15:45:07 +0000 (16:45 +0100)
committerLukasz Luba <l.luba@partner.samsung.com>
Mon, 10 Sep 2018 08:20:12 +0000 (10:20 +0200)
To maximize throughput in systems with asymmetric cpu capacities (e.g.
high RT/IRQ load and/or ARM big.LITTLE) load-balancing has to consider
task and cpu utilization as well as per-cpu compute capacity when
load-balancing in addition to the current average load based
load-balancing policy. Tasks that are scheduled on a lower capacity
cpu need to be identified and migrated to a higher capacity cpu if
possible to maximize throughput.

To implement this additional policy an additional group_type
(load-balance scenario) is added: group_misfit_task. This represents
scenarios where a sched_group has one or more tasks that are not
suitable for its per-cpu capacity. group_misfit_task is only considered
if the system is not overloaded in any other way (group_imbalanced or
group_overloaded).

Identifying misfit tasks requires the rq lock to be held. To avoid
taking remote rq locks to examine source sched_groups for misfit tasks,
each cpu is responsible for tracking misfit tasks themselves and update
the rq->misfit_task flag. This means checking task utilization when
tasks are scheduled and on sched_tick.

cc: Ingo Molnar <mingo@redhat.com>
cc: Peter Zijlstra <peterz@infradead.org>

Signed-off-by: Morten Rasmussen <morten.rasmussen@arm.com>
Signed-off-by: Lukasz Luba <l.luba@partner.samsung.com>
kernel/sched/fair.c
kernel/sched/sched.h

index 03151768c641c10d50860ad3159f0826fd473874..730d82418f3f7d23ab8ce4943519dc7964adc86d 100644 (file)
@@ -6234,6 +6234,11 @@ static int cpu_util_wake(int cpu, struct task_struct *p)
        return (util >= capacity) ? capacity : util;
 }
 
+static inline int task_fits_capacity(struct task_struct *p, long capacity)
+{
+       return capacity * 1024 > task_util(p) * capacity_margin;
+}
+
 /*
  * Disable WAKE_AFFINE in the case where task @p doesn't fit in the
  * capacity of either the waking CPU @cpu or the previous CPU @prev_cpu.
@@ -6255,7 +6260,7 @@ static int wake_cap(struct task_struct *p, int cpu, int prev_cpu)
        /* Bring task utilization in sync with prev_cpu */
        sync_entity_load_avg(&p->se);
 
-       return min_cap * 1024 < task_util(p) * capacity_margin;
+       return task_fits_capacity(p, min_cap);
 }
 
 static bool cpu_overutilized(int cpu)
@@ -6690,9 +6695,12 @@ done: __maybe_unused
        if (hrtick_enabled(rq))
                hrtick_start_fair(rq, p);
 
+       rq->misfit_task = !task_fits_capacity(p, capacity_of(rq->cpu));
+
        return p;
 
 idle:
+       rq->misfit_task = 0;
        new_tasks = idle_balance(rq, rf);
 
        /*
@@ -6898,6 +6906,13 @@ static unsigned long __read_mostly max_load_balance_interval = HZ/10;
 
 enum fbq_type { regular, remote, all };
 
+enum group_type {
+       group_other = 0,
+       group_misfit_task,
+       group_imbalanced,
+       group_overloaded,
+};
+
 #define LBF_ALL_PINNED 0x01
 #define LBF_NEED_BREAK 0x02
 #define LBF_DST_PINNED  0x04
@@ -7411,12 +7426,6 @@ static unsigned long task_h_load(struct task_struct *p)
 
 /********** Helpers for find_busiest_group ************************/
 
-enum group_type {
-       group_other = 0,
-       group_imbalanced,
-       group_overloaded,
-};
-
 /*
  * sg_lb_stats - stats of a sched_group required for load_balancing
  */
@@ -7432,6 +7441,7 @@ struct sg_lb_stats {
        unsigned int group_weight;
        enum group_type group_type;
        int group_no_capacity;
+       int group_misfit_task; /* A cpu has a task too big for its capacity */
 #ifdef CONFIG_NUMA_BALANCING
        unsigned int nr_numa_running;
        unsigned int nr_preferred_running;
@@ -7731,6 +7741,9 @@ group_type group_classify(struct sched_group *group,
        if (sg_imbalanced(group))
                return group_imbalanced;
 
+       if (sgs->group_misfit_task)
+               return group_misfit_task;
+
        return group_other;
 }
 
@@ -7780,6 +7793,10 @@ static inline void update_sg_lb_stats(struct lb_env *env,
                 */
                if (!nr_running && idle_cpu(i))
                        sgs->idle_cpus++;
+
+               if (env->sd->flags & SD_ASYM_CPUCAPACITY &&
+                   !sgs->group_misfit_task && rq->misfit_task)
+                       sgs->group_misfit_task = capacity_of(i);
        }
 
        /* Adjust by relative CPU capacity of the group */
@@ -9404,6 +9421,8 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
 
        if (static_branch_unlikely(&sched_numa_balancing))
                task_tick_numa(rq, curr);
+
+       rq->misfit_task = !task_fits_capacity(curr, capacity_of(rq->cpu));
 }
 
 /*
index f7d562e106ea344e7cef0aa97a9c7b600b2d0f60..e0048c2d8fa6d859e94e4ad0f244523342a2cee7 100644 (file)
@@ -747,6 +747,8 @@ struct rq {
        struct callback_head *balance_callback;
 
        unsigned char idle_balance;
+
+       unsigned int misfit_task;
        /* For active balancing */
        int active_balance;
        int push_cpu;