linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
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	[thread overview]
Message-ID: <20170606232450.30278-8-nicolas.pitre@linaro.org> (raw)
In-Reply-To: <20170606232450.30278-1-nicolas.pitre@linaro.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 <nico@linaro.org>
---
 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 <linux/linkage.h>
 #include <linux/rbtree.h>
 #include <linux/spinlock_types.h>
@@ -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 <linux/mutex.h>
+
+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

  parent reply	other threads:[~2017-06-06 23:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-06 23:24 [PATCH v2 0/8] scheduler tinification Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 1/8] cpuset/sched: cpuset makes sense for SMP only Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 2/8] sched: omit stop_sched_class when !SMP Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 3/8] futex: make PI support optional Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 4/8] sched/deadline: move dl related code out of sched/core.c Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 5/8] sched/rt: move rt " Nicolas Pitre
2017-06-06 23:24 ` [PATCH v2 6/8] sched/deadline: make it configurable Nicolas Pitre
2017-06-06 23:24 ` Nicolas Pitre [this message]
2017-06-06 23:24 ` [PATCH v2 8/8] sched/rt: " Nicolas Pitre
2017-06-07 16:00 ` [PATCH v2 0/8] scheduler tinification Ingo Molnar
2017-06-07 17:09   ` Nicolas Pitre
2017-06-07 18:49     ` Alan Cox
2017-06-07 21:15       ` Nicolas Pitre
2017-06-07 21:53         ` Alan Cox
2017-06-08  7:59     ` Ingo Molnar
2017-06-08 18:14       ` Alan Cox
2017-06-08 20:16       ` Nicolas Pitre
2017-06-11  9:23         ` Ingo Molnar
2017-06-11 15:26           ` Nicolas Pitre
2017-06-11  9:42         ` Ingo Molnar
2017-06-11 16:45           ` Nicolas Pitre
2017-06-13  7:12             ` Ingo Molnar
2017-06-13 12:29               ` Nicolas Pitre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170606232450.30278-8-nicolas.pitre@linaro.org \
    --to=nicolas.pitre@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).