aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKefeng Wang <wangkefeng.wang@huawei.com>2021-12-03 15:59:34 +0800
committerPeter Zijlstra <peterz@infradead.org>2021-12-04 10:56:25 +0100
commitc0bed69daf4b67809b58cc7cd81a8fa4f45bc161 (patch)
tree2e5eac02c318c1145dace9791e1e53b74ca0dc49 /include
parentlockdep/selftests: Adapt ww-tests for PREEMPT_RT (diff)
downloadlinux-dev-c0bed69daf4b67809b58cc7cd81a8fa4f45bc161.tar.xz
linux-dev-c0bed69daf4b67809b58cc7cd81a8fa4f45bc161.zip
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. Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20211203075935.136808-2-wangkefeng.wang@huawei.com
Diffstat (limited to 'include')
-rw-r--r--include/linux/sched.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 78c351e35fec..ff609d9c2f21 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2171,6 +2171,15 @@ extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
#endif
#ifdef CONFIG_SMP
+static inline bool owner_on_cpu(struct task_struct *owner)
+{
+ /*
+ * As lock holder preemption issue, we both skip spinning if
+ * task is not on cpu or its cpu is preempted
+ */
+ return owner->on_cpu && !vcpu_is_preempted(task_cpu(owner));
+}
+
/* Returns effective CPU energy utilization, as seen by the scheduler */
unsigned long sched_cpu_util(int cpu, unsigned long max);
#endif /* CONFIG_SMP */