Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Feb 2018 10:44:47 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r329977 - in stable/11/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201802251044.w1PAilPj023595@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sun Feb 25 10:44:47 2018
New Revision: 329977
URL: https://svnweb.freebsd.org/changeset/base/329977

Log:
  MFC r329509:
  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().
  
  Submitted by:	Johannes Lundberg <johalun0@gmail.com>
  Sponsored by:	Mellanox Technologies
  Sponsored by:	Limelight Networks

Modified:
  stable/11/sys/compat/linuxkpi/common/include/linux/ktime.h
  stable/11/sys/compat/linuxkpi/common/src/linux_hrtimer.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/ktime.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/ktime.h	Sun Feb 25 10:40:41 2018	(r329976)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/ktime.h	Sun Feb 25 10:44:47 2018	(r329977)
@@ -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,23 +139,20 @@ 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));
+
+	return (ktime_to_ns(timespec_to_ktime(ts)));
 }
 
-#define	ktime_get_raw_ns()	ktime_get_ns()
-
 static inline ktime_t
 ktime_get(void)
 {
@@ -188,6 +178,24 @@ ktime_get_real(void)
 
 	nanotime(&ts);
 	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 */

Modified: stable/11/sys/compat/linuxkpi/common/src/linux_hrtimer.c
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/src/linux_hrtimer.c	Sun Feb 25 10:40:41 2018	(r329976)
+++ stable/11/sys/compat/linuxkpi/common/src/linux_hrtimer.c	Sun Feb 25 10:44:47 2018	(r329977)
@@ -98,7 +98,7 @@ linux_hrtimer_start_range_ns(struct hrtimer *hrtimer, 
 {
 
 	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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802251044.w1PAilPj023595>