14c0bc591SWarner Losh.\" 24c0bc591SWarner Losh.\" Copyright (c) 2021 Netflix, Inc. 34c0bc591SWarner Losh.\" 44c0bc591SWarner Losh.\" Redistribution and use in source and binary forms, with or without 54c0bc591SWarner Losh.\" modification, are permitted provided that the following conditions 64c0bc591SWarner Losh.\" are met: 74c0bc591SWarner Losh.\" 1. Redistributions of source code must retain the above copyright 84c0bc591SWarner Losh.\" notice, this list of conditions and the following disclaimer. 94c0bc591SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright 104c0bc591SWarner Losh.\" notice, this list of conditions and the following disclaimer in the 114c0bc591SWarner Losh.\" documentation and/or other materials provided with the distribution. 124c0bc591SWarner Losh.\" 134c0bc591SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 144c0bc591SWarner Losh.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 154c0bc591SWarner Losh.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 164c0bc591SWarner Losh.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 174c0bc591SWarner Losh.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 184c0bc591SWarner Losh.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 194c0bc591SWarner Losh.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 204c0bc591SWarner Losh.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 214c0bc591SWarner Losh.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 224c0bc591SWarner Losh.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 234c0bc591SWarner Losh.\" POSSIBILITY OF SUCH DAMAGE. 244c0bc591SWarner Losh.\" 25*1426907fSWarner Losh.Dd July 1, 2021 264c0bc591SWarner Losh.Dt HZ 9 274c0bc591SWarner Losh.Os 284c0bc591SWarner Losh.Sh NAME 294c0bc591SWarner Losh.Nm hz , 304c0bc591SWarner Losh.Nm tick , 314c0bc591SWarner Losh.Nm stathz , 324c0bc591SWarner Losh.Nm profhz 334c0bc591SWarner Losh.Nd system time model 344c0bc591SWarner Losh.Sh SYNOPSIS 354c0bc591SWarner Losh.In sys/kernel.h 364c0bc591SWarner Losh.Pp 374c0bc591SWarner Losh.Vt extern int hz; 384c0bc591SWarner Losh.Vt extern int tick; 39*1426907fSWarner Losh.Vt extern int stathz; 404c0bc591SWarner Losh.Vt extern int profhz; /* deprecated */ 414c0bc591SWarner Losh.Sh DESCRIPTION 424c0bc591SWarner Losh.Fx 434c0bc591SWarner Loshutilizes periodic, one-shot, global or per-CPU 444c0bc591SWarner Loshtiming hardware using 454c0bc591SWarner Losh.Xr eventtimers 9 464c0bc591SWarner Loshto produce traditional clock behavior. 47*1426907fSWarner LoshThese clocks regulate periodic events in the system. 484c0bc591SWarner Losh.Pp 494c0bc591SWarner LoshThe main clock is used to update the system's notion of time via 504c0bc591SWarner Losh.Xr timecounters 9 51*1426907fSWarner Loshand to pace periodic system processing as documented in 524c0bc591SWarner Losh.Xr hardclock 9 . 53*1426907fSWarner LoshThat routine may be called once every 1 / 544c0bc591SWarner Losh.Va hz 55*1426907fSWarner Loshseconds, though the call is omitted if no work is needed in the next tick and it 56*1426907fSWarner Loshhas not been 0.5 seconds since the last call. 574c0bc591SWarner Losh.Pp 58*1426907fSWarner LoshThe stat clock running at 594c0bc591SWarner Losh.Va stathz 60*1426907fSWarner Loshgathers statistics on the system and its processes. 61*1426907fSWarner LoshIt computes values for 62*1426907fSWarner Losh.Xr getrusage 2 63*1426907fSWarner Loshand statistics displayed by 64*1426907fSWarner Losh.Xr ps 1 65*1426907fSWarner Loshand 66*1426907fSWarner Losh.Xr top 1 . 67*1426907fSWarner Losh.Pp 68*1426907fSWarner LoshFinally, a profiling clock may run at 69*1426907fSWarner Losh.Vt profhz 70*1426907fSWarner Loshto sample user program counter values for profiling purposes. 71*1426907fSWarner LoshThis profiling mechanism has been replaced by the more functional 72*1426907fSWarner Losh.Xr hwpmc 4 73*1426907fSWarner Loshand may be removed in a future version of 74*1426907fSWarner Losh.Fx . 754c0bc591SWarner Losh.Pp 764c0bc591SWarner Losh.Va tick 774c0bc591SWarner Loshis the length of time in microseconds of one system tick. 784c0bc591SWarner Losh.Pp 794c0bc591SWarner LoshThese system variables are also available as 804c0bc591SWarner Losh.Em struct clockinfo 814c0bc591SWarner Loshfrom 824c0bc591SWarner Losh.Xr sysctl 3 834c0bc591SWarner Loshand 844c0bc591SWarner Losh.Sy kern.clockrate 854c0bc591SWarner Loshfrom 864c0bc591SWarner Losh.Xr sysctl 8 . 874c0bc591SWarner Losh.Pp 88*1426907fSWarner LoshThe current global and per-CPU CPU time usage is returned to the user in units 89*1426907fSWarner Loshof 1 / 90*1426907fSWarner Losh.Va stathz 91*1426907fSWarner Loshticks in the 92*1426907fSWarner Losh.Sy kern.cp_time 93*1426907fSWarner Loshand 94*1426907fSWarner Losh.Sy kern.cp_times 95*1426907fSWarner Loshsysctl MIBs. 96*1426907fSWarner Losh.Pp 974c0bc591SWarner LoshThe 984c0bc591SWarner Losh.Va hz 994c0bc591SWarner Loshrate may be overridden by defining 1004c0bc591SWarner Losh.Dv HZ 1014c0bc591SWarner Loshin the kernel configuration file or setting 1024c0bc591SWarner Losh.Sy kern.hz 1034c0bc591SWarner Loshsystem tuneable via 1044c0bc591SWarner Losh.Xr loader.conf 5 . 1054c0bc591SWarner Losh.Pp 1064c0bc591SWarner LoshThe current default is 1000 Hz for a tick of 1 ms for real hardware. 1074c0bc591SWarner LoshFor virtual machine guests, the default is 100 Hz for a tick of 10 ms. 1084c0bc591SWarner LoshOnly override the default value if you really know what you are doing. 1094c0bc591SWarner LoshDue to the adaptive nature of timeouts, changing this value has less effect than 1104c0bc591SWarner Loshit had in the past. 1114c0bc591SWarner Losh.Sh SEE ALSO 112*1426907fSWarner Losh.Xr ps 1 , 113*1426907fSWarner Losh.Xr top 1 , 1144c0bc591SWarner Losh.Xr setitimer 2 , 1154c0bc591SWarner Losh.Xr timer_settime 2 , 1164c0bc591SWarner Losh.Xr loader.conf 5 , 1174c0bc591SWarner Losh.Xr eventtimers 9 , 1184c0bc591SWarner Losh.Xr hardclock 9 , 1194c0bc591SWarner Losh.Xr microtime 9 , 1204c0bc591SWarner Losh.Xr time_second 9 , 1214c0bc591SWarner Losh.Xr timecounters 9 122*1426907fSWarner Losh.Sh IMPLEMENTATION NOTES 123*1426907fSWarner LoshHistorically, both the 124*1426907fSWarner Losh.Va stathz 125*1426907fSWarner Loshand 126*1426907fSWarner Losh.Va profhz 127*1426907fSWarner Loshclocks have run off the same physical timer running at the slower rate when no 128*1426907fSWarner Loshprocess is using the profile features, or at the higher rate when at least one 129*1426907fSWarner Loshprocess is using it. 130*1426907fSWarner LoshAlthough the interface is deprecated by 131*1426907fSWarner Losh.St -p1003.1-2008 132*1426907fSWarner Loshin favor of 133*1426907fSWarner Losh.Xr timer_settime 2 , 134*1426907fSWarner Loshseveral programs still use 135*1426907fSWarner Losh.Xr setitimer 2 136*1426907fSWarner Loshand 137*1426907fSWarner Losh.Va ITIMER_PROF 138*1426907fSWarner Loshfor a higher-resolution periodic interrupt than has been traditionally 139*1426907fSWarner Loshavailable. 140*1426907fSWarner Losh.Pp 141*1426907fSWarner LoshHistorically, 142*1426907fSWarner Losh.Xr hardclock 9 143*1426907fSWarner Loshhas also been run off a separate interrupt, except on constrained platforms that 144*1426907fSWarner Loshlack enough periodic interrupt sources. 145*1426907fSWarner Losh.Fx 146*1426907fSWarner Loshuses 147*1426907fSWarner Losh.Xr eventtimers 9 148*1426907fSWarner Loshto abstract these details away, though some old code may still harbor 149*1426907fSWarner Loshassumptions that are an imperfect fit to this abstraction. 150*1426907fSWarner Losh.Pp 151*1426907fSWarner Losh.Xr timecounters 9 152*1426907fSWarner Loshare limited to 32-bits and wrap after about a second, so we must update the 153*1426907fSWarner Loshtime hands they maintain at least every half second to get the proper wrapping 154*1426907fSWarner Loshmath. 155*1426907fSWarner LoshIn addition, 156*1426907fSWarner Losh.Va kern.cp_times 157*1426907fSWarner Loshneeds to updated at least once a second so that the values displayed by 158*1426907fSWarner Losh.Xr top 1 159*1426907fSWarner Loshupdate every second. 160