path: root/sys/sys/clock.h
Commit message (Collapse)AuthorAgeFilesLines
* Kill tz_minuteswest and tz_dsttime.Warner Losh2019-03-121-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add a set of convenience routines for RTC drivers to use for debug output,Ian Lepore2018-02-121-0/+12
| | | | | | | and a debug.clock_show_io sysctl to control debugging output. Notes: svn path=/head/; revision=329172
* Replace the existing print_ct() private debugging function with a set ofIan Lepore2018-02-121-0/+9
| | | | | | | | 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-6/+8
| | | | Notes: svn path=/head/; revision=328956
* Add RTC clock conversions for BCD values, with non-panic validation.Ian Lepore2018-01-141-3/+53
| | | | | | | | | | | | | | | | | | | | | | | 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/sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. 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. Notes: svn path=/head/; revision=326256
* Add clock_schedule(), a feature that allows realtime clock drivers toIan Lepore2017-07-311-3/+11
| | | | | | | | | | | | | | | | | | | | request that their clock_settime() methods be called at a given offset from top-of-second. This adds a timeout_task to the rtc_instance so that each clock can be separately added to taskqueue_thread with the scheduling it prefers, instead of looping through all the clocks at once with a single task on taskqueue_thread. If a driver doesn't call clock_schedule() the default is the old behavior: clock_settime() is queued immediately. The motivation behind this is that I was on the path of adding identical code to a third RTC driver to figure out a delta to top-of-second and sleep for that amount of time because writing the the RTC registers resets the hardware's concept of top-of-second. (Sometimes it's not top-of-second, some RTC clocks tick over a half second after you set their time registers.) Worst-case would be to sleep for almost a full second, which is a rude thing to do on a shared task queue thread. Notes: svn path=/head/; revision=321745
* Support multiple realtime clocks, and remove locking/sleeping restrictionsIan Lepore2017-07-121-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | on clock drivers. This tracks multiple concurrent realtime clock drivers in a list sorted by clock resolution. When system time changes (and periodically) the clock_settime() methods of all registered clocks are invoked. To initialize system time, each driver is tried in turn from best to worst resolution, until one succesfully returns a valid time. The code no longer holds a mutex while calling the clock_settime() and clock_gettime() methods of the registered clocks. This allows clock drivers to do whatever kind of locking or sleeping is necessary (this is especially important for i2c clock chips since i2c drivers often need to sleep). A new clock_register_flags() function allows the clock driver to pass flags. The flags currently defined help support drivers that use their own techniques to avoid roundoff errors (prevents the 4/5 rounding done by the subr_rtc code). A driver which may need to wait for resources (such as bus ownership) may pass a flag to indicate that it will obtain system time for itself after waiting for resources; this is merely an optimization to avoid the common code retrieving a timespec that will never get used. Relnotes: yes Differential Revision: https://reviews.freebsd.org/D11484 Notes: svn path=/head/; revision=320902
* Make resettodr_lock accessible outside subr_rtc.c. ProtectKonstantin Belousov2016-09-211-0/+1
| | | | | | | | | | | | | | CLOCK_GETTIME() with the lock. Now all time-related accesses to the CMOS for RTC should be under the lock. This is needed to allow upcoming EFI Runtime Services support to provide required execution environment for the firmware calls. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=306089
* The NetBSD Foundation has granted permission to remove clause 3 and 4 fromJoel Dahl2010-03-031-7/+0
| | | | | | | | | the software. Obtained from: NetBSD Notes: svn path=/head/; revision=204646
* Now that all platforms use genclock, shuffle things around slightlyPoul-Henning Kamp2008-04-221-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Better naming of fattime conversion functions, they do convert to timespecPoul-Henning Kamp2006-10-241-2/+2
| | | | | | | | | | after all. Add 'utc' argument to control if fattimestamps are on UTC or local timezone calendar. Notes: svn path=/head/; revision=163646
* Add two new functions to convert FAT filesystem format timestampsPoul-Henning Kamp2006-10-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to and from struct timespec, to replace the crummy conversion function which have been copy&pasted into three different filesystems already. Apart from general crummyness as indicated by code like: for (year = 1970;; year++) { inc = year & 0x03 ? 365 : 366; if (days < inc) break; days -= inc; } They also contain specialized crummyness which tries to compensate for the general crummyness by caching recent conversion results, with no regard for locking or consistency. These replacement functions are smaller, O(1) and handle the Y2.1K leap-year correctly. Ideally, these functions should live in a module of their own, which the three offending filesystems would depend on, but the size is 877 bytes of code (on i386), so that would be false economy. Notes: svn path=/head/; revision=163611
* Use utc_offset() where applicable, and hide the internals of itPoul-Henning Kamp2006-10-021-2/+1
| | | | | | | 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/+2
| | | | | | | place. Notes: svn path=/head/; revision=162962
* First part of a little cleanup in the calendar/timezone/RTC handling.Poul-Henning Kamp2006-10-021-2/+22
| | | | | | | | | Move relevant variables to <sys/clock.h> and fix #includes as necessary. Use libkern's much more time- & spamce-efficient BCD routines. Notes: svn path=/head/; revision=162954
* The year field is the 4 digit year (eg, 2006), not 'year - 1900' (egWarner Losh2006-03-241-1/+1
| | | | | | | 106). Fix the comment to reflect this. Notes: svn path=/head/; revision=157084
* Add a generic implementation of inittodr() and resettodr(), as well asThomas Moestl2002-04-041-0/+77
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