From owner-dev-commits-src-main@freebsd.org Wed May 5 18:35:24 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C67385FEE79; Wed, 5 May 2021 18:35:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fb54D4vRyz4cFW; Wed, 5 May 2021 18:35:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9B58418F6; Wed, 5 May 2021 18:35:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 145IZOIm043456; Wed, 5 May 2021 18:35:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 145IZOg9043455; Wed, 5 May 2021 18:35:24 GMT (envelope-from git) Date: Wed, 5 May 2021 18:35:24 GMT Message-Id: <202105051835.145IZOg9043455@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: a512d0ab009e - main - kern: clarify boot time MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a512d0ab009eedf2f1876fce86d6386bfee626d8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 18:35:24 -0000 The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a512d0ab009eedf2f1876fce86d6386bfee626d8 commit a512d0ab009eedf2f1876fce86d6386bfee626d8 Author: Warner Losh AuthorDate: 2021-05-05 18:32:13 +0000 Commit: Warner Losh CommitDate: 2021-05-05 18:32:13 +0000 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 --- share/man/man9/time.9 | 16 ++++++++++++++-- sys/kern/kern_tc.c | 8 +++++++- 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, "");