From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751581AbdFFXZZ (ORCPT ); Tue, 6 Jun 2017 19:25:25 -0400 Received: from alt42.smtp-out.videotron.ca ([23.233.128.29]:10193 "EHLO alt42.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751454AbdFFXZD (ORCPT ); Tue, 6 Jun 2017 19:25:03 -0400 X-Authority-Analysis: v=2.1 cv=YqOvP9sX 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=LWSFodeU3zMA:10 a=KKAkSRfTAAAA:8 a=-V1JewGKzsJttYLv6mQA:9 a=cvBusfyB2V15izCimMoJ:22 From: Nicolas Pitre To: Ingo Molnar , Peter Zijlstra Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 7/8] rtmutex: compatibility wrappers when no RT support is configured Date: Tue, 6 Jun 2017 19:24:49 -0400 Message-Id: <20170606232450.30278-8-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170606232450.30278-1-nicolas.pitre@linaro.org> References: <20170606232450.30278-1-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfM0/chHqovxu/EbmcMH/lliL2bTWvlybT0m+pnuuA+3z40nVr6mtk/W/KPM4j3guXtXUX86nggXlwNQBGRQlJpJUN1hnv6HfkltjKI6llzQKl4mn0CiR ewOGJHewp84WZ5aR3Jh5Q+qevBhKHeBj1ApTG7pQUcmVsJz7lkzmdHH1LZaaVnKDtaH8SUBpYf/x7CnlbOj/KJNYHZB+aImj67Hl6W3qcs9ZQ9EZq8oFB4hM Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare the code for the next patch making RT task support optional. 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. The code that makes explicit assumptions about actual RT mutexes such as RT mutex debugging and PI futexes will have to be made conditional on the availability of RT task support. This will be done in a later patch when CONFIG_SCHED_RT gets defined. Signed-off-by: Nicolas Pitre --- include/linux/rtmutex.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 1abba5ce2a..01db77a41b 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 +#if 1 /* will become def CONFIG_SCHED_RT later */ + #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 -- 2.9.4