Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/kern_todr.c
RevisionDateAuthorComments
 1.49  08-Sep-2025  thorpej Introduce a device call "device-is-system-todr", which allows the
platform device tree to be consulted if there are multiple TODR / RTC
devices present on the system; if the call is not supported, the behavior
is un-changed: the first TODR device is attached, all others ignored. If
the call is supported, devices other than the specified system TODR are
skipped.

Implement this device call for FDT.

kern/59630
 1.48  07-Sep-2025  thorpej todr_chip_handle::base_time -> todr_chip_handle::todr_base_time

NFCI
 1.47  03-Apr-2021  simonb Print the "preposterous TOD clock time" message only if the RTC is
before very late 2020 (1/1/2021 minus a few leap days) instead of
late 1994. Someone(TM) should remember to adjust this in somewhat
less than 26 years.
 1.46  03-Jan-2020  thorpej branches: 1.46.8; 1.46.10;
- In todr_gettime(), in the todr_gettime_ymdhms, pre-zero the clock_ymdhms
struct before asking the back-end to fill it in.
- Tidy up todr_settime() a teensy bit.
 1.45  01-Jan-2020  thorpej Now that we know if we're shutting down, enable locking in resettodr().
In the shutting_down case, we acquire the todr_mutex as a trylock. Under
most circumstances, this lock will be uncontended. But if we happen to
panic while accessing the TOD clock (via clock_settime() or whatever),
then trylock will prevent us from getting stuck (and a warning will be
displayed on the console).
 1.44  01-Jan-2020  thorpej First steps towards properly serializing access to the TOD clock.
- Add a mutex around the TODR, and provide lock/unlock/lock-owned
functions to manipulate it.
- Rename inittodr() to todr_set_systime() and resettodr() to
todr_save_systime() to better reflect what they do. These functions
are intended to be called with the TODR lock held, which will allow
for a pattern like:
-> todr_lock()
-> todr_save_systime()
-> [do machine-dependent stuff to sleep/suspend]
-> [magically awaken]
-> todr_set_systime(...)
-> todr_unlock()
- Provide historically-named wrappers inittodr() and resettodr() that
do the dance of acquiring / releasing the lock around the actual
substance.

NOTE: resettodr()'s use of the TODR lock is currently disabled (and
todr_save_systime() does not assert it's held) until such time as
issues around shutdown / reboot under duress can be addressed.
 1.43  01-Jan-2020  thorpej Fix some issues around todr_wenable():
- As previously defined, it was not possible to return an error from the
back-end RTC driver. Make it a real function so that it can do so.
- Only the mc146818 and mk48txx drivers used it (for historical reasons).
Centralize the logic for how it's used in kern_todr.c (and make it private
to that file) for consistency.
 1.42  01-Jan-2020  thorpej todr_gettime() and todr_settime() are not referenced outside of kern_todr.c,
so make them private to that file.
 1.41  01-Jan-2020  thorpej Remove superfluous splclock()/splx() pair around tc_setclock().
 1.40  07-Jul-2019  maxv The whole 'tv' structure gets added to the RND pool, so clear it first,
otherwise each random buffer gets tainted by uninitialized bytes from the
padding.
 1.39  13-Apr-2015  riastradh branches: 1.39.18;
<sys/rnd.h> -> <sys/rndsource.h> in kern_todr.c.
 1.38  11-Jan-2015  jmcneill defflag TODR_DEBUG
 1.37  17-Nov-2014  christos branches: 1.37.2;
PR/49207: Kamil Rytarowski: Add sys/clock.h with generic time macros
(derived from clock_subr.h). Keep clock_subr.h with the kernel structures
and functions to reduce diffs, and have clock.h only include standalone
constants and macros.
 1.36  12-Oct-2014  jmcneill fix compilation with TODR_DEBUG
 1.35  29-Aug-2013  tls Mix in boot time (wherever we may find it). Helps avoid predictable output
on young systems.
 1.34  08-Feb-2011  rmind branches: 1.34.4; 1.34.14; 1.34.18;
Remove clause 3 (UCB advertising clause) from the University of Utah
copyright. Confirmed by Mike Hibler, mike at cs.utah.edu - thanks!
Also, merge UCB and Utah copyright texts back into one, as they
originally were.

Extra verification by snj@.
 1.33  02-Jan-2010  tsutsui branches: 1.33.4; 1.33.6; 1.33.8;
Update default TOD value to 2010/01/01 12:00:00.
 1.32  12-Dec-2009  tsutsui Remove `volatile' qualifier from argument types of
struct timeval passed to todr_gettime(9) and todr_settime(9).
We no longer have an ancient and volatile struct timeval `time'
global since we have switched to MI timercounter(9) on all port.

XXX1: some of these RTC drivers still assume 32bit time_t
XXX2: some of these should be rewritten to use todr_[gs]ettime_ymdhms()
XXX3: todr(9) man page doesn't mention todr_[gs]ettime_ymdhms()
 1.31  12-Dec-2009  tsutsui Use bool where appropriate.
 1.30  12-Dec-2009  tsutsui Don't use int to get delta of time_t values.
 1.29  21-Mar-2009  ad Fix 'boot -z' bogons.
 1.28  14-Feb-2009  christos remove 2038 comment
 1.27  20-Jan-2008  joerg branches: 1.27.10; 1.27.18; 1.27.24;
Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.26  22-Dec-2007  yamt reduce #ifdef __HAVE_TIMECOUNTER.
 1.25  29-Nov-2007  ad branches: 1.25.2; 1.25.6;
Pull in sys/intr.h
 1.24  24-Sep-2006  peter branches: 1.24.4; 1.24.24; 1.24.26; 1.24.32;
Minor KNF, replace some spaces with tabs.
 1.23  20-Sep-2006  tsutsui Tweak some debug messages.
 1.22  16-Sep-2006  gdamore branches: 1.22.2;
Pass the filesystem time to clock drivers in the todr_chip_handle, so that
vax, and pmax can use it.
 1.21  12-Sep-2006  gdamore Comment nit (remove first person), from simon@.
 1.20  12-Sep-2006  gdamore Centralize rtc_offset handling for ports that __HAVE_GENERIC_TODR and use
a simple second counter instead of the clock_ymdhms support.
 1.19  12-Sep-2006  gdamore Remove attempt to incorrectly support fictional double leap seconds.
While here, make the comparisions for hour, min, and sec use ">" consistently
like the date comparisions.
 1.18  12-Sep-2006  gdamore Fix to compile on platforms without __HAVE_GENERIC_TODR. Sorry about
that. Pointed out jdc@ and he@.
 1.17  12-Sep-2006  gdamore Add some optional debug (enabled with TODR_DEBUG) to see what your RTC
is giving you. Also, while here, bump the threshold for "preposterous"
dates by 20 years. Now any date earlier than late 1994 is considered
preposterous.
 1.16  11-Sep-2006  gdamore Don't bother checking wday, that breaks some clock chips. Thank to Kurt Schreiner <ks at ub dot uni-mainz dot de>.
 1.15  10-Sep-2006  gdamore Allow for leap seconds.
 1.14  10-Sep-2006  gavan dsrtc_settime already takes a volatile struct timeval *, also qualify
with volatile for dsrtc_gettime.
 1.13  10-Sep-2006  tsutsui - add more sanity checks (from playstation2/clock.c)
- fix a typo
 1.12  07-Sep-2006  gdamore branches: 1.12.2; 1.12.4;
Run tc_setclock at splclock(). Suggested by kardel@.
 1.11  07-Sep-2006  dogcow Now compiles on systems without __HAVE_GENERIC_TODR
 1.10  07-Sep-2006  gdamore Eliminate the 2038 year check, because clock_ymdhms_to_sec already performs
that check. So instead, we test to make sure we have a non-negative second
after the conversion.

While here, we also add a check to round the second counter up when setting
time if we are more than half-way into the second.
 1.9  07-Sep-2006  gdamore Add a few consistency checks for ymdhms. Taken from the mc146818 code.
 1.8  07-Sep-2006  uwe Make timeval argument to todr_settime volatile to keep non-timecounter
ports happy.
 1.7  07-Sep-2006  uwe Mark sizeof(tvp->tv_sec) check CONSTCOND.
No space between the sizeof and the paren.
 1.6  07-Sep-2006  gdamore Add support for new todr entry points for drivers- todr_gettime_ymdhms and
todr_settime_ymdhms. This allows drivers to avoid repeated conversions, and
allows us to centralize check for Y2038 overflow. As discussed on
tech-kern.
 1.5  05-Sep-2006  matt Before calling todr_gettime, fill in tv.tv_sec. At least one port (vax)
needs that functionality.
 1.4  03-Sep-2006  gdamore Update the base time (used when no filesystem or rtc time exists) to 12pm,
Jan 1, 2006. This is somewhat arbitrary, but its a heck of a lot better than
mid 1991. :-)
 1.3  03-Sep-2006  gdamore branches: 1.3.2;
Don't warn about RTC losing/gaining days if the filesystem time is bogus.
 1.2  03-Sep-2006  gdamore Incorporate changes from x86/i386 as follows:

1) don't set a clock when panicing during early boot
2) if the filesystem time is newer than the rtc time (by at least 2 days) then
revert to the filesystem time.
3) use x86 style messaging.

We still use a threshold of 2 days of gain or loss in time to warn though.
 1.1  02-Sep-2006  gdamore Add MI implementation of inittodr, todr_attach, and resettodr.

This is triggered upon __HAVE_GENRIC_TODR in machine/types.h. Conversion of
evbmips port forthcoming.
 1.3.2.3  14-Sep-2006  yamt sync with head.
 1.3.2.2  03-Sep-2006  yamt sync with head.
 1.3.2.1  03-Sep-2006  yamt file kern_todr.c was added on branch yamt-pdpolicy on 2006-09-03 15:25:22 +0000
 1.12.4.2  09-Sep-2006  rpaulo sync with head
 1.12.4.1  07-Sep-2006  rpaulo file kern_todr.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:57:16 +0000
 1.12.2.1  18-Nov-2006  ad Sync with head.
 1.22.2.1  22-Oct-2006  yamt sync with head
 1.24.32.3  18-Feb-2008  mjf Sync with HEAD.
 1.24.32.2  27-Dec-2007  mjf Sync with HEAD.
 1.24.32.1  08-Dec-2007  mjf Sync with HEAD.
 1.24.26.2  23-Mar-2008  matt sync with HEAD
 1.24.26.1  09-Jan-2008  matt sync with HEAD
 1.24.24.1  03-Dec-2007  joerg Sync with HEAD.
 1.24.4.4  21-Jan-2008  yamt sync with head
 1.24.4.3  07-Dec-2007  yamt sync with head
 1.24.4.2  30-Dec-2006  yamt sync with head.
 1.24.4.1  24-Sep-2006  yamt file kern_todr.c was added on branch yamt-lazymbuf on 2006-12-30 20:50:06 +0000
 1.25.6.2  23-Jan-2008  bouyer Sync with HEAD.
 1.25.6.1  02-Jan-2008  bouyer Sync with HEAD
 1.25.2.1  26-Dec-2007  ad Sync with head.
 1.27.24.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.27.18.2  28-Apr-2009  skrll Sync with HEAD.
 1.27.18.1  03-Mar-2009  skrll Sync with HEAD.
 1.27.10.2  11-Mar-2010  yamt sync with head
 1.27.10.1  04-May-2009  yamt sync with head.
 1.33.8.1  17-Feb-2011  bouyer Sync with HEAD
 1.33.6.1  06-Jun-2011  jruoho Sync with HEAD.
 1.33.4.1  05-Mar-2011  rmind sync with head
 1.34.18.1  18-May-2014  rmind sync with head
 1.34.14.2  03-Dec-2017  jdolecek update from HEAD
 1.34.14.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.4.1  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.37.2.2  06-Jun-2015  skrll Sync with HEAD
 1.37.2.1  06-Apr-2015  skrll Sync with HEAD
 1.39.18.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.18.1  08-Apr-2020  martin Merge changes from current as of 20200406
 1.46.10.1  03-Apr-2021  thorpej Sync with HEAD.
 1.46.8.1  03-Apr-2021  thorpej Sync with HEAD.

RSS XML Feed