Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/ktime.h
Context not available. | |||||
#define ktime_get_ts(x) getnanouptime(x) | #define ktime_get_ts(x) getnanouptime(x) | ||||
/* time values in nanoseconds */ | /* time values in nanoseconds */ | ||||
union ktime { | typedef s64 ktime_t; | ||||
int64_t tv64; | |||||
}; | |||||
typedef union ktime ktime_t; | |||||
#define KTIME_MAX ((s64)~((u64)1 << 63)) | #define KTIME_MAX ((s64)~((u64)1 << 63)) | ||||
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) | #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) | ||||
Context not available. | |||||
static inline int64_t | static inline int64_t | ||||
ktime_to_ns(ktime_t kt) | ktime_to_ns(ktime_t kt) | ||||
{ | { | ||||
return kt.tv64; | return (kt); | ||||
} | } | ||||
static inline ktime_t | static inline s64 | ||||
ns_to_ktime(uint64_t nsec) | ns_to_ktime(uint64_t nsec) | ||||
{ | { | ||||
ktime_t kt; | return (nsec); | ||||
kt.tv64 = nsec; | |||||
return (kt); | |||||
} | } | ||||
static inline int64_t | static inline int64_t | ||||
ktime_divns(const ktime_t kt, int64_t div) | ktime_divns(const ktime_t kt, int64_t div) | ||||
{ | { | ||||
return kt.tv64 / div; | return (kt / div); | ||||
} | } | ||||
static inline int64_t | static inline int64_t | ||||
ktime_to_us(ktime_t kt) | ktime_to_us(ktime_t kt) | ||||
{ | { | ||||
return ktime_divns(kt, NSEC_PER_USEC); | return (ktime_divns(kt, NSEC_PER_USEC)); | ||||
} | } | ||||
static inline int64_t | static inline int64_t | ||||
ktime_to_ms(ktime_t kt) | ktime_to_ms(ktime_t kt) | ||||
{ | { | ||||
return ktime_divns(kt, NSEC_PER_MSEC); | return (ktime_divns(kt, NSEC_PER_MSEC)); | ||||
} | } | ||||
static inline struct timeval | static inline struct timeval | ||||
ktime_to_timeval(ktime_t kt) | ktime_to_timeval(ktime_t kt) | ||||
{ | { | ||||
return ns_to_timeval(kt.tv64); | return (ns_to_timeval(kt)); | ||||
} | } | ||||
static inline ktime_t | static inline ktime_t | ||||
Context not available. | |||||
{ | { | ||||
ktime_t res; | ktime_t res; | ||||
res.tv64 = kt.tv64 + ns; | res = kt + ns; | ||||
return kt; | return (kt); | ||||
} | } | ||||
static inline ktime_t | static inline ktime_t | ||||
Context not available. | |||||
{ | { | ||||
ktime_t res; | ktime_t res; | ||||
res.tv64 = kt.tv64 - ns; | res = kt - ns; | ||||
return kt; | return (kt); | ||||
} | } | ||||
static inline ktime_t | static inline ktime_t | ||||
Context not available. | |||||
static inline ktime_t | static inline ktime_t | ||||
ktime_sub(ktime_t lhs, ktime_t rhs) | ktime_sub(ktime_t lhs, ktime_t rhs) | ||||
{ | { | ||||
lhs.tv64 -= rhs.tv64; | lhs -= rhs; | ||||
return (lhs); | return (lhs); | ||||
} | } | ||||
Context not available. | |||||
ktime_us_delta(ktime_t later, ktime_t earlier) | ktime_us_delta(ktime_t later, ktime_t earlier) | ||||
{ | { | ||||
ktime_t diff = ktime_sub(later, earlier); | ktime_t diff = ktime_sub(later, earlier); | ||||
return ktime_to_us(diff); | return (ktime_to_us(diff)); | ||||
} | } | ||||
static inline int64_t | static inline int64_t | ||||
ktime_ms_delta(ktime_t later, ktime_t earlier) | ktime_ms_delta(ktime_t later, ktime_t earlier) | ||||
{ | { | ||||
ktime_t diff = ktime_sub(later, earlier); | ktime_t diff = ktime_sub(later, earlier); | ||||
return ktime_to_ms(diff); | return (ktime_to_ms(diff)); | ||||
} | } | ||||
static inline ktime_t | static inline ktime_t | ||||
ktime_add(ktime_t lhs, ktime_t rhs) | ktime_add(ktime_t lhs, ktime_t rhs) | ||||
{ | { | ||||
lhs.tv64 += rhs.tv64; | lhs += rhs; | ||||
return (lhs); | return (lhs); | ||||
} | } | ||||
Context not available. | |||||
return (ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC)); | return (ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC)); | ||||
} | } | ||||
#define ktime_to_timespec(kt) ns_to_timespec((kt).tv64) | #define ktime_to_timespec(kt) ns_to_timespec((kt)) | ||||
#define ktime_to_timeval(kt) ns_to_timeval((kt).tv64) | #define ktime_to_timeval(kt) ns_to_timeval((kt)) | ||||
#define ktime_to_ns(kt) ((kt).tv64) | #define ktime_to_ns(kt) (kt) | ||||
static inline int64_t | static inline int64_t | ||||
ktime_get_ns(void) | ktime_get_ns(void) | ||||
Context not available. | |||||
return (ktime_to_ns(kt)); | return (ktime_to_ns(kt)); | ||||
} | } | ||||
#define ktime_get_raw_ns() ktime_get_ns() | |||||
static inline ktime_t | static inline ktime_t | ||||
ktime_get(void) | ktime_get(void) | ||||
{ | { | ||||
Context not available. | |||||
return (timespec_to_ktime(ts)); | return (timespec_to_ktime(ts)); | ||||
} | } | ||||
static inline ktime_t | |||||
ktime_get_real_seconds(void) | |||||
{ | |||||
struct timespec ts; | |||||
ktime_t kt; | |||||
nanotime(&ts); | |||||
kt = ts.tv_sec; | |||||
return (kt); | |||||
} | |||||
static inline u64 | |||||
ktime_get_raw_ns(void) | |||||
{ | |||||
struct timespec ts; | |||||
nanouptime(&ts); | |||||
return ((ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec); | |||||
} | |||||
#endif /* _LINUX_KTIME_H */ | #endif /* _LINUX_KTIME_H */ | ||||
Context not available. |