[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210714105924.GD2591@worktop.programming.kicks-ass.net>
Date: Wed, 14 Jul 2021 12:59:24 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Juri Lelli <juri.lelli@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Daniel Bristot de Oliveira <bristot@...hat.com>,
Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>,
Boqun Feng <boqun.feng@...il.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Davidlohr Bueso <dave@...olabs.net>
Subject: Re: [patch 26/50] locking/rtmutex: Provide the spin/rwlock core lock
function
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);
> +}
Powered by blists - more mailing lists