Skip to content

Commit 3273163

Browse files
msrasmussenIngo Molnar
authored andcommitted
sched/fair: Let asymmetric CPU configurations balance at wake-up
Currently, SD_WAKE_AFFINE always takes priority over wakeup balancing if SD_BALANCE_WAKE is set on the sched_domains. For asymmetric configurations SD_WAKE_AFFINE is only desirable if the waking task's compute demand (utilization) is suitable for the waking CPU and the previous CPU, and all CPUs within their respective SD_SHARE_PKG_RESOURCES domains (sd_llc). If not, let wakeup balancing take over (find_idlest_{group, cpu}()). This patch makes affine wake-ups conditional on whether both the waker CPU and the previous CPU has sufficient capacity for the waking task, or not, assuming that the CPU capacities within an SD_SHARE_PKG_RESOURCES domain (sd_llc) are homogeneous. Signed-off-by: Morten Rasmussen <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Vincent Guittot <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent cd92bfd commit 3273163

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

kernel/sched/fair.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ unsigned int __read_mostly sysctl_sched_shares_window = 10000000UL;
114114
unsigned int sysctl_sched_cfs_bandwidth_slice = 5000UL;
115115
#endif
116116

117+
/*
118+
* The margin used when comparing utilization with CPU capacity:
119+
* util * 1024 < capacity * margin
120+
*/
121+
unsigned int capacity_margin = 1280; /* ~20% */
122+
117123
static inline void update_load_add(struct load_weight *lw, unsigned long inc)
118124
{
119125
lw->weight += inc;
@@ -5376,6 +5382,32 @@ static int cpu_util(int cpu)
53765382
return (util >= capacity) ? capacity : util;
53775383
}
53785384

5385+
static inline int task_util(struct task_struct *p)
5386+
{
5387+
return p->se.avg.util_avg;
5388+
}
5389+
5390+
/*
5391+
* Disable WAKE_AFFINE in the case where task @p doesn't fit in the
5392+
* capacity of either the waking CPU @cpu or the previous CPU @prev_cpu.
5393+
*
5394+
* In that case WAKE_AFFINE doesn't make sense and we'll let
5395+
* BALANCE_WAKE sort things out.
5396+
*/
5397+
static int wake_cap(struct task_struct *p, int cpu, int prev_cpu)
5398+
{
5399+
long min_cap, max_cap;
5400+
5401+
min_cap = min(capacity_orig_of(prev_cpu), capacity_orig_of(cpu));
5402+
max_cap = cpu_rq(cpu)->rd->max_cpu_capacity;
5403+
5404+
/* Minimum capacity is close to max, no need to abort wake_affine */
5405+
if (max_cap - min_cap < max_cap >> 3)
5406+
return 0;
5407+
5408+
return min_cap * 1024 < task_util(p) * capacity_margin;
5409+
}
5410+
53795411
/*
53805412
* select_task_rq_fair: Select target runqueue for the waking task in domains
53815413
* that have the 'sd_flag' flag set. In practice, this is SD_BALANCE_WAKE,
@@ -5399,7 +5431,8 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
53995431

54005432
if (sd_flag & SD_BALANCE_WAKE) {
54015433
record_wakee(p);
5402-
want_affine = !wake_wide(p) && cpumask_test_cpu(cpu, tsk_cpus_allowed(p));
5434+
want_affine = !wake_wide(p) && !wake_cap(p, cpu, prev_cpu)
5435+
&& cpumask_test_cpu(cpu, tsk_cpus_allowed(p));
54035436
}
54045437

54055438
rcu_read_lock();

0 commit comments

Comments
 (0)