This source file includes following definitions.
- clock_gettime_fallback
- gettimeofday_fallback
- clock_getres_fallback
- clock_gettime_fallback
- clock_gettime32_fallback
- gettimeofday_fallback
- clock_getres_fallback
- clock_getres32_fallback
- vread_pvclock
- vread_hvclock
- __arch_get_hw_counter
- __arch_get_vdso_data
- vdso_calc_delta
1
2
3
4
5
6
7
8
9
10 #ifndef __ASM_VDSO_GETTIMEOFDAY_H
11 #define __ASM_VDSO_GETTIMEOFDAY_H
12
13 #ifndef __ASSEMBLY__
14
15 #include <uapi/linux/time.h>
16 #include <asm/vgtod.h>
17 #include <asm/vvar.h>
18 #include <asm/unistd.h>
19 #include <asm/msr.h>
20 #include <asm/pvclock.h>
21 #include <clocksource/hyperv_timer.h>
22
23 #define __vdso_data (VVAR(_vdso_data))
24
25 #define VDSO_HAS_TIME 1
26
27 #define VDSO_HAS_CLOCK_GETRES 1
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 #ifdef CONFIG_PARAVIRT_CLOCK
45
46
47
48
49
50 extern struct pvclock_vsyscall_time_info pvclock_page
51 __attribute__((visibility("hidden")));
52 #endif
53
54 #ifdef CONFIG_HYPERV_TIMER
55 extern struct ms_hyperv_tsc_page hvclock_page
56 __attribute__((visibility("hidden")));
57 #endif
58
59 #ifndef BUILD_VDSO32
60
61 static __always_inline
62 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
63 {
64 long ret;
65
66 asm ("syscall" : "=a" (ret), "=m" (*_ts) :
67 "0" (__NR_clock_gettime), "D" (_clkid), "S" (_ts) :
68 "rcx", "r11");
69
70 return ret;
71 }
72
73 static __always_inline
74 long gettimeofday_fallback(struct __kernel_old_timeval *_tv,
75 struct timezone *_tz)
76 {
77 long ret;
78
79 asm("syscall" : "=a" (ret) :
80 "0" (__NR_gettimeofday), "D" (_tv), "S" (_tz) : "memory");
81
82 return ret;
83 }
84
85 static __always_inline
86 long clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
87 {
88 long ret;
89
90 asm ("syscall" : "=a" (ret), "=m" (*_ts) :
91 "0" (__NR_clock_getres), "D" (_clkid), "S" (_ts) :
92 "rcx", "r11");
93
94 return ret;
95 }
96
97 #else
98
99 #define VDSO_HAS_32BIT_FALLBACK 1
100
101 static __always_inline
102 long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
103 {
104 long ret;
105
106 asm (
107 "mov %%ebx, %%edx \n"
108 "mov %[clock], %%ebx \n"
109 "call __kernel_vsyscall \n"
110 "mov %%edx, %%ebx \n"
111 : "=a" (ret), "=m" (*_ts)
112 : "0" (__NR_clock_gettime64), [clock] "g" (_clkid), "c" (_ts)
113 : "edx");
114
115 return ret;
116 }
117
118 static __always_inline
119 long clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
120 {
121 long ret;
122
123 asm (
124 "mov %%ebx, %%edx \n"
125 "mov %[clock], %%ebx \n"
126 "call __kernel_vsyscall \n"
127 "mov %%edx, %%ebx \n"
128 : "=a" (ret), "=m" (*_ts)
129 : "0" (__NR_clock_gettime), [clock] "g" (_clkid), "c" (_ts)
130 : "edx");
131
132 return ret;
133 }
134
135 static __always_inline
136 long gettimeofday_fallback(struct __kernel_old_timeval *_tv,
137 struct timezone *_tz)
138 {
139 long ret;
140
141 asm(
142 "mov %%ebx, %%edx \n"
143 "mov %2, %%ebx \n"
144 "call __kernel_vsyscall \n"
145 "mov %%edx, %%ebx \n"
146 : "=a" (ret)
147 : "0" (__NR_gettimeofday), "g" (_tv), "c" (_tz)
148 : "memory", "edx");
149
150 return ret;
151 }
152
153 static __always_inline long
154 clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
155 {
156 long ret;
157
158 asm (
159 "mov %%ebx, %%edx \n"
160 "mov %[clock], %%ebx \n"
161 "call __kernel_vsyscall \n"
162 "mov %%edx, %%ebx \n"
163 : "=a" (ret), "=m" (*_ts)
164 : "0" (__NR_clock_getres_time64), [clock] "g" (_clkid), "c" (_ts)
165 : "edx");
166
167 return ret;
168 }
169
170 static __always_inline
171 long clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts)
172 {
173 long ret;
174
175 asm (
176 "mov %%ebx, %%edx \n"
177 "mov %[clock], %%ebx \n"
178 "call __kernel_vsyscall \n"
179 "mov %%edx, %%ebx \n"
180 : "=a" (ret), "=m" (*_ts)
181 : "0" (__NR_clock_getres), [clock] "g" (_clkid), "c" (_ts)
182 : "edx");
183
184 return ret;
185 }
186
187 #endif
188
189 #ifdef CONFIG_PARAVIRT_CLOCK
190 static u64 vread_pvclock(void)
191 {
192 const struct pvclock_vcpu_time_info *pvti = &pvclock_page.pvti;
193 u32 version;
194 u64 ret;
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 do {
219 version = pvclock_read_begin(pvti);
220
221 if (unlikely(!(pvti->flags & PVCLOCK_TSC_STABLE_BIT)))
222 return U64_MAX;
223
224 ret = __pvclock_read_cycles(pvti, rdtsc_ordered());
225 } while (pvclock_read_retry(pvti, version));
226
227 return ret;
228 }
229 #endif
230
231 #ifdef CONFIG_HYPERV_TIMER
232 static u64 vread_hvclock(void)
233 {
234 return hv_read_tsc_page(&hvclock_page);
235 }
236 #endif
237
238 static inline u64 __arch_get_hw_counter(s32 clock_mode)
239 {
240 if (clock_mode == VCLOCK_TSC)
241 return (u64)rdtsc_ordered();
242
243
244
245
246
247
248 #ifdef CONFIG_PARAVIRT_CLOCK
249 if (clock_mode == VCLOCK_PVCLOCK) {
250 barrier();
251 return vread_pvclock();
252 }
253 #endif
254 #ifdef CONFIG_HYPERV_TIMER
255 if (clock_mode == VCLOCK_HVCLOCK) {
256 barrier();
257 return vread_hvclock();
258 }
259 #endif
260 return U64_MAX;
261 }
262
263 static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
264 {
265 return __vdso_data;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 static __always_inline
287 u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult)
288 {
289 if (cycles > last)
290 return (cycles - last) * mult;
291 return 0;
292 }
293 #define vdso_calc_delta vdso_calc_delta
294
295 #endif
296
297 #endif