xref: /freebsd/share/man/man9/eventtimers.9 (revision ecb0bac9ab371a397376630dd87e71c6bc40feb7)
1f42acd0fSAlexander Motin.\"
2f42acd0fSAlexander Motin.\" Copyright (c) 2011 Alexander Motin <mav@FreeBSD.org>
3f42acd0fSAlexander Motin.\" All rights reserved.
4f42acd0fSAlexander Motin.\"
5f42acd0fSAlexander Motin.\" Redistribution and use in source and binary forms, with or without
6f42acd0fSAlexander Motin.\" modification, are permitted provided that the following conditions
7f42acd0fSAlexander Motin.\" are met:
8f42acd0fSAlexander Motin.\" 1. Redistributions of source code must retain the above copyright
9f42acd0fSAlexander Motin.\"    notice, this list of conditions and the following disclaimer.
10f42acd0fSAlexander Motin.\" 2. Redistributions in binary form must reproduce the above copyright
11f42acd0fSAlexander Motin.\"    notice, this list of conditions and the following disclaimer in the
12f42acd0fSAlexander Motin.\"    documentation and/or other materials provided with the distribution.
13f42acd0fSAlexander Motin.\"
14f42acd0fSAlexander Motin.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
15f42acd0fSAlexander Motin.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16f42acd0fSAlexander Motin.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17f42acd0fSAlexander Motin.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
18f42acd0fSAlexander Motin.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19f42acd0fSAlexander Motin.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20f42acd0fSAlexander Motin.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21f42acd0fSAlexander Motin.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22f42acd0fSAlexander Motin.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23f42acd0fSAlexander Motin.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24f42acd0fSAlexander Motin.\"
25f42acd0fSAlexander Motin.\" $FreeBSD$
26f42acd0fSAlexander Motin.\"
27f42acd0fSAlexander Motin.Dd December 14, 2011
28f42acd0fSAlexander Motin.Dt EVENTTIMERS 9
29f42acd0fSAlexander Motin.Os
30f42acd0fSAlexander Motin.Sh NAME
31f42acd0fSAlexander Motin.Nm eventtimers
32f42acd0fSAlexander Motin.Nd kernel event timers subsystem
33f42acd0fSAlexander Motin.Sh SYNOPSIS
34f42acd0fSAlexander Motin.In sys/timeet.h
35f42acd0fSAlexander Motin.Bd -literal
36f42acd0fSAlexander Motinstruct eventtimer;
37f42acd0fSAlexander Motin
38f42acd0fSAlexander Motintypedef int et_start_t(struct eventtimer *et,
39f42acd0fSAlexander Motin    struct bintime *first, struct bintime *period);
40f42acd0fSAlexander Motintypedef int et_stop_t(struct eventtimer *et);
41f42acd0fSAlexander Motintypedef void et_event_cb_t(struct eventtimer *et, void *arg);
42f42acd0fSAlexander Motintypedef int et_deregister_cb_t(struct eventtimer *et, void *arg);
43f42acd0fSAlexander Motin
44f42acd0fSAlexander Motinstruct eventtimer {
45f42acd0fSAlexander Motin	SLIST_ENTRY(eventtimer)	et_all;
46f42acd0fSAlexander Motin	char			*et_name;
47f42acd0fSAlexander Motin	int			et_flags;
48f42acd0fSAlexander Motin#define ET_FLAGS_PERIODIC	1
49f42acd0fSAlexander Motin#define ET_FLAGS_ONESHOT	2
50f42acd0fSAlexander Motin#define ET_FLAGS_PERCPU		4
51f42acd0fSAlexander Motin#define ET_FLAGS_C3STOP		8
52f42acd0fSAlexander Motin#define ET_FLAGS_POW2DIV	16
53f42acd0fSAlexander Motin	int			et_quality;
54f42acd0fSAlexander Motin	int			et_active;
556b99842aSEd Schouten	uint64_t		et_frequency;
56f42acd0fSAlexander Motin	struct bintime		et_min_period;
57f42acd0fSAlexander Motin	struct bintime		et_max_period;
58f42acd0fSAlexander Motin	et_start_t		*et_start;
59f42acd0fSAlexander Motin	et_stop_t		*et_stop;
60f42acd0fSAlexander Motin	et_event_cb_t		*et_event_cb;
61f42acd0fSAlexander Motin	et_deregister_cb_t	*et_deregister_cb;
62f42acd0fSAlexander Motin	void 			*et_arg;
63f42acd0fSAlexander Motin	void			*et_priv;
64f42acd0fSAlexander Motin	struct sysctl_oid	*et_sysctl;
65f42acd0fSAlexander Motin};
66f42acd0fSAlexander Motin.Ed
67f42acd0fSAlexander Motin.Ft int
68f42acd0fSAlexander Motin.Fn et_register "struct eventtimer *et"
69f42acd0fSAlexander Motin.Ft int
70f42acd0fSAlexander Motin.Fn et_deregister "struct eventtimer *et"
71f42acd0fSAlexander Motin.Fn ET_LOCK
72f42acd0fSAlexander Motin.Fn ET_UNLOCK
73f42acd0fSAlexander Motin.Ft struct eventtimer *
74f42acd0fSAlexander Motin.Fn et_find "const char *name" "int check" "int want"
75f42acd0fSAlexander Motin.Ft int
76f42acd0fSAlexander Motin.Fn et_init "struct eventtimer *et" "et_event_cb_t *event" "et_deregister_cb_t *deregister" "void *arg"
77f42acd0fSAlexander Motin.Ft int
78f42acd0fSAlexander Motin.Fn et_start "struct eventtimer *et" "struct bintime *first" "struct bintime *period"
79f42acd0fSAlexander Motin.Ft int
80f42acd0fSAlexander Motin.Fn et_stop "struct eventtimer *et"
81f42acd0fSAlexander Motin.Ft int
82f42acd0fSAlexander Motin.Fn et_ban "struct eventtimer *et"
83f42acd0fSAlexander Motin.Ft int
84f42acd0fSAlexander Motin.Fn et_free "struct eventtimer *et"
85f42acd0fSAlexander Motin.Sh DESCRIPTION
86f42acd0fSAlexander MotinEvent timers are responsible for generating interrupts at specified time
87f42acd0fSAlexander Motinor periodically, to run different time-based events.
88f42acd0fSAlexander MotinSubsystem consists of three main parts:
89*ecb0bac9SGlen Barber.Bl -tag -width "Consumers"
90f42acd0fSAlexander Motin.It Drivers
91f42acd0fSAlexander MotinManage hardware to generate requested time events.
92f42acd0fSAlexander Motin.It Consumers
93f42acd0fSAlexander Motin.Pa sys/kern/kern_clocksource.c
94f42acd0fSAlexander Motinuses event timers to supply kernel with
95f42acd0fSAlexander Motin.Fn hardclock ,
96f42acd0fSAlexander Motin.Fn statclock
97f42acd0fSAlexander Motinand
98f42acd0fSAlexander Motin.Fn profclock
99f42acd0fSAlexander Motintime events.
100f42acd0fSAlexander Motin.It Glue code
101f42acd0fSAlexander Motin.Pa sys/sys/timeet.h ,
102f42acd0fSAlexander Motin.Pa sys/kern/kern_et.c
103f42acd0fSAlexander Motinprovide APIs for event timer drivers and consumers.
104f42acd0fSAlexander Motin.El
105f42acd0fSAlexander Motin.Sh DRIVER API
106f42acd0fSAlexander MotinDriver API is built around eventtimer structure.
107f42acd0fSAlexander MotinTo register its functionality driver allocates that structure and calls
108f42acd0fSAlexander Motin.Fn et_register .
109f42acd0fSAlexander MotinDriver should fill following fields there:
110*ecb0bac9SGlen Barber.Bl -tag -width Va
111f42acd0fSAlexander Motin.It Va et_name
112f42acd0fSAlexander MotinUnique name of the event timer for management purposes.
113f42acd0fSAlexander Motin.It Va et_flags
114f42acd0fSAlexander MotinSet of flags, describing timer capabilities:
115f42acd0fSAlexander Motin.Bl -tag -width "ET_FLAGS_PERIODIC" -compact
116f42acd0fSAlexander Motin.It ET_FLAGS_PERIODIC
117f42acd0fSAlexander MotinPeriodic mode supported.
118f42acd0fSAlexander Motin.It ET_FLAGS_ONESHOT
119f42acd0fSAlexander MotinOne-shot mode supported.
120f42acd0fSAlexander Motin.It ET_FLAGS_PERCPU
121f42acd0fSAlexander MotinTimer is per-CPU.
122f42acd0fSAlexander Motin.It ET_FLAGS_C3STOP
123f42acd0fSAlexander MotinTimer may stop in CPU sleep state.
124f42acd0fSAlexander Motin.It ET_FLAGS_POW2DIV
125f42acd0fSAlexander MotinTimer supports only 2^n divisors.
126f42acd0fSAlexander Motin.El
127f42acd0fSAlexander Motin.It Va et_quality
128f42acd0fSAlexander MotinAbstract value to certify whether this timecounter is better than the others.
129f42acd0fSAlexander MotinHigher value means better.
130f42acd0fSAlexander Motin.It Va et_frequency
131f42acd0fSAlexander MotinTimer oscillator's base frequency, if applicable and known.
132f42acd0fSAlexander MotinUsed by consumers to predict set of possible frequencies that could be
133f42acd0fSAlexander Motinobtained by dividing it.
134f42acd0fSAlexander MotinShould be zero if not applicable or unknown.
135f42acd0fSAlexander Motin.It Va et_min_period , et_max_period
136f42acd0fSAlexander MotinMinimal and maximal reliably programmable time periods.
137f42acd0fSAlexander Motin.It Va et_start
138f42acd0fSAlexander MotinDriver's timer start function pointer.
139f42acd0fSAlexander Motin.It Va et_stop
140f42acd0fSAlexander MotinDriver's timer stop function pointer.
141f42acd0fSAlexander Motin.It Va et_priv
142f42acd0fSAlexander MotinDriver's private data storage.
143f42acd0fSAlexander Motin.El
144f42acd0fSAlexander Motin.Pp
145f42acd0fSAlexander MotinAfter the event timer functionality is registered, it is controlled via
146f42acd0fSAlexander Motin.Va et_start
147f42acd0fSAlexander Motinand
148f42acd0fSAlexander Motin.Va et_stop
149f42acd0fSAlexander Motinmethods.
150f42acd0fSAlexander Motin.Va et_start
151f42acd0fSAlexander Motinmethod is called to start the specified event timer.
152f42acd0fSAlexander MotinThe last two arguments are used to specify time when events should be
153f42acd0fSAlexander Motingenerated.
154f42acd0fSAlexander Motin.Va first
155f42acd0fSAlexander Motinargument specifies time period before the first event generated.
156f42acd0fSAlexander MotinIn periodic mode NULL value specifies that first period is equal to the
157f42acd0fSAlexander Motin.Va period
158f42acd0fSAlexander Motinargument value.
159f42acd0fSAlexander Motin.Va period
160f42acd0fSAlexander Motinargument specifies the time period between following events for the
161f42acd0fSAlexander Motinperiodic mode.
162f42acd0fSAlexander MotinThe NULL value there specifies the one-shot mode.
163f42acd0fSAlexander MotinAt least one of these two arguments should be not NULL.
164f42acd0fSAlexander MotinWhen event time arrive, driver should call
165f42acd0fSAlexander Motin.Va et_event_cb
166f42acd0fSAlexander Motincallback function, passing
167f42acd0fSAlexander Motin.Va et_arg
168f42acd0fSAlexander Motinas the second argument.
169f42acd0fSAlexander Motin.Va et_stop
170f42acd0fSAlexander Motinmethod is called to stop the specified event timer.
171f42acd0fSAlexander MotinFor the per-CPU event timers
172f42acd0fSAlexander Motin.Va et_start
173f42acd0fSAlexander Motinand
174f42acd0fSAlexander Motin.Va et_stop
175f42acd0fSAlexander Motinmethods control timers associated with the current CPU.
176f42acd0fSAlexander Motin.Pp
177f42acd0fSAlexander MotinDriver may deregister its functionality by calling
178f42acd0fSAlexander Motin.Fn et_deregister .
179f42acd0fSAlexander Motin.Sh CONSUMER API
180f42acd0fSAlexander Motin.Fn et_find
181f42acd0fSAlexander Motinallows consumer to find available event timer, optionally matching specific
182f42acd0fSAlexander Motinname and/or capability flags.
183f42acd0fSAlexander MotinConsumer may read returned eventtimer structure, but should not modify it.
184f42acd0fSAlexander MotinWhen wanted event timer is found,
185f42acd0fSAlexander Motin.Fn et_init
186f42acd0fSAlexander Motinshould be called for it, submitting
187f42acd0fSAlexander Motin.Va event
188f42acd0fSAlexander Motinand optionally
189f42acd0fSAlexander Motin.Va deregister
190f42acd0fSAlexander Motincallbacks functions, and the opaque argument
191f42acd0fSAlexander Motin.Va arg .
192f42acd0fSAlexander MotinThat argument will be passed as argument to the callbacks.
193f42acd0fSAlexander MotinEvent callback function will be called on scheduled time events.
194f42acd0fSAlexander MotinIt is called from the hardware interrupt context, so no sleep is permitted
195f42acd0fSAlexander Motinthere.
196f42acd0fSAlexander MotinDeregister callback function may be called to report consumer that the event
197f42acd0fSAlexander Motintimer functionality is no longer available.
198f42acd0fSAlexander MotinOn this call, consumer should stop using event timer before the return.
199f42acd0fSAlexander Motin.Pp
200f42acd0fSAlexander MotinAfter the timer is found and initialized, it can be controlled via
201f42acd0fSAlexander Motin.Fn et_start
202f42acd0fSAlexander Motinand
203f42acd0fSAlexander Motin.Fn et_stop .
204f42acd0fSAlexander MotinThe arguments are the same as described in driver API.
205f42acd0fSAlexander MotinPer-CPU event timers can be controlled only from specific CPUs.
206f42acd0fSAlexander Motin.Pp
207f42acd0fSAlexander Motin.Fn et_ban
208f42acd0fSAlexander Motinallows consumer to mark event timer as broken via clearing both one-shot and
209f42acd0fSAlexander Motinperiodic capability flags, if it was somehow detected.
210f42acd0fSAlexander Motin.Fn et_free
211f42acd0fSAlexander Motinis the opposite to
212f42acd0fSAlexander Motin.Fn et_init .
213f42acd0fSAlexander MotinIt releases the event timer for other consumers use.
214f42acd0fSAlexander Motin.Pp
215f42acd0fSAlexander Motin.Fn ET_LOCK
216f42acd0fSAlexander Motinand
217f42acd0fSAlexander Motin.Fn ET_UNLOCK
218f42acd0fSAlexander Motinmacros should be used to manage
219f42acd0fSAlexander Motin.Xr mutex 9
220f42acd0fSAlexander Motinlock around
221f42acd0fSAlexander Motin.Fn et_find ,
222f42acd0fSAlexander Motin.Fn et_init
223f42acd0fSAlexander Motinand
224f42acd0fSAlexander Motin.Fn et_free
225f42acd0fSAlexander Motincalls to serialize access to the list of the registered event timers and the
226f42acd0fSAlexander Motinpointers returned by
227f42acd0fSAlexander Motin.Fn et_find .
228f42acd0fSAlexander Motin.Fn et_start
229f42acd0fSAlexander Motinand
230f42acd0fSAlexander Motin.Fn et_stop
231f42acd0fSAlexander Motincalls should be serialized in consumer's internal way to avoid concurrent
232f42acd0fSAlexander Motintimer hardware access.
233f42acd0fSAlexander Motin.Sh SEE ALSO
234f42acd0fSAlexander Motin.Xr eventtimers 4
235f42acd0fSAlexander Motin.Sh AUTHORS
236f42acd0fSAlexander Motin.An Alexander Motin Aq mav@FreeBSD.org
237