Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 May 2014 14:58:53 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r266924 - head/sys/compat/linux
Message-ID:  <201405311458.s4VEwrWY058828@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sat May 31 14:58:53 2014
New Revision: 266924
URL: http://svnweb.freebsd.org/changeset/base/266924

Log:
  Glibc was switched to the FUTEX_WAIT_BITSET op and CLOCK_REALTIME
  flag has been added instead of FUTEX_WAIT to replace the FUTEX_WAIT
  logic which needs to do gettimeofday() calls before the futex syscall
  to convert the absolute timeout to a relative timeout.
  Before this the CLOCK_MONOTONIC used by the FUTEX_WAIT_BITSET op.
  
  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.
  
  Properly calculate the timeout for the CLOCK_MONOTONIC case.
  
  MFC after:	3 days

Modified:
  head/sys/compat/linux/linux_futex.c

Modified: head/sys/compat/linux/linux_futex.c
==============================================================================
--- head/sys/compat/linux/linux_futex.c	Sat May 31 14:38:05 2014	(r266923)
+++ head/sys/compat/linux/linux_futex.c	Sat May 31 14:58:53 2014	(r266924)
@@ -128,9 +128,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 *",
@@ -144,6 +142,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 *",
@@ -554,15 +553,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);
@@ -570,30 +566,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;
 
@@ -683,6 +658,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, val;
 
@@ -756,7 +734,38 @@ 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);
+			} else if (args->op == LINUX_FUTEX_WAIT_BITSET) {
+				microuptime(&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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405311458.s4VEwrWY058828>