1221676a1SAlexander Motin.\" Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org> 2221676a1SAlexander Motin.\" All rights reserved. 3221676a1SAlexander Motin.\" 4221676a1SAlexander Motin.\" Redistribution and use in source and binary forms, with or without 5221676a1SAlexander Motin.\" modification, are permitted provided that the following conditions 6221676a1SAlexander Motin.\" are met: 7221676a1SAlexander Motin.\" 1. Redistributions of source code must retain the above copyright 8221676a1SAlexander Motin.\" notice, this list of conditions and the following disclaimer. 9221676a1SAlexander Motin.\" 2. Redistributions in binary form must reproduce the above copyright 10221676a1SAlexander Motin.\" notice, this list of conditions and the following disclaimer in the 11221676a1SAlexander Motin.\" documentation and/or other materials provided with the distribution. 12221676a1SAlexander Motin.\" 13221676a1SAlexander Motin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14221676a1SAlexander Motin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15221676a1SAlexander Motin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16221676a1SAlexander Motin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17221676a1SAlexander Motin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18221676a1SAlexander Motin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19221676a1SAlexander Motin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20221676a1SAlexander Motin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21221676a1SAlexander Motin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22221676a1SAlexander Motin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23221676a1SAlexander Motin.\" SUCH DAMAGE. 24221676a1SAlexander Motin.\" 25*fd053faeSAlexander Motin.Dd March 13, 2012 26221676a1SAlexander Motin.Dt EVENTTIMERS 4 27221676a1SAlexander Motin.Os 28221676a1SAlexander Motin.Sh NAME 29221676a1SAlexander Motin.Nm eventtimers 30221676a1SAlexander Motin.Nd kernel event timers subsystem 31221676a1SAlexander Motin.Sh SYNOPSIS 32221676a1SAlexander MotinKernel uses several types of time-related devices, such as: real time clocks, 33221676a1SAlexander Motintime counters and event timers. 34221676a1SAlexander MotinReal time clocks responsible for tracking real world time, mostly when system 35221676a1SAlexander Motinis down. 36221676a1SAlexander MotinTime counters are responsible for generation of monotonically increasing 37221676a1SAlexander Motintimestamps for precise uptime tracking purposes, when system is running. 38221676a1SAlexander MotinEvent timers are responsible for generating interrupts at specified time or 39221676a1SAlexander Motinperiodically, to run different time-based events. 40221676a1SAlexander MotinThis page is about the last. 41221676a1SAlexander Motin.Sh DESCRIPTION 42221676a1SAlexander MotinKernel uses time-based events for many different purposes: scheduling, 43221676a1SAlexander Motinstatistics, time keeping, profiling and many other things, based on 44221676a1SAlexander Motin.Xr callout 9 45221676a1SAlexander Motinmechanism. 46221676a1SAlexander MotinThese purposes now grouped into three main callbacks: 479c121fecSAlexander Motin.Bl -tag -width ".Fn hardclock" 489c121fecSAlexander Motin.It Fn hardclock 49221676a1SAlexander Motin.Xr callout 9 509c121fecSAlexander Motinand timekeeping events entry. 519c121fecSAlexander MotinCalled with frequency defined by 529c121fecSAlexander Motin.Va hz 539c121fecSAlexander Motinvariable, 54221676a1SAlexander Motinusually 1000Hz. 559c121fecSAlexander Motin.It Fn statclock 569c121fecSAlexander Motinstatistics and scheduler events entry. 579c121fecSAlexander MotinCalled with frequency about 128Hz. 589c121fecSAlexander Motin.It Fn profclock 599c121fecSAlexander Motinprofiler events entry. 609c121fecSAlexander MotinWhen enabled, called with frequency about 8KHz. 61221676a1SAlexander Motin.El 629c121fecSAlexander Motin.Pp 63221676a1SAlexander MotinDifferent platforms provide different kinds of timer hardware. 64221676a1SAlexander MotinThe goal of the event timers subsystem is to provide unified way to control 65221676a1SAlexander Motinthat hardware, and to use it, supplying kernel with all required time-based 66221676a1SAlexander Motinevents. 67221676a1SAlexander Motin.Pp 68221676a1SAlexander MotinEach driver implementing event timers, registers them at the subsystem. 69221676a1SAlexander MotinIt is possible to see the list of present event timers, like this, via 70221676a1SAlexander Motin.Va kern.eventtimer 71221676a1SAlexander Motinsysctl: 72221676a1SAlexander Motin.Bd -literal 73221676a1SAlexander Motinkern.eventtimer.choice: HPET(550) LAPIC(400) i8254(100) RTC(0) 74221676a1SAlexander Motinkern.eventtimer.et.LAPIC.flags: 15 75221676a1SAlexander Motinkern.eventtimer.et.LAPIC.frequency: 0 76221676a1SAlexander Motinkern.eventtimer.et.LAPIC.quality: 400 77221676a1SAlexander Motinkern.eventtimer.et.i8254.flags: 1 78221676a1SAlexander Motinkern.eventtimer.et.i8254.frequency: 1193182 79221676a1SAlexander Motinkern.eventtimer.et.i8254.quality: 100 80221676a1SAlexander Motinkern.eventtimer.et.RTC.flags: 17 81221676a1SAlexander Motinkern.eventtimer.et.RTC.frequency: 32768 82221676a1SAlexander Motinkern.eventtimer.et.RTC.quality: 0 83221676a1SAlexander Motinkern.eventtimer.et.HPET.flags: 7 84221676a1SAlexander Motinkern.eventtimer.et.HPET.frequency: 14318180 85221676a1SAlexander Motinkern.eventtimer.et.HPET.quality: 550 86221676a1SAlexander Motin.Ed 879c121fecSAlexander Motin.Pp 889c121fecSAlexander Motinwhere: 899c121fecSAlexander Motin.Bl -inset 90221676a1SAlexander Motin.It Va kern.eventtimer.et. Ns Ar X Ns Va .flags 919c121fecSAlexander Motinis a 92221676a1SAlexander Motinbitmask, defining event timer capabilities: 939c121fecSAlexander Motin.Bl -tag -offset indent -width indent -compact 94221676a1SAlexander Motin.It 1 95221676a1SAlexander Motinperiodic mode supported, 96221676a1SAlexander Motin.It 2 97221676a1SAlexander Motinone-shot mode supported, 98221676a1SAlexander Motin.It 4 99221676a1SAlexander Motintimer is per-CPU, 100221676a1SAlexander Motin.It 8 101221676a1SAlexander Motintimer may stop when CPU goes to sleep state, 102221676a1SAlexander Motin.It 16 103221676a1SAlexander Motintimer supports only power-of-2 divisors. 104221676a1SAlexander Motin.El 105221676a1SAlexander Motin.It Va kern.eventtimer.et. Ns Ar X Ns Va .frequency 1069c121fecSAlexander Motinis a 107221676a1SAlexander Motintimer base frequency, 108221676a1SAlexander Motin.It Va kern.eventtimer.et. Ns Ar X Ns Va .quality 1099c121fecSAlexander Motinis an 110221676a1SAlexander Motinintegral value, defining how good is this timer, comparing to others. 111221676a1SAlexander Motin.El 112221676a1SAlexander Motin.Pp 113221676a1SAlexander MotinTimers management code of the kernel chooses one timer from that list. 114221676a1SAlexander MotinCurrent choice can be read and affected via 115221676a1SAlexander Motin.Va kern.eventtimer.timer 116221676a1SAlexander Motintunable/sysctl. 117221676a1SAlexander MotinSeveral other tunables/sysctls are affecting how exactly this timer is used: 1189c121fecSAlexander Motin.Bl -inset 119221676a1SAlexander Motin.It Va kern.eventtimer.periodic 120221676a1SAlexander Motinallows to choose periodic and one-shot operation mode. 121221676a1SAlexander MotinIn periodic mode, periodic interrupts from timer hardware are taken as the 122221676a1SAlexander Motinonly source of time for time events. 123221676a1SAlexander MotinOne-shot mode instead uses currently selected time counter to precisely 124221676a1SAlexander Motinschedule all needed events and programs event timer to generate interrupt 125221676a1SAlexander Motinexactly in specified time. 126221676a1SAlexander MotinDefault value depends of chosen timer capabilities, but one-shot mode is 127221676a1SAlexander Motinpreferred, until other is forced by user or hardware. 128221676a1SAlexander Motin.It Va kern.eventtimer.singlemul 129221676a1SAlexander Motinin periodic mode specifies how much times higher timer frequency should be, 1309c121fecSAlexander Motinto not strictly alias 1319c121fecSAlexander Motin.Fn hardclock 1329c121fecSAlexander Motinand 1339c121fecSAlexander Motin.Fn statclock 1349c121fecSAlexander Motinevents. 1359c121fecSAlexander MotinDefault values are 136221676a1SAlexander Motin1, 2 or 4, depending on configured HZ value. 137221676a1SAlexander Motin.It Va kern.eventtimer.idletick 138221676a1SAlexander Motinmakes each CPU to receive every timer interrupt independently of whether they 1399c121fecSAlexander Motinbusy or not. 1409c121fecSAlexander MotinBy default this options is disabled. 1419c121fecSAlexander MotinIf chosen timer is per-CPU 142221676a1SAlexander Motinand runs in periodic mode, this option has no effect - all interrupts are 143221676a1SAlexander Motinalways generating. 144221676a1SAlexander Motin.El 145221676a1SAlexander Motin.Sh SEE ALSO 14673889c80SAlexander Motin.Xr apic 4 , 147221676a1SAlexander Motin.Xr atrtc 4 , 1489c121fecSAlexander Motin.Xr attimer 4 , 149f42acd0fSAlexander Motin.Xr hpet 4 , 1502a6be868SAlexander Motin.Xr timecounters 4 , 151f42acd0fSAlexander Motin.Xr eventtimers 9 152