FROMLIST: lib: vdso: add support for time
authorMark Salyzyn <salyzyn@google.com>
Fri, 27 Oct 2017 15:58:18 +0000 (08:58 -0700)
committerBruno Martins <bgcngm@gmail.com>
Fri, 20 Oct 2023 16:03:36 +0000 (17:03 +0100)
(cherry pick from url https://patchwork.kernel.org/patch/10053549/)

Add time() vdso support to match up with existing support in the x86's
vdso.  Currently benefitting arm and arm64 which uses the common
vgettimeofday.c implementation.  On arm provides about a ~14 fold
improvement in speed over the straight syscall, and about a ~5 fold
improvement in speed over an alternate library implementation that
relies on the vdso call to gettimeofday to fulfill the request.

We can provide __vdso_time even if we can not provide a speed
enhanced __vdso_gettimeofday.

Signed-off-by: Mark Salyzyn <salyzyn@android.com>
Bug: 63737556
Bug: 20045882
Change-Id: I0bb3c6bafe57f9ed69350e2dd54edaae58316e8f

arch/arm/kernel/vdso.c
arch/arm/vdso/vdso.lds.S
arch/arm64/kernel/vdso/compiler.h
arch/arm64/kernel/vdso/vdso.lds.S
lib/vdso/vgettimeofday.c

index 056b93f5a1e0a51dce27a9d345c368893c7cc104..598e34e47bb53ee5f8c38d237cf686b59d2d12a8 100644 (file)
@@ -176,6 +176,7 @@ static void __init patch_vdso(void *ehdr)
                vdso_nullpatch_one(&einfo, "__vdso_gettimeofday");
                vdso_nullpatch_one(&einfo, "__vdso_clock_gettime");
                vdso_nullpatch_one(&einfo, "__vdso_clock_getres");
+               /* do not zero out __vdso_time, no cntvct_ok dependency */
        }
 }
 
index 1d81e8c3acf6bb9a00a5a578a262ba720bb861ca..1eb577091d1f85e6f11cc327bffbc42e4b409474 100644 (file)
@@ -83,6 +83,7 @@ VERSION
                __vdso_clock_gettime;
                __vdso_gettimeofday;
                __vdso_clock_getres;
+               __vdso_time;
        local: *;
        };
 }
index 921a7191b49762387775ebd4193cc35fabe4c420..fb27545640f2a3e9d724b5abf2397d6e3db20be1 100644 (file)
@@ -65,5 +65,6 @@ static __always_inline notrace u64 arch_vdso_read_counter(void)
 #define __vdso_clock_gettime __kernel_clock_gettime
 #define __vdso_gettimeofday __kernel_gettimeofday
 #define __vdso_clock_getres __kernel_clock_getres
+#define __vdso_time __kernel_time
 
 #endif /* __VDSO_COMPILER_H */
index b3e6c4d5b75c8f8bc008edc3cc146d6fdc43f83b..3dc1198b5ec93b213e1f7f1319a0e1f0779fff77 100644 (file)
@@ -94,6 +94,7 @@ VERSION
                __kernel_gettimeofday;
                __kernel_clock_gettime;
                __kernel_clock_getres;
+               __kernel_time;
        local: *;
        };
 }
index 075a1171944d7966e3ba4a6515a7daec8673bb79..00d93df8045f7945cc20ca956ec06b0a45d761a9 100644 (file)
@@ -385,3 +385,13 @@ int __vdso_clock_getres(clockid_t clock, struct timespec *res)
 
        return 0;
 }
+
+notrace time_t __vdso_time(time_t *t)
+{
+       const struct vdso_data *vd = __get_datapage();
+       time_t result = READ_ONCE(vd->xtime_coarse_sec);
+
+       if (t)
+               *t = result;
+       return result;
+}