From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 001C0C4338F for ; Wed, 11 Aug 2021 12:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAAFF60FDA for ; Wed, 11 Aug 2021 12:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238436AbhHKMZT (ORCPT ); Wed, 11 Aug 2021 08:25:19 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50646 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238016AbhHKMXc (ORCPT ); Wed, 11 Aug 2021 08:23:32 -0400 Message-ID: <20210811121415.939671868@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628684587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=UhZlfkZHli3kJViY0uXJXqXJyf0hkjx6ZecSBVuLjiI=; b=KnsCG8TBNv9UthkS1NQkO+HMBvpArUsvXwW4dqTrqF9e9DZmYg3ZfdnLdDFWhO9cYWYEu7 tfWbcsUgr6404wzDZPPwf+iBYmFsJEGs/lklUV8+F9PGwPKqaika+SpdQ2S+Vzkc06uYGx vGrzHYAGRH5nImtHNVuP1c0X8SamEmoAVwmr2BcNzDfsLK1rEgwo+vgt3uK4Au2m/FqepE /pTkKZ/FNqUQSO6I/+eUhERTrMtS+ZlhVskwxy+69js9fmY29hy3bflf6HG9LOdGe8JAli rrE0T5wI0cJkFlliqjAblf/tHyyYfe4661wRz2rTywOpqXELzNBCAxG7loqTkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628684587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=UhZlfkZHli3kJViY0uXJXqXJyf0hkjx6ZecSBVuLjiI=; b=s/LiwXzad3F2R1MabW7wn5roJ0xkWoeDnwggIo3OcuElQXXpJyRmMrm/O59DN3PfC2t4KP Fi3nCJSqMWrFd4BQ== From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Steven Rostedt , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , Sebastian Andrzej Siewior , Davidlohr Bueso , Mike Galbraith Subject: [patch V4 30/68] locking/rtmutex: Provide the spin/rwlock core lock function References: <20210811120348.855823694@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Date: Wed, 11 Aug 2021 14:23:07 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner A simplified version of the rtmutex slowlock function which neither handles signals nor timeouts and is careful about preserving the state of the blocked task across the lock operation. Signed-off-by: Thomas Gleixner --- kernel/locking/rtmutex.c | 60 ++++++++++++++++++++++++++++++++++++++++ kernel/locking/rtmutex_common.h | 2 - 2 files changed, 61 insertions(+), 1 deletion(-) --- --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1416,3 +1416,63 @@ static __always_inline int __rt_mutex_lo return rt_mutex_slowlock(lock, state); } #endif /* RT_MUTEX_BUILD_MUTEX */ + +#ifdef RT_MUTEX_BUILD_SPINLOCKS +/* + * Functions required for spin/rw_lock substitution on RT kernels + */ + +/** + * rtlock_slowlock_locked - Slow path lock acquisition for RT locks + * @lock: The underlying rt mutex + */ +static void __sched rtlock_slowlock_locked(struct rt_mutex_base *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); + } + + /* 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); +} + +static __always_inline void __sched rtlock_slowlock(struct rt_mutex_base *lock) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&lock->wait_lock, flags); + rtlock_slowlock_locked(lock); + raw_spin_unlock_irqrestore(&lock->wait_lock, flags); +} + +#endif /* RT_MUTEX_BUILD_SPINLOCKS */ --- a/kernel/locking/rtmutex_common.h +++ b/kernel/locking/rtmutex_common.h @@ -181,7 +181,7 @@ static inline void rt_mutex_init_waiter( waiter->task = NULL; } -static inline void rtlock_init_rtmutex_waiter(struct rt_mutex_waiter *waiter) +static inline void rt_mutex_init_rtlock_waiter(struct rt_mutex_waiter *waiter) { rt_mutex_init_waiter(waiter); waiter->wake_state = TASK_RTLOCK_WAIT;