From patchwork Mon May 29 21:03:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 100685 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp497963qge; Mon, 29 May 2017 14:18:40 -0700 (PDT) X-Received: by 10.99.113.6 with SMTP id m6mr20652382pgc.188.1496092720219; Mon, 29 May 2017 14:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496092720; cv=none; d=google.com; s=arc-20160816; b=mIpe/sGzwJFDlFD3+Kw9FrUQ7kxROvmGO7Bv8d+RuT6kngjckugGDKZ3dPWFbbPUHf allfSCqwCGLjykDF+qbkYkvm6u+MVwKk2+4hl1CgM9nkaCr7OzW3VfoG9ch9e1Gbwbk1 RFThy9NuWw9DYALbIL3z+vEzf8I9Ke1ERZJgmvMNDE5VZ7L6QdgaJvjhrWRYPLoQJyvw lENG5ujPvPsSCru/M4c6lzt5RwaAR5PwdYtlimc0IsGFwQL0emdaOPtDKFxveGWCqIDg 8qDb5FtL8JNuQ4PpvVMju9ZJTkjS70eDPFBJSxcIVAC3rwYb+O4jHlOyC7aADMj7JSQD /xOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=h941sO6GqJGcEch5q3hyFjxyHqXPvgSndWS8aFPeOqk=; b=bm0myAQgm8yR6HgLuGXEhefQYYZsTFhE+GbWmavrvxp6SgsOSXFL6pOnMiBx/gFQyU Sd+CRr6Dk7/1eDz/4nU6OsujfMoS3ZFFYGBzAW9Qlb+amV3aAVraPrbFM+l55auao6PL iG9F6wgtmj6RLQAJc6GZJ7+6GqfRRvu8o4pSW9lNygKcz7dRM3yiCSCVz/c/LEjqaN3b lZsEz24rPGimTH02TuRC/gRCj/ZVGqPSvw0ezKQGBDCqXApO/61HXgSB3v1bKniMNQ5t zW8vrcI2x5MmwnQu9bNRLYkv4sySgujB9SBwCIEbgRKvhi7MWN+sPL1HVeNmd5f+H13s Duhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c75si11400563pfe.281.2017.05.29.14.18.39; Mon, 29 May 2017 14:18:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751289AbdE2VSY (ORCPT + 25 others); Mon, 29 May 2017 17:18:24 -0400 Received: from alt13.smtp-out.videotron.ca ([135.19.0.26]:14648 "EHLO alt12.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751058AbdE2VSV (ORCPT ); Mon, 29 May 2017 17:18:21 -0400 X-Greylist: delayed 910 seconds by postgrey-1.27 at vger.kernel.org; Mon, 29 May 2017 17:18:21 EDT Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id FRojdYOZBHh2dFRokdM179; Mon, 29 May 2017 17:03:10 -0400 X-Authority-Analysis: v=2.1 cv=Lv0ysipc c=1 sm=1 tr=0 a=keA3yYpnlypCNW5BNWqu+w==:117 a=keA3yYpnlypCNW5BNWqu+w==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=tJ8p9aeEuA8A:10 a=KKAkSRfTAAAA:8 a=q6nQrmvF2vcxgBNYUgcA:9 a=cvBusfyB2V15izCimMoJ:22 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id E61F22DA06E6; Mon, 29 May 2017 17:03:07 -0400 (EDT) From: Nicolas Pitre To: Ingo Molnar , Peter Zijlstra Cc: linux-kernel@vger.kernel.org Subject: [PATCH 7/7] rtmutex: compatibility with CONFIG_SCHED_RT=n Date: Mon, 29 May 2017 17:03:02 -0400 Message-Id: <20170529210302.26868-8-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170529210302.26868-1-nicolas.pitre@linaro.org> References: <20170529210302.26868-1-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfM49yb3LMlFfOArgvD9gEvpVi3eHzSvSMe3whRUChUOS5/48Equ164SuZlIfU84P4IRcFSmiOG5ZH5Td8zpQI0MiW4CFovpidB+J8ID4Y7qOgebpPY4c GU4M7PZnGvakMg3+PSlG6NClWgYa0tUkU1gkQLadnSeddanHps/8A9O0j+7v8ErXmBNtuUkRkDpzoy2ika2dgviJx4GH8uCM1dRCyZUoRpOfoInwsvnL7ZLd Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With no actual RT task, there is no priority inversion issues to care about. We can therefore map RT mutexes to regular mutexes in that case and remain compatible with most users. Signed-off-by: Nicolas Pitre --- include/linux/rtmutex.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ kernel/locking/Makefile | 2 ++ lib/Kconfig.debug | 2 +- 3 files changed, 72 insertions(+), 1 deletion(-) -- 2.9.4 diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 1abba5ce2a..05c444f930 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -12,6 +12,8 @@ #ifndef __LINUX_RT_MUTEX_H #define __LINUX_RT_MUTEX_H +#ifdef CONFIG_SCHED_RT + #include #include #include @@ -98,4 +100,71 @@ extern int rt_mutex_trylock(struct rt_mutex *lock); extern void rt_mutex_unlock(struct rt_mutex *lock); +#else /* CONFIG_SCHED_RT */ + +/* + * We have no realtime task support and therefore no priority inversion + * may occur. Let's map RT mutexes using regular mutexes. + */ + +#include + +struct rt_mutex { + struct mutex m; +}; + +#define __RT_MUTEX_INITIALIZER(m) \ + { .m = __MUTEX_INITIALIZER(m) } + +#define DEFINE_RT_MUTEX(mutexname) \ + struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) + +static inline void __rt_mutex_init(struct rt_mutex *lock, const char *name) +{ + static struct lock_class_key __key; + __mutex_init(&lock->m, name, &__key); +} + +#define rt_mutex_init(mutex) __rt_mutex_init(mutex, #mutex) + +static inline int rt_mutex_is_locked(struct rt_mutex *lock) +{ + return mutex_is_locked(&lock->m); +} + +static inline void rt_mutex_destroy(struct rt_mutex *lock) +{ + mutex_destroy(&lock->m); +} + +static inline void rt_mutex_lock(struct rt_mutex *lock) +{ + mutex_lock(&lock->m); +} + +static inline int rt_mutex_lock_interruptible(struct rt_mutex *lock) +{ + return mutex_lock_interruptible(&lock->m); +} + +static inline int rt_mutex_trylock(struct rt_mutex *lock) +{ + return mutex_trylock(&lock->m); +} + +static inline void rt_mutex_unlock(struct rt_mutex *lock) +{ + mutex_unlock(&lock->m); +} + +static inline int rt_mutex_debug_check_no_locks_freed(const void *from, + unsigned long len) +{ + return 0; +} +#define rt_mutex_debug_check_no_locks_held(task) do { } while (0) +#define rt_mutex_debug_task_free(t) do { } while (0) + +#endif /* CONFIG_SCHED_RT */ + #endif diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile index 760158d9d9..7a076be456 100644 --- a/kernel/locking/Makefile +++ b/kernel/locking/Makefile @@ -20,8 +20,10 @@ obj-$(CONFIG_SMP) += spinlock.o obj-$(CONFIG_LOCK_SPIN_ON_OWNER) += osq_lock.o obj-$(CONFIG_PROVE_LOCKING) += spinlock.o obj-$(CONFIG_QUEUED_SPINLOCKS) += qspinlock.o +ifeq ($(CONFIG_SCHED_RT),y) obj-$(CONFIG_RT_MUTEXES) += rtmutex.o obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o +endif obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index e4587ebe52..0ecc7eb9dc 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1008,7 +1008,7 @@ menu "Lock Debugging (spinlocks, mutexes, etc...)" config DEBUG_RT_MUTEXES bool "RT Mutex debugging, deadlock detection" - depends on DEBUG_KERNEL && RT_MUTEXES + depends on DEBUG_KERNEL && RT_MUTEXES && SCHED_RT help This allows rt mutex semantics violations and rt mutex related deadlocks (lockups) to be detected and reported automatically.