Time¶
functions¶
clock types¶
- MM_CLK_REALTIME
- system-wide clock measuring real time. This clock is affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), and by the incremental adjustments performed by NTP.
- MM_CLK_MONOTONIC
- represents monotonic time since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but it may by affected by the incremental adjustments performed by NTP. In other word, this clock may be sped up/slowed down by the kernel as necessary to match real time through NTP to ensure that 1s with MM_CLK_MONOTONIC is really 1s.
- MM_CLK_CPU_PROCESS
- Per-process CPU-time clock (measures CPU time consumed by all threads in the process).
- MM_CLK_CPU_THREAD
- Thread-specific CPU-time clock.
- MM_CLK_MONOTONIC_RAW
- Similar to MM_CLK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to NTP adjustments. On modern CPU, this clock is often based on the cycle counter of the CPU (when a reliable one is available) which makes it a good basis for code profile.
struct mm_timespec¶
-
struct
mm_timespec
¶ interval broken down into seconds and nanoseconds.
Definition¶
struct mm_timespec {
time_t tv_sec;
long tv_nsec;
}
Members¶
- tv_sec
- whole seconds (valid values are >= 0)
- tv_nsec
- nanoseconds (valid values are [0, 999999999])
Description¶
This structure is meant to be binary compatible with the struct timespec defined on the platform while avoid the issue of missing declaration of struct timespec (if compiled with old C standard < C11 without posix feature) or multiple definition of it (in certain circumstances, on Win32 with mingw using pthread.h).
mm_timediff_ns¶
#include <mmtime.h>
-
int64_t
mm_timediff_ns
(const struct mm_timespec* ts, const struct mm_timespec* orig)¶ compute time difference in nanoseconds
Parameters: - ts (const struct mm_timespec*) – time point
- orig (const struct mm_timespec*) – time reference
Return¶
the interval ts
- orig
in nanoseconds
mm_timediff_us¶
#include <mmtime.h>
-
int64_t
mm_timediff_us
(const struct mm_timespec* ts, const struct mm_timespec* orig)¶ compute time difference in microseconds
Parameters: - ts (const struct mm_timespec*) – time point
- orig (const struct mm_timespec*) – time reference
Return¶
the interval ts
- orig
in microseconds
mm_timediff_ms¶
#include <mmtime.h>
-
int64_t
mm_timediff_ms
(const struct mm_timespec* ts, const struct mm_timespec* orig)¶ compute time difference in milliseconds
Parameters: - ts (const struct mm_timespec*) – time point
- orig (const struct mm_timespec*) – time reference
Return¶
the interval ts
- orig
in milliseconds
mm_timeadd_ns¶
#include <mmtime.h>
-
void
mm_timeadd_ns
(struct mm_timespec* ts, int64_t dt)¶ apply nanosecond offset to timestamp
Parameters: - ts (struct mm_timespec*) – time point
- dt (int64_t) – offset in nanoseconds to apply to
ts
mm_timeadd_us¶
#include <mmtime.h>
-
void
mm_timeadd_us
(struct mm_timespec* ts, int64_t dt)¶ apply microsecond offset to timestamp
Parameters: - ts (struct mm_timespec*) – time point
- dt (int64_t) – offset in microseconds to apply to
ts
mm_timeadd_ms¶
#include <mmtime.h>
-
void
mm_timeadd_ms
(struct mm_timespec* ts, int64_t dt)¶ apply millisecond offset to timestamp
Parameters: - ts (struct mm_timespec*) – time point
- dt (int64_t) – offset in milliseconds to apply to
ts
mm_relative_sleep_ns¶
#include <mmtime.h>
-
int
mm_relative_sleep_ns
(int64_t duration_ns)¶ relative sleep in nanoseconds
Parameters: - duration_ns (int64_t) – duration of sleep in nanoseconds
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.
mm_relative_sleep_us¶
#include <mmtime.h>
-
int
mm_relative_sleep_us
(int64_t duration_us)¶ relative sleep in microseconds
Parameters: - duration_us (int64_t) – duration of sleep in microseconds
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.
mm_relative_sleep_ms¶
#include <mmtime.h>
-
int
mm_relative_sleep_ms
(int64_t duration_ms)¶ relative sleep in milliseconds
Parameters: - duration_ms (int64_t) – duration of sleep in milliseconds
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.
mm_gettime¶
#include <mmtime.h>
-
int
mm_gettime
(clockid_t clock_id, struct mm_timespec * ts)¶ Get clock value
Parameters: - clock_id (clockid_t) – ID clock type (one of the MM_CLK_* value)
- ts (struct mm_timespec *) – location that must receive the clock value
Description¶
This function get the current value ts
for the specified clock clock_id
.
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.
mm_getres¶
#include <mmtime.h>
-
int
mm_getres
(clockid_t clock_id, struct mm_timespec * res)¶ Get clock resolution
Parameters: - clock_id (clockid_t) – ID clock type (one of the MM_CLK_* value)
- res (struct mm_timespec *) – location that must receive the clock resolution
Description¶
This function get the resolution of the specified clock clock_id
. The
resolution of the specified clock shall be stored in the location pointed
to by res
.
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.
NOTE¶
The resolution of a clock is the minimal time difference that a clock can observe. If two measure points are taken closer than the resolution step, the difference between the 2 reported values will be either 0 or the resolution step. The resolution must not be confused with the accuracy which refers to how much the system deviates from the truth. The accuracy of a system can never exceed its resolution! However it is possible to a accuracy much worse than its resolution.
mm_nanosleep¶
#include <mmtime.h>
-
int
mm_nanosleep
(clockid_t clock_id, const struct mm_timespec * ts)¶ Absolute time sleep with specifiable clock
Parameters: - clock_id (clockid_t) – ID clock type (one of the MM_CLK_* value)
- ts (const struct mm_timespec *) – absolute time when execution must resume
Description¶
This function cause the current thread to be suspended from execution
until either the time value of the clock specified by clock_id
reaches
the absolute time specified by the ts
argument. If, at the time of the
call, the time value specified by ts
is less than or equal to the time
value of the specified clock, then mm_nanosleep()
shall return
immediately and the calling process shall not be suspended.
Return¶
0 in case of success, -1 otherwise with error state set to indicate the error.