Re: [patch 26/50] locking/rtmutex: Provide the spin/rwlock core lock function
From: Peter Zijlstra
Date: Wed Jul 14 2021 - 07:00:16 EST
On Tue, Jul 13, 2021 at 05:11:20PM +0200, Thomas Gleixner wrote:
> +/**
> + * rtlock_slowlock_locked - Slow path lock acquisition for RT locks
> + * @lock: The underlying rt mutex
> + */
> +static void __sched rtlock_slowlock_locked(struct rt_mutex *lock)
> +{
> + struct rt_mutex_waiter waiter;
> +
> + lockdep_assert_held(&lock->wait_lock);
> +
> + if (try_to_take_rt_mutex(lock, current, NULL))
> + return;
> +
> + rt_mutex_init_rtlock_waiter(&waiter);
> +
> + /* Save current state and set state to TASK_RTLOCK_WAIT */
> + current_save_and_set_rtlock_wait_state();
> +
> + task_blocks_on_rt_mutex(lock, &waiter, current, RT_MUTEX_MIN_CHAINWALK);
> +
> + for (;;) {
> + /* Try to acquire the lock again. */
> + if (try_to_take_rt_mutex(lock, current, &waiter))
> + break;
> +
> + raw_spin_unlock_irq(&lock->wait_lock);
> +
> + schedule_rtlock();
> +
> + raw_spin_lock_irq(&lock->wait_lock);
> + set_current_state(TASK_RTLOCK_WAIT);
Since both waker and waiter are fully serialized on ->wait_lock, this
can be __set_current_state(), there is no race condition AFAICT.
Might not be worth it though..
> + }
> +
> + /* Restore the task state */
> + current_restore_rtlock_saved_state();
> +
> + /*
> + * try_to_take_rt_mutex() sets the waiter bit unconditionally. We
> + * might have to fix that up:
> + */
> + fixup_rt_mutex_waiters(lock);
> + debug_rt_mutex_free_waiter(&waiter);
> +}