Skip to contentSkip to conversation

backport: add ktime_get_raw_ts64() backport for < 3.19

PATCH Superseded Luca Coelho 2 participants 4 messages Sep 20, 2018 – Sep 24, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backport: add ktime_get_raw_ts64() backport for < 3.19

From: Luca Coelho <[email protected]>

The getrawmonotonic64() function that is used by the ktime_get_raw_ts64() backport was only introduced in 3.19. To fix compilation with earlier kernels, do the convertion from getrawmonotonic() manually if the kernel is < 3.19.

Additionally, add timespec_to_timespec64() that we need for this conversion (and which was only introduced in 4.15).

---
 backport/backport-include/linux/timekeeping.h | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
backport/backport-include/linux/timekeeping.h +29 -0
index aebb00ca366b..56fca5759b8e 100644
@@ -55,11 +55,40 @@ static inline void ktime_get_ts64(struct timespec64 *ts)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(3,19,0)
+/* This was introduced in 4.15, but we only need it in the
+ * ktime_get_raw_ts64 backport() for < 3.19.
+ */
+#if __BITS_PER_LONG == 64
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	return *(const struct timespec64 *)&ts;
+}
+
+#else
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	struct timespec64 ret;
+
+	ret.tv_sec = ts.tv_sec;
+	ret.tv_nsec = ts.tv_nsec;
+	return ret;
+}
+#endif
+#endif /* < 3.19 */
+
 #if LINUX_VERSION_IS_LESS(4,18,0)
 #define ktime_get_raw_ts64 LINUX_BACKPORT(ktime_get_raw_ts64)
 static inline void ktime_get_raw_ts64(struct timespec64 *ts)
 {
+#if LINUX_VERSION_IS_LESS(3,19,0)
+	struct timespec64 ts64;
+
+	getrawmonotonic(&ts64);
+	*ts = timespec_to_timespec64(ts64);
+#else
 	return getrawmonotonic64(ts);
+#endif /* < 3.19 */
 }
 #endif
 
Signature · 4 lines
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#1 lore raw
Quoted 20 lines · Luca Coelho

From: Luca Coelho <[email protected]>

The getrawmonotonic64() function that is used by the ktime_get_raw_ts64() backport was only introduced in 3.19. To fix compilation with earlier kernels, do the convertion from getrawmonotonic() manually if the kernel is < 3.19.

Additionally, add timespec_to_timespec64() that we need for this conversion (and which was only introduced in 4.15).

---
 backport/backport-include/linux/timekeeping.h | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
backport/backport-include/linux/timekeeping.h +0 -0
index aebb00ca366b..56fca5759b8e 100644

backport/backport-include/linux/timekeeping.h static inline void ktime_get_ts64(struct timespec64 *ts) · line 60

Quoted 6 lines
backport/backport-include/linux/timekeeping.h +3 -0
@@ -55,11 +55,40 @@ static inline void ktime_get_ts64(struct timespec64 *ts)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(3,19,0)
+/* This was introduced in 4.15, but we only need it in the
+ * ktime_get_raw_ts64 backport() for < 3.19.

timespec_to_timespec64() was already added in 3.17, see
https://elixir.bootlin.com/linux/v3.17.8/ident/timespec_to_timespec64

Quoted 19 lines
backport/backport-include/linux/timekeeping.h +19 -0
+ */
+#if __BITS_PER_LONG == 64
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	return *(const struct timespec64 *)&ts;
+}
+
+#else
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	struct timespec64 ret;
+
+	ret.tv_sec = ts.tv_sec;
+	ret.tv_nsec = ts.tv_nsec;
+	return ret;
+}
+#endif
+#endif /* < 3.19 */
+
#2 lore raw
Quoted 27 lines · Hauke Mehrtens
Quoted 26 lines · Luca Coelho

From: Luca Coelho <[email protected]>

The getrawmonotonic64() function that is used by the ktime_get_raw_ts64() backport was only introduced in 3.19. To fix compilation with earlier kernels, do the convertion from getrawmonotonic() manually if the kernel is < 3.19.

Additionally, add timespec_to_timespec64() that we need for this conversion (and which was only introduced in 4.15).

---
 backport/backport-include/linux/timekeeping.h | 29
+++++++++++++++++++
 1 file changed, 29 insertions(+)
backport/backport-include/linux/timekeeping.h +0 -0
index aebb00ca366b..56fca5759b8e 100644
@@ -55,11 +55,40 @@ static inline void ktime_get_ts64(struct
 timespec64 *ts)
 }
 #endif
 
Quoted 6 lines

backport/backport-include/linux/timekeeping.h static inline void ktime_get_ts64(struct timespec64 *ts) · line 60

Quoted 3 lines
backport/backport-include/linux/timekeeping.h +3 -0
+#if LINUX_VERSION_IS_LESS(3,19,0)
+/* This was introduced in 4.15, but we only need it in the
+ * ktime_get_raw_ts64 backport() for < 3.19.

timespec_to_timespec64() was already added in 3.17, see
https://elixir.bootlin.com/linux/v3.17.8/ident/timespec_to_timespec64

Oh, you're right. I somehow got confused here. I'm running some tests and will resend a fixed version.

Thanks!

--
Luca.

--
To unsubscribe from this list: send the line "unsubscribe backports" in

#3 lore raw

PATCH v2 1/1 backport: add ktime_get_raw_ts64() backport for < 3.19

From: Luca Coelho <[email protected]>

The getrawmonotonic64() function that is used by the ktime_get_raw_ts64() backport was only introduced in 3.19. To fix compilation with earlier kernels, do the convertion from getrawmonotonic() manually if the kernel is < 3.19.

Additionally, add timespec_to_timespec64() that we need for this conversion (and which was only introduced in 3.17).

---
 backport/backport-include/linux/timekeeping.h | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
backport/backport-include/linux/timekeeping.h +29 -0
index aebb00ca366b..718715316a1d 100644
@@ -55,11 +55,40 @@ static inline void ktime_get_ts64(struct timespec64 *ts)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(3,17,0)
+/* This was introduced in 4.15, but we only need it in the
+ * ktime_get_raw_ts64 backport() for < 3.17.
+ */
+#if __BITS_PER_LONG == 64
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	return *(const struct timespec64 *)&ts;
+}
+
+#else
+static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
+{
+	struct timespec64 ret;
+
+	ret.tv_sec = ts.tv_sec;
+	ret.tv_nsec = ts.tv_nsec;
+	return ret;
+}
+#endif
+#endif /* < 3.17 */
+
 #if LINUX_VERSION_IS_LESS(4,18,0)
 #define ktime_get_raw_ts64 LINUX_BACKPORT(ktime_get_raw_ts64)
 static inline void ktime_get_raw_ts64(struct timespec64 *ts)
 {
+#if LINUX_VERSION_IS_LESS(3,19,0)
+	struct timespec64 ts64;
+
+	getrawmonotonic(&ts64);
+	*ts = timespec_to_timespec64(ts64);
+#else
 	return getrawmonotonic64(ts);
+#endif /* < 3.19 */
 }
 #endif
 
Signature · 4 lines
2.19.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in