Skip to content

Commit c58d25f

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/fair: Move record_wakee()
Since I want to make ->task_woken() conditional on the task getting migrated, we cannot use it to call record_wakee(). Move it to select_task_rq_fair(), which gets called in almost all the same conditions. The only exception is if the woken task (@p) is CPU-bound (as per the nr_cpus_allowed test in select_task_rq()). Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Hunter <ahh@google.com> Cc: Ben Segall <bsegall@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Mike Galbraith <efault@gmx.de> Cc: Mike Galbraith <umgwanakikbuti@gmail.com> Cc: Morten Rasmussen <morten.rasmussen@arm.com> Cc: Paul Turner <pjt@google.com> Cc: Pavan Kondeti <pkondeti@codeaurora.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: byungchul.park@lge.com Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 4eb8676 commit c58d25f

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

kernel/sched/fair.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,24 +4810,6 @@ static unsigned long cpu_avg_load_per_task(int cpu)
48104810
return 0;
48114811
}
48124812

4813-
static void record_wakee(struct task_struct *p)
4814-
{
4815-
/*
4816-
* Rough decay (wiping) for cost saving, don't worry
4817-
* about the boundary, really active task won't care
4818-
* about the loss.
4819-
*/
4820-
if (time_after(jiffies, current->wakee_flip_decay_ts + HZ)) {
4821-
current->wakee_flips >>= 1;
4822-
current->wakee_flip_decay_ts = jiffies;
4823-
}
4824-
4825-
if (current->last_wakee != p) {
4826-
current->last_wakee = p;
4827-
current->wakee_flips++;
4828-
}
4829-
}
4830-
48314813
static void task_waking_fair(struct task_struct *p)
48324814
{
48334815
struct sched_entity *se = &p->se;
@@ -4847,7 +4829,6 @@ static void task_waking_fair(struct task_struct *p)
48474829
#endif
48484830

48494831
se->vruntime -= min_vruntime;
4850-
record_wakee(p);
48514832
}
48524833

48534834
#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -4965,17 +4946,39 @@ static long effective_load(struct task_group *tg, int cpu, long wl, long wg)
49654946

49664947
#endif
49674948

4949+
static void record_wakee(struct task_struct *p)
4950+
{
4951+
/*
4952+
* Only decay a single time; tasks that have less then 1 wakeup per
4953+
* jiffy will not have built up many flips.
4954+
*/
4955+
if (time_after(jiffies, current->wakee_flip_decay_ts + HZ)) {
4956+
current->wakee_flips >>= 1;
4957+
current->wakee_flip_decay_ts = jiffies;
4958+
}
4959+
4960+
if (current->last_wakee != p) {
4961+
current->last_wakee = p;
4962+
current->wakee_flips++;
4963+
}
4964+
}
4965+
49684966
/*
49694967
* Detect M:N waker/wakee relationships via a switching-frequency heuristic.
4968+
*
49704969
* A waker of many should wake a different task than the one last awakened
4971-
* at a frequency roughly N times higher than one of its wakees. In order
4972-
* to determine whether we should let the load spread vs consolodating to
4973-
* shared cache, we look for a minimum 'flip' frequency of llc_size in one
4974-
* partner, and a factor of lls_size higher frequency in the other. With
4975-
* both conditions met, we can be relatively sure that the relationship is
4976-
* non-monogamous, with partner count exceeding socket size. Waker/wakee
4977-
* being client/server, worker/dispatcher, interrupt source or whatever is
4978-
* irrelevant, spread criteria is apparent partner count exceeds socket size.
4970+
* at a frequency roughly N times higher than one of its wakees.
4971+
*
4972+
* In order to determine whether we should let the load spread vs consolidating
4973+
* to shared cache, we look for a minimum 'flip' frequency of llc_size in one
4974+
* partner, and a factor of lls_size higher frequency in the other.
4975+
*
4976+
* With both conditions met, we can be relatively sure that the relationship is
4977+
* non-monogamous, with partner count exceeding socket size.
4978+
*
4979+
* Waker/wakee being client/server, worker/dispatcher, interrupt source or
4980+
* whatever is irrelevant, spread criteria is apparent partner count exceeds
4981+
* socket size.
49794982
*/
49804983
static int wake_wide(struct task_struct *p)
49814984
{
@@ -5280,8 +5283,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
52805283
int want_affine = 0;
52815284
int sync = wake_flags & WF_SYNC;
52825285

5283-
if (sd_flag & SD_BALANCE_WAKE)
5286+
if (sd_flag & SD_BALANCE_WAKE) {
5287+
record_wakee(p);
52845288
want_affine = !wake_wide(p) && cpumask_test_cpu(cpu, tsk_cpus_allowed(p));
5289+
}
52855290

52865291
rcu_read_lock();
52875292
for_each_domain(cpu, tmp) {

0 commit comments

Comments
 (0)