From owner-svn-src-head@FreeBSD.ORG Sat Nov 19 11:17:28 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 79DE91065673; Sat, 19 Nov 2011 11:17:28 +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 5FDE58FC08; Sat, 19 Nov 2011 11:17:28 +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 pAJBHSPY039926; Sat, 19 Nov 2011 11:17:28 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pAJBHSXC039923; Sat, 19 Nov 2011 11:17:28 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201111191117.pAJBHSXC039923@svn.freebsd.org> From: Hans Petter Selasky Date: Sat, 19 Nov 2011 11:17:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r227706 - in head/sys: dev/usb kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Nov 2011 11:17:28 -0000 Author: hselasky Date: Sat Nov 19 11:17:27 2011 New Revision: 227706 URL: http://svn.freebsd.org/changeset/base/227706 Log: 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 positive. Suggested by: Bruce Evans MFC after: 1 week Modified: head/sys/dev/usb/usb_util.c head/sys/kern/kern_synch.c Modified: head/sys/dev/usb/usb_util.c ============================================================================== --- head/sys/dev/usb/usb_util.c Sat Nov 19 10:49:03 2011 (r227705) +++ head/sys/dev/usb/usb_util.c Sat Nov 19 11:17:27 2011 (r227706) @@ -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: head/sys/kern/kern_synch.c ============================================================================== --- head/sys/kern/kern_synch.c Sat Nov 19 10:49:03 2011 (r227705) +++ head/sys/kern/kern_synch.c Sat Nov 19 11:17:27 2011 (r227706) @@ -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() is almost 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. During cold bootup pause() + * will use the DELAY() function instead of tsleep() to wait the given + * number of system ticks. The passed "timo" argument must not be + * negative and also greater than zero. */ int pause(const char *wmesg, int timo) { - KASSERT(timo != 0, ("pause: timeout required")); + KASSERT(timo > 0, ("pause: a positive and non-zero " + "timeout is required")); + + if (cold) { + /* + * We delay one HZ at a time to avoid overflowing the + * DELAY() argument: + */ + while (timo >= hz) { + DELAY(1000000); + timo -= hz; + } + if (timo > 0) + DELAY(timo * tick); + return (0); + } return (tsleep(&pause_wchan, 0, wmesg, timo)); }