clock_gettime_ns(), clock_gettime_mon_ns(), clock_gettime_rt_ns()
QNX SDP8.0C Library ReferenceAPIDeveloper
Get the time of a clock, in nanoseconds
Synopsis:
#include <time.h>
int clock_gettime_ns( clockid_t clock_id,
uint64_t * now_ns );
uint64_t clock_gettime_mon_ns( void );
uint64_t clock_gettime_rt_ns( void );
Arguments:
- clock_id
- The ID of the clock to use to measure the time. The possible clock types
are:
- CLOCK_REALTIME — the standard POSIX-defined clock. Timers based on this clock wake up the processor if it's in a power-saving mode.
- CLOCK_SOFTTIME — (a QNX OS extension) this clock is active only when the processor isn't in a power-saving mode. For example, an application using a CLOCK_SOFTTIME timer to sleep wouldn't wake up the processor when the application was due to wake up. This will allow the processor to enter a power-saving mode. While the processor isn't in a power-saving mode, CLOCK_SOFTTIME behaves the same as CLOCK_REALTIME.
- CLOCK_MONOTONIC — this clock always increases at a constant rate and can't be adjusted.
- CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID, or a clock ID returned
by clock_getcpuclockid(), pthread_getcpuclockid(), or ClockId(),
representing the amount of time the process or thread has spent
actually running. CLOCK_PROCESS_CPUTIME_ID and
CLOCK_THREAD_CPUTIME_ID are special clock IDs
that refer to the CPU time of the calling process and thread,
respectively. See
Monitoring execution times
in theUnderstanding the Microkernel's Concept of Time
chapter of the QNX OS Programmer's Guide.
- now_ns
- A pointer to the location where the function can store the current time, in nanoseconds.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The clock_gettime_ns() function gets the current time of the clock specified by clock_id, and stores it object pointed to by now_ns. Calling this function is similar to calling ClockTime(), except this function has less overhead if you specify CLOCK_REALTIME, CLOCK_SOFTTIME, or CLOCK_MONOTONIC as the clock_id. Also, unlike clock_gettime(), clock_gettime_ns() returns the time in nanoseconds rather than in a timespec structure.
The clock_gettime_mon_ns() and
clock_gettime_rt_ns() functions return the current time (in
nanoseconds) for CLOCK_MONOTONIC and CLOCK_REALTIME
(or CLOCK_SOFTIME since they return the same value), respectively.
These functions are versions of clock_gettime_ns() but return the
clock time directly without needing to pass arguments to them. The following lines
of code demonstrate how to use clock_gettime_mon_ns() and
clock_gettime_rt_ns():
uint64_t const now_mon_ns = clock_gettime_mon_ns();
uint64_t const now_rt_ns = clock_gettime_rt_ns();
Note:
In order to get the time for a CPU-time clock associated with another process,
your process must have the PROCMGR_AID_XPROCESS_QUERY ability
enabled. For more information, see procmgr_ability().
Returns:
- clock_gettime_ns() returns 0 on success. If an error occurs, the function returns -1 and sets errno.
- clock_gettime_mon_ns() and clock_gettime_rt_ns() return the current time, in nanoseconds.
Errors:
- EFAULT
- A fault occurred when the kernel tried to access the buffers provided.
- EINVAL
- The clock ID isn't valid.
- EPERM
- The calling process doesn't have the required permission; see procmgr_ability().
- ESRCH
- The process associated with this request doesn't exist.
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |
Page updated: