Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * RT-Mutexes: simple blocking mutual exclusion locks with PI support |
| 3 | * |
| 4 | * started by Ingo Molnar and Thomas Gleixner. |
| 5 | * |
| 6 | * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 7 | * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com> |
| 8 | * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt |
| 9 | * Copyright (C) 2006 Esben Nielsen |
Steven Rostedt | d07fe82c2 | 2006-07-30 03:04:03 -0700 | [diff] [blame] | 10 | * |
| 11 | * See Documentation/rt-mutex-design.txt for details. |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 12 | */ |
| 13 | #include <linux/spinlock.h> |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 15 | #include <linux/sched.h> |
Clark Williams | 8bd75c7 | 2013-02-07 09:47:07 -0600 | [diff] [blame] | 16 | #include <linux/sched/rt.h> |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 17 | #include <linux/sched/deadline.h> |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 18 | #include <linux/timer.h> |
| 19 | |
| 20 | #include "rtmutex_common.h" |
| 21 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 22 | /* |
| 23 | * lock->owner state tracking: |
| 24 | * |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 25 | * lock->owner holds the task_struct pointer of the owner. Bit 0 |
| 26 | * is used to keep track of the "lock has waiters" state. |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 27 | * |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 28 | * owner bit0 |
| 29 | * NULL 0 lock is free (fast acquire possible) |
| 30 | * NULL 1 lock is free and has waiters and the top waiter |
| 31 | * is going to take the lock* |
| 32 | * taskpointer 0 lock is held (fast release possible) |
| 33 | * taskpointer 1 lock is held and has waiters** |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 34 | * |
| 35 | * The fast atomic compare exchange based acquire and release is only |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 36 | * possible when bit 0 of lock->owner is 0. |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 37 | * |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 38 | * (*) It also can be a transitional state when grabbing the lock |
| 39 | * with ->wait_lock is held. To prevent any fast path cmpxchg to the lock, |
| 40 | * we need to set the bit0 before looking at the lock, and the owner may be |
| 41 | * NULL in this small time, hence this can be a transitional state. |
| 42 | * |
| 43 | * (**) There is a small time when bit 0 is set but there are no |
| 44 | * waiters. This can happen when grabbing the lock in the slow path. |
| 45 | * To prevent a cmpxchg of the owner releasing the lock, we need to |
| 46 | * set this bit before looking at the lock. |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 47 | */ |
| 48 | |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 49 | static void |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 50 | rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 51 | { |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 52 | unsigned long val = (unsigned long)owner; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 53 | |
| 54 | if (rt_mutex_has_waiters(lock)) |
| 55 | val |= RT_MUTEX_HAS_WAITERS; |
| 56 | |
| 57 | lock->owner = (struct task_struct *)val; |
| 58 | } |
| 59 | |
| 60 | static inline void clear_rt_mutex_waiters(struct rt_mutex *lock) |
| 61 | { |
| 62 | lock->owner = (struct task_struct *) |
| 63 | ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS); |
| 64 | } |
| 65 | |
| 66 | static void fixup_rt_mutex_waiters(struct rt_mutex *lock) |
| 67 | { |
| 68 | if (!rt_mutex_has_waiters(lock)) |
| 69 | clear_rt_mutex_waiters(lock); |
| 70 | } |
| 71 | |
| 72 | /* |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 73 | * We can speed up the acquire/release, if the architecture |
| 74 | * supports cmpxchg and if there's no debugging state to be set up |
| 75 | */ |
| 76 | #if defined(__HAVE_ARCH_CMPXCHG) && !defined(CONFIG_DEBUG_RT_MUTEXES) |
| 77 | # define rt_mutex_cmpxchg(l,c,n) (cmpxchg(&l->owner, c, n) == c) |
| 78 | static inline void mark_rt_mutex_waiters(struct rt_mutex *lock) |
| 79 | { |
| 80 | unsigned long owner, *p = (unsigned long *) &lock->owner; |
| 81 | |
| 82 | do { |
| 83 | owner = *p; |
| 84 | } while (cmpxchg(p, owner, owner | RT_MUTEX_HAS_WAITERS) != owner); |
| 85 | } |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * Safe fastpath aware unlock: |
| 89 | * 1) Clear the waiters bit |
| 90 | * 2) Drop lock->wait_lock |
| 91 | * 3) Try to unlock the lock with cmpxchg |
| 92 | */ |
| 93 | static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock) |
| 94 | __releases(lock->wait_lock) |
| 95 | { |
| 96 | struct task_struct *owner = rt_mutex_owner(lock); |
| 97 | |
| 98 | clear_rt_mutex_waiters(lock); |
| 99 | raw_spin_unlock(&lock->wait_lock); |
| 100 | /* |
| 101 | * If a new waiter comes in between the unlock and the cmpxchg |
| 102 | * we have two situations: |
| 103 | * |
| 104 | * unlock(wait_lock); |
| 105 | * lock(wait_lock); |
| 106 | * cmpxchg(p, owner, 0) == owner |
| 107 | * mark_rt_mutex_waiters(lock); |
| 108 | * acquire(lock); |
| 109 | * or: |
| 110 | * |
| 111 | * unlock(wait_lock); |
| 112 | * lock(wait_lock); |
| 113 | * mark_rt_mutex_waiters(lock); |
| 114 | * |
| 115 | * cmpxchg(p, owner, 0) != owner |
| 116 | * enqueue_waiter(); |
| 117 | * unlock(wait_lock); |
| 118 | * lock(wait_lock); |
| 119 | * wake waiter(); |
| 120 | * unlock(wait_lock); |
| 121 | * lock(wait_lock); |
| 122 | * acquire(lock); |
| 123 | */ |
| 124 | return rt_mutex_cmpxchg(lock, owner, NULL); |
| 125 | } |
| 126 | |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 127 | #else |
| 128 | # define rt_mutex_cmpxchg(l,c,n) (0) |
| 129 | static inline void mark_rt_mutex_waiters(struct rt_mutex *lock) |
| 130 | { |
| 131 | lock->owner = (struct task_struct *) |
| 132 | ((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS); |
| 133 | } |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Simple slow path only version: lock->owner is protected by lock->wait_lock. |
| 137 | */ |
| 138 | static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock) |
| 139 | __releases(lock->wait_lock) |
| 140 | { |
| 141 | lock->owner = NULL; |
| 142 | raw_spin_unlock(&lock->wait_lock); |
| 143 | return true; |
| 144 | } |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 145 | #endif |
| 146 | |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 147 | static inline int |
| 148 | rt_mutex_waiter_less(struct rt_mutex_waiter *left, |
| 149 | struct rt_mutex_waiter *right) |
| 150 | { |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 151 | if (left->prio < right->prio) |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 152 | return 1; |
| 153 | |
| 154 | /* |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 155 | * If both waiters have dl_prio(), we check the deadlines of the |
| 156 | * associated tasks. |
| 157 | * If left waiter has a dl_prio(), and we didn't return 1 above, |
| 158 | * then right waiter has a dl_prio() too. |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 159 | */ |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 160 | if (dl_prio(left->prio)) |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 161 | return (left->task->dl.deadline < right->task->dl.deadline); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter) |
| 168 | { |
| 169 | struct rb_node **link = &lock->waiters.rb_node; |
| 170 | struct rb_node *parent = NULL; |
| 171 | struct rt_mutex_waiter *entry; |
| 172 | int leftmost = 1; |
| 173 | |
| 174 | while (*link) { |
| 175 | parent = *link; |
| 176 | entry = rb_entry(parent, struct rt_mutex_waiter, tree_entry); |
| 177 | if (rt_mutex_waiter_less(waiter, entry)) { |
| 178 | link = &parent->rb_left; |
| 179 | } else { |
| 180 | link = &parent->rb_right; |
| 181 | leftmost = 0; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | if (leftmost) |
| 186 | lock->waiters_leftmost = &waiter->tree_entry; |
| 187 | |
| 188 | rb_link_node(&waiter->tree_entry, parent, link); |
| 189 | rb_insert_color(&waiter->tree_entry, &lock->waiters); |
| 190 | } |
| 191 | |
| 192 | static void |
| 193 | rt_mutex_dequeue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter) |
| 194 | { |
| 195 | if (RB_EMPTY_NODE(&waiter->tree_entry)) |
| 196 | return; |
| 197 | |
| 198 | if (lock->waiters_leftmost == &waiter->tree_entry) |
| 199 | lock->waiters_leftmost = rb_next(&waiter->tree_entry); |
| 200 | |
| 201 | rb_erase(&waiter->tree_entry, &lock->waiters); |
| 202 | RB_CLEAR_NODE(&waiter->tree_entry); |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | rt_mutex_enqueue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter) |
| 207 | { |
| 208 | struct rb_node **link = &task->pi_waiters.rb_node; |
| 209 | struct rb_node *parent = NULL; |
| 210 | struct rt_mutex_waiter *entry; |
| 211 | int leftmost = 1; |
| 212 | |
| 213 | while (*link) { |
| 214 | parent = *link; |
| 215 | entry = rb_entry(parent, struct rt_mutex_waiter, pi_tree_entry); |
| 216 | if (rt_mutex_waiter_less(waiter, entry)) { |
| 217 | link = &parent->rb_left; |
| 218 | } else { |
| 219 | link = &parent->rb_right; |
| 220 | leftmost = 0; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (leftmost) |
| 225 | task->pi_waiters_leftmost = &waiter->pi_tree_entry; |
| 226 | |
| 227 | rb_link_node(&waiter->pi_tree_entry, parent, link); |
| 228 | rb_insert_color(&waiter->pi_tree_entry, &task->pi_waiters); |
| 229 | } |
| 230 | |
| 231 | static void |
| 232 | rt_mutex_dequeue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter) |
| 233 | { |
| 234 | if (RB_EMPTY_NODE(&waiter->pi_tree_entry)) |
| 235 | return; |
| 236 | |
| 237 | if (task->pi_waiters_leftmost == &waiter->pi_tree_entry) |
| 238 | task->pi_waiters_leftmost = rb_next(&waiter->pi_tree_entry); |
| 239 | |
| 240 | rb_erase(&waiter->pi_tree_entry, &task->pi_waiters); |
| 241 | RB_CLEAR_NODE(&waiter->pi_tree_entry); |
| 242 | } |
| 243 | |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 244 | /* |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 245 | * Calculate task priority from the waiter tree priority |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 246 | * |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 247 | * Return task->normal_prio when the waiter tree is empty or when |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 248 | * the waiter is not allowed to do priority boosting |
| 249 | */ |
| 250 | int rt_mutex_getprio(struct task_struct *task) |
| 251 | { |
| 252 | if (likely(!task_has_pi_waiters(task))) |
| 253 | return task->normal_prio; |
| 254 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 255 | return min(task_top_pi_waiter(task)->prio, |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 256 | task->normal_prio); |
| 257 | } |
| 258 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 259 | struct task_struct *rt_mutex_get_top_task(struct task_struct *task) |
| 260 | { |
| 261 | if (likely(!task_has_pi_waiters(task))) |
| 262 | return NULL; |
| 263 | |
| 264 | return task_top_pi_waiter(task)->task; |
| 265 | } |
| 266 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 267 | /* |
Thomas Gleixner | c365c29 | 2014-02-07 20:58:42 +0100 | [diff] [blame] | 268 | * Called by sched_setscheduler() to check whether the priority change |
| 269 | * is overruled by a possible priority boosting. |
| 270 | */ |
| 271 | int rt_mutex_check_prio(struct task_struct *task, int newprio) |
| 272 | { |
| 273 | if (!task_has_pi_waiters(task)) |
| 274 | return 0; |
| 275 | |
| 276 | return task_top_pi_waiter(task)->task->prio <= newprio; |
| 277 | } |
| 278 | |
| 279 | /* |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 280 | * Adjust the priority of a task, after its pi_waiters got modified. |
| 281 | * |
| 282 | * This can be both boosting and unboosting. task->pi_lock must be held. |
| 283 | */ |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 284 | static void __rt_mutex_adjust_prio(struct task_struct *task) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 285 | { |
| 286 | int prio = rt_mutex_getprio(task); |
| 287 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 288 | if (task->prio != prio || dl_prio(prio)) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 289 | rt_mutex_setprio(task, prio); |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Adjust task priority (undo boosting). Called from the exit path of |
| 294 | * rt_mutex_slowunlock() and rt_mutex_slowlock(). |
| 295 | * |
| 296 | * (Note: We do this outside of the protection of lock->wait_lock to |
| 297 | * allow the lock to be taken while or before we readjust the priority |
| 298 | * of task. We do not use the spin_xx_mutex() variants here as we are |
| 299 | * outside of the debug path.) |
| 300 | */ |
| 301 | static void rt_mutex_adjust_prio(struct task_struct *task) |
| 302 | { |
| 303 | unsigned long flags; |
| 304 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 305 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 306 | __rt_mutex_adjust_prio(task); |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 307 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Max number of times we'll walk the boosting chain: |
| 312 | */ |
| 313 | int max_lock_depth = 1024; |
| 314 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 315 | static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p) |
| 316 | { |
| 317 | return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL; |
| 318 | } |
| 319 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 320 | /* |
| 321 | * Adjust the priority chain. Also used for deadlock detection. |
| 322 | * Decreases task's usage by one - may thus free the task. |
Juri Lelli | 0c10617 | 2013-05-15 11:04:10 +0200 | [diff] [blame] | 323 | * |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 324 | * @task: the task owning the mutex (owner) for which a chain walk is |
| 325 | * probably needed |
Juri Lelli | 0c10617 | 2013-05-15 11:04:10 +0200 | [diff] [blame] | 326 | * @deadlock_detect: do we have to carry out deadlock detection? |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 327 | * @orig_lock: the mutex (can be NULL if we are walking the chain to recheck |
| 328 | * things for a task that has just got its priority adjusted, and |
| 329 | * is waiting on a mutex) |
| 330 | * @next_lock: the mutex on which the owner of @orig_lock was blocked before |
| 331 | * we dropped its pi_lock. Is never dereferenced, only used for |
| 332 | * comparison to detect lock chain changes. |
Juri Lelli | 0c10617 | 2013-05-15 11:04:10 +0200 | [diff] [blame] | 333 | * @orig_waiter: rt_mutex_waiter struct for the task that has just donated |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 334 | * its priority to the mutex owner (can be NULL in the case |
| 335 | * depicted above or if the top waiter is gone away and we are |
| 336 | * actually deboosting the owner) |
| 337 | * @top_task: the current top waiter |
Juri Lelli | 0c10617 | 2013-05-15 11:04:10 +0200 | [diff] [blame] | 338 | * |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 339 | * Returns 0 or -EDEADLK. |
| 340 | */ |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 341 | static int rt_mutex_adjust_prio_chain(struct task_struct *task, |
| 342 | int deadlock_detect, |
| 343 | struct rt_mutex *orig_lock, |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 344 | struct rt_mutex *next_lock, |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 345 | struct rt_mutex_waiter *orig_waiter, |
| 346 | struct task_struct *top_task) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 347 | { |
| 348 | struct rt_mutex *lock; |
| 349 | struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter; |
| 350 | int detect_deadlock, ret = 0, depth = 0; |
| 351 | unsigned long flags; |
| 352 | |
| 353 | detect_deadlock = debug_rt_mutex_detect_deadlock(orig_waiter, |
| 354 | deadlock_detect); |
| 355 | |
| 356 | /* |
| 357 | * The (de)boosting is a step by step approach with a lot of |
| 358 | * pitfalls. We want this to be preemptible and we want hold a |
| 359 | * maximum of two locks per step. So we have to check |
| 360 | * carefully whether things change under us. |
| 361 | */ |
| 362 | again: |
| 363 | if (++depth > max_lock_depth) { |
| 364 | static int prev_max; |
| 365 | |
| 366 | /* |
| 367 | * Print this only once. If the admin changes the limit, |
| 368 | * print a new message when reaching the limit again. |
| 369 | */ |
| 370 | if (prev_max != max_lock_depth) { |
| 371 | prev_max = max_lock_depth; |
| 372 | printk(KERN_WARNING "Maximum lock depth %d reached " |
| 373 | "task: %s (%d)\n", max_lock_depth, |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 374 | top_task->comm, task_pid_nr(top_task)); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 375 | } |
| 376 | put_task_struct(task); |
| 377 | |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 378 | return -EDEADLK; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 379 | } |
| 380 | retry: |
| 381 | /* |
| 382 | * Task can not go away as we did a get_task() before ! |
| 383 | */ |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 384 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 385 | |
| 386 | waiter = task->pi_blocked_on; |
| 387 | /* |
| 388 | * Check whether the end of the boosting chain has been |
| 389 | * reached or the state of the chain has changed while we |
| 390 | * dropped the locks. |
| 391 | */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 392 | if (!waiter) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 393 | goto out_unlock_pi; |
| 394 | |
Thomas Gleixner | 1a539a8 | 2007-06-08 13:46:58 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Check the orig_waiter state. After we dropped the locks, |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 397 | * the previous owner of the lock might have released the lock. |
Thomas Gleixner | 1a539a8 | 2007-06-08 13:46:58 -0700 | [diff] [blame] | 398 | */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 399 | if (orig_waiter && !rt_mutex_owner(orig_lock)) |
Thomas Gleixner | 1a539a8 | 2007-06-08 13:46:58 -0700 | [diff] [blame] | 400 | goto out_unlock_pi; |
| 401 | |
| 402 | /* |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 403 | * We dropped all locks after taking a refcount on @task, so |
| 404 | * the task might have moved on in the lock chain or even left |
| 405 | * the chain completely and blocks now on an unrelated lock or |
| 406 | * on @orig_lock. |
| 407 | * |
| 408 | * We stored the lock on which @task was blocked in @next_lock, |
| 409 | * so we can detect the chain change. |
| 410 | */ |
| 411 | if (next_lock != waiter->lock) |
| 412 | goto out_unlock_pi; |
| 413 | |
| 414 | /* |
Thomas Gleixner | 1a539a8 | 2007-06-08 13:46:58 -0700 | [diff] [blame] | 415 | * Drop out, when the task has no waiters. Note, |
| 416 | * top_waiter can be NULL, when we are in the deboosting |
| 417 | * mode! |
| 418 | */ |
Thomas Gleixner | 397335f | 2014-05-22 03:25:39 +0000 | [diff] [blame] | 419 | if (top_waiter) { |
| 420 | if (!task_has_pi_waiters(task)) |
| 421 | goto out_unlock_pi; |
| 422 | /* |
| 423 | * If deadlock detection is off, we stop here if we |
| 424 | * are not the top pi waiter of the task. |
| 425 | */ |
| 426 | if (!detect_deadlock && top_waiter != task_top_pi_waiter(task)) |
| 427 | goto out_unlock_pi; |
| 428 | } |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 429 | |
| 430 | /* |
| 431 | * When deadlock detection is off then we check, if further |
| 432 | * priority adjustment is necessary. |
| 433 | */ |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 434 | if (!detect_deadlock && waiter->prio == task->prio) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 435 | goto out_unlock_pi; |
| 436 | |
| 437 | lock = waiter->lock; |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 438 | if (!raw_spin_trylock(&lock->wait_lock)) { |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 439 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 440 | cpu_relax(); |
| 441 | goto retry; |
| 442 | } |
| 443 | |
Thomas Gleixner | 397335f | 2014-05-22 03:25:39 +0000 | [diff] [blame] | 444 | /* |
| 445 | * Deadlock detection. If the lock is the same as the original |
| 446 | * lock which caused us to walk the lock chain or if the |
| 447 | * current lock is owned by the task which initiated the chain |
| 448 | * walk, we detected a deadlock. |
| 449 | */ |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 450 | if (lock == orig_lock || rt_mutex_owner(lock) == top_task) { |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 451 | debug_rt_mutex_deadlock(deadlock_detect, orig_waiter, lock); |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 452 | raw_spin_unlock(&lock->wait_lock); |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 453 | ret = -EDEADLK; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 454 | goto out_unlock_pi; |
| 455 | } |
| 456 | |
| 457 | top_waiter = rt_mutex_top_waiter(lock); |
| 458 | |
| 459 | /* Requeue the waiter */ |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 460 | rt_mutex_dequeue(lock, waiter); |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 461 | waiter->prio = task->prio; |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 462 | rt_mutex_enqueue(lock, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 463 | |
| 464 | /* Release the task */ |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 465 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 466 | if (!rt_mutex_owner(lock)) { |
| 467 | /* |
| 468 | * If the requeue above changed the top waiter, then we need |
| 469 | * to wake the new top waiter up to try to get the lock. |
| 470 | */ |
| 471 | |
| 472 | if (top_waiter != rt_mutex_top_waiter(lock)) |
| 473 | wake_up_process(rt_mutex_top_waiter(lock)->task); |
| 474 | raw_spin_unlock(&lock->wait_lock); |
| 475 | goto out_put_task; |
| 476 | } |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 477 | put_task_struct(task); |
| 478 | |
| 479 | /* Grab the next task */ |
| 480 | task = rt_mutex_owner(lock); |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 481 | get_task_struct(task); |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 482 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 483 | |
| 484 | if (waiter == rt_mutex_top_waiter(lock)) { |
| 485 | /* Boost the owner */ |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 486 | rt_mutex_dequeue_pi(task, top_waiter); |
| 487 | rt_mutex_enqueue_pi(task, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 488 | __rt_mutex_adjust_prio(task); |
| 489 | |
| 490 | } else if (top_waiter == waiter) { |
| 491 | /* Deboost the owner */ |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 492 | rt_mutex_dequeue_pi(task, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 493 | waiter = rt_mutex_top_waiter(lock); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 494 | rt_mutex_enqueue_pi(task, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 495 | __rt_mutex_adjust_prio(task); |
| 496 | } |
| 497 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 498 | /* |
| 499 | * Check whether the task which owns the current lock is pi |
| 500 | * blocked itself. If yes we store a pointer to the lock for |
| 501 | * the lock chain change detection above. After we dropped |
| 502 | * task->pi_lock next_lock cannot be dereferenced anymore. |
| 503 | */ |
| 504 | next_lock = task_blocked_on_lock(task); |
| 505 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 506 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 507 | |
| 508 | top_waiter = rt_mutex_top_waiter(lock); |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 509 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 510 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 511 | /* |
| 512 | * We reached the end of the lock chain. Stop right here. No |
| 513 | * point to go back just to figure that out. |
| 514 | */ |
| 515 | if (!next_lock) |
| 516 | goto out_put_task; |
| 517 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 518 | if (!detect_deadlock && waiter != top_waiter) |
| 519 | goto out_put_task; |
| 520 | |
| 521 | goto again; |
| 522 | |
| 523 | out_unlock_pi: |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 524 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 525 | out_put_task: |
| 526 | put_task_struct(task); |
Ingo Molnar | 36c8b58 | 2006-07-03 00:25:41 -0700 | [diff] [blame] | 527 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | /* |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 532 | * Try to take an rt-mutex |
| 533 | * |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 534 | * Must be called with lock->wait_lock held. |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 535 | * |
| 536 | * @lock: the lock to be acquired. |
| 537 | * @task: the task which wants to acquire the lock |
| 538 | * @waiter: the waiter that is queued to the lock's wait list. (could be NULL) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 539 | */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 540 | static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task, |
| 541 | struct rt_mutex_waiter *waiter) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 542 | { |
| 543 | /* |
| 544 | * We have to be careful here if the atomic speedups are |
| 545 | * enabled, such that, when |
| 546 | * - no other waiter is on the lock |
| 547 | * - the lock has been released since we did the cmpxchg |
| 548 | * the lock can be released or taken while we are doing the |
| 549 | * checks and marking the lock with RT_MUTEX_HAS_WAITERS. |
| 550 | * |
| 551 | * The atomic acquire/release aware variant of |
| 552 | * mark_rt_mutex_waiters uses a cmpxchg loop. After setting |
| 553 | * the WAITERS bit, the atomic release / acquire can not |
| 554 | * happen anymore and lock->wait_lock protects us from the |
| 555 | * non-atomic case. |
| 556 | * |
| 557 | * Note, that this might set lock->owner = |
| 558 | * RT_MUTEX_HAS_WAITERS in the case the lock is not contended |
| 559 | * any more. This is fixed up when we take the ownership. |
| 560 | * This is the transitional state explained at the top of this file. |
| 561 | */ |
| 562 | mark_rt_mutex_waiters(lock); |
| 563 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 564 | if (rt_mutex_owner(lock)) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 565 | return 0; |
| 566 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 567 | /* |
| 568 | * It will get the lock because of one of these conditions: |
| 569 | * 1) there is no waiter |
| 570 | * 2) higher priority than waiters |
| 571 | * 3) it is top waiter |
| 572 | */ |
| 573 | if (rt_mutex_has_waiters(lock)) { |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 574 | if (task->prio >= rt_mutex_top_waiter(lock)->prio) { |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 575 | if (!waiter || waiter != rt_mutex_top_waiter(lock)) |
| 576 | return 0; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | if (waiter || rt_mutex_has_waiters(lock)) { |
| 581 | unsigned long flags; |
| 582 | struct rt_mutex_waiter *top; |
| 583 | |
| 584 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
| 585 | |
| 586 | /* remove the queued waiter. */ |
| 587 | if (waiter) { |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 588 | rt_mutex_dequeue(lock, waiter); |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 589 | task->pi_blocked_on = NULL; |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | * We have to enqueue the top waiter(if it exists) into |
| 594 | * task->pi_waiters list. |
| 595 | */ |
| 596 | if (rt_mutex_has_waiters(lock)) { |
| 597 | top = rt_mutex_top_waiter(lock); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 598 | rt_mutex_enqueue_pi(task, top); |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 599 | } |
| 600 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
| 601 | } |
| 602 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 603 | /* We got the lock. */ |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 604 | debug_rt_mutex_lock(lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 605 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 606 | rt_mutex_set_owner(lock, task); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 607 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 608 | rt_mutex_deadlock_account_lock(lock, task); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 609 | |
| 610 | return 1; |
| 611 | } |
| 612 | |
| 613 | /* |
| 614 | * Task blocks on lock. |
| 615 | * |
| 616 | * Prepare waiter and propagate pi chain |
| 617 | * |
| 618 | * This must be called with lock->wait_lock held. |
| 619 | */ |
| 620 | static int task_blocks_on_rt_mutex(struct rt_mutex *lock, |
| 621 | struct rt_mutex_waiter *waiter, |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 622 | struct task_struct *task, |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 623 | int detect_deadlock) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 624 | { |
Ingo Molnar | 36c8b58 | 2006-07-03 00:25:41 -0700 | [diff] [blame] | 625 | struct task_struct *owner = rt_mutex_owner(lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 626 | struct rt_mutex_waiter *top_waiter = waiter; |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 627 | struct rt_mutex *next_lock; |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 628 | int chain_walk = 0, res; |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 629 | unsigned long flags; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 630 | |
Thomas Gleixner | 397335f | 2014-05-22 03:25:39 +0000 | [diff] [blame] | 631 | /* |
| 632 | * Early deadlock detection. We really don't want the task to |
| 633 | * enqueue on itself just to untangle the mess later. It's not |
| 634 | * only an optimization. We drop the locks, so another waiter |
| 635 | * can come in before the chain walk detects the deadlock. So |
| 636 | * the other will detect the deadlock and return -EDEADLOCK, |
| 637 | * which is wrong, as the other waiter is not in a deadlock |
| 638 | * situation. |
| 639 | */ |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 640 | if (owner == task) |
Thomas Gleixner | 397335f | 2014-05-22 03:25:39 +0000 | [diff] [blame] | 641 | return -EDEADLK; |
| 642 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 643 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 644 | __rt_mutex_adjust_prio(task); |
| 645 | waiter->task = task; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 646 | waiter->lock = lock; |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 647 | waiter->prio = task->prio; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 648 | |
| 649 | /* Get the top priority waiter on the lock */ |
| 650 | if (rt_mutex_has_waiters(lock)) |
| 651 | top_waiter = rt_mutex_top_waiter(lock); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 652 | rt_mutex_enqueue(lock, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 653 | |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 654 | task->pi_blocked_on = waiter; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 655 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 656 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 657 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 658 | if (!owner) |
| 659 | return 0; |
| 660 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 661 | raw_spin_lock_irqsave(&owner->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 662 | if (waiter == rt_mutex_top_waiter(lock)) { |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 663 | rt_mutex_dequeue_pi(owner, top_waiter); |
| 664 | rt_mutex_enqueue_pi(owner, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 665 | |
| 666 | __rt_mutex_adjust_prio(owner); |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 667 | if (owner->pi_blocked_on) |
| 668 | chain_walk = 1; |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 669 | } else if (debug_rt_mutex_detect_deadlock(waiter, detect_deadlock)) { |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 670 | chain_walk = 1; |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 671 | } |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 672 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 673 | /* Store the lock on which owner is blocked or NULL */ |
| 674 | next_lock = task_blocked_on_lock(owner); |
| 675 | |
| 676 | raw_spin_unlock_irqrestore(&owner->pi_lock, flags); |
| 677 | /* |
| 678 | * Even if full deadlock detection is on, if the owner is not |
| 679 | * blocked itself, we can avoid finding this out in the chain |
| 680 | * walk. |
| 681 | */ |
| 682 | if (!chain_walk || !next_lock) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 683 | return 0; |
| 684 | |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 685 | /* |
| 686 | * The owner can't disappear while holding a lock, |
| 687 | * so the owner struct is protected by wait_lock. |
| 688 | * Gets dropped in rt_mutex_adjust_prio_chain()! |
| 689 | */ |
| 690 | get_task_struct(owner); |
| 691 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 692 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 693 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 694 | res = rt_mutex_adjust_prio_chain(owner, detect_deadlock, lock, |
| 695 | next_lock, waiter, task); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 696 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 697 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 698 | |
| 699 | return res; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * Wake up the next waiter on the lock. |
| 704 | * |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 705 | * Remove the top waiter from the current tasks pi waiter list and |
| 706 | * wake it up. |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 707 | * |
| 708 | * Called with lock->wait_lock held. |
| 709 | */ |
| 710 | static void wakeup_next_waiter(struct rt_mutex *lock) |
| 711 | { |
| 712 | struct rt_mutex_waiter *waiter; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 713 | unsigned long flags; |
| 714 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 715 | raw_spin_lock_irqsave(¤t->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 716 | |
| 717 | waiter = rt_mutex_top_waiter(lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 718 | |
| 719 | /* |
| 720 | * Remove it from current->pi_waiters. We do not adjust a |
| 721 | * possible priority boost right now. We execute wakeup in the |
| 722 | * boosted mode and go back to normal after releasing |
| 723 | * lock->wait_lock. |
| 724 | */ |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 725 | rt_mutex_dequeue_pi(current, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 726 | |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 727 | /* |
| 728 | * As we are waking up the top waiter, and the waiter stays |
| 729 | * queued on the lock until it gets the lock, this lock |
| 730 | * obviously has waiters. Just set the bit here and this has |
| 731 | * the added benefit of forcing all new tasks into the |
| 732 | * slow path making sure no task of lower priority than |
| 733 | * the top waiter can steal this lock. |
| 734 | */ |
| 735 | lock->owner = (void *) RT_MUTEX_HAS_WAITERS; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 736 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 737 | raw_spin_unlock_irqrestore(¤t->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 738 | |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 739 | /* |
| 740 | * It's safe to dereference waiter as it cannot go away as |
| 741 | * long as we hold lock->wait_lock. The waiter task needs to |
| 742 | * acquire it in order to dequeue the waiter. |
| 743 | */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 744 | wake_up_process(waiter->task); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /* |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 748 | * Remove a waiter from a lock and give up |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 749 | * |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 750 | * Must be called with lock->wait_lock held and |
| 751 | * have just failed to try_to_take_rt_mutex(). |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 752 | */ |
Thomas Gleixner | bd19723 | 2007-06-17 21:11:10 +0200 | [diff] [blame] | 753 | static void remove_waiter(struct rt_mutex *lock, |
| 754 | struct rt_mutex_waiter *waiter) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 755 | { |
| 756 | int first = (waiter == rt_mutex_top_waiter(lock)); |
Ingo Molnar | 36c8b58 | 2006-07-03 00:25:41 -0700 | [diff] [blame] | 757 | struct task_struct *owner = rt_mutex_owner(lock); |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 758 | struct rt_mutex *next_lock = NULL; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 759 | unsigned long flags; |
| 760 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 761 | raw_spin_lock_irqsave(¤t->pi_lock, flags); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 762 | rt_mutex_dequeue(lock, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 763 | current->pi_blocked_on = NULL; |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 764 | raw_spin_unlock_irqrestore(¤t->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 765 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 766 | if (!owner) |
| 767 | return; |
| 768 | |
| 769 | if (first) { |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 770 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 771 | raw_spin_lock_irqsave(&owner->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 772 | |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 773 | rt_mutex_dequeue_pi(owner, waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 774 | |
| 775 | if (rt_mutex_has_waiters(lock)) { |
| 776 | struct rt_mutex_waiter *next; |
| 777 | |
| 778 | next = rt_mutex_top_waiter(lock); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 779 | rt_mutex_enqueue_pi(owner, next); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 780 | } |
| 781 | __rt_mutex_adjust_prio(owner); |
| 782 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 783 | /* Store the lock on which owner is blocked or NULL */ |
| 784 | next_lock = task_blocked_on_lock(owner); |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 785 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 786 | raw_spin_unlock_irqrestore(&owner->pi_lock, flags); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 789 | if (!next_lock) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 790 | return; |
| 791 | |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 792 | /* gets dropped in rt_mutex_adjust_prio_chain()! */ |
| 793 | get_task_struct(owner); |
| 794 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 795 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 796 | |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 797 | rt_mutex_adjust_prio_chain(owner, 0, lock, next_lock, NULL, current); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 798 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 799 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 803 | * Recheck the pi chain, in case we got a priority setting |
| 804 | * |
| 805 | * Called from sched_setscheduler |
| 806 | */ |
| 807 | void rt_mutex_adjust_pi(struct task_struct *task) |
| 808 | { |
| 809 | struct rt_mutex_waiter *waiter; |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 810 | struct rt_mutex *next_lock; |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 811 | unsigned long flags; |
| 812 | |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 813 | raw_spin_lock_irqsave(&task->pi_lock, flags); |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 814 | |
| 815 | waiter = task->pi_blocked_on; |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 816 | if (!waiter || (waiter->prio == task->prio && |
| 817 | !dl_prio(task->prio))) { |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 818 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 819 | return; |
| 820 | } |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 821 | next_lock = waiter->lock; |
Thomas Gleixner | 1d61548 | 2009-11-17 14:54:03 +0100 | [diff] [blame] | 822 | raw_spin_unlock_irqrestore(&task->pi_lock, flags); |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 823 | |
Steven Rostedt | db63063 | 2006-09-29 01:59:44 -0700 | [diff] [blame] | 824 | /* gets dropped in rt_mutex_adjust_prio_chain()! */ |
| 825 | get_task_struct(task); |
Thomas Gleixner | 8208498 | 2014-06-05 11:16:12 +0200 | [diff] [blame] | 826 | |
| 827 | rt_mutex_adjust_prio_chain(task, 0, NULL, next_lock, NULL, task); |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 830 | /** |
| 831 | * __rt_mutex_slowlock() - Perform the wait-wake-try-to-take loop |
| 832 | * @lock: the rt_mutex to take |
| 833 | * @state: the state the task should block in (TASK_INTERRUPTIBLE |
| 834 | * or TASK_UNINTERRUPTIBLE) |
| 835 | * @timeout: the pre-initialized and started timer, or NULL for none |
| 836 | * @waiter: the pre-initialized rt_mutex_waiter |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 837 | * |
| 838 | * lock->wait_lock must be held by the caller. |
| 839 | */ |
| 840 | static int __sched |
| 841 | __rt_mutex_slowlock(struct rt_mutex *lock, int state, |
| 842 | struct hrtimer_sleeper *timeout, |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 843 | struct rt_mutex_waiter *waiter) |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 844 | { |
| 845 | int ret = 0; |
| 846 | |
| 847 | for (;;) { |
| 848 | /* Try to acquire the lock: */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 849 | if (try_to_take_rt_mutex(lock, current, waiter)) |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | /* |
| 853 | * TASK_INTERRUPTIBLE checks for signals and |
| 854 | * timeout. Ignored otherwise. |
| 855 | */ |
| 856 | if (unlikely(state == TASK_INTERRUPTIBLE)) { |
| 857 | /* Signal pending? */ |
| 858 | if (signal_pending(current)) |
| 859 | ret = -EINTR; |
| 860 | if (timeout && !timeout->task) |
| 861 | ret = -ETIMEDOUT; |
| 862 | if (ret) |
| 863 | break; |
| 864 | } |
| 865 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 866 | raw_spin_unlock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 867 | |
| 868 | debug_rt_mutex_print_deadlock(waiter); |
| 869 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 870 | schedule_rt_mutex(lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 871 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 872 | raw_spin_lock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 873 | set_current_state(state); |
| 874 | } |
| 875 | |
| 876 | return ret; |
| 877 | } |
| 878 | |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 879 | static void rt_mutex_handle_deadlock(int res, int detect_deadlock, |
| 880 | struct rt_mutex_waiter *w) |
| 881 | { |
| 882 | /* |
| 883 | * If the result is not -EDEADLOCK or the caller requested |
| 884 | * deadlock detection, nothing to do here. |
| 885 | */ |
| 886 | if (res != -EDEADLOCK || detect_deadlock) |
| 887 | return; |
| 888 | |
| 889 | /* |
| 890 | * Yell lowdly and stop the task right here. |
| 891 | */ |
| 892 | rt_mutex_print_deadlock(w); |
| 893 | while (1) { |
| 894 | set_current_state(TASK_INTERRUPTIBLE); |
| 895 | schedule(); |
| 896 | } |
| 897 | } |
| 898 | |
Thomas Gleixner | 95e02ca | 2006-06-27 02:55:02 -0700 | [diff] [blame] | 899 | /* |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 900 | * Slow path lock function: |
| 901 | */ |
| 902 | static int __sched |
| 903 | rt_mutex_slowlock(struct rt_mutex *lock, int state, |
| 904 | struct hrtimer_sleeper *timeout, |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 905 | int detect_deadlock) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 906 | { |
| 907 | struct rt_mutex_waiter waiter; |
| 908 | int ret = 0; |
| 909 | |
| 910 | debug_rt_mutex_init_waiter(&waiter); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 911 | RB_CLEAR_NODE(&waiter.pi_tree_entry); |
| 912 | RB_CLEAR_NODE(&waiter.tree_entry); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 913 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 914 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 915 | |
| 916 | /* Try to acquire the lock again: */ |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 917 | if (try_to_take_rt_mutex(lock, current, NULL)) { |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 918 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | set_current_state(state); |
| 923 | |
| 924 | /* Setup the timer, when timeout != NULL */ |
Peter Zijlstra | 720a259 | 2008-02-13 15:45:36 +0100 | [diff] [blame] | 925 | if (unlikely(timeout)) { |
Arjan van de Ven | cc584b2 | 2008-09-01 15:02:30 -0700 | [diff] [blame] | 926 | hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS); |
Peter Zijlstra | 720a259 | 2008-02-13 15:45:36 +0100 | [diff] [blame] | 927 | if (!hrtimer_active(&timeout->timer)) |
| 928 | timeout->task = NULL; |
| 929 | } |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 930 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 931 | ret = task_blocks_on_rt_mutex(lock, &waiter, current, detect_deadlock); |
| 932 | |
| 933 | if (likely(!ret)) |
| 934 | ret = __rt_mutex_slowlock(lock, state, timeout, &waiter); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 935 | |
| 936 | set_current_state(TASK_RUNNING); |
| 937 | |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 938 | if (unlikely(ret)) { |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 939 | remove_waiter(lock, &waiter); |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 940 | rt_mutex_handle_deadlock(ret, detect_deadlock, &waiter); |
| 941 | } |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 942 | |
| 943 | /* |
| 944 | * try_to_take_rt_mutex() sets the waiter bit |
| 945 | * unconditionally. We might have to fix that up. |
| 946 | */ |
| 947 | fixup_rt_mutex_waiters(lock); |
| 948 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 949 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 950 | |
| 951 | /* Remove pending timer: */ |
| 952 | if (unlikely(timeout)) |
| 953 | hrtimer_cancel(&timeout->timer); |
| 954 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 955 | debug_rt_mutex_free_waiter(&waiter); |
| 956 | |
| 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * Slow path try-lock function: |
| 962 | */ |
Thomas Gleixner | 88f2b4c | 2014-06-10 22:53:40 +0200 | [diff] [blame^] | 963 | static inline int rt_mutex_slowtrylock(struct rt_mutex *lock) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 964 | { |
Thomas Gleixner | 88f2b4c | 2014-06-10 22:53:40 +0200 | [diff] [blame^] | 965 | int ret; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 966 | |
Thomas Gleixner | 88f2b4c | 2014-06-10 22:53:40 +0200 | [diff] [blame^] | 967 | /* |
| 968 | * If the lock already has an owner we fail to get the lock. |
| 969 | * This can be done without taking the @lock->wait_lock as |
| 970 | * it is only being read, and this is a trylock anyway. |
| 971 | */ |
| 972 | if (rt_mutex_owner(lock)) |
| 973 | return 0; |
| 974 | |
| 975 | /* |
| 976 | * The mutex has currently no owner. Lock the wait lock and |
| 977 | * try to acquire the lock. |
| 978 | */ |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 979 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 980 | |
Thomas Gleixner | 88f2b4c | 2014-06-10 22:53:40 +0200 | [diff] [blame^] | 981 | ret = try_to_take_rt_mutex(lock, current, NULL); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 982 | |
Thomas Gleixner | 88f2b4c | 2014-06-10 22:53:40 +0200 | [diff] [blame^] | 983 | /* |
| 984 | * try_to_take_rt_mutex() sets the lock waiters bit |
| 985 | * unconditionally. Clean this up. |
| 986 | */ |
| 987 | fixup_rt_mutex_waiters(lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 988 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 989 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 990 | |
| 991 | return ret; |
| 992 | } |
| 993 | |
| 994 | /* |
| 995 | * Slow path to release a rt-mutex: |
| 996 | */ |
| 997 | static void __sched |
| 998 | rt_mutex_slowunlock(struct rt_mutex *lock) |
| 999 | { |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1000 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1001 | |
| 1002 | debug_rt_mutex_unlock(lock); |
| 1003 | |
| 1004 | rt_mutex_deadlock_account_unlock(current); |
| 1005 | |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 1006 | /* |
| 1007 | * We must be careful here if the fast path is enabled. If we |
| 1008 | * have no waiters queued we cannot set owner to NULL here |
| 1009 | * because of: |
| 1010 | * |
| 1011 | * foo->lock->owner = NULL; |
| 1012 | * rtmutex_lock(foo->lock); <- fast path |
| 1013 | * free = atomic_dec_and_test(foo->refcnt); |
| 1014 | * rtmutex_unlock(foo->lock); <- fast path |
| 1015 | * if (free) |
| 1016 | * kfree(foo); |
| 1017 | * raw_spin_unlock(foo->lock->wait_lock); |
| 1018 | * |
| 1019 | * So for the fastpath enabled kernel: |
| 1020 | * |
| 1021 | * Nothing can set the waiters bit as long as we hold |
| 1022 | * lock->wait_lock. So we do the following sequence: |
| 1023 | * |
| 1024 | * owner = rt_mutex_owner(lock); |
| 1025 | * clear_rt_mutex_waiters(lock); |
| 1026 | * raw_spin_unlock(&lock->wait_lock); |
| 1027 | * if (cmpxchg(&lock->owner, owner, 0) == owner) |
| 1028 | * return; |
| 1029 | * goto retry; |
| 1030 | * |
| 1031 | * The fastpath disabled variant is simple as all access to |
| 1032 | * lock->owner is serialized by lock->wait_lock: |
| 1033 | * |
| 1034 | * lock->owner = NULL; |
| 1035 | * raw_spin_unlock(&lock->wait_lock); |
| 1036 | */ |
| 1037 | while (!rt_mutex_has_waiters(lock)) { |
| 1038 | /* Drops lock->wait_lock ! */ |
| 1039 | if (unlock_rt_mutex_safe(lock) == true) |
| 1040 | return; |
| 1041 | /* Relock the rtmutex and try again */ |
| 1042 | raw_spin_lock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Thomas Gleixner | 27e3571 | 2014-06-11 18:44:04 +0000 | [diff] [blame] | 1045 | /* |
| 1046 | * The wakeup next waiter path does not suffer from the above |
| 1047 | * race. See the comments there. |
| 1048 | */ |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1049 | wakeup_next_waiter(lock); |
| 1050 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1051 | raw_spin_unlock(&lock->wait_lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* Undo pi boosting if necessary: */ |
| 1054 | rt_mutex_adjust_prio(current); |
| 1055 | } |
| 1056 | |
| 1057 | /* |
| 1058 | * debug aware fast / slowpath lock,trylock,unlock |
| 1059 | * |
| 1060 | * The atomic acquire/release ops are compiled away, when either the |
| 1061 | * architecture does not support cmpxchg or when debugging is enabled. |
| 1062 | */ |
| 1063 | static inline int |
| 1064 | rt_mutex_fastlock(struct rt_mutex *lock, int state, |
| 1065 | int detect_deadlock, |
| 1066 | int (*slowfn)(struct rt_mutex *lock, int state, |
| 1067 | struct hrtimer_sleeper *timeout, |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1068 | int detect_deadlock)) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1069 | { |
| 1070 | if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) { |
| 1071 | rt_mutex_deadlock_account_lock(lock, current); |
| 1072 | return 0; |
| 1073 | } else |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1074 | return slowfn(lock, state, NULL, detect_deadlock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static inline int |
| 1078 | rt_mutex_timed_fastlock(struct rt_mutex *lock, int state, |
| 1079 | struct hrtimer_sleeper *timeout, int detect_deadlock, |
| 1080 | int (*slowfn)(struct rt_mutex *lock, int state, |
| 1081 | struct hrtimer_sleeper *timeout, |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1082 | int detect_deadlock)) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1083 | { |
| 1084 | if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) { |
| 1085 | rt_mutex_deadlock_account_lock(lock, current); |
| 1086 | return 0; |
| 1087 | } else |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1088 | return slowfn(lock, state, timeout, detect_deadlock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | static inline int |
| 1092 | rt_mutex_fasttrylock(struct rt_mutex *lock, |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1093 | int (*slowfn)(struct rt_mutex *lock)) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1094 | { |
| 1095 | if (likely(rt_mutex_cmpxchg(lock, NULL, current))) { |
| 1096 | rt_mutex_deadlock_account_lock(lock, current); |
| 1097 | return 1; |
| 1098 | } |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1099 | return slowfn(lock); |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | static inline void |
| 1103 | rt_mutex_fastunlock(struct rt_mutex *lock, |
| 1104 | void (*slowfn)(struct rt_mutex *lock)) |
| 1105 | { |
| 1106 | if (likely(rt_mutex_cmpxchg(lock, current, NULL))) |
| 1107 | rt_mutex_deadlock_account_unlock(current); |
| 1108 | else |
| 1109 | slowfn(lock); |
| 1110 | } |
| 1111 | |
| 1112 | /** |
| 1113 | * rt_mutex_lock - lock a rt_mutex |
| 1114 | * |
| 1115 | * @lock: the rt_mutex to be locked |
| 1116 | */ |
| 1117 | void __sched rt_mutex_lock(struct rt_mutex *lock) |
| 1118 | { |
| 1119 | might_sleep(); |
| 1120 | |
| 1121 | rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, 0, rt_mutex_slowlock); |
| 1122 | } |
| 1123 | EXPORT_SYMBOL_GPL(rt_mutex_lock); |
| 1124 | |
| 1125 | /** |
| 1126 | * rt_mutex_lock_interruptible - lock a rt_mutex interruptible |
| 1127 | * |
| 1128 | * @lock: the rt_mutex to be locked |
| 1129 | * @detect_deadlock: deadlock detection on/off |
| 1130 | * |
| 1131 | * Returns: |
| 1132 | * 0 on success |
| 1133 | * -EINTR when interrupted by a signal |
| 1134 | * -EDEADLK when the lock would deadlock (when deadlock detection is on) |
| 1135 | */ |
| 1136 | int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock, |
| 1137 | int detect_deadlock) |
| 1138 | { |
| 1139 | might_sleep(); |
| 1140 | |
| 1141 | return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, |
| 1142 | detect_deadlock, rt_mutex_slowlock); |
| 1143 | } |
| 1144 | EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); |
| 1145 | |
| 1146 | /** |
Luis Henriques | 23b94b9 | 2009-04-29 21:54:51 +0100 | [diff] [blame] | 1147 | * rt_mutex_timed_lock - lock a rt_mutex interruptible |
| 1148 | * the timeout structure is provided |
| 1149 | * by the caller |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1150 | * |
| 1151 | * @lock: the rt_mutex to be locked |
| 1152 | * @timeout: timeout structure or NULL (no timeout) |
| 1153 | * @detect_deadlock: deadlock detection on/off |
| 1154 | * |
| 1155 | * Returns: |
| 1156 | * 0 on success |
| 1157 | * -EINTR when interrupted by a signal |
Jean Delvare | 3ac49a1 | 2009-06-04 16:20:28 +0200 | [diff] [blame] | 1158 | * -ETIMEDOUT when the timeout expired |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1159 | * -EDEADLK when the lock would deadlock (when deadlock detection is on) |
| 1160 | */ |
| 1161 | int |
| 1162 | rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout, |
| 1163 | int detect_deadlock) |
| 1164 | { |
| 1165 | might_sleep(); |
| 1166 | |
| 1167 | return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, |
| 1168 | detect_deadlock, rt_mutex_slowlock); |
| 1169 | } |
| 1170 | EXPORT_SYMBOL_GPL(rt_mutex_timed_lock); |
| 1171 | |
| 1172 | /** |
| 1173 | * rt_mutex_trylock - try to lock a rt_mutex |
| 1174 | * |
| 1175 | * @lock: the rt_mutex to be locked |
| 1176 | * |
| 1177 | * Returns 1 on success and 0 on contention |
| 1178 | */ |
| 1179 | int __sched rt_mutex_trylock(struct rt_mutex *lock) |
| 1180 | { |
| 1181 | return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock); |
| 1182 | } |
| 1183 | EXPORT_SYMBOL_GPL(rt_mutex_trylock); |
| 1184 | |
| 1185 | /** |
| 1186 | * rt_mutex_unlock - unlock a rt_mutex |
| 1187 | * |
| 1188 | * @lock: the rt_mutex to be unlocked |
| 1189 | */ |
| 1190 | void __sched rt_mutex_unlock(struct rt_mutex *lock) |
| 1191 | { |
| 1192 | rt_mutex_fastunlock(lock, rt_mutex_slowunlock); |
| 1193 | } |
| 1194 | EXPORT_SYMBOL_GPL(rt_mutex_unlock); |
| 1195 | |
Luis Henriques | 23b94b9 | 2009-04-29 21:54:51 +0100 | [diff] [blame] | 1196 | /** |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1197 | * rt_mutex_destroy - mark a mutex unusable |
| 1198 | * @lock: the mutex to be destroyed |
| 1199 | * |
| 1200 | * This function marks the mutex uninitialized, and any subsequent |
| 1201 | * use of the mutex is forbidden. The mutex must not be locked when |
| 1202 | * this function is called. |
| 1203 | */ |
| 1204 | void rt_mutex_destroy(struct rt_mutex *lock) |
| 1205 | { |
| 1206 | WARN_ON(rt_mutex_is_locked(lock)); |
| 1207 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
| 1208 | lock->magic = NULL; |
| 1209 | #endif |
| 1210 | } |
| 1211 | |
| 1212 | EXPORT_SYMBOL_GPL(rt_mutex_destroy); |
| 1213 | |
| 1214 | /** |
| 1215 | * __rt_mutex_init - initialize the rt lock |
| 1216 | * |
| 1217 | * @lock: the rt lock to be initialized |
| 1218 | * |
| 1219 | * Initialize the rt lock to unlocked state. |
| 1220 | * |
| 1221 | * Initializing of a locked rt lock is not allowed |
| 1222 | */ |
| 1223 | void __rt_mutex_init(struct rt_mutex *lock, const char *name) |
| 1224 | { |
| 1225 | lock->owner = NULL; |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1226 | raw_spin_lock_init(&lock->wait_lock); |
Peter Zijlstra | fb00aca | 2013-11-07 14:43:43 +0100 | [diff] [blame] | 1227 | lock->waiters = RB_ROOT; |
| 1228 | lock->waiters_leftmost = NULL; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1229 | |
| 1230 | debug_rt_mutex_init(lock, name); |
| 1231 | } |
| 1232 | EXPORT_SYMBOL_GPL(__rt_mutex_init); |
Ingo Molnar | 0cdbee9 | 2006-06-27 02:54:57 -0700 | [diff] [blame] | 1233 | |
| 1234 | /** |
| 1235 | * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a |
| 1236 | * proxy owner |
| 1237 | * |
| 1238 | * @lock: the rt_mutex to be locked |
| 1239 | * @proxy_owner:the task to set as owner |
| 1240 | * |
| 1241 | * No locking. Caller has to do serializing itself |
| 1242 | * Special API call for PI-futex support |
| 1243 | */ |
| 1244 | void rt_mutex_init_proxy_locked(struct rt_mutex *lock, |
| 1245 | struct task_struct *proxy_owner) |
| 1246 | { |
| 1247 | __rt_mutex_init(lock, NULL); |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 1248 | debug_rt_mutex_proxy_lock(lock, proxy_owner); |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1249 | rt_mutex_set_owner(lock, proxy_owner); |
Ingo Molnar | 0cdbee9 | 2006-06-27 02:54:57 -0700 | [diff] [blame] | 1250 | rt_mutex_deadlock_account_lock(lock, proxy_owner); |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * rt_mutex_proxy_unlock - release a lock on behalf of owner |
| 1255 | * |
| 1256 | * @lock: the rt_mutex to be locked |
| 1257 | * |
| 1258 | * No locking. Caller has to do serializing itself |
| 1259 | * Special API call for PI-futex support |
| 1260 | */ |
| 1261 | void rt_mutex_proxy_unlock(struct rt_mutex *lock, |
| 1262 | struct task_struct *proxy_owner) |
| 1263 | { |
| 1264 | debug_rt_mutex_proxy_unlock(lock); |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1265 | rt_mutex_set_owner(lock, NULL); |
Ingo Molnar | 0cdbee9 | 2006-06-27 02:54:57 -0700 | [diff] [blame] | 1266 | rt_mutex_deadlock_account_unlock(proxy_owner); |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1270 | * rt_mutex_start_proxy_lock() - Start lock acquisition for another task |
| 1271 | * @lock: the rt_mutex to take |
| 1272 | * @waiter: the pre-initialized rt_mutex_waiter |
| 1273 | * @task: the task to prepare |
| 1274 | * @detect_deadlock: perform deadlock detection (1) or not (0) |
| 1275 | * |
| 1276 | * Returns: |
| 1277 | * 0 - task blocked on lock |
| 1278 | * 1 - acquired the lock for task, caller should wake it up |
| 1279 | * <0 - error |
| 1280 | * |
| 1281 | * Special API call for FUTEX_REQUEUE_PI support. |
| 1282 | */ |
| 1283 | int rt_mutex_start_proxy_lock(struct rt_mutex *lock, |
| 1284 | struct rt_mutex_waiter *waiter, |
| 1285 | struct task_struct *task, int detect_deadlock) |
| 1286 | { |
| 1287 | int ret; |
| 1288 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1289 | raw_spin_lock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1290 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1291 | if (try_to_take_rt_mutex(lock, task, NULL)) { |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1292 | raw_spin_unlock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1293 | return 1; |
| 1294 | } |
| 1295 | |
Thomas Gleixner | 3d5c934 | 2014-06-05 12:34:23 +0200 | [diff] [blame] | 1296 | /* We enforce deadlock detection for futexes */ |
| 1297 | ret = task_blocks_on_rt_mutex(lock, waiter, task, 1); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1298 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1299 | if (ret && !rt_mutex_owner(lock)) { |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1300 | /* |
| 1301 | * Reset the return value. We might have |
| 1302 | * returned with -EDEADLK and the owner |
| 1303 | * released the lock while we were walking the |
| 1304 | * pi chain. Let the waiter sort it out. |
| 1305 | */ |
| 1306 | ret = 0; |
| 1307 | } |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1308 | |
| 1309 | if (unlikely(ret)) |
| 1310 | remove_waiter(lock, waiter); |
| 1311 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1312 | raw_spin_unlock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1313 | |
| 1314 | debug_rt_mutex_print_deadlock(waiter); |
| 1315 | |
| 1316 | return ret; |
| 1317 | } |
| 1318 | |
| 1319 | /** |
Ingo Molnar | 0cdbee9 | 2006-06-27 02:54:57 -0700 | [diff] [blame] | 1320 | * rt_mutex_next_owner - return the next owner of the lock |
| 1321 | * |
| 1322 | * @lock: the rt lock query |
| 1323 | * |
| 1324 | * Returns the next owner of the lock or NULL |
| 1325 | * |
| 1326 | * Caller has to serialize against other accessors to the lock |
| 1327 | * itself. |
| 1328 | * |
| 1329 | * Special API call for PI-futex support |
| 1330 | */ |
| 1331 | struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock) |
| 1332 | { |
| 1333 | if (!rt_mutex_has_waiters(lock)) |
| 1334 | return NULL; |
| 1335 | |
| 1336 | return rt_mutex_top_waiter(lock)->task; |
| 1337 | } |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1338 | |
| 1339 | /** |
| 1340 | * rt_mutex_finish_proxy_lock() - Complete lock acquisition |
| 1341 | * @lock: the rt_mutex we were woken on |
| 1342 | * @to: the timeout, null if none. hrtimer should already have |
| 1343 | * been started. |
| 1344 | * @waiter: the pre-initialized rt_mutex_waiter |
| 1345 | * @detect_deadlock: perform deadlock detection (1) or not (0) |
| 1346 | * |
| 1347 | * Complete the lock acquisition started our behalf by another thread. |
| 1348 | * |
| 1349 | * Returns: |
| 1350 | * 0 - success |
| 1351 | * <0 - error, one of -EINTR, -ETIMEDOUT, or -EDEADLK |
| 1352 | * |
| 1353 | * Special API call for PI-futex requeue support |
| 1354 | */ |
| 1355 | int rt_mutex_finish_proxy_lock(struct rt_mutex *lock, |
| 1356 | struct hrtimer_sleeper *to, |
| 1357 | struct rt_mutex_waiter *waiter, |
| 1358 | int detect_deadlock) |
| 1359 | { |
| 1360 | int ret; |
| 1361 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1362 | raw_spin_lock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1363 | |
| 1364 | set_current_state(TASK_INTERRUPTIBLE); |
| 1365 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1366 | ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1367 | |
| 1368 | set_current_state(TASK_RUNNING); |
| 1369 | |
Lai Jiangshan | 8161239 | 2011-01-14 17:09:41 +0800 | [diff] [blame] | 1370 | if (unlikely(ret)) |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1371 | remove_waiter(lock, waiter); |
| 1372 | |
| 1373 | /* |
| 1374 | * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might |
| 1375 | * have to fix that up. |
| 1376 | */ |
| 1377 | fixup_rt_mutex_waiters(lock); |
| 1378 | |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 1379 | raw_spin_unlock(&lock->wait_lock); |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1380 | |
Darren Hart | 8dac456 | 2009-04-03 13:40:12 -0700 | [diff] [blame] | 1381 | return ret; |
| 1382 | } |