Skip to content

Commit 44f57d7

Browse files
thule-vincenzoKAGA-KOKO
authored andcommitted
timekeeping: Provide a generic update_vsyscall() implementation
The new generic VDSO library allows to unify the update_vsyscall[_tz]() implementations. Provide a generic implementation based on the x86 code and the bindings which need to be implemented in architecture specific code. [ tglx: Moved it into kernel/time where it belongs. Removed the pointless line breaks in the stub functions. Massaged changelog ] Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Shijith Thotton <sthotton@marvell.com> Tested-by: Andre Przywara <andre.przywara@arm.com> Cc: linux-arch@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mips@vger.kernel.org Cc: linux-kselftest@vger.kernel.org Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Russell King <linux@armlinux.org.uk> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Burton <paul.burton@mips.com> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Mark Salyzyn <salyzyn@android.com> Cc: Peter Collingbourne <pcc@google.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Huw Davies <huw@codeweavers.com> Link: https://lkml.kernel.org/r/20190621095252.32307-4-vincenzo.frascino@arm.com
1 parent 629fdf7 commit 44f57d7

4 files changed

Lines changed: 195 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __ASM_GENERIC_VSYSCALL_H
3+
#define __ASM_GENERIC_VSYSCALL_H
4+
5+
#ifndef __ASSEMBLY__
6+
7+
#ifndef __arch_get_k_vdso_data
8+
static __always_inline struct vdso_data *__arch_get_k_vdso_data(void)
9+
{
10+
return NULL;
11+
}
12+
#endif /* __arch_get_k_vdso_data */
13+
14+
#ifndef __arch_update_vdso_data
15+
static __always_inline int __arch_update_vdso_data(void)
16+
{
17+
return 0;
18+
}
19+
#endif /* __arch_update_vdso_data */
20+
21+
#ifndef __arch_get_clock_mode
22+
static __always_inline int __arch_get_clock_mode(struct timekeeper *tk)
23+
{
24+
return 0;
25+
}
26+
#endif /* __arch_get_clock_mode */
27+
28+
#ifndef __arch_use_vsyscall
29+
static __always_inline int __arch_use_vsyscall(struct vdso_data *vdata)
30+
{
31+
return 1;
32+
}
33+
#endif /* __arch_use_vsyscall */
34+
35+
#ifndef __arch_update_vsyscall
36+
static __always_inline void __arch_update_vsyscall(struct vdso_data *vdata,
37+
struct timekeeper *tk)
38+
{
39+
}
40+
#endif /* __arch_update_vsyscall */
41+
42+
#ifndef __arch_sync_vdso_data
43+
static __always_inline void __arch_sync_vdso_data(struct vdso_data *vdata)
44+
{
45+
}
46+
#endif /* __arch_sync_vdso_data */
47+
48+
#endif /* !__ASSEMBLY__ */
49+
50+
#endif /* __ASM_GENERIC_VSYSCALL_H */

‎include/vdso/vsyscall.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __VDSO_VSYSCALL_H
3+
#define __VDSO_VSYSCALL_H
4+
5+
#ifndef __ASSEMBLY__
6+
7+
#include <asm/vdso/vsyscall.h>
8+
9+
#endif /* !__ASSEMBLY__ */
10+
11+
#endif /* __VDSO_VSYSCALL_H */

‎kernel/time/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
1616
endif
1717
obj-$(CONFIG_GENERIC_SCHED_CLOCK) += sched_clock.o
1818
obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o tick-sched.o
19+
obj-$(CONFIG_HAVE_GENERIC_VDSO) += vsyscall.o
1920
obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o
2021
obj-$(CONFIG_TEST_UDELAY) += test_udelay.o

‎kernel/time/vsyscall.c‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright 2019 ARM Ltd.
4+
*
5+
* Generic implementation of update_vsyscall and update_vsyscall_tz.
6+
*
7+
* Based on the x86 specific implementation.
8+
*/
9+
10+
#include <linux/hrtimer.h>
11+
#include <linux/timekeeper_internal.h>
12+
#include <vdso/datapage.h>
13+
#include <vdso/helpers.h>
14+
#include <vdso/vsyscall.h>
15+
16+
static inline void update_vdso_data(struct vdso_data *vdata,
17+
struct timekeeper *tk)
18+
{
19+
struct vdso_timestamp *vdso_ts;
20+
u64 nsec;
21+
22+
vdata[CS_HRES_COARSE].cycle_last = tk->tkr_mono.cycle_last;
23+
vdata[CS_HRES_COARSE].mask = tk->tkr_mono.mask;
24+
vdata[CS_HRES_COARSE].mult = tk->tkr_mono.mult;
25+
vdata[CS_HRES_COARSE].shift = tk->tkr_mono.shift;
26+
vdata[CS_RAW].cycle_last = tk->tkr_raw.cycle_last;
27+
vdata[CS_RAW].mask = tk->tkr_raw.mask;
28+
vdata[CS_RAW].mult = tk->tkr_raw.mult;
29+
vdata[CS_RAW].shift = tk->tkr_raw.shift;
30+
31+
/* CLOCK_REALTIME */
32+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME];
33+
vdso_ts->sec = tk->xtime_sec;
34+
vdso_ts->nsec = tk->tkr_mono.xtime_nsec;
35+
36+
/* CLOCK_MONOTONIC */
37+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC];
38+
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
39+
40+
nsec = tk->tkr_mono.xtime_nsec;
41+
nsec += ((u64)tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
42+
while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
43+
nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
44+
vdso_ts->sec++;
45+
}
46+
vdso_ts->nsec = nsec;
47+
48+
/* CLOCK_MONOTONIC_RAW */
49+
vdso_ts = &vdata[CS_RAW].basetime[CLOCK_MONOTONIC_RAW];
50+
vdso_ts->sec = tk->raw_sec;
51+
vdso_ts->nsec = tk->tkr_raw.xtime_nsec;
52+
53+
/* CLOCK_BOOTTIME */
54+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_BOOTTIME];
55+
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
56+
nsec = tk->tkr_mono.xtime_nsec;
57+
nsec += ((u64)(tk->wall_to_monotonic.tv_nsec +
58+
ktime_to_ns(tk->offs_boot)) << tk->tkr_mono.shift);
59+
while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
60+
nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
61+
vdso_ts->sec++;
62+
}
63+
vdso_ts->nsec = nsec;
64+
65+
/* CLOCK_TAI */
66+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_TAI];
67+
vdso_ts->sec = tk->xtime_sec + (s64)tk->tai_offset;
68+
vdso_ts->nsec = tk->tkr_mono.xtime_nsec;
69+
70+
/*
71+
* Read without the seqlock held by clock_getres().
72+
* Note: No need to have a second copy.
73+
*/
74+
WRITE_ONCE(vdata[CS_HRES_COARSE].hrtimer_res, hrtimer_resolution);
75+
}
76+
77+
void update_vsyscall(struct timekeeper *tk)
78+
{
79+
struct vdso_data *vdata = __arch_get_k_vdso_data();
80+
struct vdso_timestamp *vdso_ts;
81+
u64 nsec;
82+
83+
if (__arch_update_vdso_data()) {
84+
/*
85+
* Some architectures might want to skip the update of the
86+
* data page.
87+
*/
88+
return;
89+
}
90+
91+
/* copy vsyscall data */
92+
vdso_write_begin(vdata);
93+
94+
vdata[CS_HRES_COARSE].clock_mode = __arch_get_clock_mode(tk);
95+
vdata[CS_RAW].clock_mode = __arch_get_clock_mode(tk);
96+
97+
/* CLOCK_REALTIME_COARSE */
98+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME_COARSE];
99+
vdso_ts->sec = tk->xtime_sec;
100+
vdso_ts->nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
101+
102+
/* CLOCK_MONOTONIC_COARSE */
103+
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC_COARSE];
104+
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
105+
nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
106+
nsec = nsec + tk->wall_to_monotonic.tv_nsec;
107+
while (nsec >= NSEC_PER_SEC) {
108+
nsec = nsec - NSEC_PER_SEC;
109+
vdso_ts->sec++;
110+
}
111+
vdso_ts->nsec = nsec;
112+
113+
if (__arch_use_vsyscall(vdata))
114+
update_vdso_data(vdata, tk);
115+
116+
__arch_update_vsyscall(vdata, tk);
117+
118+
vdso_write_end(vdata);
119+
120+
__arch_sync_vdso_data(vdata);
121+
}
122+
123+
void update_vsyscall_tz(void)
124+
{
125+
struct vdso_data *vdata = __arch_get_k_vdso_data();
126+
127+
if (__arch_use_vsyscall(vdata)) {
128+
vdata[CS_HRES_COARSE].tz_minuteswest = sys_tz.tz_minuteswest;
129+
vdata[CS_HRES_COARSE].tz_dsttime = sys_tz.tz_dsttime;
130+
}
131+
132+
__arch_sync_vdso_data(vdata);
133+
}

0 commit comments

Comments
 (0)