summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_tc.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2019-12-12 17:52:25 +0000
committercheloha <cheloha@openbsd.org>2019-12-12 17:52:25 +0000
commit9098a9c748e0175c27172dc7a6838e8f0b097e3e (patch)
tree7c8109486711383c3be8c57f8fb9dc7ef6bc5379 /sys/kern/kern_tc.c
parentReintroduce socket locking inside socket event filters. (diff)
downloadwireguard-openbsd-9098a9c748e0175c27172dc7a6838e8f0b097e3e.tar.xz
wireguard-openbsd-9098a9c748e0175c27172dc7a6838e8f0b097e3e.zip
Recommit "tc_windup: separate timecounter.tc_freq_adj from timehands.th_adjustment"
Reverted with backout of tickless timeouts. Original commit message: We currently mix timecounter.tc_freq_adj and timehands.th_adjtimedelta in ntp_update_second() to produce timehands.th_adjustment, our net skew. But if you set a low enough adjfreq(2) adjustment you can freeze time. This prevents ntp_update_second() from running again. So even if you then set a sane adjfreq(2) you cannot unfreeze time without rebooting. If we just reread timecounter.tc_freq_adj every time we recompute timehands.th_scale we avoid this trap. visa@ notes that this is more costly than what we currently do but that the cost itself is negligible. Intuitively, timecounter.tc_freq_adj is a constant skew and should be handled separately from timehands.th_adjtimedelta, an adjustment that we chip away at very slowly. tedu@ notes that this problem is sort-of an argument for imposing range limits on adjfreq(2) inputs. He's right, but I think we should still separate the counter adjustment from the adjtime(2) adjustment, with or without range limits. ok visa@
Diffstat (limited to 'sys/kern/kern_tc.c')
-rw-r--r--sys/kern/kern_tc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index a9b853b0a14..96ee6dd2c55 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_tc.c,v 1.53 2019/12/02 21:47:54 cheloha Exp $ */
+/* $OpenBSD: kern_tc.c,v 1.54 2019/12/12 17:52:25 cheloha Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
@@ -594,7 +594,8 @@ tc_windup(struct bintime *new_boottime, struct bintime *new_offset,
*
*/
scale = (u_int64_t)1 << 63;
- scale += (th->th_adjustment / 1024) * 2199;
+ scale += \
+ ((th->th_adjustment + th->th_counter->tc_freq_adj) / 1024) * 2199;
scale /= th->th_counter->tc_frequency;
th->th_scale = scale * 2;
@@ -751,7 +752,7 @@ sysctl_tc(int *name, u_int namelen, void *oldp, size_t *oldlenp,
}
/*
- * Skew the timehands according to any adjfreq(2)/adjtime(2) adjustments.
+ * Skew the timehands according to any adjtime(2) adjustment.
*/
void
ntp_update_second(struct timehands *th)
@@ -766,7 +767,6 @@ ntp_update_second(struct timehands *th)
adj = MAX(-5000, th->th_adjtimedelta);
th->th_adjtimedelta -= adj;
th->th_adjustment = (adj * 1000) << 32;
- th->th_adjustment += th->th_counter->tc_freq_adj;
}
void