API Reference Manual  1.45.0
ODP TIME

API Description

SoC global and CPU local wall clock time.

Data Structures

struct  odp_time_t
 
struct  odp_time_startup_t
 Time stamp values at ODP startup. More...
 

Macros

#define ODP_TIME_NULL   ((odp_time_t){.u64 = 0})
 Zero time stamp.
 
#define ODP_TIME_USEC_IN_NS   1000ULL
 A microsecond in nanoseconds.
 
#define ODP_TIME_MSEC_IN_NS   1000000ULL
 A millisecond in nanoseconds.
 
#define ODP_TIME_SEC_IN_NS   1000000000ULL
 A second in nanoseconds.
 
#define ODP_TIME_MIN_IN_NS   60000000000ULL
 A minute in nanoseconds.
 
#define ODP_TIME_HOUR_IN_NS   3600000000000ULL
 An hour in nanoseconds.
 

Typedefs

typedef struct odp_time_t odp_time_t
 ODP time stamp. More...
 
typedef struct odp_time_startup_t odp_time_startup_t
 Time stamp values at ODP startup.
 

Functions

odp_time_t odp_time_local (void)
 Current local time. More...
 
uint64_t odp_time_local_ns (void)
 Current local time in nanoseconds. More...
 
odp_time_t odp_time_local_strict (void)
 Current local time (strict) More...
 
uint64_t odp_time_local_strict_ns (void)
 Current local time in nanoseconds (strict) More...
 
odp_time_t odp_time_global (void)
 Current global time. More...
 
uint64_t odp_time_global_ns (void)
 Current global time in nanoseconds. More...
 
odp_time_t odp_time_global_strict (void)
 Current global time (strict) More...
 
uint64_t odp_time_global_strict_ns (void)
 Current global time in nanoseconds (strict) More...
 
odp_time_t odp_time_diff (odp_time_t t2, odp_time_t t1)
 Time difference. More...
 
uint64_t odp_time_diff_ns (odp_time_t t2, odp_time_t t1)
 Time difference in nanoseconds. More...
 
odp_time_t odp_time_add_ns (odp_time_t time, uint64_t ns)
 Add nanoseconds into time. More...
 
odp_time_t odp_time_sum (odp_time_t t1, odp_time_t t2)
 Time sum. More...
 
uint64_t odp_time_to_ns (odp_time_t time)
 Convert time to nanoseconds. More...
 
odp_time_t odp_time_local_from_ns (uint64_t ns)
 Convert nanoseconds to local time. More...
 
odp_time_t odp_time_global_from_ns (uint64_t ns)
 Convert nanoseconds to global time. More...
 
int odp_time_cmp (odp_time_t t2, odp_time_t t1)
 Compare two times. More...
 
uint64_t odp_time_local_res (void)
 Local time resolution in hertz. More...
 
uint64_t odp_time_global_res (void)
 Global time resolution in hertz. More...
 
void odp_time_wait_until (odp_time_t time)
 Wait until the specified (wall clock) time has been reached. More...
 
void odp_time_wait_ns (uint64_t ns)
 Wait the specified number of nanoseconds. More...
 
void odp_time_startup (odp_time_startup_t *startup)
 Get ODP instance startup time. More...
 

Typedef Documentation

◆ odp_time_t

ODP time stamp.

Time structure used for both POSIX timespec and HW counter implementations.

Time stamp can represent a time stamp from local or global time source. A local time stamp must not be shared between threads. API calls work correctly only when all time stamps for input are from the same time source.

Function Documentation

◆ odp_time_local()

odp_time_t odp_time_local ( void  )

Current local time.

Returns current CPU local time stamp value. The used time source is specific to the calling thread and the CPU it is running on during the call. Time stamp values from different time sources cannot be compared or otherwise mixed.

Local time stamp value advances with a constant rate defined by odp_time_local_res(). The rate remains constant even during dynamic CPU frequency scaling. Local time stamp and related nanosecond values may not start from zero, but are guaranteed not to wrap around in at least 10 years from the ODP instance startup.

Returns
CPU local time stamp value
Examples
odp_atomic_perf.c, odp_bench_misc.c, odp_bench_packet.c, odp_classifier.c, odp_cpu_bench.c, odp_crc.c, odp_l2fwd.c, odp_lock_perf.c, odp_mem_perf.c, odp_packet_dump.c, odp_packet_gen.c, odp_ping.c, odp_pktio_perf.c, odp_pool_perf.c, odp_queue_perf.c, odp_random.c, odp_sched_perf.c, odp_sched_pktio.c, odp_stash_perf.c, odp_stress.c, odp_switch.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_time_local_ns()

uint64_t odp_time_local_ns ( void  )

Current local time in nanoseconds.

Like odp_time_local(), but the time stamp value is converted into nanoseconds.

Returns
Local time stamp in nanoseconds
Examples
odp_bench_misc.c.

◆ odp_time_local_strict()

odp_time_t odp_time_local_strict ( void  )

Current local time (strict)

Like odp_time_local(), but reads the time stamp value more strictly in the program order. The function may decrease CPU performance around the call, as it may include additional barrier instructions or otherwise limit out-of-order execution.

Returns
Local time stamp
Examples
odp_bench_misc.c, odp_bench_pktio_sp.c, odp_dma_perf.c, odp_icache_perf.c, odp_pool_latency.c, odp_pool_perf.c, and odp_random.c.

◆ odp_time_local_strict_ns()

uint64_t odp_time_local_strict_ns ( void  )

Current local time in nanoseconds (strict)

Like odp_time_local_strict(), but the time stamp value is converted into nanoseconds.

Returns
Local time stamp in nanoseconds
Examples
odp_bench_misc.c.

◆ odp_time_global()

odp_time_t odp_time_global ( void  )

Current global time.

Returns current SoC global time stamp value. Global time stamp values read by different threads (or CPUs) may be compared or otherwise mixed as those come from the same time source.

Global time stamp value advances with a constant rate defined by odp_time_global_res(). The rate remains constant even during dynamic CPU frequency scaling. Global time stamp and related nanosecond values may not start from zero, but are guaranteed not to wrap around in at least 10 years from the ODP instance startup.

Returns
SoC global time stamp value
Examples
odp_bench_misc.c, odp_ipfragreass.c, odp_timer_accuracy.c, odp_timer_perf.c, and odp_timer_simple.c.

◆ odp_time_global_ns()

uint64_t odp_time_global_ns ( void  )

Current global time in nanoseconds.

Like odp_time_global(), but the time stamp value is converted into nanoseconds.

Returns
Global time stamp in nanoseconds
Examples
odp_bench_misc.c, odp_bench_timer.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_time_global_strict()

odp_time_t odp_time_global_strict ( void  )

Current global time (strict)

Like odp_time_global(), but reads the time stamp value more strictly (see odp_time_local_strict() documentation) in the program order.

Returns
Global time stamp
Examples
odp_bench_misc.c, odp_dma_perf.c, odp_packet_gen.c, odp_sched_latency.c, and odp_timer_accuracy.c.

◆ odp_time_global_strict_ns()

uint64_t odp_time_global_strict_ns ( void  )

Current global time in nanoseconds (strict)

Like odp_time_global_strict(), but the time stamp value is converted into nanoseconds.

Returns
Global time stamp in nanoseconds
Examples
odp_bench_misc.c, and odp_bench_timer.c.

◆ odp_time_diff()

odp_time_t odp_time_diff ( odp_time_t  t2,
odp_time_t  t1 
)

Time difference.

Parameters
t2Second time stamp
t1First time stamp
Returns
Difference of time stamps
Examples
odp_bench_misc.c, odp_l2fwd.c, odp_pktio_perf.c, and odp_switch.c.

◆ odp_time_diff_ns()

uint64_t odp_time_diff_ns ( odp_time_t  t2,
odp_time_t  t1 
)

◆ odp_time_add_ns()

odp_time_t odp_time_add_ns ( odp_time_t  time,
uint64_t  ns 
)

Add nanoseconds into time.

Adds 'ns' nanoseconds into the time stamp value. The resulting time may wrap around, if the sum of 'time' and 'ns' is more than 10 years from the ODP instance startup.

Parameters
timeTime stamp
nsNanoseconds to be added
Returns
Time stamp incremented by 'ns' nanoseconds
Examples
odp_bench_misc.c.

◆ odp_time_sum()

odp_time_t odp_time_sum ( odp_time_t  t1,
odp_time_t  t2 
)

Time sum.

Returns the sum of time stamp values. Time stamps must be from the same time source (global or local). The resulting time may wrap around, if the sum exceeds 10 years from the ODP instance startup.

Parameters
t1Time stamp
t2Time stamp
Returns
Sum of time stamps
Examples
odp_bench_misc.c, odp_pktio_perf.c, and odp_stress.c.

◆ odp_time_to_ns()

uint64_t odp_time_to_ns ( odp_time_t  time)

◆ odp_time_local_from_ns()

odp_time_t odp_time_local_from_ns ( uint64_t  ns)

Convert nanoseconds to local time.

Parameters
nsTime in nanoseconds
Returns
Local time stamp
Examples
odp_bench_misc.c, odp_packet_gen.c, odp_pktio_perf.c, odp_stress.c, and odp_switch.c.

◆ odp_time_global_from_ns()

odp_time_t odp_time_global_from_ns ( uint64_t  ns)

Convert nanoseconds to global time.

Parameters
nsTime in nanoseconds
Returns
Global time stamp
Examples
odp_bench_misc.c.

◆ odp_time_cmp()

int odp_time_cmp ( odp_time_t  t2,
odp_time_t  t1 
)

Compare two times.

Parameters
t2Second time
t1First time
Return values
<0when t2 < t1
0when t2 == t1
>0when t2 > t1
Examples
odp_bench_misc.c, odp_packet_dump.c, odp_pktio_perf.c, odp_stress.c, and odp_switch.c.

◆ odp_time_local_res()

uint64_t odp_time_local_res ( void  )

Local time resolution in hertz.

Returns
Local time resolution in hertz
Examples
odp_bench_misc.c, and odp_packet_gen.c.

◆ odp_time_global_res()

uint64_t odp_time_global_res ( void  )

Global time resolution in hertz.

Returns
Global time resolution in hertz
Examples
odp_bench_misc.c.

◆ odp_time_wait_until()

void odp_time_wait_until ( odp_time_t  time)

Wait until the specified (wall clock) time has been reached.

The thread potentially busy loop the entire wait time.

Parameters
timeTime to reach before continue
Examples
odp_packet_gen.c.

◆ odp_time_wait_ns()

void odp_time_wait_ns ( uint64_t  ns)

Wait the specified number of nanoseconds.

The thread potentially busy loop the entire wait time.

Parameters
nsTime in nanoseconds to wait
Examples
odp_bench_timer.c, odp_cli.c, odp_debug.c, odp_hello.c, odp_packet_gen.c, odp_pktio.c, odp_pktio_perf.c, odp_pool_latency.c, odp_random.c, odp_sched_perf.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_time_startup()

void odp_time_startup ( odp_time_startup_t startup)

Get ODP instance startup time.

Outputs time stamp values captured at ODP instance startup. Application may use those to calculate time stamp values relative to ODP startup time.

Parameters
[out]startupStartup time structure for output
Examples
odp_bench_misc.c.