2019-09-10 11:19:01 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1+
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2018 Red Hat, Inc.
|
2018-10-17 14:09:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __NM_TIME_UTILS_H__
|
|
|
|
|
#define __NM_TIME_UTILS_H__
|
|
|
|
|
|
2019-07-23 11:40:01 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
static inline gint64
|
|
|
|
|
nm_utils_timespec_to_ns (const struct timespec *ts)
|
|
|
|
|
{
|
|
|
|
|
return (((gint64) ts->tv_sec) * ((gint64) NM_UTILS_NS_PER_SECOND))
|
|
|
|
|
+ ((gint64) ts->tv_nsec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gint64
|
|
|
|
|
nm_utils_timespec_to_ms (const struct timespec *ts)
|
|
|
|
|
{
|
|
|
|
|
return (((gint64) ts->tv_sec) * ((gint64) 1000))
|
|
|
|
|
+ (((gint64) ts->tv_nsec) / ((gint64) NM_UTILS_NS_PER_SECOND / 1000));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 14:09:13 +02:00
|
|
|
gint64 nm_utils_get_monotonic_timestamp_ns (void);
|
|
|
|
|
gint64 nm_utils_get_monotonic_timestamp_us (void);
|
|
|
|
|
gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
|
|
|
|
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
|
|
|
|
gint64 nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ticks_per_ns);
|
2019-11-20 11:29:13 +01:00
|
|
|
gint64 nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_ns_per_tick);
|
2018-10-17 14:09:13 +02:00
|
|
|
|
|
|
|
|
static inline gint64
|
|
|
|
|
nm_utils_get_monotonic_timestamp_ns_cached (gint64 *cache_now)
|
|
|
|
|
{
|
|
|
|
|
return (*cache_now)
|
|
|
|
|
?: (*cache_now = nm_utils_get_monotonic_timestamp_ns ());
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-23 11:40:01 +02:00
|
|
|
gint64 nm_utils_clock_gettime_ns (clockid_t clockid);
|
|
|
|
|
gint64 nm_utils_clock_gettime_ms (clockid_t clockid);
|
|
|
|
|
|
2018-10-17 14:09:13 +02:00
|
|
|
#endif /* __NM_TIME_UTILS_H__ */
|