Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

csky: Add VDSO with GENERIC_GETTIMEOFDAY, GENERIC_TIME_VSYSCALL, HAVE_GENERIC_VDSO

It could help to reduce the latency of the time-related functions
in user space.

We have referenced arm's and riscv's implementation for the patch.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Cc: Vincent Chen <vincent.chen@sifive.com>
Cc: Arnd Bergmann <arnd@arndb.de>

Guo Ren 0d3b051a 8dcbc611

+225 -3
+4
arch/csky/Kconfig
··· 35 35 select GENERIC_IRQ_MULTI_HANDLER 36 36 select GENERIC_SCHED_CLOCK 37 37 select GENERIC_SMP_IDLE_THREAD 38 + select GENERIC_TIME_VSYSCALL 39 + select GENERIC_VDSO_32 40 + select GENERIC_GETTIMEOFDAY 38 41 select GX6605S_TIMER if CPU_CK610 39 42 select HAVE_ARCH_TRACEHOOK 40 43 select HAVE_ARCH_AUDITSYSCALL ··· 49 46 select HAVE_DEBUG_KMEMLEAK 50 47 select HAVE_DYNAMIC_FTRACE 51 48 select HAVE_DYNAMIC_FTRACE_WITH_REGS 49 + select HAVE_GENERIC_VDSO 52 50 select HAVE_FUNCTION_TRACER 53 51 select HAVE_FUNCTION_GRAPH_TRACER 54 52 select HAVE_FUNCTION_ERROR_INJECTION
+5
arch/csky/abiv1/inc/abi/regdef.h
··· 4 4 #ifndef __ASM_CSKY_REGDEF_H 5 5 #define __ASM_CSKY_REGDEF_H 6 6 7 + #ifdef __ASSEMBLY__ 7 8 #define syscallid r1 9 + #else 10 + #define syscallid "r1" 11 + #endif 12 + 8 13 #define regs_syscallid(regs) regs->regs[9] 9 14 #define regs_fp(regs) regs->regs[2] 10 15
+5
arch/csky/abiv2/inc/abi/regdef.h
··· 4 4 #ifndef __ASM_CSKY_REGDEF_H 5 5 #define __ASM_CSKY_REGDEF_H 6 6 7 + #ifdef __ASSEMBLY__ 7 8 #define syscallid r7 9 + #else 10 + #define syscallid "r7" 11 + #endif 12 + 8 13 #define regs_syscallid(regs) regs->regs[3] 9 14 #define regs_fp(regs) regs->regs[4] 10 15
+8
arch/csky/include/asm/clocksource.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_VDSO_CSKY_CLOCKSOURCE_H 4 + #define __ASM_VDSO_CSKY_CLOCKSOURCE_H 5 + 6 + #include <asm/vdso/clocksource.h> 7 + 8 + #endif
+2
arch/csky/include/asm/vdso.h
··· 5 5 6 6 #include <linux/types.h> 7 7 8 + #ifndef GENERIC_TIME_VSYSCALL 8 9 struct vdso_data { 9 10 }; 11 + #endif 10 12 11 13 /* 12 14 * The VDSO symbols are mapped into Linux so we can just use regular symbol
+9
arch/csky/include/asm/vdso/clocksource.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_VDSO_CSKY_CLOCKSOURCE_H 4 + #define __ASM_VDSO_CSKY_CLOCKSOURCE_H 5 + 6 + #define VDSO_ARCH_CLOCKMODES \ 7 + VDSO_CLOCKMODE_ARCHTIMER 8 + 9 + #endif /* __ASM_VDSO_CSKY_CLOCKSOURCE_H */
+114
arch/csky/include/asm/vdso/gettimeofday.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_VDSO_CSKY_GETTIMEOFDAY_H 4 + #define __ASM_VDSO_CSKY_GETTIMEOFDAY_H 5 + 6 + #ifndef __ASSEMBLY__ 7 + 8 + #include <asm/barrier.h> 9 + #include <asm/unistd.h> 10 + #include <abi/regdef.h> 11 + #include <uapi/linux/time.h> 12 + 13 + #define VDSO_HAS_CLOCK_GETRES 1 14 + 15 + static __always_inline 16 + int gettimeofday_fallback(struct __kernel_old_timeval *_tv, 17 + struct timezone *_tz) 18 + { 19 + register struct __kernel_old_timeval *tv asm("a0") = _tv; 20 + register struct timezone *tz asm("a1") = _tz; 21 + register long ret asm("a0"); 22 + register long nr asm(syscallid) = __NR_gettimeofday; 23 + 24 + asm volatile ("trap 0\n" 25 + : "=r" (ret) 26 + : "r"(tv), "r"(tz), "r"(nr) 27 + : "memory"); 28 + 29 + return ret; 30 + } 31 + 32 + static __always_inline 33 + long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) 34 + { 35 + register clockid_t clkid asm("a0") = _clkid; 36 + register struct __kernel_timespec *ts asm("a1") = _ts; 37 + register long ret asm("a0"); 38 + register long nr asm(syscallid) = __NR_clock_gettime64; 39 + 40 + asm volatile ("trap 0\n" 41 + : "=r" (ret) 42 + : "r"(clkid), "r"(ts), "r"(nr) 43 + : "memory"); 44 + 45 + return ret; 46 + } 47 + 48 + static __always_inline 49 + long clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) 50 + { 51 + register clockid_t clkid asm("a0") = _clkid; 52 + register struct old_timespec32 *ts asm("a1") = _ts; 53 + register long ret asm("a0"); 54 + register long nr asm(syscallid) = __NR_clock_gettime; 55 + 56 + asm volatile ("trap 0\n" 57 + : "=r" (ret) 58 + : "r"(clkid), "r"(ts), "r"(nr) 59 + : "memory"); 60 + 61 + return ret; 62 + } 63 + 64 + static __always_inline 65 + int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) 66 + { 67 + register clockid_t clkid asm("a0") = _clkid; 68 + register struct __kernel_timespec *ts asm("a1") = _ts; 69 + register long ret asm("a0"); 70 + register long nr asm(syscallid) = __NR_clock_getres_time64; 71 + 72 + asm volatile ("trap 0\n" 73 + : "=r" (ret) 74 + : "r"(clkid), "r"(ts), "r"(nr) 75 + : "memory"); 76 + 77 + return ret; 78 + } 79 + 80 + static __always_inline 81 + int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) 82 + { 83 + register clockid_t clkid asm("a0") = _clkid; 84 + register struct old_timespec32 *ts asm("a1") = _ts; 85 + register long ret asm("a0"); 86 + register long nr asm(syscallid) = __NR_clock_getres; 87 + 88 + asm volatile ("trap 0\n" 89 + : "=r" (ret) 90 + : "r"(clkid), "r"(ts), "r"(nr) 91 + : "memory"); 92 + 93 + return ret; 94 + } 95 + 96 + uint64_t csky_pmu_read_cc(void); 97 + static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, 98 + const struct vdso_data *vd) 99 + { 100 + #ifdef CONFIG_CSKY_PMU_V1 101 + return csky_pmu_read_cc(); 102 + #else 103 + return 0; 104 + #endif 105 + } 106 + 107 + static __always_inline const struct vdso_data *__arch_get_vdso_data(void) 108 + { 109 + return _vdso_data; 110 + } 111 + 112 + #endif /* !__ASSEMBLY__ */ 113 + 114 + #endif /* __ASM_VDSO_CSKY_GETTIMEOFDAY_H */
+12
arch/csky/include/asm/vdso/processor.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef __ASM_VDSO_CSKY_PROCESSOR_H 4 + #define __ASM_VDSO_CSKY_PROCESSOR_H 5 + 6 + #ifndef __ASSEMBLY__ 7 + 8 + #define cpu_relax() barrier() 9 + 10 + #endif /* __ASSEMBLY__ */ 11 + 12 + #endif /* __ASM_VDSO_CSKY_PROCESSOR_H */
+22
arch/csky/include/asm/vdso/vsyscall.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __ASM_VDSO_CSKY_VSYSCALL_H 4 + #define __ASM_VDSO_CSKY_VSYSCALL_H 5 + 6 + #ifndef __ASSEMBLY__ 7 + 8 + #include <vdso/datapage.h> 9 + 10 + extern struct vdso_data *vdso_data; 11 + 12 + static __always_inline struct vdso_data *__csky_get_k_vdso_data(void) 13 + { 14 + return vdso_data; 15 + } 16 + #define __arch_get_k_vdso_data __csky_get_k_vdso_data 17 + 18 + #include <asm-generic/vdso/vsyscall.h> 19 + 20 + #endif /* !__ASSEMBLY__ */ 21 + 22 + #endif /* __ASM_VDSO_CSKY_VSYSCALL_H */
+1 -1
arch/csky/kernel/perf_event.c
··· 87 87 }) 88 88 89 89 /* cycle counter */ 90 - static uint64_t csky_pmu_read_cc(void) 90 + uint64_t csky_pmu_read_cc(void) 91 91 { 92 92 uint32_t lo, hi, tmp; 93 93 uint64_t result;
+4
arch/csky/kernel/vdso.c
··· 8 8 #include <linux/slab.h> 9 9 10 10 #include <asm/page.h> 11 + #ifdef GENERIC_TIME_VSYSCALL 12 + #include <vdso/datapage.h> 13 + #else 11 14 #include <asm/vdso.h> 15 + #endif 12 16 13 17 extern char vdso_start[], vdso_end[]; 14 18
+7 -2
arch/csky/kernel/vdso/Makefile
··· 6 6 include $(srctree)/lib/vdso/Makefile 7 7 8 8 # Symbols present in the vdso 9 - vdso-syms = rt_sigreturn 9 + vdso-syms += rt_sigreturn 10 + vdso-syms += vgettimeofday 10 11 11 12 # Files to link into the vdso 12 13 obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o 13 14 14 - ccflags-y := -fno-stack-protector 15 + ifneq ($(c-gettimeofday-y),) 16 + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) 17 + endif 18 + 19 + ccflags-y := -fno-stack-protector -DBUILD_VDSO32 15 20 16 21 # Build rules 17 22 targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o
+4
arch/csky/kernel/vdso/vdso.lds.S
··· 49 49 LINUX_5.10 { 50 50 global: 51 51 __vdso_rt_sigreturn; 52 + __vdso_clock_gettime; 53 + __vdso_clock_gettime64; 54 + __vdso_gettimeofday; 55 + __vdso_clock_getres; 52 56 local: *; 53 57 }; 54 58 }
+28
arch/csky/kernel/vdso/vgettimeofday.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <linux/time.h> 4 + #include <linux/types.h> 5 + 6 + int __vdso_clock_gettime(clockid_t clock, 7 + struct old_timespec32 *ts) 8 + { 9 + return __cvdso_clock_gettime32(clock, ts); 10 + } 11 + 12 + int __vdso_clock_gettime64(clockid_t clock, 13 + struct __kernel_timespec *ts) 14 + { 15 + return __cvdso_clock_gettime(clock, ts); 16 + } 17 + 18 + int __vdso_gettimeofday(struct __kernel_old_timeval *tv, 19 + struct timezone *tz) 20 + { 21 + return __cvdso_gettimeofday(tv, tz); 22 + } 23 + 24 + int __vdso_clock_getres(clockid_t clock_id, 25 + struct old_timespec32 *res) 26 + { 27 + return __cvdso_clock_getres_time32(clock_id, res); 28 + }