perf: include asm/unistd.h instead of syscall.h to fix conflict with kernel headers
[openwrt/staging/chunkeey.git] / toolchain / musl / patches / 030-mips-add-vdso-support.patch
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
5
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.
9
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.
15
16 These are some measurements of calling clock_gettime(CLOCK_MONOTONIC,
17 &tp); 1.000.000 times.
18
19 without vdso:
20 root@OpenWrt:/# time ./vdso-test
21 real 0m 0.95s
22 user 0m 0.24s
23 sys 0m 0.70s
24
25 with vdso:
26 root@OpenWrt:/# time /usr/bin/vdso-test
27 real 0m 0.35s
28 user 0m 0.34s
29 sys 0m 0.00s
30
31 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
32 ---
33 arch/mips/syscall_arch.h | 4 ++++
34 src/time/clock_gettime.c | 12 +++++++++++-
35 2 files changed, 15 insertions(+), 1 deletion(-)
36
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);
43 return r2;
44 }
45 +
46 +#define VDSO_USEFUL
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)
55 {
56 #ifdef VDSO_CGT_SYM
57 + int ret;
58 static int (*volatile cgt)(clockid_t, struct timespec *);
59 if (!cgt) {
60 void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
61 if (!f) f = (void *)sc_clock_gettime;
62 a_cas_p(&cgt, 0, f);
63 }
64 - return cgt(clk, ts);
65 + ret = cgt(clk, ts);
66 +
67 + /*
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.
71 + */
72 + if (ret == -ENOSYS)
73 + return sc_clock_gettime(clk, ts);
74 + return ret;
75 #else
76 return sc_clock_gettime(clk, ts);
77 #endif
78 --
79 2.7.0.rc3
80