]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ramfs: Use kernel internal `clock_gettime` variant
authorSergiu Moga <sergiu@unikraft.io>
Fri, 7 Feb 2025 10:25:11 +0000 (12:25 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 13 Feb 2025 16:47:20 +0000 (16:47 +0000)
Use the kernel internal variant of `clock_gettime`,
`uk_sys_clock_gettime`.
This helps avoid unnecessary execution of the syscall wrappers'
logic of syscall shim that would have otherwise been run through
`uk_syscall_r_clock_gettime`.

Lastly, since now RAMFS uses a definition available only through
posix-time, add a dependency to it in the Config.uk. Ideally,
this should have been a depends on HAVE_TIME and an imply, but seeing
that currently this is the only library offering us time services,
do it like this for now.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1587

lib/ramfs/Config.uk
lib/ramfs/ramfs_vnops.c

index 52e4388c4e64b914c890a5641a56909c714ac0a8..79926dcbe312541ae487b9478979bf055e920f53 100644 (file)
@@ -2,3 +2,4 @@ config LIBRAMFS
        bool "ramfs: simple RAM file system"
        default n
        depends on LIBVFSCORE
+       select LIBPOSIX_TIME
index df08d159f7581b69b2f8902b3cb956a86bda5d43..292a789f42452adbfa1bf3ca7b55c5ed24c4fbfe 100644 (file)
@@ -56,6 +56,8 @@
 #include <fcntl.h>
 #include <vfscore/fs.h>
 
+#include <uk/posix-time.h>
+
 /* 16 bits are enough for file mode as defined by POSIX, the rest we can use */
 #define RAMFS_MODEMASK 0xffff
 #define RAMFS_DELMODE 0x10000
@@ -70,8 +72,19 @@ set_times_to_now(struct timespec *time1, struct timespec *time2,
                 struct timespec *time3)
 {
        struct timespec now;
+       int rc;
+
+       rc = uk_sys_clock_gettime(CLOCK_REALTIME, &now);
+       if (unlikely(rc)) {
+               /*
+                * We do not consider this a fatal error, but rather
+                * something that might indicate a misconfigured kernel.
+                * Just print the error and ignore.
+                */
+               uk_pr_err("Failed to set current time for vnode: %d\n", rc);
+               UK_ASSERT(rc < 0);
+       }
 
-       clock_gettime(CLOCK_REALTIME, &now);
        if (time1)
                memcpy(time1, &now, sizeof(struct timespec));
        if (time2)