From: Sergiu Moga Date: Fri, 7 Feb 2025 10:25:11 +0000 (+0200) Subject: lib/ramfs: Use kernel internal `clock_gettime` variant X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=1434864988dbbea21039d2c20f3f02e28385c6b1;p=unikraft%2Funikraft.git lib/ramfs: Use kernel internal `clock_gettime` variant 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 Approved-by: Andrei Tatar Reviewed-by: Andrei Tatar GitHub-Closes: #1587 --- diff --git a/lib/ramfs/Config.uk b/lib/ramfs/Config.uk index 52e4388c4..79926dcbe 100644 --- a/lib/ramfs/Config.uk +++ b/lib/ramfs/Config.uk @@ -2,3 +2,4 @@ config LIBRAMFS bool "ramfs: simple RAM file system" default n depends on LIBVFSCORE + select LIBPOSIX_TIME diff --git a/lib/ramfs/ramfs_vnops.c b/lib/ramfs/ramfs_vnops.c index df08d159f..292a789f4 100644 --- a/lib/ramfs/ramfs_vnops.c +++ b/lib/ramfs/ramfs_vnops.c @@ -56,6 +56,8 @@ #include #include +#include + /* 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)