Re: [PATCH RT v3 3/5] sched: migrate_dis/enable: Use rt_invol_sleep

Scott Wood
2019-09-24T13:54:11Z

On Tue, 2019-09-24 at 13:21 +0200, Sebastian Andrzej Siewior wrote:
> On 2019-09-23 19:52:33 [+0200], To Scott Wood wrote:
>
> I made dis:
>
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index 885a195dfbe02..25afa2bb1a2cf 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -308,7 +308,9 @@ void pin_current_cpu(void)
> preempt_lazy_enable();
> preempt_enable();
>
> + sleeping_lock_inc();
> __read_rt_lock(cpuhp_pin);
> + sleeping_lock_dec();
>
> preempt_disable();
> preempt_lazy_disable();
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index e1bdd7f9be054..63a6420d01053 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7388,6 +7388,7 @@ void migrate_enable(void)
>
> WARN_ON(smp_processor_id() != task_cpu(p));
> if (!cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) {
> + struct task_struct *self = current;
> const struct cpumask *cpu_valid_mask =
> cpu_active_mask;
> struct migration_arg arg;
> unsigned int dest_cpu;
> @@ -7405,7 +7406,21 @@ void migrate_enable(void)
> unpin_current_cpu();
> preempt_lazy_enable();
> preempt_enable();
> + rt_invol_sleep_inc();
> +
> + raw_spin_lock_irq(&self->pi_lock);
> + self->saved_state = self->state;
> + __set_current_state_no_track(TASK_RUNNING);
> + raw_spin_unlock_irq(&self->pi_lock);
> +
> stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
> +
> + raw_spin_lock_irq(&self->pi_lock);
> + __set_current_state_no_track(self->saved_state);
> + self->saved_state = TASK_RUNNING;
> + raw_spin_unlock_irq(&self->pi_lock);
> +
> + rt_invol_sleep_dec();
> return;
> }
> }
>
> I think we need to preserve the current state, otherwise we will lose
> anything != TASK_RUNNING here. So the spin_lock() would preserve it
> while waiting but the migrate_enable() will lose it if it needs to
> change the CPU at the end.
> I will try to prepare all commits for the next release before I release
> so you can have a look first and yell if needed.

As I pointed out in the "[PATCH RT 6/8] sched: migrate_enable: Set state to
TASK_RUNNING" discussion, we can get here inside the rtmutex code (e.g. from
debug_rt_mutex_print_deadlock) where saved_state is already holding
something -- plus, the waker won't have WF_LOCK_SLEEPER and therefore
saved_state will get cleared anyway.

-Scott