Add wait_event_interruptible_timeout to linuxkpi.

Submitted by:	Krishnamraju Eraparaju @ Chelsio
Reviewed by:	hselasky@
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D5776
This commit is contained in:
np 2016-03-31 17:11:58 +00:00
parent 1191e72322
commit fe781dcbf6
3 changed files with 57 additions and 10 deletions

View File

@ -95,4 +95,14 @@ get_jiffies_64(void)
return ((u64)(unsigned)ticks);
}
static inline int
linux_timer_jiffies_until(unsigned long expires)
{
int delta = expires - jiffies;
/* guard against already expired values */
if (delta < 1)
delta = 1;
return (delta);
}
#endif /* _LINUX_JIFFIES_H_ */

View File

@ -34,6 +34,7 @@
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/jiffies.h>
#include <sys/param.h>
#include <sys/systm.h>
@ -113,6 +114,52 @@ do { \
-_error; \
})
#define wait_event_interruptible_timeout(q, cond, timeout) \
({ \
void *c = &(q).wchan; \
long end = jiffies + timeout; \
int __ret = 0; \
int __rc = 0; \
\
if (!(cond)) { \
for (; __rc == 0;) { \
sleepq_lock(c); \
if (cond) { \
sleepq_release(c); \
__ret = 1; \
break; \
} \
sleepq_add(c, NULL, "completion", \
SLEEPQ_SLEEP | SLEEPQ_INTERRUPTIBLE, 0); \
sleepq_set_timeout(c, linux_timer_jiffies_until(end));\
__rc = sleepq_timedwait_sig (c, 0); \
if (__rc != 0) { \
/* check for timeout or signal. \
* 0 if the condition evaluated to false\
* after the timeout elapsed, 1 if the \
* condition evaluated to true after the\
* timeout elapsed. \
*/ \
if (__rc == EWOULDBLOCK) \
__ret = (cond); \
else \
__ret = -ERESTARTSYS; \
} \
\
} \
} else { \
/* return remaining jiffies (at least 1) if the \
* condition evaluated to true before the timeout \
* elapsed. \
*/ \
__ret = (end - jiffies); \
if( __ret < 1 ) \
__ret = 1; \
} \
__ret; \
})
static inline int
waitqueue_active(wait_queue_head_t *q)
{

View File

@ -894,16 +894,6 @@ kasprintf(gfp_t gfp, const char *fmt, ...)
return (p);
}
static int
linux_timer_jiffies_until(unsigned long expires)
{
int delta = expires - jiffies;
/* guard against already expired values */
if (delta < 1)
delta = 1;
return (delta);
}
static void
linux_timer_callback_wrapper(void *context)
{