2 .\" Copyright (c) 2011-2013 Alexander Motin <mav@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
15 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 .Nd kernel event timers subsystem
38 typedef int et_start_t(struct eventtimer *et,
39 sbintime_t first, sbintime_t period);
40 typedef int et_stop_t(struct eventtimer *et);
41 typedef void et_event_cb_t(struct eventtimer *et, void *arg);
42 typedef int et_deregister_cb_t(struct eventtimer *et, void *arg);
45 SLIST_ENTRY(eventtimer) et_all;
48 #define ET_FLAGS_PERIODIC 1
49 #define ET_FLAGS_ONESHOT 2
50 #define ET_FLAGS_PERCPU 4
51 #define ET_FLAGS_C3STOP 8
52 #define ET_FLAGS_POW2DIV 16
55 uint64_t et_frequency;
56 sbintime_t et_min_period;
57 sbintime_t et_max_period;
60 et_event_cb_t *et_event_cb;
61 et_deregister_cb_t *et_deregister_cb;
64 struct sysctl_oid *et_sysctl;
68 .Fn et_register "struct eventtimer *et"
70 .Fn et_deregister "struct eventtimer *et"
72 .Fn et_change_frequency "struct eventtimer *et" "uint64_t newfreq"
75 .Ft struct eventtimer *
76 .Fn et_find "const char *name" "int check" "int want"
78 .Fn et_init "struct eventtimer *et" "et_event_cb_t *event" "et_deregister_cb_t *deregister" "void *arg"
80 .Fn et_start "struct eventtimer *et" "sbintime_t first" "sbintime_t period"
82 .Fn et_stop "struct eventtimer *et"
84 .Fn et_ban "struct eventtimer *et"
86 .Fn et_free "struct eventtimer *et"
88 Event timers are responsible for generating interrupts at specified time
89 or periodically, to run different time-based events.
90 Subsystem consists of three main parts:
91 .Bl -tag -width "Consumers"
93 Manage hardware to generate requested time events.
95 .Pa sys/kern/kern_clocksource.c
96 uses event timers to supply kernel with
103 .Pa sys/sys/timeet.h ,
104 .Pa sys/kern/kern_et.c
105 provide APIs for event timer drivers and consumers.
108 Driver API is built around eventtimer structure.
109 To register its functionality driver allocates that structure and calls
111 Driver should fill following fields there:
114 Unique name of the event timer for management purposes.
116 Set of flags, describing timer capabilities:
117 .Bl -tag -width "ET_FLAGS_PERIODIC" -compact
118 .It ET_FLAGS_PERIODIC
119 Periodic mode supported.
121 One-shot mode supported.
125 Timer may stop in CPU sleep state.
127 Timer supports only 2^n divisors.
130 Abstract value to certify whether this timecounter is better than the others.
131 Higher value means better.
133 Timer oscillator's base frequency, if applicable and known.
134 Used by consumers to predict set of possible frequencies that could be
135 obtained by dividing it.
136 Should be zero if not applicable or unknown.
137 .It Va et_min_period , et_max_period
138 Minimal and maximal reliably programmable time periods.
140 Driver's timer start function pointer.
142 Driver's timer stop function pointer.
144 Driver's private data storage.
147 After the event timer functionality is registered, it is controlled via
153 method is called to start the specified event timer.
154 The last two arguments are used to specify time when events should be
157 argument specifies time period before the first event generated.
158 In periodic mode NULL value specifies that first period is equal to the
162 argument specifies the time period between following events for the
164 The NULL value there specifies the one-shot mode.
165 At least one of these two arguments should be not NULL.
166 When event time arrive, driver should call
168 callback function, passing
170 as the second argument.
172 method is called to stop the specified event timer.
173 For the per-CPU event timers
177 methods control timers associated with the current CPU.
179 Driver may deregister its functionality by calling
182 If the frequency of the clock hardware can change while it is
183 running (for example, during power-saving modes), the driver must call
184 .Fn et_change_frequency
186 If the given event timer is the active timer,
187 .Fn et_change_frequency
188 stops the timer on all CPUs, updates
190 then restarts the timer on all CPUs so that all
191 current events are rescheduled using the new frequency.
192 If the given timer is not currently active,
193 .Fn et_change_frequency
198 allows consumer to find available event timer, optionally matching specific
199 name and/or capability flags.
200 Consumer may read returned eventtimer structure, but should not modify it.
201 When wanted event timer is found,
203 should be called for it, submitting
207 callbacks functions, and the opaque argument
209 That argument will be passed as argument to the callbacks.
210 Event callback function will be called on scheduled time events.
211 It is called from the hardware interrupt context, so no sleep is permitted
213 Deregister callback function may be called to report consumer that the event
214 timer functionality is no longer available.
215 On this call, consumer should stop using event timer before the return.
217 After the timer is found and initialized, it can be controlled via
221 The arguments are the same as described in driver API.
222 Per-CPU event timers can be controlled only from specific CPUs.
225 allows consumer to mark event timer as broken via clearing both one-shot and
226 periodic capability flags, if it was somehow detected.
230 It releases the event timer for other consumers use.
235 macros should be used to manage
242 calls to serialize access to the list of the registered event timers and the
248 calls should be serialized in consumer's internal way to avoid concurrent
249 timer hardware access.
253 .An Alexander Motin Aq Mt mav@FreeBSD.org