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

From: Scott Wood
Date: Tue Sep 24 2019 - 11:47:42 EST


On Tue, 2019-09-24 at 17:25 +0200, Sebastian Andrzej Siewior wrote:
> On 2019-09-24 08:53:43 [-0500], Scott Wood wrote:
> > 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.
>
> So let me drop the saved_state pieces and get back to it once I get to
> the other thread (which you replied and I didn't realised until now).
>
> Regarding the WF_LOCK_SLEEPER part. I think this works as expected.
> Imagine:
>
> CPU0 CPU1
> spin_lock();
> set_current_state(TASK_UNINTERRUPTIBLE);
> â
> spin_unlock()
> -> migrate_enable();
> -> stop_one_cpu(); <-- A)
> other_func(); <-- B)
> schedule();
>
> So. With only CPU0 we enter schedule() with TASK_UNINTERRUPTIBLE because
> the state gets preserved with the change I added (which is expected).
> If CPU1 sends a wake_up() at A) then the saved_state gets overwritten
> and we enter schedule() with TASK_RUNNING. Same happens if it is sent at
> B) point which is outside of any migrate/spin lock related code.
>
> Was this clear or did I miss the point?

When the stop machine finishes it will do a wake_up_process() via
complete(). Since this does not pass WF_LOCK_SLEEPER, saved_state will be
cleared, and you'll have TASK_RUNNING when you get to other_func() and
schedule(), regardless of whether CPU1 sends wake_up() -- so this change
doesn't actually accomplish anything.

While as noted in the other thread I don't think these spurious wakeups are
a huge problem, we could avoid them by doing stop_one_cpu_nowait() and then
schedule() without messing with task state. Since we're stopping our own
cpu, it should be guaranteed that the stopper has finished by the time we
exit schedule().

-Scott