aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include/linux/sched.h
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2017-06-09 19:41:12 +0000
committerMark Johnston <markj@FreeBSD.org>2017-06-09 19:41:12 +0000
commit465659643b5539bd609c00c41a611e3095a31cf9 (patch)
tree9cd334dd9f8300fd8828924f53868e9fef7d9579 /sys/compat/linuxkpi/common/include/linux/sched.h
parent1bece9d5626f41adc05632184576f2b56cd148c0 (diff)
downloadsrc-465659643b5539bd609c00c41a611e3095a31cf9.tar.gz
src-465659643b5539bd609c00c41a611e3095a31cf9.zip
Augment wait queue support in the LinuxKPI.
In particular: - Don't evaluate event conditions with a sleepqueue lock held, since such code may attempt to acquire arbitrary locks. - Fix the return value for wait_event_interruptible() in the case that the wait is interrupted by a signal. - Implement wait_on_bit_timeout() and wait_on_atomic_t(). - Implement some functions used to test for pending signals. - Implement a number of wait_event_*() variants and unify the existing implementations. - Unify the mechanism used by wait_event_*() and schedule() to put the calling thread to sleep. This is required to support updated DRM drivers. Thanks to hselasky for finding and fixing a number of bugs in the original revision. Reviewed by: hselasky MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D10986
Notes
Notes: svn path=/head/; revision=319757
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/sched.h')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sched.h95
1 files changed, 44 insertions, 51 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h
index 59900c12ab1d..01d44a0ce1e7 100644
--- a/sys/compat/linuxkpi/common/include/linux/sched.h
+++ b/sys/compat/linuxkpi/common/include/linux/sched.h
@@ -48,14 +48,13 @@
#include <asm/atomic.h>
-#define MAX_SCHEDULE_TIMEOUT LONG_MAX
+#define MAX_SCHEDULE_TIMEOUT INT_MAX
-#define TASK_RUNNING 0
-#define TASK_INTERRUPTIBLE 1
-#define TASK_UNINTERRUPTIBLE 2
-#define TASK_DEAD 64
-#define TASK_WAKEKILL 128
-#define TASK_WAKING 256
+#define TASK_RUNNING 0x0000
+#define TASK_INTERRUPTIBLE 0x0001
+#define TASK_UNINTERRUPTIBLE 0x0002
+#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
+#define TASK_WAKING 0x0100
struct task_struct {
struct thread *task_thread;
@@ -89,9 +88,11 @@ struct task_struct {
#define put_pid(x) do { } while (0)
#define current_euid() (curthread->td_ucred->cr_uid)
-#define set_current_state(x) \
- atomic_store_rel_int((volatile int *)&current->state, (x))
-#define __set_current_state(x) current->state = (x)
+#define set_task_state(task, x) \
+ atomic_store_rel_int((volatile int *)&task->state, (x))
+#define __set_task_state(task, x) (task->state = (x))
+#define set_current_state(x) set_task_state(current, x)
+#define __set_current_state(x) __set_task_state(current, x)
static inline void
get_task_struct(struct task_struct *task)
@@ -106,53 +107,45 @@ put_task_struct(struct task_struct *task)
linux_free_current(task);
}
-#define schedule() \
-do { \
- void *c; \
- \
- if (cold || SCHEDULER_STOPPED()) \
- break; \
- c = curthread; \
- sleepq_lock(c); \
- if (current->state == TASK_INTERRUPTIBLE || \
- current->state == TASK_UNINTERRUPTIBLE) { \
- sleepq_add(c, NULL, "task", SLEEPQ_SLEEP, 0); \
- sleepq_wait(c, 0); \
- } else { \
- sleepq_release(c); \
- sched_relinquish(curthread); \
- } \
-} while (0)
-
-#define wake_up_process(x) \
-do { \
- int wakeup_swapper; \
- void *c; \
- \
- c = (x)->task_thread; \
- sleepq_lock(c); \
- (x)->state = TASK_RUNNING; \
- wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0); \
- sleepq_release(c); \
- if (wakeup_swapper) \
- kick_proc0(); \
-} while (0)
-
#define cond_resched() if (!cold) sched_relinquish(curthread)
+#define yield() kern_yield(PRI_UNCHANGED)
#define sched_yield() sched_relinquish(curthread)
-static inline long
-schedule_timeout(signed long timeout)
-{
- if (timeout < 0)
- return 0;
+#define need_resched() (curthread->td_flags & TDF_NEEDRESCHED)
- pause("lstim", timeout);
+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);
+void linux_send_sig(int signo, struct task_struct *task);
+
+#define signal_pending(task) linux_signal_pending(task)
+#define fatal_signal_pending(task) linux_fatal_signal_pending(task)
+#define signal_pending_state(state, task) \
+ linux_signal_pending_state(state, task)
+#define send_sig(signo, task, priv) do { \
+ CTASSERT(priv == 0); \
+ linux_send_sig(signo, task); \
+} while (0)
- return 0;
-}
+int linux_schedule_timeout(int timeout);
+
+#define schedule() \
+ (void)linux_schedule_timeout(MAX_SCHEDULE_TIMEOUT)
+#define schedule_timeout(timeout) \
+ linux_schedule_timeout(timeout)
+#define schedule_timeout_killable(timeout) \
+ schedule_timeout_uninterruptible(timeout)
+#define schedule_timeout_interruptible(timeout) ({ \
+ set_current_state(TASK_INTERRUPTIBLE); \
+ schedule_timeout(timeout); \
+})
+#define schedule_timeout_uninterruptible(timeout) ({ \
+ set_current_state(TASK_UNINTERRUPTIBLE); \
+ schedule_timeout(timeout); \
+})
-#define need_resched() (curthread->td_flags & TDF_NEEDRESCHED)
+#define io_schedule() schedule()
+#define io_schedule_timeout(timeout) schedule_timeout(timeout)
#endif /* _LINUX_SCHED_H_ */