summaryrefslogtreecommitdiff
path: root/sys/kern/kern_ntptime.c
Commit message (Collapse)AuthorAgeFilesLines
* Add kern_ntp_adjtime(9).Konstantin Belousov2020-12-041-52/+64
| | | | | | | | | | Reviewed by: brooks, cy Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27471 Notes: svn path=/head/; revision=368342
* Fix a typo in a comment.Cy Schubert2020-11-241-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=367980
* kern: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-2/+1
| | | | Notes: svn path=/head/; revision=365222
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-1/+2
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* Clear pad bytes in the struct exported by kern.ntp_pll.gettime.Mark Johnston2018-11-201-0/+2
| | | | | | | | | Reported by: Thomas Barabosch, Fraunhofer FKIE MFC after: 3 days Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340699
* Fix several leaks of kernel stack data through paddings.Konstantin Belousov2018-03-271-0/+2
| | | | | | | | | | | | | | | | | | | It is random collection of fixes for issues not yet corrected, reported at https://tsyrklevi.ch/clang_analyzer/freebsd_013017/. Many issues from that list were already corrected. Most of them are for compat32, old compat32 or affect both primary host ABI and compat32. The freebsd32_kldstat(), for instance, was already fixed by using malloc(M_ZERO). Patch includes correction to report the supplied version back, which is just pedantic. Reviewed by: brooks, emaste (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D14868 Notes: svn path=/head/; revision=331640
* ANSIfy kern_ntptime.cEd Maste2017-01-251-3/+4
| | | | Notes: svn path=/head/; revision=312775
* Fix a bug in r302252.Konstantin Belousov2016-07-271-34/+21
| | | | | | | | | | | | | | | | | Change ntpadj_lock to spinlock always, and rename stuff removing ADJ/adj from the names. ntp_update_second() requires ntp_lock and is called from the tc_windup(), so ntp_lock must be a spinlock. Add missed lock to ntp_update_second(). Tested by: pho (as part of the whole patch) Reviewed by: jhb (same) Noted by: bde Sponsored by: The FreeBSD Foundation MFC after: 1 month X-Differential revision: https://reviews.freebsd.org/D7302 Notes: svn path=/head/; revision=303386
* Currently the ntptime code and resettodr() are Giant-locked. InKonstantin Belousov2016-06-281-74/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | particular, the Giant is supposed to protect against parallel ntp_adjtime(2) invocations. But, for instance, sys_ntp_adjtime() does copyout(9) under Giant and then examines time_status to return syscall result. Since copyout(9) could sleep, the syscall result might be inconsistent. Another and more important issue is that if PPS is configured, hardpps(9) is executed without any protection against the parallel top-level code invocation. Potentially, this may result in the inconsistent state of the ntptime state variables, but I cannot say how serious such distortion is. The non-functional splclock() call in sys_ntp_adjtime() protected against clock interrupts calling hardpps() in the pre-SMP era. Modernize the locking. A mutex protects ntptime data. Due to the hardpps() KPI legitimately serving from the interrupt filters (and e.g. uart(4) does call it from filter), the lock cannot be sleepable mutex if PPS_SYNC is defined. Otherwise, use normal sleepable mutex to reduce interrupt latency. Reviewed by: imp, jhb Sponsored by: The FreeBSD Foundation Approved by: re (gjb) Differential revision: https://reviews.freebsd.org/D6825 Notes: svn path=/head/; revision=302252
* Use the monotonic (uptime) counter rather than time-of-day to measure elapsedIan Lepore2015-07-121-5/+5
| | | | | | | | | | | | | | | | | | | | | time between ntp_adjtime() clock offset adjustments. This eliminates spurious frequency steering after a large clock step (such as a 1970->2015 step on a system with no battery-backed clock hardware). This problem was discovered after the import of ntpd 4.2.8, which does things in a slightly different (but still correct) order than the 4.2.4 we had previously. In particular, 4.2.4 would step the clock then immediately after use ntp_adjtime() to set the frequency and offset to zero, which captured the post-step time-of-day as a side effect. In 4.2.8, ntpd sets frequency and offset to zero before any initial clock step, capturing the time as 1970-ish, then when it next calls ntp_adjtime() it's with a non-zero offset measurement. This non-zero value gets multiplied by the apparent 45-year interval, which blows up into a completely bogus frequency steer. That gets clamped to 500ppm, but that's still enough to make the clock drift so fast that ntpd has to keep stepping it every few minutes to compensate. Notes: svn path=/head/; revision=285424
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-2/+4
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-4/+2
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* rename scheduler->swapper and SI_SUB_RUN_SCHEDULER->SI_SUB_LASTAndriy Gapon2013-07-241-1/+1
| | | | | | | | | | | | | | | | | | | Also directly call swapper() at the end of mi_startup instead of relying on swapper being the last thing in sysinits order. Rationale: - "RUN_SCHEDULER" was misleading, scheduling already takes place at that stage - "scheduler" was misleading, the function swaps in the swapped out processes - another SYSINIT(SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY) could never be invoked depending on its relative order with scheduler; this was not obvious and the bug actually used to exist Reviewed by: kib (ealier version) MFC after: 14 days Notes: svn path=/head/; revision=253604
* Limit popcorn limit to something sane (either 2ns or 2 ticks if that'sWarner Losh2012-08-161-2/+9
| | | | | | | | | | longer). PR: 156481 Submitted by: Ian Lepore Notes: svn path=/head/; revision=239320
* Introduce the sysclock_getsnapshot() and sysclock_snap2bintime() KPIs. TheLawrence Stewart2011-12-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | sysclock_getsnapshot() function allows the caller to obtain a snapshot of all the system clock and timecounter state required to create time stamps at a later point. The sysclock_snap2bintime() function converts a previously obtained snapshot into a bintime time stamp according to the specified flags e.g. which system clock, uptime vs absolute time, etc. These KPIs enable useful functionality, including direct comparison of the feedback and feed-forward system clocks and generation of multiple time stamps with different formats from a single timecounter read. Committed on behalf of Julien Ridoux and Darryl Veitch from the University of Melbourne, Australia, as part of the FreeBSD Foundation funded "Feed-Forward Clock Synchronization Algorithms" project. For more information, see http://www.synclab.org/radclock/ In collaboration with: Julien Ridoux (jridoux at unimelb edu au) Notes: svn path=/head/; revision=228856
* Document a large number of currently undocumented sysctls. While hereEitan Adler2011-12-131-5/+9
| | | | | | | | | | | | | | | fix some style(9) issues and reduce redundancy. PR: kern/155491 PR: kern/155490 PR: kern/155489 Submitted by: Galimov Albert <wtfcrap@mail.ru> Approved by: bde Reviewed by: jhb MFC after: 1 week Notes: svn path=/head/; revision=228449
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-3/+3
| | | | | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz) Notes: svn path=/head/; revision=225617
* Add some FEATURE macros for various features (AUDIT/CAM/IPC/KTR/MAC/NFS/NTP/Alexander Leidinger2011-02-251-0/+4
| | | | | | | | | | | | | | | | PMC/SYSV/...). No FreeBSD version bump, the userland application to query the features will be committed last and can serve as an indication of the availablility if needed. Sponsored by: Google Summer of Code 2010 Submitted by: kibab Reviewed by: arch@ (parts by rwatson, trasz, jhb) X-MFC after: to be determined in last commit with code from this project Notes: svn path=/head/; revision=219028
* Fix up a few more sysctl(9) mis-typing found in various LINT builds.Matthew D Fleming2011-01-131-1/+2
| | | | Notes: svn path=/head/; revision=217368
* there must be only one SYSINIT with SI_SUB_RUN_SCHEDULER+SI_ORDER_ANY orderAndriy Gapon2010-09-301-1/+1
| | | | | | | | | | | | | | | | | | SI_SUB_RUN_SCHEDULER+SI_ORDER_ANY should only be used to call scheduler() function which turns the initial thread into swapper proper and thus there is no further SYSINIT processing. Other SYSINITs with SI_SUB_RUN_SCHEDULER+SI_ORDER_ANY may get ordered after scheduler() and thus never executed. That particular relative order is semi-arbitrary. Thus, change such places to use SI_ORDER_MIDDLE. Also, use SI_ORDER_MIDDLE instead of correct, but less appealing, SI_ORDER_ANY - 1. MFC after: 1 week Notes: svn path=/head/; revision=213305
* kern_ntptime: drop a comment that became stale after r207359Andriy Gapon2010-04-291-4/+0
| | | | | | | | MFC after: 1 week X-MFC after: r207359 Notes: svn path=/head/; revision=207362
* periodically save system time to hardware time-of-day clockAndriy Gapon2010-04-291-0/+65
| | | | | | | | | | | | | | | | | | This is done in kern_ntptime, perhaps not the best place. This is done using resettodr(). Some features: - make save period configurable via tunable and sysctl - period of zero disables saving, setting a non-zero period re-enables it or reschedules it - do saving only if system clock is ntp-synchronized - save on shutdown Discussed with: des, Peter Jeremy <peterjeremy@acm.org> X-Maybe: save time near seconds boundary for better precision MFC after: 2 weeks Notes: svn path=/head/; revision=207360
* kern_ntptime: abstract time error check into a functionAndriy Gapon2010-04-291-23/+27
| | | | | | | | | ... to avoid code duplication MFC after: 1 week Notes: svn path=/head/; revision=207359
* In keeping with style(9)'s recommendations on macros, use a ';'Robert Watson2008-03-161-1/+1
| | | | | | | | | | | | after each SYSINIT() macro invocation. This makes a number of lightweight C parsers much happier with the FreeBSD kernel source, including cflow's prcc and lxr. MFC after: 1 month Discussed with: imp, rink Notes: svn path=/head/; revision=177253
* Only require privilege to set the current time adjustment, not in order toRobert Watson2007-06-141-5/+7
| | | | | | | query it. Notes: svn path=/head/; revision=170732
* Further system call comment cleanup:Robert Watson2007-03-051-6/+6
| | | | | | | | | | | | | - Remove also "MP SAFE" after prior "MPSAFE" pass. (suggested by bde) - Remove extra blank lines in some cases. - Add extra blank lines in some cases. - Remove no-op comments consisting solely of the function name, the word "syscall", or the system call name. - Add punctuation. - Re-wrap some comments. Notes: svn path=/head/; revision=167232
* Remove 'MPSAFE' annotations from the comments above most system calls: allRobert Watson2007-03-041-6/+0
| | | | | | | | | | | system calls now enter without Giant held, and then in some cases, acquire Giant explicitly. Remove a number of other MPSAFE annotations in the credential code and tweak one or two other adjacent comments. Notes: svn path=/head/; revision=167211
* When ntp_gettime() was converted from a sysctl + wrapper to a systemWarner Losh2007-01-121-0/+1
| | | | | | | | | | | | | | | call, its semantics were unintentionally changed. It went from returning the time state to returning 0 or -1. Since 0 means time normal, and non-zero effectively only shows up around leap seconds, this went unnoticed until now. At least unnoticed until someone was trying to run a binary they didn't have source for and it was misbehaving... Submitted by: Judah Levine MFC After: 2 weeks Notes: svn path=/head/; revision=165969
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningRobert Watson2006-11-061-2/+3
| | | | | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net> Notes: svn path=/head/; revision=164033
* Explicitly acquire Giant around the ntp_gettime() and assert it in theRobert Watson2005-05-281-0/+4
| | | | | | | | | | sysctl path. While this code is close to MPSAFE, it may require some additional locking. Mark ntp_gettime1() as GIANT_REQUIRED for now. Suggested by: phk Notes: svn path=/head/; revision=146722
* Implement kern_adjtime(), kern_readv(), kern_sched_rr_get_interval(),John Baldwin2005-03-311-11/+25
| | | | | | | | kern_settimeofday(), and kern_writev() to allow for further stackgap reduction in the compat ABIs. Notes: svn path=/head/; revision=144445
* /* -> /*- for copyright notices, minor format tweaks as necessaryWarner Losh2005-01-061-1/+2
| | | | Notes: svn path=/head/; revision=139804
* Place function comment above the right function.Mark Santcroos2004-11-191-7/+7
| | | | Notes: svn path=/head/; revision=137879
* Add system call implementation of ntp_gettime(2).Mark Santcroos2004-11-181-18/+43
| | | | | | | | | | | Moved most of the work to ntp_gettime1(), which is now called by ntp_gettime() and ntp_sysctl(). Reviewed by: imp, phk, njl, peter Approved by: njl Notes: svn path=/head/; revision=137873
* Annual NTP kernel code spring-cleaning:Poul-Henning Kamp2004-03-141-8/+11
| | | | | | | | | Use int64_t rather than long long for the fixpoint type. Don't discard fractional nanosecond frequency correction. Notes: svn path=/head/; revision=126974
* Deal with MOD_FREQUENCY before MOD_OFFSET because the latter is thePoul-Henning Kamp2004-01-241-6/+6
| | | | | | | | | one which runs the actual update. This fixes a bug where there were a delay in applying the frequency adjustment. In extreme cases this could result in marginal stability of the kernel-pll. Notes: svn path=/head/; revision=124937
* During a positive leap second, the tai_time offset should beWarner Losh2003-06-251-1/+1
| | | | | | | | | | | | | | incremented at the start of the leap second, not after the leap second has been inserted. This is because at the start of the leap second, we set the time back one second. This setting back one second is the moment that the offset changes. The old code set it back after the leap second, but that's one second too late. The negative leap second case is handled correctly. Reviewed by: phk Notes: svn path=/head/; revision=116838
* Use __FBSDID().David E. O'Brien2003-06-111-2/+3
| | | | Notes: svn path=/head/; revision=116182
* Explicitly have the timecounter init happen after the cpu_initclocks isPeter Wemm2003-01-061-1/+1
| | | | | | | | | | | | called. Otherwise (depending on a non-deterministic sort), the timecounter code can be initialized before the clock rate has been set (on ia64) and it assumes hz = 100, rather than the real value of 1024. I'm not sure how much gets upset by this. Glanced at by: phk Notes: svn path=/head/; revision=108755
* Remove an unused variable.Poul-Henning Kamp2002-10-111-7/+0
| | | | Notes: svn path=/head/; revision=104881
* Hide the private parts of timecounter from a couple of places that don'tPoul-Henning Kamp2002-04-261-4/+2
| | | | | | | really need to know the gory details. Notes: svn path=/head/; revision=95529
* suser is Giant safe, so optimize a pointless case.Poul-Henning Kamp2002-04-191-3/+3
| | | | Notes: svn path=/head/; revision=95036
* Remove two debug printfs which should never have been committed.Poul-Henning Kamp2002-04-151-4/+0
| | | | Notes: svn path=/head/; revision=94800
* You have to cast int64_t's to long long if you printf them with %lld.John Baldwin2002-04-151-2/+2
| | | | | | | | | This now compiles on alpha without a warning. Pointy-hat to: phk Notes: svn path=/head/; revision=94799
* Improve the implementation of adjtime(2).Poul-Henning Kamp2002-04-151-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | Apply the change as a continuous slew rather than as a series of discrete steps and make it possible to adjust arbitraryly huge amounts of time in either direction. In practice this is done by hooking into the same once-per-second loop as the NTP PLL and setting a suitable frequency offset deducting the amount slewed from the remainder. If the remaining delta is larger than 1 second we slew at 5000PPM (5msec/sec), for a delta less than a second we slew at 500PPM (500usec/sec) and for the last one second period we will slew at whatever rate (less than 500PPM) it takes to eliminate the delta entirely. The old implementation stepped the clock a number of microseconds every HZ to acheive the same effect, using the same rates of change. Eliminate the global variables tickadj, tickdelta and timedelta and their various use and initializations. This removes the most significant obstacle to running timecounter and NTP housekeeping from a timeout rather than hardclock. Notes: svn path=/head/; revision=94754
* In the ntp_adjtime(2) syscall, return our actual estimate of unappliedPoul-Henning Kamp2002-04-151-2/+2
| | | | | | | offset correction instead of the most recent offset applied. Notes: svn path=/head/; revision=94740
* Change the suser() API to take advantage of td_ucred as well as do aJohn Baldwin2002-04-011-1/+1
| | | | | | | | | | | | | | | general cleanup of the API. The entire API now consists of two functions similar to the pre-KSE API. The suser() function takes a thread pointer as its only argument. The td_ucred member of this thread must be valid so the only valid thread pointers are curthread and a few kernel threads such as thread0. The suser_cred() function takes a pointer to a struct ucred as its first argument and an integer flag as its second argument. The flag is currently only used for the PRISON_ROOT flag. Discussed on: smp@ Notes: svn path=/head/; revision=93593
* Revise timercounters to use binary fixed point format internally.Poul-Henning Kamp2002-02-071-1/+1
| | | | | | | | | | | | | | | | | The binary format "bintime" is a 32.64 format, it will go to 64.64 when time_t does. The bintime format is available to consumers of time in the kernel, and is preferable where timeintervals needs to be accumulated. This change simplifies much of the magic math inside the timecounters and improves the frequency and time precision by a couple of bits. I have not been able to measure a performance difference which was not a tiny fraction of the standard deviation on the measurements. Notes: svn path=/head/; revision=90362
* KSE Milestone 2Julian Elischer2001-09-121-4/+4
| | | | | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha Notes: svn path=/head/; revision=83366