Skip to content

Commit 0d3b051

Browse files
committed
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>
1 parent 8dcbc61 commit 0d3b051

14 files changed

Lines changed: 225 additions & 3 deletions

File tree

arch/csky/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ config CSKY
3535
select GENERIC_IRQ_MULTI_HANDLER
3636
select GENERIC_SCHED_CLOCK
3737
select GENERIC_SMP_IDLE_THREAD
38+
select GENERIC_TIME_VSYSCALL
39+
select GENERIC_VDSO_32
40+
select GENERIC_GETTIMEOFDAY
3841
select GX6605S_TIMER if CPU_CK610
3942
select HAVE_ARCH_TRACEHOOK
4043
select HAVE_ARCH_AUDITSYSCALL
@@ -46,6 +49,7 @@ config CSKY
4649
select HAVE_DEBUG_KMEMLEAK
4750
select HAVE_DYNAMIC_FTRACE
4851
select HAVE_DYNAMIC_FTRACE_WITH_REGS
52+
select HAVE_GENERIC_VDSO
4953
select HAVE_FUNCTION_TRACER
5054
select HAVE_FUNCTION_GRAPH_TRACER
5155
select HAVE_FUNCTION_ERROR_INJECTION

arch/csky/abiv1/inc/abi/regdef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#ifndef __ASM_CSKY_REGDEF_H
55
#define __ASM_CSKY_REGDEF_H
66

7+
#ifdef __ASSEMBLY__
78
#define syscallid r1
9+
#else
10+
#define syscallid "r1"
11+
#endif
12+
813
#define regs_syscallid(regs) regs->regs[9]
914
#define regs_fp(regs) regs->regs[2]
1015

arch/csky/abiv2/inc/abi/regdef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#ifndef __ASM_CSKY_REGDEF_H
55
#define __ASM_CSKY_REGDEF_H
66

7+
#ifdef __ASSEMBLY__
78
#define syscallid r7
9+
#else
10+
#define syscallid "r7"
11+
#endif
12+
813
#define regs_syscallid(regs) regs->regs[3]
914
#define regs_fp(regs) regs->regs[4]
1015

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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

arch/csky/include/asm/vdso.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#include <linux/types.h>
77

8+
#ifndef GENERIC_TIME_VSYSCALL
89
struct vdso_data {
910
};
11+
#endif
1012

1113
/*
1214
* The VDSO symbols are mapped into Linux so we can just use regular symbol
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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 */
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 */

arch/csky/kernel/perf_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int csky_pmu_irq;
8787
})
8888

8989
/* cycle counter */
90-
static uint64_t csky_pmu_read_cc(void)
90+
uint64_t csky_pmu_read_cc(void)
9191
{
9292
uint32_t lo, hi, tmp;
9393
uint64_t result;

0 commit comments

Comments
 (0)