Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Mar 2018 16:17:36 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330851 - in stable/11/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201803131617.w2DGHafB000120@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Mar 13 16:17:36 2018
New Revision: 330851
URL: https://svnweb.freebsd.org/changeset/base/330851

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

Modified:
  stable/11/sys/compat/linuxkpi/common/include/linux/delay.h
  stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/delay.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/delay.h	Tue Mar 13 16:14:52 2018	(r330850)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/delay.h	Tue Mar 13 16:17:36 2018	(r330851)
@@ -36,14 +36,20 @@
 #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)
 
 static inline void
@@ -64,5 +70,7 @@ usleep_range(unsigned long min, unsigned long max)
 {
 	DELAY(min);
 }
+
+extern unsigned int linux_msleep_interruptible(unsigned int ms);
 
 #endif	/* _LINUX_DELAY_H_ */

Modified: stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c	Tue Mar 13 16:14:52 2018	(r330850)
+++ stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c	Tue Mar 13 16:17:36 2018	(r330851)
@@ -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>
@@ -72,6 +73,25 @@ linux_add_to_sleepqueue(void *wchan, struct task_struc
 		ret = -ERESTARTSYS;
 	}
 	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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803131617.w2DGHafB000120>