From owner-svn-src-all@FreeBSD.ORG Tue Aug 24 07:29:55 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B2741065672; Tue, 24 Aug 2010 07:29:55 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5B1FB8FC1E; Tue, 24 Aug 2010 07:29:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7O7Tt8H066820; Tue, 24 Aug 2010 07:29:55 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7O7TtBG066818; Tue, 24 Aug 2010 07:29:55 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201008240729.o7O7TtBG066818@svn.freebsd.org> From: David Xu Date: Tue, 24 Aug 2010 07:29:55 +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: r211733 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 24 Aug 2010 07:29:55 -0000 Author: davidxu Date: Tue Aug 24 07:29:55 2010 New Revision: 211733 URL: http://svn.freebsd.org/changeset/base/211733 Log: Optimize thr_suspend, if timeout is zero, don't call msleep, just return immediately. Modified: head/sys/kern/kern_thr.c Modified: head/sys/kern/kern_thr.c ============================================================================== --- head/sys/kern/kern_thr.c Tue Aug 24 07:22:24 2010 (r211732) +++ head/sys/kern/kern_thr.c Tue Aug 24 07:29:55 2010 (r211733) @@ -430,15 +430,12 @@ int kern_thr_suspend(struct thread *td, struct timespec *tsp) { struct timeval tv; - int error = 0, hz = 0; + int error = 0; + int timo = 0; if (tsp != NULL) { if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000) return (EINVAL); - if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) - return (ETIMEDOUT); - TIMESPEC_TO_TIMEVAL(&tv, tsp); - hz = tvtohz(&tv); } if (td->td_pflags & TDP_WAKEUP) { @@ -447,9 +444,17 @@ kern_thr_suspend(struct thread *td, stru } PROC_LOCK(td->td_proc); - if ((td->td_flags & TDF_THRWAKEUP) == 0) - error = msleep((void *)td, &td->td_proc->p_mtx, PCATCH, "lthr", - hz); + if ((td->td_flags & TDF_THRWAKEUP) == 0) { + if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) + error = EWOULDBLOCK; + else { + TIMESPEC_TO_TIMEVAL(&tv, tsp); + timo = tvtohz(&tv); + error = msleep((void *)td, &td->td_proc->p_mtx, + PCATCH, "lthr", timo); + } + } + if (td->td_flags & TDF_THRWAKEUP) { thread_lock(td); td->td_flags &= ~TDF_THRWAKEUP; @@ -461,7 +466,7 @@ kern_thr_suspend(struct thread *td, stru if (error == EWOULDBLOCK) error = ETIMEDOUT; else if (error == ERESTART) { - if (hz != 0) + if (timo != 0) error = EINTR; } return (error);