From owner-svn-src-user@FreeBSD.ORG Mon Mar 11 20:01:39 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 1C3A4895; Mon, 11 Mar 2013 20:01:39 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 0F29AD2F; Mon, 11 Mar 2013 20:01:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2BK1c26073581; Mon, 11 Mar 2013 20:01:38 GMT (envelope-from dchagin@svn.freebsd.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2BK1csD073580; Mon, 11 Mar 2013 20:01:38 GMT (envelope-from dchagin@svn.freebsd.org) Message-Id: <201303112001.r2BK1csD073580@svn.freebsd.org> From: Dmitry Chagin Date: Mon, 11 Mar 2013 20:01:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r248174 - user/dchagin/lemul/sys/compat/linux X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Mar 2013 20:01:39 -0000 Author: dchagin Date: Mon Mar 11 20:01:38 2013 New Revision: 248174 URL: http://svnweb.freebsd.org/changeset/base/248174 Log: When the FUTEX_CLOCK_REALTIME is specified the timeout is an absolute time, not a relative time. Rework futex_wait to handle this. On the side fix the futex leak in error case and remove useless parentheses. Modified: user/dchagin/lemul/sys/compat/linux/linux_futex.c Modified: user/dchagin/lemul/sys/compat/linux/linux_futex.c ============================================================================== --- user/dchagin/lemul/sys/compat/linux/linux_futex.c Mon Mar 11 18:01:55 2013 (r248173) +++ user/dchagin/lemul/sys/compat/linux/linux_futex.c Mon Mar 11 20:01:38 2013 (r248174) @@ -125,9 +125,7 @@ LIN_SDT_PROBE_DEFINE3(futex, futex_reque "struct waiting_proc *", "uint32_t"); LIN_SDT_PROBE_DEFINE1(futex, futex_requeue, return, "int"); LIN_SDT_PROBE_DEFINE4(futex, futex_wait, entry, "struct futex *", - "struct waiting_proc **", "struct l_timespec *", "uint32_t"); -LIN_SDT_PROBE_DEFINE1(futex, futex_wait, copyin_error, "int"); -LIN_SDT_PROBE_DEFINE1(futex, futex_wait, itimerfix_error, "int"); + "struct waiting_proc **", "int", "uint32_t"); LIN_SDT_PROBE_DEFINE1(futex, futex_wait, sleep_error, "int"); LIN_SDT_PROBE_DEFINE1(futex, futex_wait, return, "int"); LIN_SDT_PROBE_DEFINE3(futex, futex_atomic_op, entry, "struct thread *", @@ -141,6 +139,7 @@ LIN_SDT_PROBE_DEFINE1(futex, futex_atomi LIN_SDT_PROBE_DEFINE2(futex, linux_sys_futex, entry, "struct thread *", "struct linux_sys_futex_args *"); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, unimplemented_clockswitch); +LIN_SDT_PROBE_DEFINE1(futex, linux_sys_futex, itimerfix_error, "int"); LIN_SDT_PROBE_DEFINE1(futex, linux_sys_futex, copyin_error, "int"); LIN_SDT_PROBE_DEFINE0(futex, linux_sys_futex, invalid_cmp_requeue_use); LIN_SDT_PROBE_DEFINE3(futex, linux_sys_futex, debug_wait, "uint32_t *", @@ -552,15 +551,12 @@ futex_requeue(struct futex *f, int n, st } static int -futex_wait(struct futex *f, struct waiting_proc *wp, struct l_timespec *ts, +futex_wait(struct futex *f, struct waiting_proc *wp, int timeout_hz, uint32_t bitset) { - struct l_timespec timeout; - struct timeval tv; - int timeout_hz; int error; - LIN_SDT_PROBE4(futex, futex_wait, entry, f, wp, ts, bitset); + LIN_SDT_PROBE4(futex, futex_wait, entry, f, wp, timeout_hz, bitset); if (bitset == 0) { LIN_SDT_PROBE1(futex, futex_wait, return, EINVAL); @@ -568,30 +564,9 @@ futex_wait(struct futex *f, struct waiti } f->f_bitset = bitset; - - if (ts != NULL) { - error = copyin(ts, &timeout, sizeof(timeout)); - if (error) { - LIN_SDT_PROBE1(futex, futex_wait, copyin_error, error); - LIN_SDT_PROBE1(futex, futex_wait, return, error); - return (error); - } - TIMESPEC_TO_TIMEVAL(&tv, &timeout); - error = itimerfix(&tv); - if (error) { - LIN_SDT_PROBE1(futex, futex_wait, itimerfix_error, - error); - LIN_SDT_PROBE1(futex, futex_wait, return, error); - return (error); - } - timeout_hz = tvtohz(&tv); - } else - timeout_hz = 0; - error = futex_sleep(f, wp, timeout_hz); - if (error) { + if (error) LIN_SDT_PROBE1(futex, futex_wait, sleep_error, error); - } if (error == EWOULDBLOCK) error = ETIMEDOUT; @@ -681,6 +656,9 @@ linux_sys_futex(struct thread *td, struc struct linux_emuldata *em; struct waiting_proc *wp; struct futex *f, *f2; + struct l_timespec timeout; + struct timeval utv, ctv; + int timeout_hz; int error; uint32_t flags; @@ -754,7 +732,35 @@ linux_sys_futex(struct thread *td, struc return (EWOULDBLOCK); } - error = futex_wait(f, wp, args->timeout, args->val3); + if (args->timeout != NULL) { + error = copyin(args->timeout, &timeout, sizeof(timeout)); + if (error) { + LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error, + error); + LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + futex_put(f, wp); + return (error); + } + TIMESPEC_TO_TIMEVAL(&utv, &timeout); + error = itimerfix(&utv); + if (error) { + LIN_SDT_PROBE1(futex, linux_sys_futex, itimerfix_error, + error); + LIN_SDT_PROBE1(futex, linux_sys_futex, return, error); + futex_put(f, wp); + return (error); + } + if (clockrt) { + microtime(&ctv); + timevalsub(&utv, &ctv); + } + if (utv.tv_sec < 0) + timevalclear(&utv); + timeout_hz = tvtohz(&utv); + } else + timeout_hz = 0; + + error = futex_wait(f, wp, timeout_hz, args->val3); break; case LINUX_FUTEX_WAKE: