aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2021-05-05 18:32:13 +0000
committerWarner Losh <imp@FreeBSD.org>2021-05-05 18:32:13 +0000
commita512d0ab009eedf2f1876fce86d6386bfee626d8 (patch)
tree0b8ee86f1fd20683fa79c6f892d3602c1093affb
parentcb5880594387d5b07c5d580c4aa1b633947a6046 (diff)
downloadsrc-a512d0ab009eedf2f1876fce86d6386bfee626d8.tar.gz
src-a512d0ab009eedf2f1876fce86d6386bfee626d8.zip
kern: clarify boot time
In FreeBSD, the current time is computed from uptime + boottime. Uptime is a continuous, smooth function that's monotonically increasing. To effect changes to the current time, boottime is adjusted. boottime is mutable and shouldn't be cached against future need. Document the current implementation, with the caveat that we may stop stepping boottime on resume in the future and will step uptime instead (noted in the commit message, but not in the code). Sponsored by: Netflix Reviewed by: phk, rpokala Differential Revision: https://reviews.freebsd.org/D30116
-rw-r--r--share/man/man9/time.916
-rw-r--r--sys/kern/kern_tc.c8
2 files changed, 21 insertions, 3 deletions
diff --git a/share/man/man9/time.9 b/share/man/man9/time.9
index 4a2b2f7240e1..443608dd3f5b 100644
--- a/share/man/man9/time.9
+++ b/share/man/man9/time.9
@@ -31,7 +31,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 17, 2004
+.Dd May 4, 2021
.Dt TIME 9
.Os
.Sh NAME
@@ -48,7 +48,18 @@
.Sh DESCRIPTION
The
.Va boottime
-variable holds the system boot time.
+variable holds the estimated system boot time.
+This time is initially set when the system boots, either from the RTC, or from a
+time estimated from the system's root filesystem.
+When the current system time is set, stepped by
+.Xr ntpd 8 ,
+or a new time is read from the RTC as the system resumes,
+.Va boottime
+is recomputed as new_time - uptime.
+The
+.Xr sysctl 8
+.Va kern.boottime
+returns this value.
.Pp
The
.Va time_second
@@ -83,6 +94,7 @@ and in an atomic manner.
The
.Va boottime
variable may be read and written without special precautions.
+It is adjusted when the phase of the system time changes.
.Sh SEE ALSO
.Xr clock_settime 2 ,
.Xr ntp_adjtime 2 ,
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index b1dcb18e31be..4d4e20ef1934 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -103,11 +103,17 @@ int tc_min_ticktock_freq = 1;
volatile time_t time_second = 1;
volatile time_t time_uptime = 1;
+/*
+ * The system time is always computed by summing the estimated boot time and the
+ * system uptime. The timehands track boot time, but it changes when the system
+ * time is set by the user, stepped by ntpd or adjusted when resuming. It
+ * is set to new_time - uptime.
+ */
static int sysctl_kern_boottime(SYSCTL_HANDLER_ARGS);
SYSCTL_PROC(_kern, KERN_BOOTTIME, boottime,
CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
sysctl_kern_boottime, "S,timeval",
- "System boottime");
+ "Estimated system boottime");
SYSCTL_NODE(_kern, OID_AUTO, timecounter, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"");