2006-06-27 09:54:53 +00:00
|
|
|
/*
|
|
|
|
* RT Mutexes: blocking mutual exclusion locks with PI support
|
|
|
|
*
|
|
|
|
* started by Ingo Molnar and Thomas Gleixner:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
|
|
|
|
* Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
|
|
|
|
*
|
|
|
|
* This file contains the public data structure and API definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_RT_MUTEX_H
|
|
|
|
#define __LINUX_RT_MUTEX_H
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
rtmutex: Turn the plist into an rb-tree
Turn the pi-chains from plist to rb-tree, in the rt_mutex code,
and provide a proper comparison function for -deadline and
-priority tasks.
This is done mainly because:
- classical prio field of the plist is just an int, which might
not be enough for representing a deadline;
- manipulating such a list would become O(nr_deadline_tasks),
which might be to much, as the number of -deadline task increases.
Therefore, an rb-tree is used, and tasks are queued in it according
to the following logic:
- among two -priority (i.e., SCHED_BATCH/OTHER/RR/FIFO) tasks, the
one with the higher (lower, actually!) prio wins;
- among a -priority and a -deadline task, the latter always wins;
- among two -deadline tasks, the one with the earliest deadline
wins.
Queueing and dequeueing functions are changed accordingly, for both
the list of a task's pi-waiters and the list of tasks blocked on
a pi-lock.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Dario Faggioli <raistlin@linux.it>
Signed-off-by: Juri Lelli <juri.lelli@gmail.com>
Signed-off-again-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1383831828-15501-10-git-send-email-juri.lelli@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2013-11-07 13:43:43 +00:00
|
|
|
#include <linux/rbtree.h>
|
2006-06-27 09:54:53 +00:00
|
|
|
#include <linux/spinlock_types.h>
|
|
|
|
|
2010-03-10 23:24:09 +00:00
|
|
|
extern int max_lock_depth; /* for sysctl */
|
|
|
|
|
2007-01-26 08:57:09 +00:00
|
|
|
/**
|
2006-06-27 09:54:53 +00:00
|
|
|
* The rt_mutex structure
|
|
|
|
*
|
|
|
|
* @wait_lock: spinlock to protect the structure
|
2017-09-08 23:15:01 +00:00
|
|
|
* @waiters: rbtree root to enqueue waiters in priority order;
|
|
|
|
* caches top-waiter (leftmost node).
|
2006-06-27 09:54:53 +00:00
|
|
|
* @owner: the mutex owner
|
|
|
|
*/
|
|
|
|
struct rt_mutex {
|
2009-11-17 17:22:11 +00:00
|
|
|
raw_spinlock_t wait_lock;
|
2017-09-08 23:15:01 +00:00
|
|
|
struct rb_root_cached waiters;
|
2006-06-27 09:54:53 +00:00
|
|
|
struct task_struct *owner;
|
|
|
|
#ifdef CONFIG_DEBUG_RT_MUTEXES
|
|
|
|
int save_state;
|
2017-09-08 23:15:01 +00:00
|
|
|
const char *name, *file;
|
2006-06-27 09:54:53 +00:00
|
|
|
int line;
|
|
|
|
void *magic;
|
|
|
|
#endif
|
2016-09-19 10:15:37 +00:00
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
struct lockdep_map dep_map;
|
|
|
|
#endif
|
2006-06-27 09:54:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rt_mutex_waiter;
|
|
|
|
struct hrtimer_sleeper;
|
|
|
|
|
2006-06-27 09:54:55 +00:00
|
|
|
#ifdef CONFIG_DEBUG_RT_MUTEXES
|
|
|
|
extern int rt_mutex_debug_check_no_locks_freed(const void *from,
|
|
|
|
unsigned long len);
|
|
|
|
extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task);
|
|
|
|
#else
|
|
|
|
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)
|
|
|
|
#endif
|
|
|
|
|
2006-06-27 09:54:53 +00:00
|
|
|
#ifdef CONFIG_DEBUG_RT_MUTEXES
|
|
|
|
# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
|
|
|
|
, .name = #mutexname, .file = __FILE__, .line = __LINE__
|
2016-09-19 10:15:37 +00:00
|
|
|
|
|
|
|
# define rt_mutex_init(mutex) \
|
|
|
|
do { \
|
|
|
|
static struct lock_class_key __key; \
|
|
|
|
__rt_mutex_init(mutex, __func__, &__key); \
|
|
|
|
} while (0)
|
|
|
|
|
2006-06-27 09:54:53 +00:00
|
|
|
extern void rt_mutex_debug_task_free(struct task_struct *tsk);
|
|
|
|
#else
|
|
|
|
# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
|
2016-09-19 10:15:37 +00:00
|
|
|
# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL, NULL)
|
2006-06-27 09:54:55 +00:00
|
|
|
# define rt_mutex_debug_task_free(t) do { } while (0)
|
2006-06-27 09:54:53 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-19 10:15:37 +00:00
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
|
|
|
|
, .dep_map = { .name = #mutexname }
|
|
|
|
#else
|
|
|
|
#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
|
|
|
|
#endif
|
|
|
|
|
2006-06-27 09:54:53 +00:00
|
|
|
#define __RT_MUTEX_INITIALIZER(mutexname) \
|
2009-11-17 17:22:11 +00:00
|
|
|
{ .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
|
2017-09-08 23:15:01 +00:00
|
|
|
, .waiters = RB_ROOT_CACHED \
|
2006-06-27 09:54:53 +00:00
|
|
|
, .owner = NULL \
|
2016-09-19 10:15:37 +00:00
|
|
|
__DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
|
|
|
|
__DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)}
|
2006-06-27 09:54:53 +00:00
|
|
|
|
|
|
|
#define DEFINE_RT_MUTEX(mutexname) \
|
|
|
|
struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
|
|
|
|
|
2007-01-26 08:57:09 +00:00
|
|
|
/**
|
2006-06-27 09:54:53 +00:00
|
|
|
* rt_mutex_is_locked - is the mutex locked
|
|
|
|
* @lock: the mutex to be queried
|
|
|
|
*
|
|
|
|
* Returns 1 if the mutex is locked, 0 if unlocked.
|
|
|
|
*/
|
|
|
|
static inline int rt_mutex_is_locked(struct rt_mutex *lock)
|
|
|
|
{
|
|
|
|
return lock->owner != NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-19 10:15:37 +00:00
|
|
|
extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
|
2006-06-27 09:54:53 +00:00
|
|
|
extern void rt_mutex_destroy(struct rt_mutex *lock);
|
|
|
|
|
|
|
|
extern void rt_mutex_lock(struct rt_mutex *lock);
|
2014-05-22 03:25:50 +00:00
|
|
|
extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
|
2006-06-27 09:54:53 +00:00
|
|
|
extern int rt_mutex_timed_lock(struct rt_mutex *lock,
|
2014-05-22 03:25:50 +00:00
|
|
|
struct hrtimer_sleeper *timeout);
|
2006-06-27 09:54:53 +00:00
|
|
|
|
|
|
|
extern int rt_mutex_trylock(struct rt_mutex *lock);
|
|
|
|
|
|
|
|
extern void rt_mutex_unlock(struct rt_mutex *lock);
|
|
|
|
|
|
|
|
#endif
|