Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Dec 2011 15:37:31 +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-9@freebsd.org
Subject:   svn commit: r229119 - in stable/9/sys: dev/usb kern
Message-ID:  <201112311537.pBVFbVRb071249@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sat Dec 31 15:37:31 2011
New Revision: 229119
URL: http://svn.freebsd.org/changeset/base/229119

Log:
  MFC r227706, r227748, r227749 and r228234:
  Simplify the usb_pause_mtx() function by factoring out the generic parts
  to the kernel's pause() function. The pause() function can now be used
  when cold != 0. Also assert that the timeout in system ticks must be
  greater or equal to zero.

Modified:
  stable/9/sys/dev/usb/usb_util.c
  stable/9/sys/kern/kern_synch.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)

Modified: stable/9/sys/dev/usb/usb_util.c
==============================================================================
--- stable/9/sys/dev/usb/usb_util.c	Sat Dec 31 15:31:34 2011	(r229118)
+++ stable/9/sys/dev/usb/usb_util.c	Sat Dec 31 15:37:31 2011	(r229119)
@@ -115,33 +115,21 @@ device_set_usb_desc(device_t dev)
  *
  * This function will delay the code by the passed number of system
  * ticks. The passed mutex "mtx" will be dropped while waiting, if
- * "mtx" is not NULL.
+ * "mtx" is different from NULL.
  *------------------------------------------------------------------------*/
 void
-usb_pause_mtx(struct mtx *mtx, int _ticks)
+usb_pause_mtx(struct mtx *mtx, int timo)
 {
 	if (mtx != NULL)
 		mtx_unlock(mtx);
 
-	if (cold) {
-		/* convert to milliseconds */
-		_ticks = (_ticks * 1000) / hz;
-		/* convert to microseconds, rounded up */
-		_ticks = (_ticks + 1) * 1000;
-		DELAY(_ticks);
-
-	} else {
-
-		/*
-		 * Add one to the number of ticks so that we don't return
-		 * too early!
-		 */
-		_ticks++;
-
-		if (pause("USBWAIT", _ticks)) {
-			/* ignore */
-		}
-	}
+	/*
+	 * Add one tick to the timeout so that we don't return too
+	 * early! Note that pause() will assert that the passed
+	 * timeout is positive and non-zero!
+	 */
+	pause("USBWAIT", timo + 1);
+
 	if (mtx != NULL)
 		mtx_lock(mtx);
 }

Modified: stable/9/sys/kern/kern_synch.c
==============================================================================
--- stable/9/sys/kern/kern_synch.c	Sat Dec 31 15:31:34 2011	(r229118)
+++ stable/9/sys/kern/kern_synch.c	Sat Dec 31 15:37:31 2011	(r229119)
@@ -325,16 +325,34 @@ msleep_spin(void *ident, struct mtx *mtx
 }
 
 /*
- * pause() is like tsleep() except that the intention is to not be
- * explicitly woken up by another thread.  Instead, the current thread
- * simply wishes to sleep until the timeout expires.  It is
- * implemented using a dummy wait channel.
+ * pause() delays the calling thread by the given number of system ticks.
+ * During cold bootup, pause() uses the DELAY() function instead of
+ * the tsleep() function to do the waiting. The "timo" argument must be
+ * greater than or equal to zero. A "timo" value of zero is equivalent
+ * to a "timo" value of one.
  */
 int
 pause(const char *wmesg, int timo)
 {
+	KASSERT(timo >= 0, ("pause: timo must be >= 0"));
 
-	KASSERT(timo != 0, ("pause: timeout required"));
+	/* silently convert invalid timeouts */
+	if (timo < 1)
+		timo = 1;
+
+	if (cold) {
+		/*
+		 * We delay one HZ at a time to avoid overflowing the
+		 * system specific DELAY() function(s):
+		 */
+		while (timo >= hz) {
+			DELAY(1000000);
+			timo -= hz;
+		}
+		if (timo > 0)
+			DELAY(timo * tick);
+		return (0);
+	}
 	return (tsleep(&pause_wchan, 0, wmesg, timo));
 }
 



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