Lines Matching refs:mutex
6 RT-mutex implementation design
11 Documentation/rt-mutex.txt. Although this document does explain problems
26 to use a resource that a lower priority process has (a mutex for example),
83 mutex - In this document, to differentiate from locks that implement
85 the PI locks will be called a mutex.
97 a process being blocked on the mutex, it is fine to allocate
99 structure holds a pointer to the task, as well as the mutex that
101 place the task in the waiter_list of a mutex as well as the
102 pi_list of a mutex owner task (described below).
105 on a mutex. This is the same as waiter->task.
107 waiters - A list of processes that are blocked on a mutex.
109 top waiter - The highest priority process waiting on a specific mutex.
124 mutex at a time.
145 another mutex L5 where B owns L5 and F is blocked on mutex L5.
151 Since a process may own more than one mutex, but never be blocked on more than
166 Also since a mutex may have more than one process blocked on it, we can
168 blocked on mutex L2:
207 Every mutex keeps track of all the waiters that are blocked on itself. The mutex
209 a spin lock that is located in the struct of the mutex. This lock is called
223 is waiting on a mutex that is owned by the task. So if the task has
313 The mutex structure contains a pointer to the owner of the mutex. If the
314 mutex is not owned, this owner is set to NULL. Since all architectures
318 in Documentation/rt-mutex.txt, but will also be briefly described here.
322 in more detail, but is set whenever there are waiters on a mutex.
373 a mutex owned by the task, then that higher priority should be returned.
392 process has just blocked on a mutex owned by the task, __rt_mutex_adjust_prio
394 were for some reason to leave the mutex (timeout or signal), this same function
396 always contains the highest priority task that is waiting on a mutex owned
414 (de)boosting (the owner of a mutex that a process is blocking on), a flag to
415 check for deadlocking, the mutex that the task owns, and a pointer to a waiter
416 that is the process's waiter struct that is blocked on the mutex (although this
435 prevents new tasks from completing the blocking on a mutex that is owned by this
438 If the task is not blocked on a mutex then the loop is exited. We are at
442 on the current mutex) is the top pi waiter of the task. That is, is this
448 task that owns a mutex that this current task is waiting on. A priority chain
457 Next, we look at the mutex that the task is blocked on. The mutex's wait_lock
463 the mutex the task is blocked on, we update the task's waiter's plist node
464 that is located on the mutex's wait_list.
468 Next the owner of the mutex has its pi_lock taken, so we can update the
470 process on the mutex's wait_list, then we remove the previous top waiter
473 Note: It is possible that the task was the current top waiter on the mutex,
478 If the task was not the top waiter of the mutex, but it was before we
483 Lastly, we unlock both the pi_lock of the task, as well as the mutex's
485 loop, the previous owner of the mutex will be the task that will be
488 Note: One might think that the owner of this mutex might have changed
489 since we just grab the mutex's wait_lock. And one could be right.
493 So as long as there is an owner of this mutex that is not the same
499 protected only by the task's pi_lock. But the code to unlock the mutex
501 the protection of the mutex's wait_lock, which was not taken yet.
504 The answer is No! The trick is the spin_trylock of the mutex's
508 In the code to release the lock, the wait_lock of the mutex is held
510 new owner of the mutex. So if the switch of a new owner were to happen
524 One of the flags in the owner field of the mutex structure is "Pending Owner".
526 mutex, but that owner has yet to wake up and actually take the mutex.
528 Why is this important? Why can't we just give the mutex to another process
533 If a high priority process owns a mutex that a lower priority process is
534 blocked on, when the mutex is released it would be given to the lower priority
535 process. What if the higher priority process wants to take that mutex again.
536 The high priority process would fail to take that mutex that it just gave up
541 There's no reason a high priority process that gives up a mutex should be
542 penalized if it tries to take that mutex again. If the new owner of the
543 mutex has not woken up yet, there's no reason that the higher priority process
544 could not take that mutex away.
547 new process is given a mutex that it was blocked on, it is only given
549 priority process comes in and tries to grab that mutex. If a higher priority
550 process does come along and wants that mutex, we let the higher priority
551 process "steal" the mutex from the pending owner (only if it is still pending)
552 and continue with the mutex.
555 Taking of a mutex (The walk through)
559 taking a mutex.
561 The first thing that is tried is the fast taking of the mutex. This is
563 fails). Only when the owner field of the mutex is NULL can the lock be
572 the task on the wait_list of the mutex, and if need be, the pi_list of
575 The wait_lock of the mutex is taken since the slow path of unlocking the
576 mutex also takes this lock.
582 try_to_take_rt_mutex is used every time the task tries to grab a mutex in the
584 the "Has Waiters" flag of the mutex's owner field. Yes, this could really
585 be false, because if the mutex has no owner, there are no waiters and
589 now, the owner of the mutex can't release the mutex without going into the
595 mutex, we check to see if we can take the ownership. This is done if the
596 mutex doesn't have a owner, or if we can steal the mutex from a pending
602 The mutex has a owner, but it hasn't woken up and the mutex flag
605 owner to grab the mutex. When a pending owner wakes up, it checks to see
606 if it can take the mutex, and this is done if the owner is already set to
614 is never blocked on a mutex. So there is no PI chain to worry about. It also
615 means that if the mutex doesn't have any waiters, there's no accounting needed
617 blocked on the current mutex.
619 If there are waiters on this mutex, and we just stole the ownership, we need
624 from itself. When the pending owner tries to grab the mutex, it will fail
631 of the mutex to current, and set the flag of "Has Waiters" if the current
632 mutex actually has waiters, or we clear the flag if it doesn't. See, it was
644 If the mutex has a timeout, we set up a timer to go off to break us out
645 of this mutex if we failed to get it after a specified amount of time.
647 Now we enter a loop that will continue to try to take ownership of the mutex, or
650 Once again we try to take the mutex. This will usually fail the first time
651 in the loop, since it had just failed to get the mutex. But the second time
655 If the mutex is TASK_INTERRUPTIBLE a check for signals and timeout is done
659 on the mutex. This field can be NULL the first time it goes through the loop
660 or if the task is a pending owner and had its mutex stolen. If the "task"
663 Task blocks on mutex
666 The accounting of a mutex and process is done with the waiter structure of
668 to the mutex. The plist nodes are initialized to the processes current
673 priority process currently waiting on this mutex, then we remove the
680 (or deadlock checking is on), we unlock the wait_lock of the mutex and go ahead
684 mutex (waiter "task" field is not NULL), then we go to sleep (call schedule).
690 1) we were given pending ownership of the mutex.
695 ownership of the mutex. If we succeed, we exit the loop, otherwise we continue
696 and on signal and timeout, will exit the loop, or if we had the mutex stolen
699 Note: For various reasons, because of timeout and signals, the steal mutex
705 Failed to get mutex on Timeout or Signal
709 NULL and the task needs to be taken off the wait_list of the mutex and perhaps
718 The unlocking of a mutex also has a fast path for those architectures with
719 CMPXCHG. Since the taking of a mutex on contention always sets the
720 "Has Waiters" flag of the mutex's owner, we use this to know if we need to
721 take the slow path when unlocking the mutex. If the mutex doesn't have any
722 waiters, the owner field of the mutex would equal the current process and
723 the mutex can be unlocked by just replacing the owner field with NULL.
729 mutex. This synchronizes the locking and unlocking of the mutex.
731 A check is made to see if the mutex has waiters or not. On architectures that
732 do not have CMPXCHG, this is the location that the owner of the mutex will
735 in the slow path too. If a waiter of a mutex woke up because of a signal
737 the grabbing of the wait_lock, the mutex may not have any waiters, thus the
738 owner still needs to make this check. If there are no waiters then the mutex
746 waiter of the lock is found and removed from the wait_list of the mutex
749 mutex is set to the new owner with the "Pending Owner" bit set, as well
751 mutex.
756 on the mutex.
759 the mutex still has waiters pending, we add the new top waiter to the pi_list