summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2019-03-10 21:16:16 +0000
committercheloha <cheloha@cvs.openbsd.org>2019-03-10 21:16:16 +0000
commit00b8abed1a52f1db369084a1b437f280070f870d (patch)
treef2a607ed1e5bbdf465daf0bb5bd76744af57a64e /sys/kern
parent7a5a47d67e40332e6adc28df84cadec89a6a4b76 (diff)
Move adjtimedelta from kern_time.c to kern_tc.c.
This will simplify upcoming MP-safety diffs for the timecounting layer. adjtimedelta is now accessed nowhere outside of kern_tc.c, so we can remove its extern declaration from kernel.h. Zeroing adjtimedelta within timecounter_mtx before we jump the real-time clock is also a bit safer than what we do now, as we are not racing a simultaneous tc_windup() call from hardclock(), which itself can modify adjtimedelta via ntp_update_second(). Discussed with visa@ and mpi@. ok visa@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_tc.c19
-rw-r--r--sys/kern/kern_time.c21
2 files changed, 26 insertions, 14 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index eccf869c19c..565c24b206f 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_tc.c,v 1.38 2019/03/09 23:04:56 cheloha Exp $ */
+/* $OpenBSD: kern_tc.c,v 1.39 2019/03/10 21:16:15 cheloha Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@@ -116,6 +116,8 @@ static struct timecounter *timecounters = &dummy_timecounter;
volatile time_t time_second = 1;
volatile time_t time_uptime = 0;
+int64_t adjtimedelta; /* unapplied time correction (microseconds) */
+
struct bintime naptime;
static int timestepwarnings;
@@ -358,6 +360,12 @@ tc_setrealtimeclock(const struct timespec *ts)
timespec2bintime(ts, &bt);
bintime_sub(&bt, &bt2);
bintime_add(&bt2, &timehands->th_boottime);
+
+ /*
+ * Adjtime in progress is meaningless or harmful after
+ * setting the clock. Cancel adjtime and then set new time.
+ */
+ adjtimedelta = 0;
timehands->th_boottime = bt;
/* XXX fiddle all the little crinkly bits around the fiords... */
@@ -724,3 +732,12 @@ tc_adjfreq(int64_t *old, int64_t *new)
}
return 0;
}
+
+void
+tc_adjtime(int64_t *old, int64_t *new)
+{
+ if (old != NULL)
+ *old = adjtimedelta;
+ if (new != NULL)
+ adjtimedelta = *new;
+}
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index e6b0d817421..5dc32a29b14 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.110 2019/01/31 18:23:27 tedu Exp $ */
+/* $OpenBSD: kern_time.c,v 1.111 2019/03/10 21:16:15 cheloha Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -48,9 +48,6 @@
#include <sys/mount.h>
#include <sys/syscallargs.h>
-
-int64_t adjtimedelta; /* unapplied time correction (microseconds) */
-
/*
* Time of day and interval timer support.
*
@@ -96,11 +93,6 @@ settime(const struct timespec *ts)
return (EPERM);
}
- /*
- * Adjtime in progress is meaningless or harmful after
- * setting the clock. Cancel adjtime and then set new time.
- */
- adjtimedelta = 0;
tc_setrealtimeclock(ts);
resettodr();
@@ -421,9 +413,10 @@ sys_adjtime(struct proc *p, void *v, register_t *retval)
syscallarg(const struct timeval *) delta;
syscallarg(struct timeval *) olddelta;
} */ *uap = v;
+ struct timeval atv;
const struct timeval *delta = SCARG(uap, delta);
struct timeval *olddelta = SCARG(uap, olddelta);
- struct timeval atv;
+ int64_t adjustment, remaining;
int error;
error = pledge_adjtime(p, delta);
@@ -431,9 +424,10 @@ sys_adjtime(struct proc *p, void *v, register_t *retval)
return error;
if (olddelta) {
+ tc_adjtime(&remaining, NULL);
memset(&atv, 0, sizeof(atv));
- atv.tv_sec = adjtimedelta / 1000000;
- atv.tv_usec = adjtimedelta % 1000000;
+ atv.tv_sec = remaining / 1000000;
+ atv.tv_usec = remaining % 1000000;
if (atv.tv_usec < 0) {
atv.tv_usec += 1000000;
atv.tv_sec--;
@@ -454,7 +448,8 @@ sys_adjtime(struct proc *p, void *v, register_t *retval)
return (EINVAL);
/* XXX Check for overflow? */
- adjtimedelta = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
+ adjustment = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
+ tc_adjtime(NULL, &adjustment);
}
return (0);