Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

getnanotime(9) [netbsd man page]

MICROTIME(9)						   BSD Kernel Developer's Manual					      MICROTIME(9)

bintime, getbintime, microtime, getmicrotime, nanotime, getnanotime -- get the current time SYNOPSIS
#include <sys/time.h> void bintime(struct bintime *bt); void getbintime(struct bintime *bt); void microtime(struct timeval *tv); void getmicrotime(struct timeval *tv); void nanotime(struct timespec *ts); void getnanotime(struct timespec *tsp); DESCRIPTION
The bintime() and getbintime() functions store the system time as a struct bintime at the addresses specified by bt. The microtime() and getmicrotime() functions perform the same utility, but record the time as a struct timeval instead. Similarly the nanotime() and getnanotime() functions store the time as a struct timespec. The structures are described in timeval(3). The bintime(), microtime(), and nanotime() functions always query the timecounter to return the current time as precisely as possible. Whereas getbintime(), getmicrotime(), and getnanotime() functions are abstractions which return a less precise, but faster to obtain, time. The intent of the getbintime(), getmicrotime(), and getnanotime() functions is to enforce the user's preference for timer accuracy versus execution time. They should be used where a precision of 1/HZ (e.g., 10 msec on a 100HZ machine, see hz(9)) is acceptable or where perfor- mance is priority. The system realtime clock is guaranteed to be monotonically increasing at all times. As such, all calls to these functions are guaranteed to return a system time greater than or equal to the system time returned in any previous calls. Comparable functions exist to retrieve the time elapsed since boot; see microuptime(9). SEE ALSO
settimeofday(2), bintime_add(9), inittodr(9), time_second(9), tvtohz(9) CODE REFERENCES
The implementation of the microtime() family of functions is in sys/kern/kern_tc.c as a part of the timecounter(9) framework. The implementation of the time counter sources used by the timecounter(9) is machine dependent, hence its location in the source code tree varies from architecture to architecture. AUTHORS
This manual page was written by Jeremy Cooper and Kelly Yancey <>. BUGS
Despite the guarantee that the system realtime clock will always be monotonically increasing, it is always possible for the system clock to be manually reset by the system administrator to any date. BSD
June 8, 2010 BSD

Check Out this Related Man Page

TIMEVAL(3)						   BSD Library Functions Manual 						TIMEVAL(3)

timeval, timespec, itimerval, itimerspec, bintime -- time structures SYNOPSIS
#include <sys/time.h> void TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts); void TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts); DESCRIPTION
The <sys/time.h> header, included by <time.h>, defines various structures related to time and timers. 1. The following structure is used by gettimeofday(2), among others: struct timeval { time_t tv_sec; suseconds_t tv_usec; }; The tv_sec member represents the elapsed time, in whole seconds. The tv_usec member captures rest of the elapsed time, represented as the number of microseconds. 2. The following structure is used by nanosleep(2), among others: struct timespec { time_t tv_sec; long tv_nsec; }; The tv_sec member is again the elapsed time in whole seconds. The tv_nsec member represents the rest of the elapsed time in nanosec- onds. A microsecond is equal to one millionth of a second, 1000 nanoseconds, or 1/1000 milliseconds. To ease the conversions, the macros TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() can be used to convert between struct timeval and struct timespec. 3. The following structure is used by setitimer(2), among others: struct itimerval { struct timeval it_interval; struct timeval it_value; }; 4. The following structure is used by timer_settime(2), among others: struct itimerspec { struct timespec it_interval; struct timespec it_value; }; Both struct itimerval and struct itimerspec are used to specify when a timer expires. Generally, it_interval specifies the period between successive timer expirations. A value zero implies that the alarm will fire only once. If it_value is non-zero, it indicates the time left to the next timer expiration. A value zero implies that the timer is disabled. 5. The following structure is used by bintime(9), among others: struct bintime { time_t sec; uint64_t frac; }; The sec member specifies the time in seconds and frac represents a 64-bit fraction of seconds. The struct bintime is meant to be used in the kernel only. It is further described in timecounter(9). EXAMPLES
It can be stressed that the traditional UNIX timeval and timespec structures represent elapsed time, measured by the system clock (see hz(9)). The following sketch implements a function suitable for use in a context where the timespec structure is required for a conditional timeout: static void example(struct timespec *spec, time_t minutes) { struct timeval elapsed; (void)gettimeofday(&elapsed, NULL); _DIAGASSERT(spec != NULL); TIMEVAL_TO_TIMESPEC(&elapsed, spec); /* Add the offset for timeout in minutes. */ spec->tv_sec = spec->tv_sec + minutes * 60; } A better alternative would use the more precise clock_gettime(2). SEE ALSO
timeradd(3), tm(3), bintime_add(9) BSD
April 12, 2011 BSD
Man Page