Re: [PATCH 7/9] sched: Add migrate_disable()

From: Peter Zijlstra
Date: Thu Sep 24 2020 - 08:35:46 EST


On Thu, Sep 24, 2020 at 12:53:25PM +0100, Valentin Schneider wrote:
> > @@ -1830,8 +1892,19 @@ static int migration_cpu_stop(void *data
> > */
> > void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask, u32 flags)
> > {
> > - cpumask_copy(&p->cpus_mask, new_mask);
> > - p->nr_cpus_allowed = cpumask_weight(new_mask);
> > + if (flags & SCA_MIGRATE_DISABLE) {
> > + p->cpus_ptr = new_mask;
> > + p->nr_cpus_allowed = 1;
> > + return;
> > + }
> > +
> > + if (flags & SCA_MIGRATE_ENABLE)
> > + p->cpus_ptr = &p->cpus_mask;
>
> There's that check in __set_cpus_allowed_ptr() that new_mask *must* be
> p->cpus_mask when SCA_MIGRATE_ENABLE; that means we could mayhaps shuffle
> that to:
>
> ---
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7cb13df48366..e0e4e42c5e32 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1892,18 +1892,14 @@ static int migration_cpu_stop(void *data)
> */
> void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask, u32 flags)
> {
> + if (flags & (SCA_MIGRATE_DISABLE | SCA_MIGRATE_ENABLE))
> p->cpus_ptr = new_mask;
> else
> cpumask_copy(&p->cpus_mask, new_mask);
>
> + if (flags & SCA_MIGRATE_DISABLE)
> + p->nr_cpus_allowed = 1;
> + else if (p->cpus_ptr == &p->cpus_mask)
> p->nr_cpus_allowed = cpumask_weight(p->cpus_ptr);
> }

I'm thinking we should let nr_cpus_allowed reflect ->cpus_mask
unconditionally. See these emails:

https://lkml.kernel.org/r/20200923170809.GY1362448@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
https://lkml.kernel.org/r/20200924082717.GA1362448@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Basically we want to keep migrate_disable() tasks elegible for
migration/PULL.

But yes, I think that function can be simplified.