From 9b8016548ef61e2c42271c7dce35d0322540d2f1 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Mon, 21 Mar 2022 11:14:05 +0100 Subject: [PATCH] linuxkpi: Add cond_resched_lock If we need to resched it takes the lock, resched, release the lock and returns 1, otherwise simply returns 0. Needed by drm v5.9 MFC after: 1 month Reviewed by: hselasky Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D34620 --- sys/compat/linuxkpi/common/include/linux/sched.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h index 5bb9047640b8..aa4bdbc65c5b 100644 --- a/sys/compat/linuxkpi/common/include/linux/sched.h +++ b/sys/compat/linuxkpi/common/include/linux/sched.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -127,6 +128,18 @@ put_task_struct(struct task_struct *task) #define need_resched() (curthread->td_flags & TDF_NEEDRESCHED) +static inline int +cond_resched_lock(spinlock_t *lock) +{ + + if (need_resched() == 0) + return (0); + spin_lock(lock); + cond_resched(); + spin_unlock(lock); + return (1); +} + bool linux_signal_pending(struct task_struct *task); bool linux_fatal_signal_pending(struct task_struct *task); bool linux_signal_pending_state(long state, struct task_struct *task);