diff options
author | Pierre Peiffer <pierre.peiffer@bull.net> | 2007-05-09 05:35:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-09 15:30:55 -0400 |
commit | d0aa7a70bf03b9de9e995ab272293be1f7937822 (patch) | |
tree | 194b30b7b8374b946f166996cb99fb95eb3b7819 /kernel/rtmutex.c | |
parent | c19384b5b296905d4988c7c684ff540a0f9d65be (diff) |
futex_requeue_pi optimization
This patch provides the futex_requeue_pi functionality, which allows some
threads waiting on a normal futex to be requeued on the wait-queue of a
PI-futex.
This provides an optimization, already used for (normal) futexes, to be used
with the PI-futexes.
This optimization is currently used by the glibc in pthread_broadcast, when
using "normal" mutexes. With futex_requeue_pi, it can be used with
PRIO_INHERIT mutexes too.
Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Ulrich Drepper <drepper@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/rtmutex.c')
-rw-r--r-- | kernel/rtmutex.c | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c index 180978cb2f75..12879f6c1ec3 100644 --- a/kernel/rtmutex.c +++ b/kernel/rtmutex.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * state. | 56 | * state. |
57 | */ | 57 | */ |
58 | 58 | ||
59 | static void | 59 | void |
60 | rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner, | 60 | rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner, |
61 | unsigned long mask) | 61 | unsigned long mask) |
62 | { | 62 | { |
@@ -81,29 +81,6 @@ static void fixup_rt_mutex_waiters(struct rt_mutex *lock) | |||
81 | } | 81 | } |
82 | 82 | ||
83 | /* | 83 | /* |
84 | * We can speed up the acquire/release, if the architecture | ||
85 | * supports cmpxchg and if there's no debugging state to be set up | ||
86 | */ | ||
87 | #if defined(__HAVE_ARCH_CMPXCHG) && !defined(CONFIG_DEBUG_RT_MUTEXES) | ||
88 | # define rt_mutex_cmpxchg(l,c,n) (cmpxchg(&l->owner, c, n) == c) | ||
89 | static inline void mark_rt_mutex_waiters(struct rt_mutex *lock) | ||
90 | { | ||
91 | unsigned long owner, *p = (unsigned long *) &lock->owner; | ||
92 | |||
93 | do { | ||
94 | owner = *p; | ||
95 | } while (cmpxchg(p, owner, owner | RT_MUTEX_HAS_WAITERS) != owner); | ||
96 | } | ||
97 | #else | ||
98 | # define rt_mutex_cmpxchg(l,c,n) (0) | ||
99 | static inline void mark_rt_mutex_waiters(struct rt_mutex *lock) | ||
100 | { | ||
101 | lock->owner = (struct task_struct *) | ||
102 | ((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS); | ||
103 | } | ||
104 | #endif | ||
105 | |||
106 | /* | ||
107 | * Calculate task priority from the waiter list priority | 84 | * Calculate task priority from the waiter list priority |
108 | * | 85 | * |
109 | * Return task->normal_prio when the waiter list is empty or when | 86 | * Return task->normal_prio when the waiter list is empty or when |
@@ -123,7 +100,7 @@ int rt_mutex_getprio(struct task_struct *task) | |||
123 | * | 100 | * |
124 | * This can be both boosting and unboosting. task->pi_lock must be held. | 101 | * This can be both boosting and unboosting. task->pi_lock must be held. |
125 | */ | 102 | */ |
126 | static void __rt_mutex_adjust_prio(struct task_struct *task) | 103 | void __rt_mutex_adjust_prio(struct task_struct *task) |
127 | { | 104 | { |
128 | int prio = rt_mutex_getprio(task); | 105 | int prio = rt_mutex_getprio(task); |
129 | 106 | ||
@@ -159,11 +136,11 @@ int max_lock_depth = 1024; | |||
159 | * Decreases task's usage by one - may thus free the task. | 136 | * Decreases task's usage by one - may thus free the task. |
160 | * Returns 0 or -EDEADLK. | 137 | * Returns 0 or -EDEADLK. |
161 | */ | 138 | */ |
162 | static int rt_mutex_adjust_prio_chain(struct task_struct *task, | 139 | int rt_mutex_adjust_prio_chain(struct task_struct *task, |
163 | int deadlock_detect, | 140 | int deadlock_detect, |
164 | struct rt_mutex *orig_lock, | 141 | struct rt_mutex *orig_lock, |
165 | struct rt_mutex_waiter *orig_waiter, | 142 | struct rt_mutex_waiter *orig_waiter, |
166 | struct task_struct *top_task) | 143 | struct task_struct *top_task) |
167 | { | 144 | { |
168 | struct rt_mutex *lock; | 145 | struct rt_mutex *lock; |
169 | struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter; | 146 | struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter; |
@@ -524,8 +501,8 @@ static void wakeup_next_waiter(struct rt_mutex *lock) | |||
524 | * | 501 | * |
525 | * Must be called with lock->wait_lock held | 502 | * Must be called with lock->wait_lock held |
526 | */ | 503 | */ |
527 | static void remove_waiter(struct rt_mutex *lock, | 504 | void remove_waiter(struct rt_mutex *lock, |
528 | struct rt_mutex_waiter *waiter) | 505 | struct rt_mutex_waiter *waiter) |
529 | { | 506 | { |
530 | int first = (waiter == rt_mutex_top_waiter(lock)); | 507 | int first = (waiter == rt_mutex_top_waiter(lock)); |
531 | struct task_struct *owner = rt_mutex_owner(lock); | 508 | struct task_struct *owner = rt_mutex_owner(lock); |