Update the ktime type in the LinuxKPI to be a signed 64-bit integer similarly
to Linux, to avoid compilation issues. Implement ktime_get_real_seconds(). MFC after: 1 week Submitted by: Johannes Lundberg <johalun0@gmail.com> Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks
This commit is contained in:
parent
a08c55ddb4
commit
d0ba7ed6c7
@ -1,5 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2015 Mellanox Technologies, Ltd.
|
||||
* Copyright (c) 2018 Limelight Networks, Inc.
|
||||
* Copyright (c) 2014-2018 Mellanox Technologies, Ltd.
|
||||
* Copyright (c) 2015 François Tigeot
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -34,104 +35,96 @@
|
||||
#include <linux/time.h>
|
||||
#include <linux/jiffies.h>
|
||||
|
||||
#define ktime_get_ts(x) getnanouptime(x)
|
||||
#define ktime_get_ts(x) getnanouptime(x)
|
||||
|
||||
/* time values in nanoseconds */
|
||||
union ktime {
|
||||
int64_t tv64;
|
||||
};
|
||||
typedef s64 ktime_t;
|
||||
|
||||
typedef union ktime ktime_t;
|
||||
|
||||
#define KTIME_MAX ((s64)~((u64)1 << 63))
|
||||
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
|
||||
#define KTIME_MAX ((s64)~((u64)1 << 63))
|
||||
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
|
||||
|
||||
static inline int64_t
|
||||
ktime_to_ns(ktime_t kt)
|
||||
{
|
||||
return kt.tv64;
|
||||
return (kt);
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ns_to_ktime(uint64_t nsec)
|
||||
{
|
||||
ktime_t kt;
|
||||
|
||||
kt.tv64 = nsec;
|
||||
return (kt);
|
||||
return (nsec);
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
ktime_divns(const ktime_t kt, int64_t div)
|
||||
{
|
||||
return kt.tv64 / div;
|
||||
return (kt / div);
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
ktime_to_us(ktime_t kt)
|
||||
{
|
||||
return ktime_divns(kt, NSEC_PER_USEC);
|
||||
return (ktime_divns(kt, NSEC_PER_USEC));
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
ktime_to_ms(ktime_t kt)
|
||||
{
|
||||
return ktime_divns(kt, NSEC_PER_MSEC);
|
||||
return (ktime_divns(kt, NSEC_PER_MSEC));
|
||||
}
|
||||
|
||||
static inline struct timeval
|
||||
ktime_to_timeval(ktime_t kt)
|
||||
{
|
||||
return ns_to_timeval(kt.tv64);
|
||||
return (ns_to_timeval(kt));
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_add_ns(ktime_t kt, int64_t ns)
|
||||
{
|
||||
kt.tv64 += ns;
|
||||
return kt;
|
||||
return (kt + ns);
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_sub_ns(ktime_t kt, int64_t ns)
|
||||
{
|
||||
kt.tv64 -= ns;
|
||||
return kt;
|
||||
return (kt - ns);
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_set(const long secs, const unsigned long nsecs)
|
||||
{
|
||||
ktime_t retval = { (s64)secs * NSEC_PER_SEC + (s64)nsecs };
|
||||
ktime_t retval = {(s64) secs * NSEC_PER_SEC + (s64) nsecs};
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_sub(ktime_t lhs, ktime_t rhs)
|
||||
{
|
||||
lhs.tv64 -= rhs.tv64;
|
||||
return (lhs);
|
||||
return (lhs - rhs);
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
ktime_us_delta(ktime_t later, ktime_t earlier)
|
||||
{
|
||||
ktime_t diff = ktime_sub(later, earlier);
|
||||
return ktime_to_us(diff);
|
||||
ktime_t diff = ktime_sub(later, earlier);
|
||||
|
||||
return (ktime_to_us(diff));
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
ktime_ms_delta(ktime_t later, ktime_t earlier)
|
||||
{
|
||||
ktime_t diff = ktime_sub(later, earlier);
|
||||
return ktime_to_ms(diff);
|
||||
ktime_t diff = ktime_sub(later, earlier);
|
||||
|
||||
return (ktime_to_ms(diff));
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_add(ktime_t lhs, ktime_t rhs)
|
||||
{
|
||||
lhs.tv64 += rhs.tv64;
|
||||
return (lhs);
|
||||
return (lhs + rhs);
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
@ -146,22 +139,19 @@ timeval_to_ktime(struct timeval tv)
|
||||
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_timeval(kt) ns_to_timeval((kt).tv64)
|
||||
#define ktime_to_ns(kt) ((kt).tv64)
|
||||
#define ktime_to_timespec(kt) ns_to_timespec(kt)
|
||||
#define ktime_to_timeval(kt) ns_to_timeval(kt)
|
||||
#define ktime_to_ns(kt) (kt)
|
||||
|
||||
static inline int64_t
|
||||
ktime_get_ns(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
ktime_t kt;
|
||||
|
||||
ktime_get_ts(&ts);
|
||||
kt = timespec_to_ktime(ts);
|
||||
return (ktime_to_ns(kt));
|
||||
}
|
||||
|
||||
#define ktime_get_raw_ns() ktime_get_ns()
|
||||
return (ktime_to_ns(timespec_to_ktime(ts)));
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_get(void)
|
||||
@ -190,4 +180,22 @@ ktime_get_real(void)
|
||||
return (timespec_to_ktime(ts));
|
||||
}
|
||||
|
||||
static inline ktime_t
|
||||
ktime_get_real_seconds(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
nanotime(&ts);
|
||||
return (ts.tv_sec);
|
||||
}
|
||||
|
||||
static inline u64
|
||||
ktime_get_raw_ns(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
nanouptime(&ts);
|
||||
return (ktime_to_ns(timespec_to_ktime(ts)));
|
||||
}
|
||||
|
||||
#endif /* _LINUX_KTIME_H */
|
||||
|
@ -98,7 +98,7 @@ linux_hrtimer_start_range_ns(struct hrtimer *hrtimer, ktime_t time, int64_t nsec
|
||||
{
|
||||
|
||||
mtx_lock(&hrtimer->mtx);
|
||||
callout_reset_sbt(&hrtimer->callout, nstosbt(time.tv64), nstosbt(nsec),
|
||||
callout_reset_sbt(&hrtimer->callout, nstosbt(time), nstosbt(nsec),
|
||||
hrtimer_call_handler, hrtimer, 0);
|
||||
mtx_unlock(&hrtimer->mtx);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user