From owner-svn-src-stable@FreeBSD.ORG Sat Dec 31 15:37:32 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 513BE106566C; Sat, 31 Dec 2011 15:37:32 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 304A88FC12; Sat, 31 Dec 2011 15:37:32 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pBVFbW89071252; Sat, 31 Dec 2011 15:37:32 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pBVFbVRb071249; Sat, 31 Dec 2011 15:37:31 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201112311537.pBVFbVRb071249@svn.freebsd.org> From: Hans Petter Selasky Date: Sat, 31 Dec 2011 15:37:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r229119 - in stable/9/sys: dev/usb kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Dec 2011 15:37:32 -0000 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)); }