From owner-svn-src-all@freebsd.org Thu Mar 31 17:11:59 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6ABA6AE4D2C; Thu, 31 Mar 2016 17:11:59 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 478581658; Thu, 31 Mar 2016 17:11:59 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2VHBw8v072906; Thu, 31 Mar 2016 17:11:58 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2VHBwFq072903; Thu, 31 Mar 2016 17:11:58 GMT (envelope-from np@FreeBSD.org) Message-Id: <201603311711.u2VHBwFq072903@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Thu, 31 Mar 2016 17:11:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297459 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2016 17:11:59 -0000 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 #include #include +#include #include #include @@ -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) {