Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Use cv_timedwaitclock_sig in futex.
details: https://anonhg.NetBSD.org/src/rev/29f99dbd12ef
branches: trunk
changeset: 932242:29f99dbd12ef
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun May 03 01:25:48 2020 +0000
description:
Use cv_timedwaitclock_sig in futex.
Possible fix for hangs observed with Java under Linux emulation.
diffstat:
sys/kern/sys_futex.c | 70 +++++++++++++--------------------------------------
sys/sys/futex.h | 6 ++--
2 files changed, 21 insertions(+), 55 deletions(-)
diffs (160 lines):
diff -r 7b14a56bb2ac -r 29f99dbd12ef sys/kern/sys_futex.c
--- a/sys/kern/sys_futex.c Sun May 03 01:24:37 2020 +0000
+++ b/sys/kern/sys_futex.c Sun May 03 01:25:48 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_futex.c,v 1.7 2020/04/28 17:27:03 riastradh Exp $ */
+/* $NetBSD: sys_futex.c,v 1.8 2020/05/03 01:25:48 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.7 2020/04/28 17:27:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.8 2020/05/03 01:25:48 riastradh Exp $");
/*
* Futexes
@@ -916,17 +916,18 @@
}
/*
- * futex_wait(fw, deadline, clkid)
+ * futex_wait(fw, timeout, clkid, clkflags)
*
- * 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.
+ * 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.
*/
static int
-futex_wait(struct futex_wait *fw, const struct timespec *deadline,
- clockid_t clkid)
+futex_wait(struct futex_wait *fw, struct timespec *timeout, clockid_t clkid,
+ int clkflags)
{
int error = 0;
@@ -934,7 +935,7 @@
mutex_enter(&fw->fw_lock);
for (;;) {
- /* If we're done yet, stop and report success. */
+ /* If we're done already, stop and report success. */
if (fw->fw_bitset == 0 || fw->fw_futex == NULL) {
error = 0;
break;
@@ -945,30 +946,8 @@
break;
/* Not done yet. Wait. */
- 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);
- }
+ error = cv_timedwaitclock_sig(&fw->fw_cv, &fw->fw_lock,
+ timeout, clkid, clkflags, DEFAULT_TIMEOUT_EPSILON);
}
/*
@@ -1188,13 +1167,11 @@
*/
static int
futex_func_wait(bool shared, int *uaddr, int val, int val3,
- const struct timespec *timeout, clockid_t clkid, int clkflags,
+ 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;
/*
@@ -1208,17 +1185,6 @@
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)
@@ -1255,7 +1221,7 @@
f = NULL;
/* Wait. */
- error = futex_wait(fw, deadline, clkid);
+ error = futex_wait(fw, timeout, clkid, clkflags);
if (error)
goto out;
@@ -1580,8 +1546,8 @@
* parsed out.
*/
int
-do_futex(int *uaddr, int op, int val, const struct timespec *timeout,
- int *uaddr2, int val2, int val3, register_t *retval)
+do_futex(int *uaddr, int op, int val, 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 7b14a56bb2ac -r 29f99dbd12ef sys/sys/futex.h
--- a/sys/sys/futex.h Sun May 03 01:24:37 2020 +0000
+++ b/sys/sys/futex.h Sun May 03 01:25:48 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: futex.h,v 1.2 2020/04/27 02:54:42 rin Exp $ */
+/* $NetBSD: futex.h,v 1.3 2020/05/03 01:25:48 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, const struct timespec *, int *, int,
- int, register_t *);
+int do_futex(int *, int, int, 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