]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/timer_settime.2
zfs: merge openzfs/zfs@a03ebd9be
[FreeBSD/FreeBSD.git] / lib / libc / sys / timer_settime.2
1 .\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice(s), this list of conditions and the following disclaimer as
9 .\"    the first lines of this file unmodified other than the possible
10 .\"    addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice(s), this list of conditions and the following disclaimer in
13 .\"    the documentation and/or other materials provided with the
14 .\"    distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .Dd September 11, 2000
29 .Dt TIMER_SETTIME 2
30 .Os
31 .Sh NAME
32 .Nm timer_getoverrun ,
33 .Nm timer_gettime ,
34 .Nm timer_settime
35 .Nd "per-process timers (REALTIME)"
36 .Sh LIBRARY
37 .Lb librt
38 .Sh SYNOPSIS
39 .In time.h
40 .Ft int
41 .Fn timer_getoverrun "timer_t timerid"
42 .Ft int
43 .Fn timer_gettime "timer_t timerid" "struct itimerspec *value"
44 .Ft int
45 .Fo timer_settime
46 .Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value"
47 .Fa "struct itimerspec *restrict ovalue"
48 .Fc
49 .Sh DESCRIPTION
50 The
51 .Fn timer_gettime
52 system call stores the amount of time until the specified timer,
53 .Fa timerid ,
54 expires and the reload value of the timer into the space pointed to by the
55 .Fa value
56 argument.
57 The
58 .Va it_value
59 member of this structure contains the amount of time
60 before the timer expires, or zero if the timer is disarmed.
61 This value is
62 returned as the interval until timer expiration, even if the timer was armed
63 with absolute time.
64 The
65 .Va it_interval
66 member of
67 .Fa value
68 contains the reload
69 value last set by
70 .Fn timer_settime .
71 .Pp
72 The
73 .Fn timer_settime
74 system call sets the time until the next expiration of the timer specified
75 by
76 .Fa timerid
77 from the
78 .Va it_value
79 member of the
80 .Fa value
81 argument and arms the timer if the
82 .Va it_value
83 member of
84 .Fa value
85 is non-zero.
86 If the specified timer was already
87 armed when
88 .Fn timer_settime
89 is called, this call resets the time until next expiration to the value
90 specified.
91 If the
92 .Va it_value
93 member of
94 .Fa value
95 is zero, the timer is disarmed.
96 If the timer is disarmed, then pending signal is removed.
97 .Pp
98 If the flag
99 .Dv TIMER_ABSTIME
100 is not set in the argument
101 .Fa flags ,
102 .Fn timer_settime
103 behaves as if the time until next expiration is set to
104 be equal to the interval specified by the
105 .Va it_value
106 member of
107 .Fa value .
108 That is,
109 the timer expires in
110 .Va it_value
111 nanoseconds from when the call is made.
112 If the flag
113 .Dv TIMER_ABSTIME
114 is set in the argument
115 .Fa flags ,
116 .Fn timer_settime
117 behaves as if the time until next expiration is set to be equal to the
118 difference between the absolute time specified by the it_value member of
119 value and the current value of the clock associated with
120 .Fa timerid .
121 That is, the timer expires when the clock reaches the value specified by the
122 .Va it_value
123 member of
124 .Fa value .
125 If the specified time has already passed, the
126 system call succeeds and the expiration notification is made.
127 .Pp
128 The reload value of the timer is set to the value specified by the
129 .Va it_interval
130 member of
131 .Fa value .
132 When a timer is armed with a non-zero
133 .Va it_interval ,
134 a periodic
135 (or repetitive) timer is specified.
136 .Pp
137 Time values that are between two consecutive non-negative integer multiples of
138 the resolution of the specified timer are rounded up to the larger multiple of
139 the resolution.
140 Quantization error will not cause the timer to expire earlier
141 than the rounded time value.
142 .Pp
143 If the argument
144 .Fa ovalue
145 is not
146 .Dv NULL ,
147 the
148 .Fn timer_settime
149 system call stores, in the location referenced by
150 .Fa ovalue ,
151 a value representing
152 the previous amount of time before the timer would have expired, or zero if the
153 timer was disarmed, together with the previous timer reload value.
154 Timers do not
155 expire before their scheduled time.
156 .Pp
157 Only a single signal is queued to the process for a given timer at any point in
158 time.
159 When a timer for which a signal is still pending expires, no signal is
160 queued, and a timer overrun will occur.
161 When a timer expiration signal is
162 accepted by a process, the
163 .Fn timer_getoverrun
164 system call returns the timer expiration overrun count for the specified timer.
165 The overrun count returned contains the number of extra timer expirations that
166 occurred between the time the signal was generated (queued) and when it was
167 accepted, up to but not including an maximum of
168 .Brq Dv DELAYTIMER_MAX .
169 If the number of
170 such extra expirations is greater than or equal to
171 .Brq Dv DELAYTIMER_MAX ,
172 then the overrun count is set to
173 .Brq Dv DELAYTIMER_MAX .
174 The value returned by
175 .Fn timer_getoverrun
176 applies to the most recent expiration signal acceptance for the timer.
177 If no
178 expiration signal has been delivered for the timer, the return value of
179 .Fn timer_getoverrun
180 is unspecified.
181 .Sh RETURN VALUES
182 If the
183 .Fn timer_getoverrun
184 system call succeeds, it returns the timer expiration overrun count as explained
185 above.
186 Otherwise the value \-1 is returned, and the global variable
187 .Va errno
188 is set to indicate the error.
189 .Pp
190 .Rv -std timer_gettime timer_settime
191 .Sh ERRORS
192 The
193 .Fn timer_settime
194 system call
195 will fail if:
196 .Bl -tag -width Er
197 .It Bq Er EINVAL
198 A
199 .Fa value
200 structure specified a nanosecond value less than zero or greater than
201 or equal to 1000 million, and the
202 .Va it_value
203 member of that structure did not
204 specify zero seconds and nanoseconds.
205 .El
206 .Pp
207 These system calls may fail if:
208 .Bl -tag -width Er
209 .It Bq Er EINVAL
210 The
211 .Fa timerid
212 argument does not correspond to an ID returned by
213 .Fn timer_create
214 but not yet deleted by
215 .Fn timer_delete .
216 .El
217 .Pp
218 The
219 .Fn timer_settime
220 system call may fail if:
221 .Bl -tag -width Er
222 .It Bq Er EINVAL
223 The
224 .Va it_interval
225 member of
226 .Fa value
227 is not zero and the timer was created with
228 notification by creation of a new thread
229 .Va ( sigev_sigev_notify
230 was
231 .Dv SIGEV_THREAD )
232 and a fixed stack address has been set in the thread attribute pointed to by
233 .Va sigev_notify_attributes .
234 .El
235 .Pp
236 The
237 .Fn timer_gettime
238 and
239 .Fn timer_settime
240 system calls
241 may fail if:
242 .Bl -tag -width Er
243 .It Bq Er EFAULT
244 Any arguments point outside the allocated address space or there is a
245 memory protection fault.
246 .El
247 .Sh SEE ALSO
248 .Xr clock_getres 2 ,
249 .Xr timer_create 2 ,
250 .Xr siginfo 3
251 .Sh STANDARDS
252 The
253 .Fn timer_getoverrun ,
254 .Fn timer_gettime ,
255 and
256 .Fn timer_settime
257 system calls conform to
258 .St -p1003.1-2004 .
259 .Sh HISTORY
260 Support for
261 .Tn POSIX
262 per-process timer first appeared in
263 .Fx 7.0 .