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.
Showing the changes to kernel (3 of 4 files). Show all
Unified · Split
| @@ -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 true | 409 | * If lock->owner is not set, the mutex has been released. Return true |
| @@ -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 preempted | 1383 | * - 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 | } |
| @@ -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 | ||
| 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 | |||
| 625 | static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem) | 616 | static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem) |
| 626 | { | 617 | { |
| 627 | struct task_struct *owner; | 618 | struct task_struct *owner; |