History

locking: Make owner_on_cpu() into <linux/sched.h>

Move the owner_on_cpu() from kernel/locking/rwsem.c into include/linux/sched.h with under CONFIG_SMP, then use it in the mutex/rwsem/rtmutex to simplify the code.

Kefeng Wang committed 4 years ago

Commit c0bed691 parent 9a75bd04 files · +13 −21Browse files

Showing the changes to kernel (3 of 4 files). Show all

Unified · Split

3 files
  1. kernel/locking/mutex.c +2 −9
  2. kernel/locking/rtmutex.c +2 −3
  3. kernel/locking/rwsem.c +0 −9
kernel/locking/mutex.c+2−9
@@ -367,8 +367,7 @@ bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner, · 366 unmodified lines
367367 /*
368368 * Use vcpu_is_preempted to detect lock holder preemption issue.
369369 */
370− if (!owner->on_cpu || need_resched() ||
371− vcpu_is_preempted(task_cpu(owner))) {
370+ if (!owner_on_cpu(owner) || need_resched()) {
372371 ret = false;
373372 break;
374373 }
@@ -403,14 +402,8 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) · 28 unmodified lines
403402 * structure won't go away during the spinning period.
404403 */
405404 owner = __mutex_owner(lock);
406−
407− /*
408− * As lock holder preemption issue, we both skip spinning if task is not
409− * on cpu or its cpu is preempted
410− */
411−
412405 if (owner)
413− retval = owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));
406+ retval = owner_on_cpu(owner);
414407
415408 /*
416409 * If lock->owner is not set, the mutex has been released. Return true
kernel/locking/rtmutex.c+2−3
@@ -1382,9 +1382,8 @@ static bool rtmutex_spin_on_owner(struct rt_mutex_base *lock, · 1381 unmodified lines
13821382 * for CONFIG_PREEMPT_RCU=y)
13831383 * - the VCPU on which owner runs is preempted
13841384 */
1385− if (!owner->on_cpu || need_resched() ||
1386− rt_mutex_waiter_is_top_waiter(lock, waiter) ||
1387− vcpu_is_preempted(task_cpu(owner))) {
1385+ if (!owner_on_cpu(owner) || need_resched() ||
1386+ rt_mutex_waiter_is_top_waiter(lock, waiter)) {
13881387 res = false;
13891388 break;
13901389 }
kernel/locking/rwsem.c+0−9
@@ -613,15 +613,6 @@ static inline bool rwsem_try_write_lock_unqueued(struct rw_semaphore *sem) · 612 unmodified lines
613613 return false;
614614 }
615615
616−static inline bool owner_on_cpu(struct task_struct *owner)
617−{
618− /*
619− * As lock holder preemption issue, we both skip spinning if
620− * task is not on cpu or its cpu is preempted
621− */
622− return owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));
623−}
624−
625616 static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
626617 {
627618 struct task_struct *owner;