Motr  M0
Generic time manipulation

Macros

#define TIME_F   "[%" PRIu64 ":%09" PRIu64 "]"
 
#define TIME_P(t)   m0_time_seconds(t), m0_time_nanoseconds(t)
 
#define M0_MKTIME(secs, ns)   ((m0_time_t)((uint64_t)(secs) * M0_TIME_ONE_SECOND + (uint64_t)(ns)))
 

Typedefs

typedef uint64_t m0_time_t
 

Enumerations

enum  { M0_TIME_ONE_SECOND = 1000000000ULL, M0_TIME_ONE_MSEC = M0_TIME_ONE_SECOND / 1000 }
 

Functions

M0_INTERNAL m0_time_t m0_clock_gettime_wrapper (enum CLOCK_SOURCES clock_id)
 
M0_INTERNAL m0_time_t m0_clock_gettimeofday_wrapper (void)
 
int m0_nanosleep (const m0_time_t req, m0_time_t *rem)
 
m0_time_t m0_time (uint64_t secs, long ns)
 
m0_time_t m0_time_add (const m0_time_t t1, const m0_time_t t2)
 
m0_time_t m0_time_sub (const m0_time_t t1, const m0_time_t t2)
 
uint64_t m0_time_seconds (const m0_time_t time)
 
uint64_t m0_time_nanoseconds (const m0_time_t time)
 
m0_time_t m0_time_from_now (uint64_t secs, long ns)
 
bool m0_time_is_in_past (m0_time_t t)
 
M0_INTERNAL int m0_time_init (void)
 
M0_INTERNAL void m0_time_fini (void)
 
m0_time_t m0_time_now (void)
 
M0_INTERNAL m0_time_t m0_time_to_realtime (m0_time_t abs_time)
 

Variables

const m0_time_t M0_TIME_IMMEDIATELY = 0
 
const m0_time_t M0_TIME_NEVER = ~0ULL
 
enum CLOCK_SOURCES M0_CLOCK_SOURCE = M0_CLOCK_SOURCE_REALTIME_MONOTONIC
 
m0_time_t m0_time_monotonic_offset
 
const m0_time_t M0_TIME_IMMEDIATELY
 
const m0_time_t M0_TIME_NEVER
 
enum CLOCK_SOURCES M0_CLOCK_SOURCE
 
m0_time_t m0_time_monotonic_offset
 

Detailed Description

M0 time delivers resolution in nanoseconds. It is an unsigned 64-bit integer.

Implementation of m0_time_t on top of kernel struct timespec

Implementation of time functions on top of all m0_time_t defs

Time functions can use different clock sources.

See also
M0_CLOCK_SOURCE

Macro Definition Documentation

◆ M0_MKTIME

#define M0_MKTIME (   secs,
  ns 
)    ((m0_time_t)((uint64_t)(secs) * M0_TIME_ONE_SECOND + (uint64_t)(ns)))

Similar to m0_time(). To be used in initialisers.

Definition at line 86 of file time.h.

◆ TIME_F

#define TIME_F   "[%" PRIu64 ":%09" PRIu64 "]"

Definition at line 44 of file time.h.

◆ TIME_P

#define TIME_P (   t)    m0_time_seconds(t), m0_time_nanoseconds(t)

Definition at line 45 of file time.h.

Typedef Documentation

◆ m0_time_t

typedef uint64_t m0_time_t

Definition at line 37 of file time.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
M0_TIME_ONE_SECOND 
M0_TIME_ONE_MSEC 

Definition at line 39 of file time.h.

Function Documentation

◆ m0_clock_gettime_wrapper()

M0_INTERNAL m0_time_t m0_clock_gettime_wrapper ( enum CLOCK_SOURCES  clock_id)

Definition at line 40 of file ktime.c.

Here is the caller graph for this function:

◆ m0_clock_gettimeofday_wrapper()

M0_INTERNAL m0_time_t m0_clock_gettimeofday_wrapper ( void  )

Definition at line 62 of file ktime.c.

Here is the caller graph for this function:

◆ m0_nanosleep()

int m0_nanosleep ( const m0_time_t  req,
m0_time_t rem 
)

Sleep for requested time

Sleep for requested time. If interrupted, remaining time returned.

Parameters
reqrequested time to sleep
rem[OUT] remaining time, NULL causes remaining time to be ignored.
Returns
0 means success. -1 means error. Remaining time is stored in rem.

Definition at line 73 of file ktime.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_time()

m0_time_t m0_time ( uint64_t  secs,
long  ns 
)

Create and return a m0_time_t from seconds and nanoseconds.

Definition at line 41 of file time.c.

Here is the caller graph for this function:

◆ m0_time_add()

m0_time_t m0_time_add ( const m0_time_t  t1,
const m0_time_t  t2 
)

Add t2 to t1 and return that result.

Returns
The result time. If either t1 or t2 is M0_TIME_NEVER, the result is M0_TIME_NEVER.

Definition at line 47 of file time.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_time_fini()

M0_INTERNAL void m0_time_fini ( void  )

Definition at line 130 of file time.c.

◆ m0_time_from_now()

m0_time_t m0_time_from_now ( uint64_t  secs,
long  ns 
)

Create a m0_time_t initialised with seconds + nanosecond in the future.

Parameters
secsseconds from now
nsnanoseconds from now
Returns
The result time.

Definition at line 96 of file time.c.

Here is the call graph for this function:

◆ m0_time_init()

M0_INTERNAL int m0_time_init ( void  )

Definition at line 115 of file time.c.

Here is the call graph for this function:

◆ m0_time_is_in_past()

bool m0_time_is_in_past ( m0_time_t  t)

Definition at line 102 of file time.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_time_nanoseconds()

uint64_t m0_time_nanoseconds ( const m0_time_t  time)

Get "nanosecond" part from the time.

Definition at line 89 of file time.c.

Here is the caller graph for this function:

◆ m0_time_now()

m0_time_t m0_time_now ( void  )

Get the current time. This may or may not relate to wall time.

Definition at line 134 of file time.c.

Here is the call graph for this function:

◆ m0_time_seconds()

uint64_t m0_time_seconds ( const m0_time_t  time)

Get "second" part from the time.

Definition at line 83 of file time.c.

Here is the caller graph for this function:

◆ m0_time_sub()

m0_time_t m0_time_sub ( const m0_time_t  t1,
const m0_time_t  t2 
)

Subtract t2 from t1 and return that result.

Returns
The result time. If t1 == M0_TIME_NEVER, M0_TIME_NEVER is returned.
Precondition
t2 < M0_TIME_NEVER && t1 >= t2

Definition at line 65 of file time.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_time_to_realtime()

M0_INTERNAL m0_time_t m0_time_to_realtime ( m0_time_t  abs_time)

Useful for mutex/semaphore implementation. This function will translate time from value obtained from m0_time_now() to value that can be used with CLOCK_REALTIME-only functions such as sem_timedwait() and pthread_mutex_timedlock().

Parameters
timeTime obtained from m0_time_now() and adjusted somehow if needed.
Returns
Converted time value.
Note
In some cases this function will have 2 calls to clock_gettime().

Definition at line 160 of file time.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ M0_CLOCK_SOURCE [1/2]

enum CLOCK_SOURCES M0_CLOCK_SOURCE

Clock source for m0_time_now()

Definition at line 112 of file time.c.

◆ M0_CLOCK_SOURCE [2/2]

Clock source for m0_time_now()

Definition at line 112 of file time.c.

◆ M0_TIME_IMMEDIATELY [1/2]

const m0_time_t M0_TIME_IMMEDIATELY

Special value of abs_timeout indicates that action should be performed immediately

Definition at line 107 of file time.c.

◆ M0_TIME_IMMEDIATELY [2/2]

const m0_time_t M0_TIME_IMMEDIATELY = 0

Special value of abs_timeout indicates that action should be performed immediately

Definition at line 107 of file time.c.

◆ m0_time_monotonic_offset [1/2]

m0_time_t m0_time_monotonic_offset

Offset for M0_CLOCK_SOURCE_REALTIME_MONOTONIC clock source.

See also
m0_utime_init()

Definition at line 113 of file time.c.

◆ m0_time_monotonic_offset [2/2]

m0_time_t m0_time_monotonic_offset

Offset for M0_CLOCK_SOURCE_REALTIME_MONOTONIC clock source.

See also
m0_utime_init()

Definition at line 113 of file time.c.

◆ M0_TIME_NEVER [1/2]

const m0_time_t M0_TIME_NEVER

The largest time that is never reached in system life.

Definition at line 108 of file time.c.

◆ M0_TIME_NEVER [2/2]

const m0_time_t M0_TIME_NEVER = ~0ULL

The largest time that is never reached in system life.

Definition at line 108 of file time.c.