Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Revert "Use cv_timedwaitclock_sig in futex."
details: https://anonhg.NetBSD.org/src/rev/6e6aec743579
branches: trunk
changeset: 971822:6e6aec743579
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue May 05 15:25:18 2020 +0000
description:
Revert "Use cv_timedwaitclock_sig in futex."
Turned out to break things; we'll do this another way.
diffstat:
sys/kern/sys_futex.c | 70 ++++++++++++++++++++++++++++++++++++++-------------
sys/sys/futex.h | 6 ++--
2 files changed, 55 insertions(+), 21 deletions(-)
diffs (160 lines):
diff -r 6eb5776bf409 -r 6e6aec743579 sys/kern/sys_futex.c
--- a/sys/kern/sys_futex.c Tue May 05 15:23:32 2020 +0000
+++ b/sys/kern/sys_futex.c Tue May 05 15:25:18 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_futex.c,v 1.10 2020/05/05 15:23:32 riastradh Exp $ */
+/* $NetBSD: sys_futex.c,v 1.11 2020/05/05 15:25:18 riastradh Exp $ */
/*-
* Copyright (c) 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.10 2020/05/05 15:23:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.11 2020/05/05 15:25:18 riastradh Exp $");
/*
* Futexes
@@ -916,18 +916,17 @@
}
/*
- * futex_wait(fw, timeout, clkid, clkflags)
+ * futex_wait(fw, deadline, clkid)
*
- * fw must be a waiter on a futex's queue. Wait for timeout on
- * the clock clkid according to clkflags (TIMER_*), or forever if
- * timeout is NULL, for a futex wakeup. Return 0 on explicit
- * wakeup or destruction of futex, ETIMEDOUT on timeout,
- * EINTR/ERESTART on signal. Either way, fw will no longer be on
- * a futex queue on return.
+ * fw must be a waiter on a futex's queue. Wait until deadline on
+ * the clock clkid, or forever if deadline is NULL, for a futex
+ * wakeup. Return 0 on explicit wakeup or destruction of futex,
+ * ETIMEDOUT on timeout, EINTR/ERESTART on signal. Either way, fw
+ * will no longer be on a futex queue on return.
*/
static int
-futex_wait(struct futex_wait *fw, struct timespec *timeout, clockid_t clkid,
- int clkflags)
+futex_wait(struct futex_wait *fw, const struct timespec *deadline,
+ clockid_t clkid)
{
int error = 0;
@@ -935,7 +934,7 @@
mutex_enter(&fw->fw_lock);
for (;;) {
- /* If we're done already, stop and report success. */
+ /* If we're done yet, stop and report success. */
if (fw->fw_bitset == 0 || fw->fw_futex == NULL) {
error = 0;
break;
@@ -946,8 +945,30 @@
break;
/* Not done yet. Wait. */
- error = cv_timedwaitclock_sig(&fw->fw_cv, &fw->fw_lock,
- timeout, clkid, clkflags, DEFAULT_TIMEOUT_EPSILON);
+ if (deadline) {
+ struct timespec ts;
+
+ /* Check our watch. */
+ error = clock_gettime1(clkid, &ts);
+ if (error)
+ break;
+
+ /* If we're past the deadline, ETIMEDOUT. */
+ if (timespeccmp(deadline, &ts, <=)) {
+ error = ETIMEDOUT;
+ break;
+ }
+
+ /* Count how much time is left. */
+ timespecsub(deadline, &ts, &ts);
+
+ /* Wait for that much time, allowing signals. */
+ error = cv_timedwait_sig(&fw->fw_cv, &fw->fw_lock,
+ tstohz(&ts));
+ } else {
+ /* Wait indefinitely, allowing signals. */
+ error = cv_wait_sig(&fw->fw_cv, &fw->fw_lock);
+ }
}
/*
@@ -1167,11 +1188,13 @@
*/
static int
futex_func_wait(bool shared, int *uaddr, int val, int val3,
- struct timespec *timeout, clockid_t clkid, int clkflags,
+ const struct timespec *timeout, clockid_t clkid, int clkflags,
register_t *retval)
{
struct futex *f;
struct futex_wait wait, *fw = &wait;
+ struct timespec ts;
+ const struct timespec *deadline;
int error;
/*
@@ -1185,6 +1208,17 @@
if (!futex_test(uaddr, val))
return EAGAIN;
+ /* Determine a deadline on the specified clock. */
+ if (timeout == NULL || (clkflags & TIMER_ABSTIME) == TIMER_ABSTIME) {
+ deadline = timeout;
+ } else {
+ error = clock_gettime1(clkid, &ts);
+ if (error)
+ return error;
+ timespecadd(&ts, timeout, &ts);
+ deadline = &ts;
+ }
+
/* Get the futex, creating it if necessary. */
error = futex_lookup_create(uaddr, shared, &f);
if (error)
@@ -1221,7 +1255,7 @@
f = NULL;
/* Wait. */
- error = futex_wait(fw, timeout, clkid, clkflags);
+ error = futex_wait(fw, deadline, clkid);
if (error)
goto out;
@@ -1546,8 +1580,8 @@
* parsed out.
*/
int
-do_futex(int *uaddr, int op, int val, struct timespec *timeout, int *uaddr2,
- int val2, int val3, register_t *retval)
+do_futex(int *uaddr, int op, int val, const struct timespec *timeout,
+ int *uaddr2, int val2, int val3, register_t *retval)
{
const bool shared = (op & FUTEX_PRIVATE_FLAG) ? false : true;
const clockid_t clkid = (op & FUTEX_CLOCK_REALTIME) ? CLOCK_REALTIME
diff -r 6eb5776bf409 -r 6e6aec743579 sys/sys/futex.h
--- a/sys/sys/futex.h Tue May 05 15:23:32 2020 +0000
+++ b/sys/sys/futex.h Tue May 05 15:25:18 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: futex.h,v 1.3 2020/05/03 01:25:48 riastradh Exp $ */
+/* $NetBSD: futex.h,v 1.4 2020/05/05 15:25:18 riastradh Exp $ */
/*-
* Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
@@ -175,8 +175,8 @@
int futex_robust_head_lookup(struct lwp *, lwpid_t, void **);
void futex_release_all_lwp(struct lwp *, lwpid_t);
-int do_futex(int *, int, int, struct timespec *, int *, int, int,
- register_t *);
+int do_futex(int *, int, int, const struct timespec *, int *, int,
+ int, register_t *);
void futex_sys_init(void);
void futex_sys_fini(void);
#endif /* _KERNEL */
Home |
Main Index |
Thread Index |
Old Index