Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Remove timedwaitclock.



details:   https://anonhg.NetBSD.org/src/rev/7d6df39e77ec
branches:  trunk
changeset: 971962:7d6df39e77ec
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon May 11 03:59:33 2020 +0000

description:
Remove timedwaitclock.

This did not fix the bug I hoped it would fix in futex, and needs
more design thought.  Might redo it somewhat differently later.

diffstat:

 share/man/man9/condvar.9 |   79 +-------------------------
 sys/kern/kern_condvar.c  |   73 +-----------------------
 sys/kern/subr_time.c     |  142 +----------------------------------------------
 sys/sys/condvar.h        |    6 +-
 sys/sys/timevar.h        |   15 +----
 5 files changed, 7 insertions(+), 308 deletions(-)

diffs (truncated from 421 to 300 lines):

diff -r ff0ba0bfcba4 -r 7d6df39e77ec share/man/man9/condvar.9
--- a/share/man/man9/condvar.9  Mon May 11 03:00:57 2020 +0000
+++ b/share/man/man9/condvar.9  Mon May 11 03:59:33 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: condvar.9,v 1.27 2020/05/03 04:06:15 riastradh Exp $
+.\"    $NetBSD: condvar.9,v 1.28 2020/05/11 03:59:33 riastradh Exp $
 .\"
 .\" Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -65,13 +65,6 @@
 .Ft int
 .Fn cv_timedwaitbt_sig "kcondvar_t *cv" "kmutex_t *mtx" "struct bintime *bt" \
 "const struct bintime *epsilon"
-.Ft int
-.Fn cv_timedwaitclock "kcondvar_t *cv" "kmutex_t *mtx" \
-"struct timespec *timeout" "clockid_t clockid" "int flags" \
-"const struct bintime *epsilon"
-.Fn cv_timedwaitclock_sig "kcondvar_t *cv" "kmutex_t *mtx" \
-"struct timespec *timeout" "clockid_t clockid" "int flags" \
-"const struct bintime *epsilon"
 .Ft void
 .Fn cv_signal "kcondvar_t *cv"
 .Ft void
@@ -264,47 +257,6 @@
 resolution and by scheduling competition, which may delay the wakeup by
 more than
 .Fa bt Li "+" Fa epsilon .
-.It Fn cv_timedwaitclock "cv" "lock" "timeout" "clockid" "flags" "epsilon"
-.It Fn cv_timedwaitclock_sig "cv" "lock" "timeout" "clockid" "flags" "epsilon"
-As per
-.Fn cv_wait
-and
-.Fn cv_wait_sig ,
-but will return early in case of timeout.
-The timeout is measured by the clock
-.Fa clockid ;
-see
-.Xr clock_settime 2
-for the supported options.
-The
-.Fa flags
-may be
-.Dv TIMER_RELTIME
-for a relative duration or
-.Dv TIMER_ABSTIME
-for an absolute time on the clock.
-For relative timeouts,
-.Fn cv_timedwaitclock
-and
-.Fn cv_timedwaitclock_sig
-subtract the elapsed time from
-.Fa timeout
-in place, or set it to zero if there is no time remaining.
-The hint
-.Fa epsilon
-requests a maximum delay after the timeout before wakeup.
-.Pp
-It is safe to pass in values of
-.Fa clockid
-and
-.Fa flags
-from userland, and timeouts copied in from userland; if anything is
-wrong with them,
-.Fn cv_timedwaitclock
-or
-.Fn cv_timedwaitclock_sig
-will return
-.Er EINVAL .
 .It Fn cv_signal "cv"
 .Pp
 Awaken one LWP waiting on the specified condition variable.
@@ -380,29 +332,6 @@
        consume(res);
 .Ed
 .Pp
-Consuming a resource using a timeout specified in a syscall by
-userland:
-.Bd -literal
-       struct timespec timeout;
-
-       error = copyin(SCARG(uap, timeout), &timeout, sizeof timeout);
-       if (error)
-               return error;
-
-       mutex_enter(&res->mutex);
-       while (res->state == BUSY) {
-               error = cv_timedwaitclock_sig(&res->condvar,
-                   &res->mutex, &timeout, SCARG(uap, clock_id),
-                   SCARG(uap, flags), DEFAULT_TIMEOUT_EPSILON);
-               if (error)
-                       break;
-       }
-       mutex_exit(&res->mutex);
-       if (error)
-               return error;
-       consume(res);
-.Ed
-.Pp
 Releasing a resource for the next consumer to use:
 .Bd -literal
        mutex_enter(&res->mutex);
@@ -442,9 +371,3 @@
 .Fn cv_timedwaitbt_sig
 primitives first appeared in
 .Nx 9.0 .
-The
-.Fn cv_timedwaitclock
-and
-.Fn cv_timedwaitclock_sig
-primitives first appeared in
-.Nx 10.0 .
diff -r ff0ba0bfcba4 -r 7d6df39e77ec sys/kern/kern_condvar.c
--- a/sys/kern/kern_condvar.c   Mon May 11 03:00:57 2020 +0000
+++ b/sys/kern/kern_condvar.c   Mon May 11 03:59:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_condvar.c,v 1.51 2020/05/04 18:23:37 riastradh Exp $      */
+/*     $NetBSD: kern_condvar.c,v 1.52 2020/05/11 03:59:33 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.51 2020/05/04 18:23:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.52 2020/05/11 03:59:33 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -245,75 +245,6 @@
 }
 
 /*
- * cv_timedwaitclock:
- *
- *     Wait on a condition variable until awoken normally, or the
- *     specified timeout expires according to the provided clock.
- *     Returns zero if awoken normally or EWOULDBLOCK if the timeout
- *     expired.  For relative timeouts ((flags & TIMER_ABSTIME) == 0),
- *     updates timeout with the time left.
- *
- *     timeout == NULL specifies an infinite timeout.  epsilon is a
- *     requested maximum error in timeout (excluding spurious
- *     wakeups).
- */
-int
-cv_timedwaitclock(kcondvar_t *cv, kmutex_t *mtx, struct timespec *timeout,
-    clockid_t clockid, int flags, const struct bintime *epsilon)
-{
-       struct timedwaitclock T;
-       int timo;
-       int error;
-
-       if (timeout == NULL) {
-               cv_wait(cv, mtx);
-               return 0;
-       }
-
-       timedwaitclock_setup(&T, timeout, clockid, flags, epsilon);
-       error = timedwaitclock_begin(&T, &timo);
-       if (error)
-               return error;
-       error = cv_timedwait(cv, mtx, timo);
-       timedwaitclock_end(&T);
-       return error;
-}
-
-/*
- * cv_timedwaitclock_sig:
- *
- *     Wait on a condition variable until awoken normally, interrupted
- *     by a signal, or the specified timeout expires according to the
- *     provided clock.  Returns zero if awoken normally,
- *     EINTR/ERESTART if interrupted by a signal, or EWOULDBLOCK if
- *     the timeout expired.  For relative timeouts ((flags &
- *     TIMER_ABSTIME) == 0), updates timeout with the time left.
- *
- *     timeout == NULL specifies an infinite timeout.  epsilon is a
- *     requested maximum error in timeout (excluding spurious
- *     wakeups).
- */
-int
-cv_timedwaitclock_sig(kcondvar_t *cv, kmutex_t *mtx, struct timespec *timeout,
-    clockid_t clockid, int flags, const struct bintime *epsilon)
-{
-       struct timedwaitclock T;
-       int timo;
-       int error;
-
-       if (timeout == NULL)
-               return cv_wait_sig(cv, mtx);
-
-       timedwaitclock_setup(&T, timeout, clockid, flags, epsilon);
-       error = timedwaitclock_begin(&T, &timo);
-       if (error)
-               return error;
-       error = cv_timedwait_sig(cv, mtx, timo);
-       timedwaitclock_end(&T);
-       return error;
-}
-
-/*
  * Given a number of seconds, sec, and 2^64ths of a second, frac, we
  * want a number of ticks for a timeout:
  *
diff -r ff0ba0bfcba4 -r 7d6df39e77ec sys/kern/subr_time.c
--- a/sys/kern/subr_time.c      Mon May 11 03:00:57 2020 +0000
+++ b/sys/kern/subr_time.c      Mon May 11 03:59:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_time.c,v 1.23 2020/05/04 18:23:37 riastradh Exp $ */
+/*     $NetBSD: subr_time.c,v 1.24 2020/05/11 03:59:33 riastradh Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.23 2020/05/04 18:23:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.24 2020/05/11 03:59:33 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -354,141 +354,3 @@
 
        return 0;
 }
-
-/*
- * timedwaitclock_setup(T, timeout, clockid, flags, epsilon)
- *
- *     Initialize state for a timedwaitclock, to be used subsequently
- *     with timedwaitclock_begin/end, possibly many times in a row.
- *
- *     No cleanup action required at the end; the caller-allocated
- *     (typically stack-allocated) timedwaitclock just holds
- *     parameters and a little state for timedwaitclock_begin/end.
- */
-void
-timedwaitclock_setup(struct timedwaitclock *T, struct timespec *timeout,
-    clockid_t clockid, int flags, const struct bintime *epsilon)
-{
-
-       memset(T, 0, sizeof(*T));
-       T->timeout = timeout;
-       T->clockid = clockid;
-       T->flags = flags;
-       T->epsilon = epsilon;
-       T->starttime = (struct timespec){0,0};
-}
-
-/*
- * timedwaitclock_begin(T, timo)
- *
- *     Decide how many ticks to wait for the timedwaitclock T and
- *     store it in *timo.  Keep state for timedwaitclock_end.  May
- *     fail with EINVAL if the specified timeout is invalid, or if the
- *     specified clock fails.  Fails with ETIMEDOUT if there is no
- *     time left to wait.
- */
-int
-timedwaitclock_begin(struct timedwaitclock *T, int *timo)
-{
-       struct timespec delta;
-       const struct timespec *deltap;
-       int error;
-
-       /* Sanity-check timeout -- may have come from userland.  */
-       if (T->timeout->tv_nsec < 0 || T->timeout->tv_nsec >= 1000000000L)
-               return EINVAL;
-
-       /*
-        * Compute the time delta.
-        */
-       if ((T->flags & TIMER_ABSTIME) == TIMER_ABSTIME) {
-               /* Check our watch.  */
-               error = clock_gettime1(T->clockid, &T->starttime);
-               if (error)
-                       return error;
-
-               /* If the deadline has passed, we're done.  */
-               if (timespeccmp(T->timeout, &T->starttime, <=))
-                       return ETIMEDOUT;
-
-               /* Count how much time is left.  */
-               timespecsub(T->timeout, &T->starttime, &delta);
-               deltap = &delta;
-       } else {
-               /* The user specified how much time is left.  */
-               deltap = T->timeout;
-
-               /* If there's none left, we've timed out.  */
-               if (deltap->tv_sec == 0 && deltap->tv_nsec == 0)
-                       return ETIMEDOUT;
-       }
-
-       /*
-        * Convert to ticks, but clamp to be >=1.
-        *
-        * XXX In the tickless future, use a high-resolution timer if



Home | Main Index | Thread Index | Old Index