diff options
| author | Alex Shi <alex.shi@linaro.org> | 2017-07-30 21:50:54 -0400 |
|---|---|---|
| committer | Jonathan Corbet <corbet@lwn.net> | 2017-08-24 15:38:14 -0400 |
| commit | 68a1e349cecf4e24531cba0f1545a436fa18ee51 (patch) | |
| tree | 3d28a6f6f95994999bd408bdd3187ad0757624bf /Documentation/locking | |
| parent | f1824df12ecd495b25c8c116876e201ac764ecea (diff) | |
rtmutex: update rt-mutex
The rtmutex remove a pending owner bit in in rt_mutex::owner, in
commit 8161239a8bcc ("rtmutex: Simplify PI algorithm and make highest prio task get lock")
But the document was changed accordingly. Updating it to a meaningful
state.
BTW, as 'Steven Rostedt' mentioned:
There is still technically a "Pending Owner", it's just not called
that anymore. The pending owner happens to be the top_waiter of a lock
that has no owner and has been woken up to grab the lock.
Signed-off-by: Alex Shi <alex.shi@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Juri Lelli <juri.lelli@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
To: linux-doc@vger.kernel.org
To: linux-kernel@vger.kernel.org
To: Jonathan Corbet <corbet@lwn.net>
To: Ingo Molnar <mingo@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/locking')
| -rw-r--r-- | Documentation/locking/rt-mutex.txt | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/Documentation/locking/rt-mutex.txt b/Documentation/locking/rt-mutex.txt index 243393d882ee..35793e003041 100644 --- a/Documentation/locking/rt-mutex.txt +++ b/Documentation/locking/rt-mutex.txt | |||
| @@ -28,14 +28,13 @@ magic bullet for poorly designed applications, but it allows | |||
| 28 | well-designed applications to use userspace locks in critical parts of | 28 | well-designed applications to use userspace locks in critical parts of |
| 29 | an high priority thread, without losing determinism. | 29 | an high priority thread, without losing determinism. |
| 30 | 30 | ||
| 31 | The enqueueing of the waiters into the rtmutex waiter list is done in | 31 | The enqueueing of the waiters into the rtmutex waiter tree is done in |
| 32 | priority order. For same priorities FIFO order is chosen. For each | 32 | priority order. For same priorities FIFO order is chosen. For each |
| 33 | rtmutex, only the top priority waiter is enqueued into the owner's | 33 | rtmutex, only the top priority waiter is enqueued into the owner's |
| 34 | priority waiters list. This list too queues in priority order. Whenever | 34 | priority waiters tree. This tree too queues in priority order. Whenever |
| 35 | the top priority waiter of a task changes (for example it timed out or | 35 | the top priority waiter of a task changes (for example it timed out or |
| 36 | got a signal), the priority of the owner task is readjusted. [The | 36 | got a signal), the priority of the owner task is readjusted. The |
| 37 | priority enqueueing is handled by "plists", see include/linux/plist.h | 37 | priority enqueueing is handled by "pi_waiters". |
| 38 | for more details.] | ||
| 39 | 38 | ||
| 40 | RT-mutexes are optimized for fastpath operations and have no internal | 39 | RT-mutexes are optimized for fastpath operations and have no internal |
| 41 | locking overhead when locking an uncontended mutex or unlocking a mutex | 40 | locking overhead when locking an uncontended mutex or unlocking a mutex |
| @@ -46,34 +45,29 @@ is used] | |||
| 46 | The state of the rt-mutex is tracked via the owner field of the rt-mutex | 45 | The state of the rt-mutex is tracked via the owner field of the rt-mutex |
| 47 | structure: | 46 | structure: |
| 48 | 47 | ||
| 49 | rt_mutex->owner holds the task_struct pointer of the owner. Bit 0 and 1 | 48 | lock->owner holds the task_struct pointer of the owner. Bit 0 is used to |
| 50 | are used to keep track of the "owner is pending" and "rtmutex has | 49 | keep track of the "lock has waiters" state. |
| 51 | waiters" state. | ||
| 52 | 50 | ||
| 53 | owner bit1 bit0 | 51 | owner bit0 |
| 54 | NULL 0 0 mutex is free (fast acquire possible) | 52 | NULL 0 lock is free (fast acquire possible) |
| 55 | NULL 0 1 invalid state | 53 | NULL 1 lock is free and has waiters and the top waiter |
| 56 | NULL 1 0 Transitional state* | 54 | is going to take the lock* |
| 57 | NULL 1 1 invalid state | 55 | taskpointer 0 lock is held (fast release possible) |
| 58 | taskpointer 0 0 mutex is held (fast release possible) | 56 | taskpointer 1 lock is held and has waiters** |
| 59 | taskpointer 0 1 task is pending owner | ||
| 60 | taskpointer 1 0 mutex is held and has waiters | ||
| 61 | taskpointer 1 1 task is pending owner and mutex has waiters | ||
| 62 | 57 | ||
| 63 | Pending-ownership handling is a performance optimization: | 58 | The fast atomic compare exchange based acquire and release is only |
| 64 | pending-ownership is assigned to the first (highest priority) waiter of | 59 | possible when bit 0 of lock->owner is 0. |
| 65 | the mutex, when the mutex is released. The thread is woken up and once | ||
| 66 | it starts executing it can acquire the mutex. Until the mutex is taken | ||
| 67 | by it (bit 0 is cleared) a competing higher priority thread can "steal" | ||
| 68 | the mutex which puts the woken up thread back on the waiters list. | ||
| 69 | 60 | ||
| 70 | The pending-ownership optimization is especially important for the | 61 | (*) It also can be a transitional state when grabbing the lock |
| 71 | uninterrupted workflow of high-prio tasks which repeatedly | 62 | with ->wait_lock is held. To prevent any fast path cmpxchg to the lock, |
| 72 | takes/releases locks that have lower-prio waiters. Without this | 63 | we need to set the bit0 before looking at the lock, and the owner may be |
| 73 | optimization the higher-prio thread would ping-pong to the lower-prio | 64 | NULL in this small time, hence this can be a transitional state. |
| 74 | task [because at unlock time we always assign a new owner]. | ||
| 75 | 65 | ||
| 76 | (*) The "mutex has waiters" bit gets set to take the lock. If the lock | 66 | (**) There is a small time when bit 0 is set but there are no |
| 77 | doesn't already have an owner, this bit is quickly cleared if there are | 67 | waiters. This can happen when grabbing the lock in the slow path. |
| 78 | no waiters. So this is a transitional state to synchronize with looking | 68 | To prevent a cmpxchg of the owner releasing the lock, we need to |
| 79 | at the owner field of the mutex and the mutex owner releasing the lock. | 69 | set this bit before looking at the lock. |
| 70 | |||
| 71 | BTW, there is still technically a "Pending Owner", it's just not called | ||
| 72 | that anymore. The pending owner happens to be the top_waiter of a lock | ||
| 73 | that has no owner and has been woken up to grab the lock. | ||
