TIMER_GETOVERRUN(3P)

โœจ TIMER_GETOVERRUN(3P) โœจ

okay bestie, welcome to the POSIX Programmer's Manual ๐Ÿ’– this is the timer_getoverrun page, and it's also bringing its two besties timer_gettime and timer_settime along for the ride. group chat of three, basically ๐Ÿซถ


๐ŸŒธ PROLOG ๐ŸŒธ

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.

tl;dr โ€” POSIX says one thing, your actual Linux box might say another, and sometimes the interface just isn't there at all. vibe check your platform first, fr fr.

๐Ÿ’… NAME ๐Ÿ’…

timer_getoverrun, timer_gettime, timer_settime โ€” per-process timers ๐Ÿ‘‘


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <time.h>

int timer_getoverrun(timer_t timerid);
int timer_gettime(timer_t timerid, struct itimerspec *value);
int timer_settime(timer_t timerid, int flags,
    const struct itimerspec *restrict value,
    struct itimerspec *restrict ovalue);

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so first up: timer_gettime() shall store the amount of time until the specified timer, timerid, expires, plus the reload value of the timer, into the space pointed to by the value argument. the it_value member of this structure shall contain the amount of time before the timer expires โ€” or zero if the timer is disarmed. and listen, this value comes back as the interval until timer expiration even if the timer was armed with absolute time. no cap. the it_interval member of value shall contain the reload value last set by timer_settime(). ๐Ÿ’ซ

now timer_settime() โ€” she's the main character ๐Ÿ‘‘ she shall set the time until the next expiration of the timer specified by timerid from the it_value member of the value argument, and arm the timer if the it_value member of value is non-zero. if the specified timer was already armed when timer_settime() is called, this call shall reset the time until next expiration to the value specified. and if the it_value member of value is zero, the timer shall be disarmed.

โš ๏ธ heads up bestie โ€” the effect of disarming or resetting a timer with pending expiration notifications is <b>unspecified</b>. we do not know. nobody knows. do not count on it.

if the flag TIMER_ABSTIME is not set in the argument flags, timer_settime() shall behave as if the time until next expiration is set to be equal to the interval specified by the it_value member of value. that is, the timer shall expire in it_value nanoseconds from when the call is made. โฑ๏ธ

if the flag TIMER_ABSTIME is set in the argument flags, timer_settime() shall behave as if the time until next expiration is set to be equal to the difference between the absolute time specified by the it_value member of value and the current value of the clock associated with timerid. that is, the timer shall expire when the clock reaches the value specified by the it_value member of value. and if the specified time has already passed? the function shall succeed and the expiration notification shall be made. yes, it just goes ahead and fires. iconic honestly โœจ

the reload value of the timer shall be set to the value specified by the it_interval member of value. when a timer is armed with a non-zero it_interval, a periodic (or repetitive) timer is specified. ๐Ÿ”

time values that are between two consecutive non-negative integer multiples of the resolution of the specified timer shall be rounded up to the larger multiple of the resolution. quantization error shall not cause the timer to expire earlier than the rounded time value. so like, it rounds up, never down. respect. ๐Ÿ’œ

if the argument ovalue is not NULL, the timer_settime() function shall store, in the location referenced by ovalue, a value representing the previous amount of time before the timer would have expired โ€” or zero if the timer was disarmed โ€” together with the previous timer reload value. timers shall not expire before their scheduled time. ๐Ÿ•ฐ๏ธ

now for the overrun girlies: only a single signal shall be queued to the process for a given timer at any point in time. when a timer for which a signal is still pending expires, no signal shall be queued, and a timer overrun shall occur. when a timer expiration signal is delivered to or accepted by a process, the timer_getoverrun() function shall return the timer expiration overrun count for the specified timer. ๐Ÿ“ฌ

the overrun count returned contains the number of extra timer expirations that occurred between the time the signal was generated (queued) and when it was delivered or accepted โ€” up to but not including an implementation-defined maximum of {DELAYTIMER_MAX}. if the number of such extra expirations is greater than or equal to {DELAYTIMER_MAX}, then the overrun count shall be set to {DELAYTIMER_MAX}. the value returned by timer_getoverrun() shall apply to the most recent expiration signal delivery or acceptance for the timer. and if no expiration signal has been delivered for the timer? the return value of timer_getoverrun() is unspecified. ๐Ÿ™ˆ

๐Ÿšจ undefined behaviour alert ๐Ÿšจ the behavior is undefined if the value specified by the timerid argument to timer_getoverrun(), timer_gettime(), or timer_settime() does not correspond to a timer ID returned by timer_create() but not yet deleted by timer_delete(). so don't be passing around stale timer IDs like they're nothing, bestie. ๐Ÿ’€

๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

  • if the timer_getoverrun() function succeeds, it shall return the timer expiration overrun count as explained above. โœ…
  • if the timer_gettime() or timer_settime() functions succeed, a value of 0 shall be returned. ๐ŸŽ‰
  • if an error occurs for any of these functions, the value -1 shall be returned, and errno set to indicate the error. ๐Ÿ˜ญ

๐Ÿ’œ ERRORS ๐Ÿ’œ

the timer_settime() function shall fail if:

  • EINVAL โ€” a value structure specified a nanosecond value less than zero or greater than or equal to 1000 million, and the it_value member of that structure did not specify zero seconds and nanoseconds.

the timer_settime() function may fail if:

  • EINVAL โ€” the it_interval member of value is not zero and the timer was created with notification by creation of a new thread (sigev_sigev_notify was SIGEV_THREAD) and a fixed stack address has been set in the thread attribute pointed to by sigev_notify_attributes.
the following sections are informative. (translation: they're the โœจloreโœจ, not the law)

๐Ÿ“ EXAMPLES ๐Ÿ“

None.

(yeah. nothing. empty. the void. moving on ๐Ÿ’€)


๐Ÿงš APPLICATION USAGE ๐Ÿงš

using fixed stack addresses is problematic when timer expiration is signaled by the creation of a new thread. since it cannot be assumed that the thread created for one expiration is finished before the next expiration of the timer, it could happen that two threads use the same memory as a stack at the same time. this is invalid and produces undefined results. ๐Ÿ™…โ™€๏ธ

two threads. one stack. absolutely not. do not do this.

โญ RATIONALE โญ

practical clocks tick at a finite rate, with rates of 100 hertz and 1000 hertz being common. the inverse of this tick rate is the clock resolution, also called the clock granularity, which in either case is expressed as a time duration โ€” being 10 milliseconds and 1 millisecond respectively for these common rates. ๐Ÿงฎ

the granularity of practical clocks implies that if one reads a given clock twice in rapid succession, one may get the same time value twice; and that timers must wait for the next clock tick after the theoretical expiration time, to ensure that a timer never returns too soon. note also that the granularity of the clock may be significantly coarser than the resolution of the data format used to set and get time and interval values. also note that some implementations may choose to adjust time and/or interval values to exactly match the ticks of the underlying clock. โฐ

this volume of POSIX.1โ€2017 defines functions that allow an application to determine the implementation-supported resolution for the clocks and requires an implementation to document the resolution supported for timers and nanosleep() if they differ from the supported clock resolution. this is more of a procurement issue than a runtime application issue. ๐Ÿ›’

if an implementation detects that the value specified by the timerid argument to timer_getoverrun(), timer_gettime(), or timer_settime() does not correspond to a timer ID returned by timer_create() but not yet deleted by timer_delete(), it is recommended that the function should fail and report an [EINVAL] error. (recommended, not required โ€” iykyk ๐Ÿ‘€)


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None.


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

  • clock_getres()
  • timer_create()

The Base Definitions volume of POSIX.1โ€2017, <time.h>


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page bestie, no details skipped, every flag accounted for, we ate and left no crumbs ๐Ÿ’…โœจ this edition came courtesy of IEEE/The Open Group, 2017 โ€” go forth and time your timers responsibly, mwah ๐Ÿซถ๐Ÿ’–

๐Ÿ“ฆ where this page comes from