aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_clock.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove duplicated empty lines from kern/*.cMateusz Guzik2020-01-301-1/+0
| | | | | | | No functional changes. Notes: svn path=/head/; revision=357312
* Kill tz_minuteswest and tz_dsttime.Warner Losh2019-03-121-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Research Unix, 7th Edition introduced TIMEZONE and DSTFLAG compile-time constants in sys/param.h to communicate these values for the machine. 4.2BSD moved from the compile-time to run-time and introduced these variables and used for localtime() to return the right offset from UTC (sometimes referred to as GMT, for this purpose is the same). 4.4BSD migrated to using the tzdata code/database and these variables were basically unused. FreeBSD removed the real need for these with adjkerntz in 1995. However, some RTC clocks continued to use these variables, though they were largely unused otherwise. Later, phk centeralized most of the uses in utc_offset, but left it using both tz_minuteswest and adjkerntz. POSIX (IEEE Std 1003.1-2017) states in the gettimeofday specification "If tzp is not a null pointer, the behavior is unspecified" so there's no standards reason to retain it anymore. In fact, gettimeofday has been marked as obsolecent, meaning it could be removed from a future release of the standard. It is the only interface defined in POSIX that references these two values. All other references come from the tzdata database via tzset(). These were used to more faithfully implement early unix ABIs which have been removed from FreeBSD. NetBSD has completely eliminated these variables years ago. Linux has migrated to tzdata as well, though these variables technically still exist for compatibility with unspecified older programs. So, there's no real reason to have them these days. They are a historical vestige that's no longer used in any meaningful way. Reviewed By: jhb@, brooks@ Differential Revision: https://reviews.freebsd.org/D19550 Notes: svn path=/head/; revision=345049
* Replace the existing print_ct() private debugging function with a set ofIan Lepore2018-02-121-14/+59
| | | | | | | | three public functions to format and print the three major data structures used by realtime clock drivers (clocktime, bcd_clocktime, and timespec). Notes: svn path=/head/; revision=329170
* Use const pointers for input data not modified by clock utility functions.Ian Lepore2018-02-061-5/+5
| | | | Notes: svn path=/head/; revision=328956
* Add RTC clock conversions for BCD values, with non-panic validation.Ian Lepore2018-01-141-0/+77
| | | | | | | | | | | | | | | | | | | | | | | RTC clock hardware frequently uses BCD numbers. Currently the low-level bcd2bin() and bin2bcd() functions will KASSERT if given out-of-range BCD values. Every RTC driver must implement its own code for validating the unreliable data coming from the hardware to avoid a potential kernel panic. This change introduces two new functions, clock_bcd_to_ts() and clock_ts_to_bcd(). The former validates its inputs and returns EINVAL if any values are out of range. The latter guarantees the returned data will be valid BCD in a known format (4-digit years, etc). A new bcd_clocktime structure is used with the new functions. It is similar to the original clocktime structure, but defines the fields holding BCD values as uint8_t (uint16_t for year), and adds a PM flag for handling hours using AM/PM mode. PR: 224813 Differential Revision: https://reviews.freebsd.org/D13730 (no reviewers) Notes: svn path=/head/; revision=327971
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Add common code to support realtime clocks that store year without century.Ian Lepore2017-07-231-3/+12
| | | | | | | | | | | | Most realtime clocks store the year as 2 BCD digits. Some add a century bit to extend the range another hundred years. Every clock driver has its own code to determine the century and pass a full year value to clock_ct_to_ts(). Now clock drivers can just convert BCD to bin and store the result in the clocktime struct and let the common code figure out the century. Clocks with a century bit can just add 100 to year if the century bit is on. Notes: svn path=/head/; revision=321400
* Minor optimization: instead of converting between days and years using loopsIan Lepore2017-07-161-4/+23
| | | | | | | | | | | | | | | | | that start in 1970, assume most conversions are going to be for recent dates and use a precomputed number of days through the end of 2016. This is a do-over of r320997, hopefully this time with 100% more workiness. The first attempt had an off-by-one error, but instead of just adding another mysterious +1 adjustment, this rearranges the relationship between recent_base_year and recent_base_days so that the latter is the number of days that occurred before the start of the associated year (instead of the count thru the end of that year). This makes the recent_base stuff work more like the original loop logic that didn't need any +1 adjustments. Notes: svn path=/head/; revision=321048
* Revert r320997. There are reports of it getting the wrong results, soIan Lepore2017-07-151-23/+4
| | | | | | | | clearly my testing was insuffficent, and it's best to just revert it until I get it straightened out. Notes: svn path=/head/; revision=321002
* Minor optimization: instead of converting between days and years usingIan Lepore2017-07-141-4/+23
| | | | | | | | loops that start in 1970, assume most conversions are going to be for recent dates and use a precomputed number of days through the end of 2016. Notes: svn path=/head/; revision=320997
* Allow setting debug.clocktime as a tunable. Print 64-bit time_t correctlyIan Lepore2017-07-141-4/+4
| | | | | | | on 32-bit systems. Notes: svn path=/head/; revision=320996
* Use time_t for intermediate values to avoid overflow in clock_ts_to_ctConrad Meyer2017-01-241-1/+15
| | | | | | | | | | | | | | | | | | | Add additionally safety and overflow checks to clock_ts_to_ct and the BCD routines while we're here. Perform a safety check in sys_clock_settime() first to avoid easy local root panic, without having to propagate an error value back through dozens of APIs currently lacking error returns. PR: 211960, 214300 Submitted by: Justin McOmie <justin.mcomie at gmail.com>, kib@ Reported by: Tim Newsham <tim.newsham at nccgroup.trust> Reviewed by: kib@ Sponsored by: Dell EMC Isilon, FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D9279 Notes: svn path=/head/; revision=312702
* Renumber license clauses in sys/kern to avoid skipping #3Ed Maste2016-09-151-1/+1
| | | | Notes: svn path=/head/; revision=305832
* Do not use Giant to prevent parallel calls to CLOCK_SETTIME(). UseKonstantin Belousov2016-06-281-2/+2
| | | | | | | | | | | | | private mtx in resettodr(), no implementation of CLOCK_SETTIME() is allowed to sleep. Reviewed by: imp, jhb Sponsored by: The FreeBSD Foundation Approved by: re (gjb) X-Differential revision: https://reviews.freebsd.org/D6825 Notes: svn path=/head/; revision=302251
* For architectures where time_t is wide enough, in particular, 64bitKonstantin Belousov2014-12-121-5/+3
| | | | | | | | | | | | platforms, avoid overflow after year 2038 in clock_ct_to_ts(). PR: 195868 Reviewed by: bde Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=275727
* Fix a 2038 bug.Brooks Davis2014-05-011-1/+2
| | | | | | | | | | | | | If time_t is 64-bit (i.e. isn't 32-bit) allow any value of year, not just years less than 2038. Don't bother fixing the underflow in the case of years before 1903. MFC after: 1 week Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=265201
* Improve style and wording of comments and sysctl descriptions [1].Bjoern A. Zeeb2011-01-091-12/+11
| | | | | | | | | | | Move machdep.ct_debug to debug.clocktime as there was no reason to actually put it under machdep in r216340. Submitted by: bde [1] MFC after: 3 days Notes: svn path=/head/; revision=217195
* Don't tie ct_debug to bootverbose. Provide a sysctl to turn it on or off.Bjoern A. Zeeb2010-12-091-1/+3
| | | | | | | | | Switch the default to always off. Reviewed by: kib Notes: svn path=/head/; revision=216340
* Fix some more style(9) issues.Rebecca Cran2010-11-141-3/+3
| | | | Notes: svn path=/head/; revision=215304
* Fix style(9) issues from r215281 and r215282.Rebecca Cran2010-11-141-1/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=215283
* Add some descriptions to sys/kern sysctls.Rebecca Cran2010-11-141-3/+3
| | | | | | | | | PR: kern/148710 Tested by: Chip Camden <sterling at camdensoftware.com> MFC after: 1 week Notes: svn path=/head/; revision=215281
* Fix an XXX comment by answering 'no'. OS X does not set the day-of-weekNathan Whitehorn2010-10-171-4/+0
| | | | | | | | | | | counter on SMU-based systems, which causes FreeBSD to reject the RTC time when used in a dual-boot environment. Since we don't use the day-of-week counter anyway, solve this by just not checking that it matches. MFC after: 3 weeks Notes: svn path=/head/; revision=213986
* Now that all platforms use genclock, shuffle things around slightlyPoul-Henning Kamp2008-04-221-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for better structure. Much of this is related to <sys/clock.h>, which should really have been called <sys/calendar.h>, but unless and until we need the name, the repocopy can wait. In general the kernel does not know about minutes, hours, days, timezones, daylight savings time, leap-years and such. All that is theoretically a matter for userland only. Parts of kernel code does however care: badly designed filesystems store timestamps in local time and RTC chips almost universally track time in a YY-MM-DD HH:MM:SS format, and sometimes in local timezone instead of UTC. For this we have <sys/clock.h> <sys/time.h> on the other hand, deals with time_t, timeval, timespec and so on. These know only seconds and fractions thereof. Move inittodr() and resettodr() prototypes to <sys/time.h>. Retain the names as it is one of the few surviving PDP/VAX references. Move startrtclock() to <machine/clock.h> on relevant platforms, it is a MD call between machdep.c/clock.c. Remove references to it elsewhere. Remove a lot of unnecessary <sys/clock.h> includes. Move the machdep.disable_rtc_set sysctl to subr_rtc.c where it belongs. XXX: should be kern.disable_rtc_set really, it's not MD. Notes: svn path=/head/; revision=178429
* fix printf type confusion on amd64Poul-Henning Kamp2008-04-121-2/+3
| | | | Notes: svn path=/head/; revision=178164
* Emit summaries of struct c(alender)t(ime) <-> struct timespec conversionsPoul-Henning Kamp2008-04-121-2/+27
| | | | | | | | | | | | | under bootverbose. Struct ct is used for setting/reading real time clocks and I'm about to Do Things to some of those, so a bit of preemptive debugging is in order. Remove a pointless __inline. Notes: svn path=/head/; revision=178162
* If clock_ct_to_ts fails to convert time time from the real time clock,David Malone2007-07-231-1/+1
| | | | | | | | | | | | print a one line error message. Add some comments on not being able to trust the day of week field (I'll act on these comments in a follow up commit). Approved by: re MFC after: 3 weeks Notes: svn path=/head/; revision=171553
* Use utc_offset() where applicable, and hide the internals of itPoul-Henning Kamp2006-10-021-3/+3
| | | | | | | as static variables. Notes: svn path=/head/; revision=162970
* Introduce utc_offset() to capture a calculation currently done all over thePoul-Henning Kamp2006-10-021-0/+7
| | | | | | | place. Notes: svn path=/head/; revision=162962
* Move tz_minuteswest and tz_dsttime to subr_clock.cPoul-Henning Kamp2006-10-021-0/+3
| | | | Notes: svn path=/head/; revision=162960
* Second part of a little cleanup in the calendar/timezone/RTC handling.Poul-Henning Kamp2006-10-021-143/+22
| | | | | | | | | | | | | | Split subr_clock.c in two parts (by repo-copy): subr_clock.c contains generic RTC and calendaric stuff. etc. subr_rtc.c contains the newbus'ified RTC interface. Centralize the machdep.{adjkerntz,disable_rtc_set,wall_cmos_clock} sysctls and associated variables into subr_clock.c. They are not machine dependent and we have generic code that relies on being present so they are not even optional. Notes: svn path=/head/; revision=162958
* Remove more straggling CPU_ macro referencesPoul-Henning Kamp2006-05-111-4/+4
| | | | Notes: svn path=/head/; revision=158450
* /* -> /*- for copyright notices, minor format tweaks as necessaryWarner Losh2005-01-061-1/+1
| | | | Notes: svn path=/head/; revision=139804
* Remove advertising clause from University of California Regent's license,Warner Losh2004-04-051-4/+0
| | | | | | | | | per letter dated July 22, 1999. Approved by: core Notes: svn path=/head/; revision=127911
* Use __FBSDID().David E. O'Brien2003-06-111-2/+4
| | | | Notes: svn path=/head/; revision=116182
* Split the global timezone structure into two integer fields toPoul-Henning Kamp2003-02-031-2/+2
| | | | | | | | | | | | | prevent the compiler from optimizing assignments into byte-copy operations which might make access to the individual fields non-atomic. Use the individual fields throughout, and don't bother locking them with Giant: it is no longer needed. Inspired by: tjr Notes: svn path=/head/; revision=110299
* Use the CPU_* OID constants instead of OID_AUTO for the clock-relatedThomas Moestl2002-08-071-3/+6
| | | | | | | sysctls for compatability with old applications. Notes: svn path=/head/; revision=101484
* Add a generic implementation of inittodr() and resettodr(), as well asThomas Moestl2002-04-041-0/+316
a set of helper routines to deal with real-time clocks. The generic functions access the clock diver using a kobj interface. This is intended to reduce code reduplication and make it easy to support more than one clock model on a single architecture. This code is currently only used on sparc64, but it is planned to convert the code of the other architectures to it later. Notes: svn path=/head/; revision=93835