From owner-svn-src-all@FreeBSD.ORG Wed Oct 6 18:51:23 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 128A5106566C; Wed, 6 Oct 2010 18:51:23 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DBBFA8FC16; Wed, 6 Oct 2010 18:51:22 +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 o96IpMcx014670; Wed, 6 Oct 2010 18:51:22 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o96IpMCx014668; Wed, 6 Oct 2010 18:51:22 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201010061851.o96IpMCx014668@svn.freebsd.org> From: Jung-uk Kim Date: Wed, 6 Oct 2010 18:51:22 +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: r213490 - head/sys/compat/linux 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: Wed, 06 Oct 2010 18:51:23 -0000 Author: jkim Date: Wed Oct 6 18:51:22 2010 New Revision: 213490 URL: http://svn.freebsd.org/changeset/base/213490 Log: Simplify timeout check in futex_wait() using itimerfix() and return error if the given timeout is invalid. Consistently use int type for timeout and correct a format string in futex_sleep(). Modified: head/sys/compat/linux/linux_futex.c Modified: head/sys/compat/linux/linux_futex.c ============================================================================== --- head/sys/compat/linux/linux_futex.c Wed Oct 6 18:36:50 2010 (r213489) +++ head/sys/compat/linux/linux_futex.c Wed Oct 6 18:51:22 2010 (r213490) @@ -238,12 +238,12 @@ futex_get(uint32_t *uaddr, struct waitin } static int -futex_sleep(struct futex *f, struct waiting_proc *wp, unsigned long timeout) +futex_sleep(struct futex *f, struct waiting_proc *wp, int timeout) { int error; FUTEX_ASSERT_LOCKED(f); - LINUX_CTR4(sys_futex, "futex_sleep enter uaddr %p wp %p timo %ld ref %d", + LINUX_CTR4(sys_futex, "futex_sleep enter uaddr %p wp %p timo %d ref %d", f->f_uaddr, wp, timeout, f->f_refcount); error = sx_sleep(wp, &f->f_lck, PCATCH, "futex", timeout); if (wp->wp_flags & FUTEX_WP_REQUEUED) { @@ -327,8 +327,8 @@ futex_requeue(struct futex *f, int n, st static int futex_wait(struct futex *f, struct waiting_proc *wp, struct l_timespec *ts) { - struct l_timespec timeout = {0, 0}; - struct timeval tv = {0, 0}; + struct l_timespec timeout; + struct timeval tv; int timeout_hz; int error; @@ -336,26 +336,14 @@ futex_wait(struct futex *f, struct waiti error = copyin(ts, &timeout, sizeof(timeout)); if (error) return (error); - } - - tv.tv_usec = timeout.tv_sec * 1000000 + timeout.tv_nsec / 1000; - timeout_hz = tvtohz(&tv); - - if (timeout.tv_sec == 0 && timeout.tv_nsec == 0) + TIMESPEC_TO_TIMEVAL(&tv, &timeout); + error = itimerfix(&tv); + if (error) + return (error); + timeout_hz = tvtohz(&tv); + } else timeout_hz = 0; - /* - * If the user process requests a non null timeout, - * make sure we do not turn it into an infinite - * timeout because timeout_hz gets null. - * - * We use a minimal timeout of 1/hz. Maybe it would - * make sense to just return ETIMEDOUT without sleeping. - */ - if (((timeout.tv_sec != 0) || (timeout.tv_nsec != 0)) && - (timeout_hz == 0)) - timeout_hz = 1; - error = futex_sleep(f, wp, timeout_hz); if (error == EWOULDBLOCK) error = ETIMEDOUT;