Skip to contentSkip to conversation

lib: vdso: add support for time

PATCH Superseded Mark Salyzyn 1 participant 1 message Nov 10, 2017

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: vdso: add support for time

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 (arm, virtual counters).

Cc James Morse <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Dmitry Safonov <[email protected]>
Cc John Stultz <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Andy Gross <[email protected]>
Cc Kevin Brodsky <[email protected]>
Cc Andrew Pinski <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc linux-kernel at vger.kernel.org
Cc linux-arm-kernel at lists.infradead.org

NB: to be applied _after_
[PATCH v5 10/12] arm64: vdso: replace gettimeofday.S with global vgettimeofday.C

---
 arch/arm/kernel/vdso.c            |  1 +
 arch/arm/vdso/vdso.lds.S          |  1 +
 arch/arm64/kernel/vdso/compiler.h |  1 +
 arch/arm64/kernel/vdso/vdso.lds.S |  1 +
 lib/vdso/vgettimeofday.c          | 10 ++++++++++
 5 files changed, 14 insertions(+)
arch/arm/kernel/vdso.c +1 -0
index da52aade40a3..b8ae87b4d526 100644
@@ -190,6 +190,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 */
 	}
 }
 
arch/arm/vdso/vdso.lds.S +1 -0
index 1d81e8c3acf6..1eb577091d1f 100644
@@ -83,6 +83,7 @@ VERSION
 		__vdso_clock_gettime;
 		__vdso_gettimeofday;
 		__vdso_clock_getres;
+		__vdso_time;
 	local: *;
 	};
 }
arch/arm64/kernel/vdso/compiler.h +1 -0
index 921a7191b497..fb27545640f2 100644
@@ -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 */
arch/arm64/kernel/vdso/vdso.lds.S +1 -0
index beca249bc2f3..9de0ffc369c5 100644
@@ -88,6 +88,7 @@ VERSION
 		__kernel_gettimeofday;
 		__kernel_clock_gettime;
 		__kernel_clock_getres;
+		__kernel_time;
 	local: *;
 	};
 }
lib/vdso/vgettimeofday.c +10 -0
index 079955162be8..d8d675d46749 100644
@@ -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;
+}
Signature · 1 line
2.15.0.448.gf294e3d99a-goog