summaryrefslogtreecommitdiff
path: root/include/linux/ktime.h
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2016-12-25 13:38:40 +0300
committerThomas Gleixner <tglx@linutronix.de>2016-12-25 19:21:22 +0300
commit2456e855354415bfaeb7badaa14e11b3e02c8466 (patch)
tree6fc81500645174c246c3fdb568cba32aa01960c6 /include/linux/ktime.h
parenta5a1d1c2914b5316924c7893eb683a5420ebd3be (diff)
downloadlinux-2456e855354415bfaeb7badaa14e11b3e02c8466.tar.xz
ktime: Get rid of the union
ktime is a union because the initial implementation stored the time in scalar nanoseconds on 64 bit machine and in a endianess optimized timespec variant for 32bit machines. The Y2038 cleanup removed the timespec variant and switched everything to scalar nanoseconds. The union remained, but become completely pointless. Get rid of the union and just keep ktime_t as simple typedef of type s64. The conversion was done with coccinelle and some manual mopping up. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org>
Diffstat (limited to 'include/linux/ktime.h')
-rw-r--r--include/linux/ktime.h68
1 files changed, 23 insertions, 45 deletions
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index 0fb7ffb1775f..8e573deda55e 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -24,21 +24,8 @@
#include <linux/time.h>
#include <linux/jiffies.h>
-/*
- * ktime_t:
- *
- * A single 64-bit variable is used to store the hrtimers
- * internal representation of time values in scalar nanoseconds. The
- * design plays out best on 64-bit CPUs, where most conversions are
- * NOPs and most arithmetic ktime_t operations are plain arithmetic
- * operations.
- *
- */
-union ktime {
- s64 tv64;
-};
-
-typedef union ktime ktime_t; /* Kill this */
+/* Nanosecond scalar representation for kernel time values */
+typedef s64 ktime_t;
/**
* ktime_set - Set a ktime_t variable from a seconds/nanoseconds value
@@ -50,39 +37,34 @@ typedef union ktime ktime_t; /* Kill this */
static inline ktime_t ktime_set(const s64 secs, const unsigned long nsecs)
{
if (unlikely(secs >= KTIME_SEC_MAX))
- return (ktime_t){ .tv64 = KTIME_MAX };
+ return KTIME_MAX;
- return (ktime_t) { .tv64 = secs * NSEC_PER_SEC + (s64)nsecs };
+ return secs * NSEC_PER_SEC + (s64)nsecs;
}
/* Subtract two ktime_t variables. rem = lhs -rhs: */
-#define ktime_sub(lhs, rhs) \
- ({ (ktime_t){ .tv64 = (lhs).tv64 - (rhs).tv64 }; })
+#define ktime_sub(lhs, rhs) ((lhs) - (rhs))
/* Add two ktime_t variables. res = lhs + rhs: */
-#define ktime_add(lhs, rhs) \
- ({ (ktime_t){ .tv64 = (lhs).tv64 + (rhs).tv64 }; })
+#define ktime_add(lhs, rhs) ((lhs) + (rhs))
/*
* Same as ktime_add(), but avoids undefined behaviour on overflow; however,
* this means that you must check the result for overflow yourself.
*/
-#define ktime_add_unsafe(lhs, rhs) \
- ({ (ktime_t){ .tv64 = (u64) (lhs).tv64 + (rhs).tv64 }; })
+#define ktime_add_unsafe(lhs, rhs) ((u64) (lhs) + (rhs))
/*
* Add a ktime_t variable and a scalar nanosecond value.
* res = kt + nsval:
*/
-#define ktime_add_ns(kt, nsval) \
- ({ (ktime_t){ .tv64 = (kt).tv64 + (nsval) }; })
+#define ktime_add_ns(kt, nsval) ((kt) + (nsval))
/*
* Subtract a scalar nanosecod from a ktime_t variable
* res = kt - nsval:
*/
-#define ktime_sub_ns(kt, nsval) \
- ({ (ktime_t){ .tv64 = (kt).tv64 - (nsval) }; })
+#define ktime_sub_ns(kt, nsval) ((kt) - (nsval))
/* convert a timespec to ktime_t format: */
static inline ktime_t timespec_to_ktime(struct timespec ts)
@@ -103,16 +85,16 @@ static inline ktime_t timeval_to_ktime(struct timeval tv)
}
/* Map the ktime_t to timespec conversion to ns_to_timespec function */
-#define ktime_to_timespec(kt) ns_to_timespec((kt).tv64)
+#define ktime_to_timespec(kt) ns_to_timespec((kt))
/* Map the ktime_t to timespec conversion to ns_to_timespec function */
-#define ktime_to_timespec64(kt) ns_to_timespec64((kt).tv64)
+#define ktime_to_timespec64(kt) ns_to_timespec64((kt))
/* Map the ktime_t to timeval conversion to ns_to_timeval function */
-#define ktime_to_timeval(kt) ns_to_timeval((kt).tv64)
+#define ktime_to_timeval(kt) ns_to_timeval((kt))
/* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */
-#define ktime_to_ns(kt) ((kt).tv64)
+#define ktime_to_ns(kt) (kt)
/**
@@ -126,7 +108,7 @@ static inline ktime_t timeval_to_ktime(struct timeval tv)
*/
static inline int ktime_equal(const ktime_t cmp1, const ktime_t cmp2)
{
- return cmp1.tv64 == cmp2.tv64;
+ return cmp1 == cmp2;
}
/**
@@ -141,9 +123,9 @@ static inline int ktime_equal(const ktime_t cmp1, const ktime_t cmp2)
*/
static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2)
{
- if (cmp1.tv64 < cmp2.tv64)
+ if (cmp1 < cmp2)
return -1;
- if (cmp1.tv64 > cmp2.tv64)
+ if (cmp1 > cmp2)
return 1;
return 0;
}
@@ -182,7 +164,7 @@ static inline s64 ktime_divns(const ktime_t kt, s64 div)
*/
BUG_ON(div < 0);
if (__builtin_constant_p(div) && !(div >> 32)) {
- s64 ns = kt.tv64;
+ s64 ns = kt;
u64 tmp = ns < 0 ? -ns : ns;
do_div(tmp, div);
@@ -199,7 +181,7 @@ static inline s64 ktime_divns(const ktime_t kt, s64 div)
* so catch them on 64bit as well.
*/
WARN_ON(div < 0);
- return kt.tv64 / div;
+ return kt / div;
}
#endif
@@ -256,7 +238,7 @@ extern ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs);
static inline __must_check bool ktime_to_timespec_cond(const ktime_t kt,
struct timespec *ts)
{
- if (kt.tv64) {
+ if (kt) {
*ts = ktime_to_timespec(kt);
return true;
} else {
@@ -275,7 +257,7 @@ static inline __must_check bool ktime_to_timespec_cond(const ktime_t kt,
static inline __must_check bool ktime_to_timespec64_cond(const ktime_t kt,
struct timespec64 *ts)
{
- if (kt.tv64) {
+ if (kt) {
*ts = ktime_to_timespec64(kt);
return true;
} else {
@@ -290,20 +272,16 @@ static inline __must_check bool ktime_to_timespec64_cond(const ktime_t kt,
* this resolution values.
*/
#define LOW_RES_NSEC TICK_NSEC
-#define KTIME_LOW_RES (ktime_t){ .tv64 = LOW_RES_NSEC }
+#define KTIME_LOW_RES (LOW_RES_NSEC)
static inline ktime_t ns_to_ktime(u64 ns)
{
- static const ktime_t ktime_zero = { .tv64 = 0 };
-
- return ktime_add_ns(ktime_zero, ns);
+ return ns;
}
static inline ktime_t ms_to_ktime(u64 ms)
{
- static const ktime_t ktime_zero = { .tv64 = 0 };
-
- return ktime_add_ms(ktime_zero, ms);
+ return ms * NSEC_PER_MSEC;
}
# include <linux/timekeeping.h>