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
367 /*367 /*
368 * Use vcpu_is_preempted to detect lock holder preemption issue.368 * Use vcpu_is_preempted to detect lock holder preemption issue.
369 */369 */
370 if (!owner->on_cpu || need_resched() ||370 if (!owner_on_cpu(owner) || need_resched()) {
371 vcpu_is_preempted(task_cpu(owner))) {
372 ret = false;371 ret = false;
373 break;372 break;
374 }373 }
@@ -403,14 +402,8 @@ static inline int mutex_can_spin_on_owner(struct mutex *lock) · 28 unmodified lines
403 * structure won't go away during the spinning period.402 * structure won't go away during the spinning period.
404 */403 */
405 owner = __mutex_owner(lock);404 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
412 if (owner)405 if (owner)
413 retval = owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));406 retval = owner_on_cpu(owner);
414 407
415 /*408 /*
416 * If lock->owner is not set, the mutex has been released. Return true409 * 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
1382 * for CONFIG_PREEMPT_RCU=y)1382 * for CONFIG_PREEMPT_RCU=y)
1383 * - the VCPU on which owner runs is preempted1383 * - the VCPU on which owner runs is preempted
1384 */1384 */
1385 if (!owner->on_cpu || need_resched() ||1385 if (!owner_on_cpu(owner) || need_resched() ||
1386 rt_mutex_waiter_is_top_waiter(lock, waiter) ||1386 rt_mutex_waiter_is_top_waiter(lock, waiter)) {
1387 vcpu_is_preempted(task_cpu(owner))) {
1388 res = false;1387 res = false;
1389 break;1388 break;
1390 }1389 }
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
613 return false;613 return false;
614}614}
615 615
616static 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
625static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)616static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
626{617{
627 struct task_struct *owner;618 struct task_struct *owner;