Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtmutex: Simplify remove_waiter()

Exit right away, when the removed waiter was not the top priority
waiter on the lock. Get rid of the extra indent level.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>

+19 -17
+19 -17
kernel/locking/rtmutex.c
··· 917 917 static void remove_waiter(struct rt_mutex *lock, 918 918 struct rt_mutex_waiter *waiter) 919 919 { 920 - int first = (waiter == rt_mutex_top_waiter(lock)); 920 + bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock)); 921 921 struct task_struct *owner = rt_mutex_owner(lock); 922 - struct rt_mutex *next_lock = NULL; 922 + struct rt_mutex *next_lock; 923 923 unsigned long flags; 924 924 925 925 raw_spin_lock_irqsave(&current->pi_lock, flags); ··· 927 927 current->pi_blocked_on = NULL; 928 928 raw_spin_unlock_irqrestore(&current->pi_lock, flags); 929 929 930 - if (!owner) 930 + /* 931 + * Only update priority if the waiter was the highest priority 932 + * waiter of the lock and there is an owner to update. 933 + */ 934 + if (!owner || !is_top_waiter) 931 935 return; 932 936 933 - if (first) { 937 + raw_spin_lock_irqsave(&owner->pi_lock, flags); 934 938 935 - raw_spin_lock_irqsave(&owner->pi_lock, flags); 939 + rt_mutex_dequeue_pi(owner, waiter); 936 940 937 - rt_mutex_dequeue_pi(owner, waiter); 941 + if (rt_mutex_has_waiters(lock)) 942 + rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock)); 938 943 939 - if (rt_mutex_has_waiters(lock)) { 940 - struct rt_mutex_waiter *next; 944 + __rt_mutex_adjust_prio(owner); 941 945 942 - next = rt_mutex_top_waiter(lock); 943 - rt_mutex_enqueue_pi(owner, next); 944 - } 945 - __rt_mutex_adjust_prio(owner); 946 + /* Store the lock on which owner is blocked or NULL */ 947 + next_lock = task_blocked_on_lock(owner); 946 948 947 - /* Store the lock on which owner is blocked or NULL */ 948 - next_lock = task_blocked_on_lock(owner); 949 + raw_spin_unlock_irqrestore(&owner->pi_lock, flags); 949 950 950 - raw_spin_unlock_irqrestore(&owner->pi_lock, flags); 951 - } 952 - 951 + /* 952 + * Don't walk the chain, if the owner task is not blocked 953 + * itself. 954 + */ 953 955 if (!next_lock) 954 956 return; 955 957