On 2021/3/22 20:56, Peter Zijlstra wrote: > On Mon, Mar 22, 2021 at 08:31:09PM +0800, Li, Aubrey wrote: >> Please let me know if I put cookie match check at the right position >> in task_hot(), if so, I'll obtain some performance data of it. >> >> Thanks, >> -Aubrey >> >> ======================================================= >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 7f2fb08..d4bdcf9 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -1912,6 +1912,13 @@ static void task_numa_find_cpu(struct task_numa_env >> *env, >> if (!cpumask_test_cpu(cpu, env->p->cpus_ptr)) >> continue; >> >> + /* >> + * Skip this cpu if source task's cookie does not match >> + * with CPU's core cookie. >> + */ >> + if (!sched_core_cookie_match(cpu_rq(cpu), env->p)) >> + continue; >> + >> env->dst_cpu = cpu; >> if (task_numa_compare(env, taskimp, groupimp, maymove)) >> break; > > This one might need a little help too, I've not fully considered NUMA > balancing though. > >> @@ -6109,7 +6120,9 @@ static int select_idle_cpu(struct task_struct *p, >> struct sched_domain *sd, int t >> for_each_cpu_wrap(cpu, cpus, target) { >> if (!--nr) >> return -1; >> - if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) >> + >> + if ((available_idle_cpu(cpu) || sched_idle_cpu(cpu)) && >> + sched_cpu_cookie_match(cpu_rq(cpu), p)) >> break; >> } >> > > This doesn't even apply... That code has changed. > >> @@ -7427,6 +7440,14 @@ static int task_hot(struct task_struct *p, struct >> lb_env *env) >> >> if (sysctl_sched_migration_cost == -1) >> return 1; >> + >> + /* >> + * Don't migrate task if the task's cookie does not match >> + * with the destination CPU's core cookie. >> + */ >> + if (!sched_core_cookie_match(cpu_rq(env->dst_cpu), p)) >> + return 1; >> + >> if (sysctl_sched_migration_cost == 0) >> return 0; >> > > Should work I think, but you've put it in a weird spot for breaking up > that sysctl_sched_migration_cost thing. I'd have put it either in front > or after that other SMT thing we have there. >
I did it on purpose. If migration cost is huge, the task should not migrate, no matter the cookie is matched or not. So have to after sysctl_sched_migration_cost == -1. And if migration cost = 0 or delta < migrate cost , the task can be migrated, but before migrate, We need to check whether cookie is matched or not. So before sysctl_sched_migration_cost == 0. Please correct me if I was wrong. Thanks, -Aubrey