Tue May 5 15:23:32 2020 UTC ()
Revert "Make sure futex waits never return ERESTART."

Part of redoing the timedwaitclock changes, which were buggy and
committed a little too fast.


(riastradh)
diff -r1.9 -r1.10 src/sys/kern/sys_futex.c

cvs diff -r1.9 -r1.10 src/sys/kern/sys_futex.c (expand / switch to unified diff)

--- src/sys/kern/sys_futex.c 2020/05/03 01:26:39 1.9
+++ src/sys/kern/sys_futex.c 2020/05/05 15:23:32 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sys_futex.c,v 1.9 2020/05/03 01:26:39 riastradh Exp $ */ 1/* $NetBSD: sys_futex.c,v 1.10 2020/05/05 15:23:32 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell and Jason R. Thorpe. 8 * by Taylor R. Campbell and Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.9 2020/05/03 01:26:39 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.10 2020/05/05 15:23:32 riastradh Exp $");
34 34
35/* 35/*
36 * Futexes 36 * Futexes
37 * 37 *
38 * The futex system call coordinates notifying threads waiting for 38 * The futex system call coordinates notifying threads waiting for
39 * changes on a 32-bit word of memory. The word can be managed by 39 * changes on a 32-bit word of memory. The word can be managed by
40 * CPU atomic operations in userland, without system calls, as long 40 * CPU atomic operations in userland, without system calls, as long
41 * as there is no contention. 41 * as there is no contention.
42 * 42 *
43 * The simplest use case demonstrating the utility is: 43 * The simplest use case demonstrating the utility is:
44 * 44 *
45 * // 32-bit word of memory shared among threads or 45 * // 32-bit word of memory shared among threads or
46 * // processes in userland. lock & 1 means owned; 46 * // processes in userland. lock & 1 means owned;
@@ -944,36 +944,32 @@ futex_wait(struct futex_wait *fw, struct @@ -944,36 +944,32 @@ futex_wait(struct futex_wait *fw, struct
944 /* If anything went wrong in the last iteration, stop. */ 944 /* If anything went wrong in the last iteration, stop. */
945 if (error) 945 if (error)
946 break; 946 break;
947 947
948 /* Not done yet. Wait. */ 948 /* Not done yet. Wait. */
949 error = cv_timedwaitclock_sig(&fw->fw_cv, &fw->fw_lock, 949 error = cv_timedwaitclock_sig(&fw->fw_cv, &fw->fw_lock,
950 timeout, clkid, clkflags, DEFAULT_TIMEOUT_EPSILON); 950 timeout, clkid, clkflags, DEFAULT_TIMEOUT_EPSILON);
951 } 951 }
952 952
953 /* 953 /*
954 * If we were woken up, the waker will have removed fw from the 954 * If we were woken up, the waker will have removed fw from the
955 * queue. But if anything went wrong, we must remove fw from 955 * queue. But if anything went wrong, we must remove fw from
956 * the queue ourselves. While here, convert EWOULDBLOCK to 956 * the queue ourselves. While here, convert EWOULDBLOCK to
957 * ETIMEDOUT in case cv_timedwait_sig returned EWOULDBLOCK, and 957 * ETIMEDOUT.
958 * convert ERESTART to EINTR so that we don't restart with the 
959 * same relative timeout after time has elapsed. 
960 */ 958 */
961 if (error) { 959 if (error) {
962 futex_wait_abort(fw); 960 futex_wait_abort(fw);
963 if (error == EWOULDBLOCK) 961 if (error == EWOULDBLOCK)
964 error = ETIMEDOUT; 962 error = ETIMEDOUT;
965 else if (error == ERESTART) 
966 error = EINTR; 
967 } 963 }
968 964
969 mutex_exit(&fw->fw_lock); 965 mutex_exit(&fw->fw_lock);
970 966
971 return error; 967 return error;
972} 968}
973 969
974/* 970/*
975 * futex_wake(f, nwake, f2, nrequeue, bitset) 971 * futex_wake(f, nwake, f2, nrequeue, bitset)
976 * 972 *
977 * Wake up to nwake waiters on f matching bitset; then, if f2 is 973 * Wake up to nwake waiters on f matching bitset; then, if f2 is
978 * provided, move up to nrequeue remaining waiters on f matching 974 * provided, move up to nrequeue remaining waiters on f matching
979 * bitset to f2. Return the number of waiters actually woken. 975 * bitset to f2. Return the number of waiters actually woken.