aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2026-06-15 00:59:46 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2026-06-15 12:56:40 +0000
commit96759ab67a42226679675e24e35549aea2aa49e0 (patch)
treed04e56b2f76210282eaf78bae81bfcb5762e1077
parent21a75a85f0e0cc328b6e9b437d783ef0c25dc52e (diff)
ntsync(9): properly handle timeouts
Reported by: Alex S <iwtcex@gmail.com> Sponsored by: The FreeBSD Foundation MFC after: 3 days
-rw-r--r--sys/dev/ntsync/ntsync.c16
-rw-r--r--sys/dev/ntsync/ntsyncvar.h1
2 files changed, 13 insertions, 4 deletions
diff --git a/sys/dev/ntsync/ntsync.c b/sys/dev/ntsync/ntsync.c
index a7b002de7cb6..2d3054e0a4ee 100644
--- a/sys/dev/ntsync/ntsync.c
+++ b/sys/dev/ntsync/ntsync.c
@@ -215,7 +215,7 @@ ntsync_wait_locked(struct ntsync_wait_state *state, struct thread *td)
if (state->ready)
break;
error = msleep_sbt(state, &state->owner->lock,
- PCATCH, "ntsync", state->sb, 0,
+ PCATCH, "ntsync", state->sb, state->prec,
C_ABSOLUTE /* | C_HARDCLOCK XXXKIB */);
/*
@@ -1195,7 +1195,6 @@ ntsync_wait_state_get(struct ntsync_wait_args *nwa, u_long cmd,
{
struct ntsync_wait_state *state;
struct ntsync_obj *obj;
- struct bintime btb;
int error, i, j;
if (nwa->count > NTSYNC_MAX_WAIT_COUNT)
@@ -1270,14 +1269,23 @@ ntsync_wait_state_get(struct ntsync_wait_args *nwa, u_long cmd,
}
}
+ state->prec = 0;
if (nwa->timeout == UINT64_MAX) {
state->sb = 0;
} else {
state->sb = nstosbt(nwa->timeout);
if ((nwa->flags & NTSYNC_WAIT_REALTIME) != 0) {
- getboottimebin(&btb);
- state->sb += bttosbt(btb);
+ struct bintime btb;
+
+ bintime(&btb);
+ state->sb -= bttosbt(btb);
+ } else {
+ struct timespec ts;
+
+ nanouptime(&ts);
+ state->sb -= tstosbt(ts);
}
+ state->sb += sbinuptime();
}
*statep = state;
diff --git a/sys/dev/ntsync/ntsyncvar.h b/sys/dev/ntsync/ntsyncvar.h
index fd875588e889..97828c99bb7d 100644
--- a/sys/dev/ntsync/ntsyncvar.h
+++ b/sys/dev/ntsync/ntsyncvar.h
@@ -81,6 +81,7 @@ struct ntsync_wait_state {
struct ntsync_obj *objs[NTSYNC_MAX_WAIT_COUNT + 1];
struct ntsync_obj_event *alert_event;
sbintime_t sb;
+ sbintime_t prec;
int error;
int index;
bool any;