diff options
| author | Peter Zijlstra <peterz@infradead.org> | 2013-11-07 08:43:43 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-01-13 07:41:50 -0500 |
| commit | fb00aca474405f4fa8a8519c3179fed722eabd83 (patch) | |
| tree | 8a779629a771dd3340d5a3ba0ba16b732b8de1c8 | |
| parent | af6ace764d03900524e9b1ac621a1c520ee49fc6 (diff) | |
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>
| -rw-r--r-- | include/linux/init_task.h | 10 | ||||
| -rw-r--r-- | include/linux/rtmutex.h | 18 | ||||
| -rw-r--r-- | include/linux/sched.h | 4 | ||||
| -rw-r--r-- | kernel/fork.c | 3 | ||||
| -rw-r--r-- | kernel/futex.c | 2 | ||||
| -rw-r--r-- | kernel/locking/rtmutex-debug.c | 8 | ||||
| -rw-r--r-- | kernel/locking/rtmutex.c | 151 | ||||
| -rw-r--r-- | kernel/locking/rtmutex_common.h | 22 | ||||
| -rw-r--r-- | kernel/sched/core.c | 4 |
9 files changed, 157 insertions, 65 deletions
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index b0ed422e4e4a..f0e52383a001 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <linux/user_namespace.h> | 11 | #include <linux/user_namespace.h> |
| 12 | #include <linux/securebits.h> | 12 | #include <linux/securebits.h> |
| 13 | #include <linux/seqlock.h> | 13 | #include <linux/seqlock.h> |
| 14 | #include <linux/rbtree.h> | ||
| 14 | #include <net/net_namespace.h> | 15 | #include <net/net_namespace.h> |
| 15 | #include <linux/sched/rt.h> | 16 | #include <linux/sched/rt.h> |
| 16 | 17 | ||
| @@ -154,6 +155,14 @@ extern struct task_group root_task_group; | |||
| 154 | 155 | ||
| 155 | #define INIT_TASK_COMM "swapper" | 156 | #define INIT_TASK_COMM "swapper" |
| 156 | 157 | ||
| 158 | #ifdef CONFIG_RT_MUTEXES | ||
| 159 | # define INIT_RT_MUTEXES(tsk) \ | ||
| 160 | .pi_waiters = RB_ROOT, \ | ||
| 161 | .pi_waiters_leftmost = NULL, | ||
| 162 | #else | ||
| 163 | # define INIT_RT_MUTEXES(tsk) | ||
| 164 | #endif | ||
| 165 | |||
| 157 | /* | 166 | /* |
| 158 | * INIT_TASK is used to set up the first task table, touch at | 167 | * INIT_TASK is used to set up the first task table, touch at |
| 159 | * your own risk!. Base=0, limit=0x1fffff (=2MB) | 168 | * your own risk!. Base=0, limit=0x1fffff (=2MB) |
| @@ -221,6 +230,7 @@ extern struct task_group root_task_group; | |||
| 221 | INIT_TRACE_RECURSION \ | 230 | INIT_TRACE_RECURSION \ |
| 222 | INIT_TASK_RCU_PREEMPT(tsk) \ | 231 | INIT_TASK_RCU_PREEMPT(tsk) \ |
| 223 | INIT_CPUSET_SEQ(tsk) \ | 232 | INIT_CPUSET_SEQ(tsk) \ |
| 233 | INIT_RT_MUTEXES(tsk) \ | ||
| 224 | INIT_VTIME(tsk) \ | 234 | INIT_VTIME(tsk) \ |
| 225 | } | 235 | } |
| 226 | 236 | ||
diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index de17134244f3..3aed8d737e1a 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | #define __LINUX_RT_MUTEX_H | 13 | #define __LINUX_RT_MUTEX_H |
| 14 | 14 | ||
| 15 | #include <linux/linkage.h> | 15 | #include <linux/linkage.h> |
| 16 | #include <linux/plist.h> | 16 | #include <linux/rbtree.h> |
| 17 | #include <linux/spinlock_types.h> | 17 | #include <linux/spinlock_types.h> |
| 18 | 18 | ||
| 19 | extern int max_lock_depth; /* for sysctl */ | 19 | extern int max_lock_depth; /* for sysctl */ |
| @@ -22,12 +22,14 @@ extern int max_lock_depth; /* for sysctl */ | |||
| 22 | * The rt_mutex structure | 22 | * The rt_mutex structure |
| 23 | * | 23 | * |
| 24 | * @wait_lock: spinlock to protect the structure | 24 | * @wait_lock: spinlock to protect the structure |
| 25 | * @wait_list: pilist head to enqueue waiters in priority order | 25 | * @waiters: rbtree root to enqueue waiters in priority order |
| 26 | * @waiters_leftmost: top waiter | ||
| 26 | * @owner: the mutex owner | 27 | * @owner: the mutex owner |
| 27 | */ | 28 | */ |
| 28 | struct rt_mutex { | 29 | struct rt_mutex { |
| 29 | raw_spinlock_t wait_lock; | 30 | raw_spinlock_t wait_lock; |
| 30 | struct plist_head wait_list; | 31 | struct rb_root waiters; |
| 32 | struct rb_node *waiters_leftmost; | ||
| 31 | struct task_struct *owner; | 33 | struct task_struct *owner; |
| 32 | #ifdef CONFIG_DEBUG_RT_MUTEXES | 34 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
| 33 | int save_state; | 35 | int save_state; |
| @@ -66,7 +68,7 @@ struct hrtimer_sleeper; | |||
| 66 | 68 | ||
| 67 | #define __RT_MUTEX_INITIALIZER(mutexname) \ | 69 | #define __RT_MUTEX_INITIALIZER(mutexname) \ |
| 68 | { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ | 70 | { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ |
| 69 | , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list) \ | 71 | , .waiters = RB_ROOT \ |
| 70 | , .owner = NULL \ | 72 | , .owner = NULL \ |
| 71 | __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} | 73 | __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} |
| 72 | 74 | ||
| @@ -98,12 +100,4 @@ extern int rt_mutex_trylock(struct rt_mutex *lock); | |||
| 98 | 100 | ||
| 99 | extern void rt_mutex_unlock(struct rt_mutex *lock); | 101 | extern void rt_mutex_unlock(struct rt_mutex *lock); |
| 100 | 102 | ||
| 101 | #ifdef CONFIG_RT_MUTEXES | ||
| 102 | # define INIT_RT_MUTEXES(tsk) \ | ||
| 103 | .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters), \ | ||
| 104 | INIT_RT_MUTEX_DEBUG(tsk) | ||
| 105 | #else | ||
| 106 | # define INIT_RT_MUTEXES(tsk) | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #endif | 103 | #endif |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 158f4c2dd852..9ea15019a5b6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -16,6 +16,7 @@ struct sched_param { | |||
| 16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
| 17 | #include <linux/timex.h> | 17 | #include <linux/timex.h> |
| 18 | #include <linux/jiffies.h> | 18 | #include <linux/jiffies.h> |
| 19 | #include <linux/plist.h> | ||
| 19 | #include <linux/rbtree.h> | 20 | #include <linux/rbtree.h> |
| 20 | #include <linux/thread_info.h> | 21 | #include <linux/thread_info.h> |
| 21 | #include <linux/cpumask.h> | 22 | #include <linux/cpumask.h> |
| @@ -1354,7 +1355,8 @@ struct task_struct { | |||
| 1354 | 1355 | ||
| 1355 | #ifdef CONFIG_RT_MUTEXES | 1356 | #ifdef CONFIG_RT_MUTEXES |
| 1356 | /* PI waiters blocked on a rt_mutex held by this task */ | 1357 | /* PI waiters blocked on a rt_mutex held by this task */ |
| 1357 | struct plist_head pi_waiters; | 1358 | struct rb_root pi_waiters; |
| 1359 | struct rb_node *pi_waiters_leftmost; | ||
| 1358 | /* Deadlock detection and priority inheritance handling */ | 1360 | /* Deadlock detection and priority inheritance handling */ |
| 1359 | struct rt_mutex_waiter *pi_blocked_on; | 1361 | struct rt_mutex_waiter *pi_blocked_on; |
| 1360 | #endif | 1362 | #endif |
diff --git a/kernel/fork.c b/kernel/fork.c index e6c0f1a22914..7049ae526a54 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -1087,7 +1087,8 @@ static void rt_mutex_init_task(struct task_struct *p) | |||
| 1087 | { | 1087 | { |
| 1088 | raw_spin_lock_init(&p->pi_lock); | 1088 | raw_spin_lock_init(&p->pi_lock); |
| 1089 | #ifdef CONFIG_RT_MUTEXES | 1089 | #ifdef CONFIG_RT_MUTEXES |
| 1090 | plist_head_init(&p->pi_waiters); | 1090 | p->pi_waiters = RB_ROOT; |
| 1091 | p->pi_waiters_leftmost = NULL; | ||
| 1091 | p->pi_blocked_on = NULL; | 1092 | p->pi_blocked_on = NULL; |
| 1092 | #endif | 1093 | #endif |
| 1093 | } | 1094 | } |
diff --git a/kernel/futex.c b/kernel/futex.c index f6ff0191ecf7..679531c61d96 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
| @@ -2316,6 +2316,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, | |||
| 2316 | * code while we sleep on uaddr. | 2316 | * code while we sleep on uaddr. |
| 2317 | */ | 2317 | */ |
| 2318 | debug_rt_mutex_init_waiter(&rt_waiter); | 2318 | debug_rt_mutex_init_waiter(&rt_waiter); |
| 2319 | RB_CLEAR_NODE(&rt_waiter.pi_tree_entry); | ||
| 2320 | RB_CLEAR_NODE(&rt_waiter.tree_entry); | ||
| 2319 | rt_waiter.task = NULL; | 2321 | rt_waiter.task = NULL; |
| 2320 | 2322 | ||
| 2321 | ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE); | 2323 | ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE); |
diff --git a/kernel/locking/rtmutex-debug.c b/kernel/locking/rtmutex-debug.c index 13b243a323fa..49b2ed3dced8 100644 --- a/kernel/locking/rtmutex-debug.c +++ b/kernel/locking/rtmutex-debug.c | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | #include <linux/kallsyms.h> | 24 | #include <linux/kallsyms.h> |
| 25 | #include <linux/syscalls.h> | 25 | #include <linux/syscalls.h> |
| 26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/plist.h> | 27 | #include <linux/rbtree.h> |
| 28 | #include <linux/fs.h> | 28 | #include <linux/fs.h> |
| 29 | #include <linux/debug_locks.h> | 29 | #include <linux/debug_locks.h> |
| 30 | 30 | ||
| @@ -57,7 +57,7 @@ static void printk_lock(struct rt_mutex *lock, int print_owner) | |||
| 57 | 57 | ||
| 58 | void rt_mutex_debug_task_free(struct task_struct *task) | 58 | void rt_mutex_debug_task_free(struct task_struct *task) |
| 59 | { | 59 | { |
| 60 | DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters)); | 60 | DEBUG_LOCKS_WARN_ON(!RB_EMPTY_ROOT(&task->pi_waiters)); |
| 61 | DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); | 61 | DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -154,16 +154,12 @@ void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock) | |||
| 154 | void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter) | 154 | void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter) |
| 155 | { | 155 | { |
