diff options
author | hselasky <hselasky@FreeBSD.org> | 2018-03-13 16:17:36 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2018-03-13 16:17:36 +0000 |
commit | 1c58d4305670f257f5881eef6243084495737096 (patch) | |
tree | 522836066ef8fa68f21c2adf0109bfceba03b4a1 /sys/compat | |
parent | 7b77f1587cc1df3f975add52696f9b2653e91b2f (diff) | |
download | FreeBSD-src-1c58d4305670f257f5881eef6243084495737096.zip FreeBSD-src-1c58d4305670f257f5881eef6243084495737096.tar.gz |
MFC r330352 and r330353:
Implement msleep_interruptible() in the LinuxKPI. While at it use pause_sbt()
instead of pause() in the msleep() function to avoid rounding errors when
converting delay values forth and back. Add a guard for a delay value
of zero milliseconds which is undefined.
Suggested by: ian@
Requested by: Johannes Lundberg <johalun0@gmail.com>
Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/delay.h | 14 | ||||
-rw-r--r-- | sys/compat/linuxkpi/common/src/linux_schedule.c | 20 |
2 files changed, 31 insertions, 3 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/delay.h b/sys/compat/linuxkpi/common/include/linux/delay.h index da38662..860d363 100644 --- a/sys/compat/linuxkpi/common/include/linux/delay.h +++ b/sys/compat/linuxkpi/common/include/linux/delay.h @@ -36,13 +36,19 @@ #include <sys/systm.h> static inline void -linux_msleep(int ms) +linux_msleep(unsigned int ms) { - pause("lnxsleep", msecs_to_jiffies(ms)); + /* guard against invalid values */ + if (ms == 0) + ms = 1; + pause_sbt("lnxsleep", mstosbt(ms), 0, C_HARDCLOCK); } #undef msleep -#define msleep linux_msleep +#define msleep(ms) linux_msleep(ms) + +#undef msleep_interruptible +#define msleep_interruptible(ms) linux_msleep_interruptible(ms) #define udelay(t) DELAY(t) @@ -65,4 +71,6 @@ usleep_range(unsigned long min, unsigned long max) DELAY(min); } +extern unsigned int linux_msleep_interruptible(unsigned int ms); + #endif /* _LINUX_DELAY_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_schedule.c b/sys/compat/linuxkpi/common/src/linux_schedule.c index 0958b3a..601f41c 100644 --- a/sys/compat/linuxkpi/common/src/linux_schedule.c +++ b/sys/compat/linuxkpi/common/src/linux_schedule.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include <sys/signalvar.h> #include <sys/sleepqueue.h> +#include <linux/delay.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/list.h> @@ -74,6 +75,25 @@ linux_add_to_sleepqueue(void *wchan, struct task_struct *task, return (ret); } +unsigned int +linux_msleep_interruptible(unsigned int ms) +{ + int ret; + + /* guard against invalid values */ + if (ms == 0) + ms = 1; + ret = -pause_sbt("lnxsleep", mstosbt(ms), 0, C_HARDCLOCK | C_CATCH); + + switch (ret) { + case -EWOULDBLOCK: + return (0); + default: + linux_schedule_save_interrupt_value(current, ret); + return (ms); + } +} + static int wake_up_task(struct task_struct *task, unsigned int state) { |