summaryrefslogtreecommitdiff
path: root/sys/kern/kern_tc.c
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/kern_tc.c
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/kern_tc.c')
-rw-r--r--sys/kern/kern_tc.c19
1 files changed, 18 insertions, 1 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;
+}