1 .\" SPDX-License-Identifier: BSD-2-Clause
3 .\" Copyright (c) 2023 Jake Freeland <jfree@FreeBSD.org>
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Nd timers with file descriptor semantics
47 .Fa "struct itimerspec *curr_value"
53 .Fa "const struct itimerspec *new_value"
54 .Fa "struct itimerspec *old_value"
59 system calls operate on timers, identified by special
62 These calls are analogous to
67 per-process timer functions, but use a
69 descriptor in place of
74 descriptors possess traditional file descriptor semantics; they may be passed
75 to other processes, preserved across
84 descriptor is no longer needed, it may be disposed of using
86 .Bl -tag -width "Fn timerfd_settime"
90 object and return its file descriptor.
93 argument specifies the clock used as a timing base and may be:
95 .Bl -tag -width "Dv CLOCK_MONOTONIC" -compact
97 Increments as a wall clock should.
98 .It Dv CLOCK_MONOTONIC
99 Increments monotonically in SI seconds.
104 argument may contain the result of
106 the following values:
108 .Bl -tag -width "Dv TFD_NONBLOCK" -compact
110 The newly generated file descriptor will close-on-exec.
112 Do not block on read/write operations.
114 .It Fn timerfd_gettime
115 Retrieve the current state of the timer denoted by
117 The result is stored in
120 .Dv struct itimerspec .
127 represent the relative time until the next expiration and the interval
128 reload value last set by
129 .Fn timerfd_settime ,
131 .It Fn timerfd_settime
132 Update the timer denoted by
135 .Dv struct itimerspec
142 should contain the amount of time before the timer expires, or zero if the
143 timer should be disarmed.
146 member should contain the reload time if an interval timer is desired.
148 The previous timer state will be stored in
157 argument may contain the result of
159 the following values:
161 .Bl -tag -width TFD_TIMER_CANCEL_ON_SET -compact
162 .It Dv TFD_TIMER_ABSTIME
163 Expiration will occur at the absolute time provided in
167 represents a relative time compared to the timer's
170 .It Dv TFD_TIMER_CANCEL_ON_SET
175 and the realtime clock has experienced a discontinuous jump,
176 then the timer will be canceled and the next
183 File operations have the following semantics:
184 .Bl -tag -width ioctl
186 Transfer the number of timer expirations that have occurred since the last
191 into the output buffer of size
193 If the expiration counter is zero,
195 blocks until a timer expiration occurs unless
201 The file descriptor is readable when its timer expiration counter is greater
204 .Bl -tag -width FIONREAD
206 A non-zero input will set the FASYNC flag.
207 A zero input will clear the FASYNC flag.
209 A non-zero input will set the FNONBLOCK flag.
210 A zero input will clear the FNONBLOCK flag.
216 system call creates a
218 object and returns its file descriptor.
219 If an error occurs, -1 is returned and the global variable
221 is set to indicate the error.
227 system calls return 0 on success.
228 If an error occurs, -1 is returned and the global variable
230 is set to indicate the error.
234 system call fails if:
245 The per-process descriptor table is full.
247 The system file table is full.
249 The kernel failed to allocate enough memory for the timer.
256 system calls fail if:
263 The addresses provided by
272 is valid, but was not generated by
276 The following errors only apply to
277 .Fn timerfd_settime :
284 A nanosecond field in the
286 argument specified a value less than zero, or greater than or equal to 10^9.
288 The timer was created with the clock ID
290 was configured with the
291 .Dv TFD_TIMER_CANCEL_ON_SET
292 flag, and the system realtime clock experienced a discontinuous change without
301 The timer's expiration counter is zero and the
303 object is is set for non-blocking I/O.
305 The timer was created with the clock ID
307 was configured with the
308 .Dv TFD_TIMER_CANCEL_ON_SET
309 flag, and the system realtime clock experienced a discontinuous change.
311 The size of the read buffer is not large enough to hold the
313 sized timer expiration counter.
321 .Xr timer_gettime 2 ,
326 system calls originated from Linux and are non-standard.
331 facility was originally ported to
333 Linux compatibility layer by
334 .An Dmitry Chagin Aq Mt dchagin@FreeBSD.org
337 It was revised and adapted to be native by
338 .An Jake Freeland Aq Mt jfree@FreeBSD.org