[Concept,01/19] linux: Add ktime.h header with time functions
Commit Message
From: Simon Glass <simon.glass@canonical.com>
The ext4l filesystem uses several ktime functions which are currently
defined inline in ext4_uboot.h.
Create a new linux/ktime.h header file with these stub implementations
to better match the Linux kernel structure. This reduces duplication
and makes ext4_uboot.h smaller.
Functions moved:
- ktime_get()
- ktime_to_ns()
- ktime_sub()
- ktime_add_ns()
- ktime_get_ns()
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
fs/ext4l/ext4_uboot.h | 25 ++--------------
include/linux/ktime.h | 70 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 22 deletions(-)
create mode 100644 include/linux/ktime.h
@@ -1032,26 +1032,8 @@ static inline void shrinker_free(struct shrinker *s)
{
}
-/* ktime functions */
-static inline ktime_t ktime_get(void)
-{
- return 0;
-}
-
-static inline s64 ktime_to_ns(ktime_t kt)
-{
- return kt;
-}
-
-static inline ktime_t ktime_sub(ktime_t a, ktime_t b)
-{
- return a - b;
-}
-
-static inline ktime_t ktime_add_ns(ktime_t kt, s64 ns)
-{
- return kt + ns;
-}
+/* ktime functions - use linux/ktime.h */
+#include <linux/ktime.h>
/* hrtimer stubs */
#define HRTIMER_MODE_ABS 0
@@ -1983,8 +1965,7 @@ int IOPRIO_PRIO_VALUE(int class, int data);
void *kvzalloc(size_t size, gfp_t flags);
#define kvmalloc(size, flags) kvzalloc(size, flags)
-/* Time operations */
-#define ktime_get_ns() (0ULL)
+/* Time operations - ktime_get_ns is in linux/ktime.h */
/* nsecs_to_jiffies is in linux/jiffies.h */
/* Superblock write operations */
new file mode 100644
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * ktime_t - nanosecond-resolution time format.
+ *
+ * Stub implementation for U-Boot.
+ */
+#ifndef _LINUX_KTIME_H
+#define _LINUX_KTIME_H
+
+#include <linux/types.h>
+
+/* ktime_t is defined in linux/types.h */
+
+/**
+ * ktime_get() - get current time
+ *
+ * U-Boot stub - returns 0 as we don't track real time during operations.
+ *
+ * Return: current time as ktime_t (always 0)
+ */
+static inline ktime_t ktime_get(void)
+{
+ return 0;
+}
+
+/**
+ * ktime_to_ns() - convert ktime_t to nanoseconds
+ * @kt: the ktime_t value to convert
+ *
+ * Return: the nanosecond value
+ */
+static inline s64 ktime_to_ns(ktime_t kt)
+{
+ return kt;
+}
+
+/**
+ * ktime_sub() - subtract two ktime_t values
+ * @a: first ktime_t value
+ * @b: second ktime_t value
+ *
+ * Return: a - b
+ */
+static inline ktime_t ktime_sub(ktime_t a, ktime_t b)
+{
+ return a - b;
+}
+
+/**
+ * ktime_add_ns() - add nanoseconds to a ktime_t value
+ * @kt: base ktime_t value
+ * @ns: nanoseconds to add
+ *
+ * Return: kt + ns
+ */
+static inline ktime_t ktime_add_ns(ktime_t kt, s64 ns)
+{
+ return kt + ns;
+}
+
+/**
+ * ktime_get_ns() - get current time in nanoseconds
+ *
+ * U-Boot stub - returns 0.
+ *
+ * Return: current time in nanoseconds (always 0)
+ */
+#define ktime_get_ns() (0ULL)
+
+#endif /* _LINUX_KTIME_H */