summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/kern_tc.c19
-rw-r--r--sys/kern/kern_time.c21
-rw-r--r--sys/sys/kernel.h3
-rw-r--r--sys/sys/timetc.h3
4 files changed, 29 insertions, 17 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);
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index c8bcde81e27..7d252153e79 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kernel.h,v 1.18 2019/01/19 01:53:44 cheloha Exp $ */
+/* $OpenBSD: kernel.h,v 1.19 2019/03/10 21:16:15 cheloha Exp $ */
/* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */
/*-
@@ -61,5 +61,4 @@ extern int lbolt; /* once a second sleep address */
extern int tickdelta;
extern long timedelta;
-extern int64_t adjtimedelta; /* unapplied time correction */
extern struct bintime naptime; /* time spent suspended */
diff --git a/sys/sys/timetc.h b/sys/sys/timetc.h
index 90b291d01cf..0be79eea736 100644
--- a/sys/sys/timetc.h
+++ b/sys/sys/timetc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timetc.h,v 1.6 2018/05/28 18:05:42 guenther Exp $ */
+/* $OpenBSD: timetc.h,v 1.7 2019/03/10 21:16:15 cheloha Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@@ -87,5 +87,6 @@ void tc_ticktock(void);
void inittimecounter(void);
int sysctl_tc(int *, u_int, void *, size_t *, void *, size_t);
int tc_adjfreq(int64_t *, int64_t *);
+void tc_adjtime(int64_t *, int64_t *);
#endif /* !_SYS_TIMETC_H_ */