svn commit: r297459 - in head/sys/compat/linuxkpi/common: include/linux src

Navdeep Parhar np at FreeBSD.org
Thu Mar 31 17:11:59 UTC 2016


Author: np
Date: Thu Mar 31 17:11:58 2016
New Revision: 297459
URL: https://svnweb.freebsd.org/changeset/base/297459

Log:
  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

Modified:
  head/sys/compat/linuxkpi/common/include/linux/jiffies.h
  head/sys/compat/linuxkpi/common/include/linux/wait.h
  head/sys/compat/linuxkpi/common/src/linux_compat.c

Modified: head/sys/compat/linuxkpi/common/include/linux/jiffies.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/jiffies.h	Thu Mar 31 17:00:47 2016	(r297458)
+++ head/sys/compat/linuxkpi/common/include/linux/jiffies.h	Thu Mar 31 17:11:58 2016	(r297459)
@@ -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_ */

Modified: head/sys/compat/linuxkpi/common/include/linux/wait.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/wait.h	Thu Mar 31 17:00:47 2016	(r297458)
+++ head/sys/compat/linuxkpi/common/include/linux/wait.h	Thu Mar 31 17:11:58 2016	(r297459)
@@ -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)
 {

Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_compat.c	Thu Mar 31 17:00:47 2016	(r297458)
+++ head/sys/compat/linuxkpi/common/src/linux_compat.c	Thu Mar 31 17:11:58 2016	(r297459)
@@ -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)
 {


More information about the svn-src-head mailing list