xref: /freebsd-14.2/lib/libc/sys/timer_settime.2 (revision fa9896e0)
15507a2aeSRuslan Ermilov.\" Copyright (c) 2005 David Xu <[email protected]>
2b1e515a3SDavid Xu.\" All rights reserved.
3bb5eebe6SDavid Xu.\"
4bb5eebe6SDavid Xu.\" Redistribution and use in source and binary forms, with or without
5bb5eebe6SDavid Xu.\" modification, are permitted provided that the following conditions
6bb5eebe6SDavid Xu.\" are met:
7bb5eebe6SDavid Xu.\" 1. Redistributions of source code must retain the above copyright
8bb5eebe6SDavid Xu.\"    notice(s), this list of conditions and the following disclaimer as
9bb5eebe6SDavid Xu.\"    the first lines of this file unmodified other than the possible
10bb5eebe6SDavid Xu.\"    addition of one or more copyright notices.
11bb5eebe6SDavid Xu.\" 2. Redistributions in binary form must reproduce the above copyright
12bb5eebe6SDavid Xu.\"    notice(s), this list of conditions and the following disclaimer in
13bb5eebe6SDavid Xu.\"    the documentation and/or other materials provided with the
14bb5eebe6SDavid Xu.\"    distribution.
15bb5eebe6SDavid Xu.\"
16bb5eebe6SDavid Xu.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17bb5eebe6SDavid Xu.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bb5eebe6SDavid Xu.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19bb5eebe6SDavid Xu.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20bb5eebe6SDavid Xu.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21bb5eebe6SDavid Xu.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22bb5eebe6SDavid Xu.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23bb5eebe6SDavid Xu.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24bb5eebe6SDavid Xu.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25bb5eebe6SDavid Xu.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26bb5eebe6SDavid Xu.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bb5eebe6SDavid Xu.\"
285507a2aeSRuslan Ermilov.Dd September 11, 2000
29bb5eebe6SDavid Xu.Dt TIMER_SETTIME 2
30bb5eebe6SDavid Xu.Os
31bb5eebe6SDavid Xu.Sh NAME
325507a2aeSRuslan Ermilov.Nm timer_getoverrun ,
335507a2aeSRuslan Ermilov.Nm timer_gettime ,
34bb5eebe6SDavid Xu.Nm timer_settime
355507a2aeSRuslan Ermilov.Nd "per-process timers (REALTIME)"
36bb5eebe6SDavid Xu.Sh LIBRARY
37e9311906SDavid Xu.Lb librt
38bb5eebe6SDavid Xu.Sh SYNOPSIS
39bb5eebe6SDavid Xu.In time.h
40bb5eebe6SDavid Xu.Ft int
41bb5eebe6SDavid Xu.Fn timer_getoverrun "timer_t timerid"
42bb5eebe6SDavid Xu.Ft int
43bb5eebe6SDavid Xu.Fn timer_gettime "timer_t timerid" "struct itimerspec *value"
44bb5eebe6SDavid Xu.Ft int
455507a2aeSRuslan Ermilov.Fo timer_settime
465507a2aeSRuslan Ermilov.Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value"
475507a2aeSRuslan Ermilov.Fa "struct itimerspec *restrict ovalue"
485507a2aeSRuslan Ermilov.Fc
49bb5eebe6SDavid Xu.Sh DESCRIPTION
50bb5eebe6SDavid XuThe
51bb5eebe6SDavid Xu.Fn timer_gettime
525507a2aeSRuslan Ermilovsystem call stores the amount of time until the specified timer,
53bb5eebe6SDavid Xu.Fa timerid ,
54bb5eebe6SDavid Xuexpires and the reload value of the timer into the space pointed to by the
55bb5eebe6SDavid Xu.Fa value
565507a2aeSRuslan Ermilovargument.
575507a2aeSRuslan ErmilovThe
585507a2aeSRuslan Ermilov.Va it_value
595507a2aeSRuslan Ermilovmember of this structure contains the amount of time
605507a2aeSRuslan Ermilovbefore the timer expires, or zero if the timer is disarmed.
615507a2aeSRuslan ErmilovThis value is
62bb5eebe6SDavid Xureturned as the interval until timer expiration, even if the timer was armed
635507a2aeSRuslan Ermilovwith absolute time.
645507a2aeSRuslan ErmilovThe
655507a2aeSRuslan Ermilov.Va it_interval
665507a2aeSRuslan Ermilovmember of
675507a2aeSRuslan Ermilov.Fa value
685507a2aeSRuslan Ermilovcontains the reload
69bb5eebe6SDavid Xuvalue last set by
70bb5eebe6SDavid Xu.Fn timer_settime .
71bb5eebe6SDavid Xu.Pp
72bb5eebe6SDavid XuThe
73bb5eebe6SDavid Xu.Fn timer_settime
745507a2aeSRuslan Ermilovsystem call sets the time until the next expiration of the timer specified
75bb5eebe6SDavid Xuby
76bb5eebe6SDavid Xu.Fa timerid
775507a2aeSRuslan Ermilovfrom the
785507a2aeSRuslan Ermilov.Va it_value
795507a2aeSRuslan Ermilovmember of the
805507a2aeSRuslan Ermilov.Fa value
815507a2aeSRuslan Ermilovargument and arms the timer if the
825507a2aeSRuslan Ermilov.Va it_value
835507a2aeSRuslan Ermilovmember of
845507a2aeSRuslan Ermilov.Fa value
855507a2aeSRuslan Ermilovis non-zero.
865507a2aeSRuslan ErmilovIf the specified timer was already
87bb5eebe6SDavid Xuarmed when
88bb5eebe6SDavid Xu.Fn timer_settime
89bb5eebe6SDavid Xuis called, this call resets the time until next expiration to the value
905507a2aeSRuslan Ermilovspecified.
915507a2aeSRuslan ErmilovIf the
925507a2aeSRuslan Ermilov.Va it_value
935507a2aeSRuslan Ermilovmember of
945507a2aeSRuslan Ermilov.Fa value
955507a2aeSRuslan Ermilovis zero, the timer is disarmed.
96bb5eebe6SDavid XuIf the timer is disarmed, then pending signal is removed.
97bb5eebe6SDavid Xu.Pp
985507a2aeSRuslan ErmilovIf the flag
995507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME
1005507a2aeSRuslan Ermilovis not set in the argument
101bb5eebe6SDavid Xu.Fa flags ,
102bb5eebe6SDavid Xu.Fn timer_settime
103bb5eebe6SDavid Xubehaves as if the time until next expiration is set to
1045507a2aeSRuslan Ermilovbe equal to the interval specified by the
1055507a2aeSRuslan Ermilov.Va it_value
1065507a2aeSRuslan Ermilovmember of
1075507a2aeSRuslan Ermilov.Fa value .
1085507a2aeSRuslan ErmilovThat is,
1095507a2aeSRuslan Ermilovthe timer expires in
1105507a2aeSRuslan Ermilov.Va it_value
1115507a2aeSRuslan Ermilovnanoseconds from when the call is made.
1125507a2aeSRuslan ErmilovIf the flag
1135507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME
1145507a2aeSRuslan Ermilovis set in the argument
1155507a2aeSRuslan Ermilov.Fa flags ,
116bb5eebe6SDavid Xu.Fn timer_settime
117bb5eebe6SDavid Xubehaves as if the time until next expiration is set to be equal to the
118bb5eebe6SDavid Xudifference between the absolute time specified by the it_value member of
119bb5eebe6SDavid Xuvalue and the current value of the clock associated with
120bb5eebe6SDavid Xu.Fa timerid .
121bb5eebe6SDavid XuThat is, the timer expires when the clock reaches the value specified by the
1225507a2aeSRuslan Ermilov.Va it_value
1235507a2aeSRuslan Ermilovmember of
1245507a2aeSRuslan Ermilov.Fa value .
1255507a2aeSRuslan ErmilovIf the specified time has already passed, the
1265507a2aeSRuslan Ermilovsystem call succeeds and the expiration notification is made.
127bb5eebe6SDavid Xu.Pp
1285507a2aeSRuslan ErmilovThe reload value of the timer is set to the value specified by the
1295507a2aeSRuslan Ermilov.Va it_interval
1305507a2aeSRuslan Ermilovmember of
1315507a2aeSRuslan Ermilov.Fa value .
1325507a2aeSRuslan ErmilovWhen a timer is armed with a non-zero
1335507a2aeSRuslan Ermilov.Va it_interval ,
1345507a2aeSRuslan Ermilova periodic
135bb5eebe6SDavid Xu(or repetitive) timer is specified.
136bb5eebe6SDavid Xu.Pp
137bb5eebe6SDavid XuTime values that are between two consecutive non-negative integer multiples of
1385507a2aeSRuslan Ermilovthe resolution of the specified timer are rounded up to the larger multiple of
1395507a2aeSRuslan Ermilovthe resolution.
1405507a2aeSRuslan ErmilovQuantization error will not cause the timer to expire earlier
141bb5eebe6SDavid Xuthan the rounded time value.
142bb5eebe6SDavid Xu.Pp
1435507a2aeSRuslan ErmilovIf the argument
1445507a2aeSRuslan Ermilov.Fa ovalue
1455507a2aeSRuslan Ermilovis not
1465507a2aeSRuslan Ermilov.Dv NULL ,
1475507a2aeSRuslan Ermilovthe
148bb5eebe6SDavid Xu.Fn timer_settime
1495507a2aeSRuslan Ermilovsystem call stores, in the location referenced by
1505507a2aeSRuslan Ermilov.Fa ovalue ,
1515507a2aeSRuslan Ermilova value representing
152bb5eebe6SDavid Xuthe previous amount of time before the timer would have expired, or zero if the
1535507a2aeSRuslan Ermilovtimer was disarmed, together with the previous timer reload value.
1545507a2aeSRuslan ErmilovTimers do not
155bb5eebe6SDavid Xuexpire before their scheduled time.
156bb5eebe6SDavid Xu.Pp
157bb5eebe6SDavid XuOnly a single signal is queued to the process for a given timer at any point in
1585507a2aeSRuslan Ermilovtime.
1595507a2aeSRuslan ErmilovWhen a timer for which a signal is still pending expires, no signal is
1605507a2aeSRuslan Ermilovqueued, and a timer overrun will occur.
1615507a2aeSRuslan ErmilovWhen a timer expiration signal is
162bb5eebe6SDavid Xuaccepted by a process, the
163bb5eebe6SDavid Xu.Fn timer_getoverrun
1645507a2aeSRuslan Ermilovsystem call returns the timer expiration overrun count for the specified timer.
165bb5eebe6SDavid XuThe overrun count returned contains the number of extra timer expirations that
166bb5eebe6SDavid Xuoccurred between the time the signal was generated (queued) and when it was
1675507a2aeSRuslan Ermilovaccepted, up to but not including an maximum of
1685507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX .
1695507a2aeSRuslan ErmilovIf the number of
1705507a2aeSRuslan Ermilovsuch extra expirations is greater than or equal to
1715507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX ,
1725507a2aeSRuslan Ermilovthen the overrun count is set to
1735507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX .
1745507a2aeSRuslan ErmilovThe value returned by
175bb5eebe6SDavid Xu.Fn timer_getoverrun
1765507a2aeSRuslan Ermilovapplies to the most recent expiration signal acceptance for the timer.
1775507a2aeSRuslan ErmilovIf no
178bb5eebe6SDavid Xuexpiration signal has been delivered for the timer, the return value of
179bb5eebe6SDavid Xu.Fn timer_getoverrun
180bb5eebe6SDavid Xuis unspecified.
181bb5eebe6SDavid Xu.Sh RETURN VALUES
182bb5eebe6SDavid XuIf the
183bb5eebe6SDavid Xu.Fn timer_getoverrun
1845507a2aeSRuslan Ermilovsystem call succeeds, it returns the timer expiration overrun count as explained
185bb5eebe6SDavid Xuabove.
1865507a2aeSRuslan ErmilovOtherwise the value \-1 is returned, and the global variable
1875507a2aeSRuslan Ermilov.Va errno
1885507a2aeSRuslan Ermilovis set to indicate the error.
189bb5eebe6SDavid Xu.Pp
1905507a2aeSRuslan Ermilov.Rv -std timer_gettime timer_settime
191bb5eebe6SDavid Xu.Sh ERRORS
192bb5eebe6SDavid XuThe
193bb5eebe6SDavid Xu.Fn timer_settime
1945507a2aeSRuslan Ermilovsystem call
195bb5eebe6SDavid Xuwill fail if:
196bb5eebe6SDavid Xu.Bl -tag -width Er
197bb5eebe6SDavid Xu.It Bq Er EINVAL
1985507a2aeSRuslan ErmilovA
1995507a2aeSRuslan Ermilov.Fa value
2005507a2aeSRuslan Ermilovstructure specified a nanosecond value less than zero or greater than
2015507a2aeSRuslan Ermilovor equal to 1000 million, and the
2025507a2aeSRuslan Ermilov.Va it_value
2035507a2aeSRuslan Ermilovmember of that structure did not
204bb5eebe6SDavid Xuspecify zero seconds and nanoseconds.
205bb5eebe6SDavid Xu.El
206bb5eebe6SDavid Xu.Pp
2075507a2aeSRuslan ErmilovThese system calls may fail if:
208bb5eebe6SDavid Xu.Bl -tag -width Er
209bb5eebe6SDavid Xu.It Bq Er EINVAL
210bb5eebe6SDavid XuThe
211bb5eebe6SDavid Xu.Fa timerid
212bb5eebe6SDavid Xuargument does not correspond to an ID returned by
213bb5eebe6SDavid Xu.Fn timer_create
214bb5eebe6SDavid Xubut not yet deleted by
215bb5eebe6SDavid Xu.Fn timer_delete .
216bb5eebe6SDavid Xu.El
217bb5eebe6SDavid Xu.Pp
2185507a2aeSRuslan ErmilovThe
2195507a2aeSRuslan Ermilov.Fn timer_settime
2205507a2aeSRuslan Ermilovsystem call may fail if:
221bb5eebe6SDavid Xu.Bl -tag -width Er
222bb5eebe6SDavid Xu.It Bq Er EINVAL
2235507a2aeSRuslan ErmilovThe
2245507a2aeSRuslan Ermilov.Va it_interval
2255507a2aeSRuslan Ermilovmember of
2265507a2aeSRuslan Ermilov.Fa value
2275507a2aeSRuslan Ermilovis not zero and the timer was created with
2285507a2aeSRuslan Ermilovnotification by creation of a new thread
2295507a2aeSRuslan Ermilov.Va ( sigev_sigev_notify
2305507a2aeSRuslan Ermilovwas
2315507a2aeSRuslan Ermilov.Dv SIGEV_THREAD )
232bb5eebe6SDavid Xuand a fixed stack address has been set in the thread attribute pointed to by
2335507a2aeSRuslan Ermilov.Va sigev_notify_attributes .
234bb5eebe6SDavid Xu.El
235bb5eebe6SDavid Xu.Pp
236bb5eebe6SDavid XuThe
237bb5eebe6SDavid Xu.Fn timer_gettime
238bb5eebe6SDavid Xuand
239bb5eebe6SDavid Xu.Fn timer_settime
2405507a2aeSRuslan Ermilovsystem calls
241bb5eebe6SDavid Xumay fail if:
242bb5eebe6SDavid Xu.Bl -tag -width Er
243bb5eebe6SDavid Xu.It Bq Er EFAULT
244bb5eebe6SDavid XuAny arguments point outside the allocated address space or there is a
245bb5eebe6SDavid Xumemory protection fault.
246bb5eebe6SDavid Xu.El
247bb5eebe6SDavid Xu.Sh SEE ALSO
248bb5eebe6SDavid Xu.Xr clock_getres 2 ,
249412295fdSDavid Xu.Xr timer_create 2 ,
250412295fdSDavid Xu.Xr siginfo 3
251bb5eebe6SDavid Xu.Sh STANDARDS
252bb5eebe6SDavid XuThe
253bb5eebe6SDavid Xu.Fn timer_getoverrun ,
254bb5eebe6SDavid Xu.Fn timer_gettime ,
255bb5eebe6SDavid Xuand
256bb5eebe6SDavid Xu.Fn timer_settime
2575507a2aeSRuslan Ermilovsystem calls conform to
258*9f63b422SGlen Barber.St -p1003.1-2004 .
2596f59c4c0SDavid Xu.Sh HISTORY
260a73a3ab5SRuslan ErmilovSupport for
261a73a3ab5SRuslan Ermilov.Tn POSIX
262a73a3ab5SRuslan Ermilovper-process timer first appeared in
2636f59c4c0SDavid Xu.Fx 7.0 .
264