1 From 93332ebdcd54b0e0c0e86bced537cc96247bc1f1 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 23 Jan 2016 16:23:09 +0100
4 Subject: [PATCH 2/2] mips: add vdso support
6 vdso support is available on mips starting with kernel 4.4, see kernel
7 commit a7f4df4e21 "MIPS: VDSO: Add implementations of gettimeofday()
8 and clock_gettime()" for details.
10 In Linux kernel 4.4.0 the mips code returns -ENOSYS in case it can not
11 handle the vdso call and assumes the libc will call the original
12 syscall in this case. Handle this case in musl. Currently Linux kernel
13 4.4.0 handles the following types: CLOCK_REALTIME_COARSE,
14 CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME and CLOCK_MONOTONIC.
16 These are some measurements of calling clock_gettime(CLOCK_MONOTONIC,
17 &tp); 1.000.000 times.
20 root@OpenWrt:/# time ./vdso-test
26 root@OpenWrt:/# time /usr/bin/vdso-test
31 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
33 arch/mips/syscall_arch.h | 4 ++++
34 src/time/clock_gettime.c | 12 +++++++++++-
35 2 files changed, 15 insertions(+), 1 deletion(-)
37 diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h
38 index e74e0ad..39c0ea3 100644
39 --- a/arch/mips/syscall_arch.h
40 +++ b/arch/mips/syscall_arch.h
41 @@ -161,3 +161,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
42 if (n == SYS_fstatat) __stat_fix(c);
47 +#define VDSO_CGT_SYM "__vdso_clock_gettime"
48 +#define VDSO_CGT_VER "LINUX_2.6"
49 diff --git a/src/time/clock_gettime.c b/src/time/clock_gettime.c
50 index 1572de0..dba99ff 100644
51 --- a/src/time/clock_gettime.c
52 +++ b/src/time/clock_gettime.c
53 @@ -26,13 +26,23 @@ void *__vdsosym(const char *, const char *);
54 int __clock_gettime(clockid_t clk, struct timespec *ts)
58 static int (*volatile cgt)(clockid_t, struct timespec *);
60 void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
61 if (!f) f = (void *)sc_clock_gettime;
64 - return cgt(clk, ts);
68 + * mips in linux kernel 4.4.0 returns -ENOSYS if it can not
69 + * handle the syscall in vdso, the original syscall should be
70 + * called by the libc in such a case.
73 + return sc_clock_gettime(clk, ts);
76 return sc_clock_gettime(clk, ts);