Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 Andi Kleen, SUSE Labs. |
| 3 | * Subject to the GNU Public License, v.2 |
| 4 | * |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 5 | * Fast user context implementation of clock_gettime, gettimeofday, and time. |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 6 | * |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 7 | * 32 Bit compat layer by Stefani Seibold <stefani@seibold.net> |
| 8 | * sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany |
| 9 | * |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 10 | * The code should have no internal unresolved relocations. |
| 11 | * Check with readelf after changing. |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 14 | #include <uapi/linux/time.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 15 | #include <asm/vgtod.h> |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 16 | #include <asm/vvar.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 17 | #include <asm/unistd.h> |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 18 | #include <asm/msr.h> |
Andy Lutomirski | 76480a6 | 2015-12-10 19:20:22 -0800 | [diff] [blame] | 19 | #include <asm/pvclock.h> |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 20 | #include <linux/math64.h> |
| 21 | #include <linux/time.h> |
Andy Lutomirski | 76480a6 | 2015-12-10 19:20:22 -0800 | [diff] [blame] | 22 | #include <linux/kernel.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 23 | |
Andy Lutomirski | 8c49d9a | 2011-05-23 09:31:24 -0400 | [diff] [blame] | 24 | #define gtod (&VVAR(vsyscall_gtod_data)) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 25 | |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 26 | extern int __vdso_clock_gettime(clockid_t clock, struct timespec *ts); |
| 27 | extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); |
| 28 | extern time_t __vdso_time(time_t *t); |
| 29 | |
Andy Lutomirski | dac16fb | 2015-12-10 19:20:20 -0800 | [diff] [blame] | 30 | #ifdef CONFIG_PARAVIRT_CLOCK |
| 31 | extern u8 pvclock_page |
| 32 | __attribute__((visibility("hidden"))); |
| 33 | #endif |
| 34 | |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 35 | #ifndef BUILD_VDSO32 |
| 36 | |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 37 | notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) |
| 38 | { |
| 39 | long ret; |
| 40 | asm("syscall" : "=a" (ret) : |
| 41 | "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : "memory"); |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) |
| 46 | { |
| 47 | long ret; |
| 48 | |
| 49 | asm("syscall" : "=a" (ret) : |
| 50 | "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory"); |
| 51 | return ret; |
| 52 | } |
| 53 | |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 54 | |
Andy Lutomirski | 76480a6 | 2015-12-10 19:20:22 -0800 | [diff] [blame] | 55 | #else |
| 56 | |
| 57 | notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) |
| 58 | { |
| 59 | long ret; |
| 60 | |
| 61 | asm( |
| 62 | "mov %%ebx, %%edx \n" |
| 63 | "mov %2, %%ebx \n" |
| 64 | "call __kernel_vsyscall \n" |
| 65 | "mov %%edx, %%ebx \n" |
| 66 | : "=a" (ret) |
| 67 | : "0" (__NR_clock_gettime), "g" (clock), "c" (ts) |
| 68 | : "memory", "edx"); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) |
| 73 | { |
| 74 | long ret; |
| 75 | |
| 76 | asm( |
| 77 | "mov %%ebx, %%edx \n" |
| 78 | "mov %2, %%ebx \n" |
| 79 | "call __kernel_vsyscall \n" |
| 80 | "mov %%edx, %%ebx \n" |
| 81 | : "=a" (ret) |
| 82 | : "0" (__NR_gettimeofday), "g" (tv), "c" (tz) |
| 83 | : "memory", "edx"); |
| 84 | return ret; |
| 85 | } |
| 86 | |
| 87 | #endif |
| 88 | |
| 89 | #ifdef CONFIG_PARAVIRT_CLOCK |
Andy Lutomirski | dac16fb | 2015-12-10 19:20:20 -0800 | [diff] [blame] | 90 | static notrace const struct pvclock_vsyscall_time_info *get_pvti0(void) |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 91 | { |
Andy Lutomirski | dac16fb | 2015-12-10 19:20:20 -0800 | [diff] [blame] | 92 | return (const struct pvclock_vsyscall_time_info *)&pvclock_page; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static notrace cycle_t vread_pvclock(int *mode) |
| 96 | { |
Andy Lutomirski | dac16fb | 2015-12-10 19:20:20 -0800 | [diff] [blame] | 97 | const struct pvclock_vcpu_time_info *pvti = &get_pvti0()->pvti; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 98 | cycle_t ret; |
Paolo Bonzini | abe9efa | 2016-06-09 20:12:34 +0200 | [diff] [blame] | 99 | u64 last; |
| 100 | u32 version; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 101 | |
| 102 | /* |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 103 | * Note: The kernel and hypervisor must guarantee that cpu ID |
| 104 | * number maps 1:1 to per-CPU pvclock time info. |
Paolo Bonzini | 73459e2 | 2015-04-23 13:20:18 +0200 | [diff] [blame] | 105 | * |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 106 | * Because the hypervisor is entirely unaware of guest userspace |
| 107 | * preemption, it cannot guarantee that per-CPU pvclock time |
| 108 | * info is updated if the underlying CPU changes or that that |
| 109 | * version is increased whenever underlying CPU changes. |
| 110 | * |
| 111 | * On KVM, we are guaranteed that pvti updates for any vCPU are |
| 112 | * atomic as seen by *all* vCPUs. This is an even stronger |
| 113 | * guarantee than we get with a normal seqlock. |
| 114 | * |
| 115 | * On Xen, we don't appear to have that guarantee, but Xen still |
| 116 | * supplies a valid seqlock using the version field. |
Andy Lutomirski | 78fd8c7 | 2016-01-04 15:14:28 -0800 | [diff] [blame] | 117 | * |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 118 | * We only do pvclock vdso timing at all if |
| 119 | * PVCLOCK_TSC_STABLE_BIT is set, and we interpret that bit to |
| 120 | * mean that all vCPUs have matching pvti and that the TSC is |
| 121 | * synced, so we can just look at vCPU 0's pvti. |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 122 | */ |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 123 | |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 124 | do { |
Paolo Bonzini | 3aed64f | 2016-06-09 13:06:08 +0200 | [diff] [blame] | 125 | version = pvclock_read_begin(pvti); |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 126 | |
Andy Lutomirski | 78fd8c7 | 2016-01-04 15:14:28 -0800 | [diff] [blame] | 127 | if (unlikely(!(pvti->flags & PVCLOCK_TSC_STABLE_BIT))) { |
| 128 | *mode = VCLOCK_NONE; |
| 129 | return 0; |
| 130 | } |
| 131 | |
Paolo Bonzini | 108b249 | 2016-09-01 14:21:03 +0200 | [diff] [blame] | 132 | ret = __pvclock_read_cycles(pvti, rdtsc_ordered()); |
Paolo Bonzini | 3aed64f | 2016-06-09 13:06:08 +0200 | [diff] [blame] | 133 | } while (pvclock_read_retry(pvti, version)); |
Andy Lutomirski | 6b078f5 | 2015-12-10 19:20:19 -0800 | [diff] [blame] | 134 | |
Andy Lutomirski | 76480a6 | 2015-12-10 19:20:22 -0800 | [diff] [blame] | 135 | /* refer to vread_tsc() comment for rationale */ |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 136 | last = gtod->cycle_last; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 137 | |
| 138 | if (likely(ret >= last)) |
| 139 | return ret; |
| 140 | |
| 141 | return last; |
| 142 | } |
| 143 | #endif |
| 144 | |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 145 | notrace static cycle_t vread_tsc(void) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 146 | { |
Andy Lutomirski | 03b9730 | 2015-06-25 18:44:08 +0200 | [diff] [blame] | 147 | cycle_t ret = (cycle_t)rdtsc_ordered(); |
| 148 | u64 last = gtod->cycle_last; |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 149 | |
| 150 | if (likely(ret >= last)) |
| 151 | return ret; |
| 152 | |
| 153 | /* |
| 154 | * GCC likes to generate cmov here, but this branch is extremely |
Adam Buchbinder | 6a6256f | 2016-02-23 15:34:30 -0800 | [diff] [blame] | 155 | * predictable (it's just a function of time and the likely is |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 156 | * very likely) and there's a data dependence, so force GCC |
| 157 | * to generate a branch instead. I don't barrier() because |
| 158 | * we don't actually need a barrier, and if this function |
| 159 | * ever gets inlined it will generate worse code. |
| 160 | */ |
| 161 | asm volatile (""); |
| 162 | return last; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 165 | notrace static inline u64 vgetsns(int *mode) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 166 | { |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 167 | u64 v; |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 168 | cycles_t cycles; |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 169 | |
| 170 | if (gtod->vclock_mode == VCLOCK_TSC) |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 171 | cycles = vread_tsc(); |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 172 | #ifdef CONFIG_PARAVIRT_CLOCK |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 173 | else if (gtod->vclock_mode == VCLOCK_PVCLOCK) |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 174 | cycles = vread_pvclock(mode); |
| 175 | #endif |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 176 | else |
| 177 | return 0; |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 178 | v = (cycles - gtod->cycle_last) & gtod->mask; |
| 179 | return v * gtod->mult; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Andy Lutomirski | 5f29347 | 2012-03-22 21:15:52 -0700 | [diff] [blame] | 182 | /* Code size doesn't matter (vdso is 4k anyway) and this is faster. */ |
| 183 | notrace static int __always_inline do_realtime(struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 184 | { |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 185 | unsigned long seq; |
| 186 | u64 ns; |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 187 | int mode; |
| 188 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 189 | do { |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 190 | seq = gtod_read_begin(gtod); |
| 191 | mode = gtod->vclock_mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 192 | ts->tv_sec = gtod->wall_time_sec; |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 193 | ns = gtod->wall_time_snsec; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 194 | ns += vgetsns(&mode); |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 195 | ns >>= gtod->shift; |
| 196 | } while (unlikely(gtod_read_retry(gtod, seq))); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 197 | |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 198 | ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); |
| 199 | ts->tv_nsec = ns; |
| 200 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 201 | return mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 204 | notrace static int __always_inline do_monotonic(struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 205 | { |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 206 | unsigned long seq; |
| 207 | u64 ns; |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 208 | int mode; |
| 209 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 210 | do { |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 211 | seq = gtod_read_begin(gtod); |
| 212 | mode = gtod->vclock_mode; |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 213 | ts->tv_sec = gtod->monotonic_time_sec; |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 214 | ns = gtod->monotonic_time_snsec; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 215 | ns += vgetsns(&mode); |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 216 | ns >>= gtod->shift; |
| 217 | } while (unlikely(gtod_read_retry(gtod, seq))); |
| 218 | |
| 219 | ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); |
| 220 | ts->tv_nsec = ns; |
Andy Lutomirski | 0f51f28 | 2011-05-23 09:31:27 -0400 | [diff] [blame] | 221 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 222 | return mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 225 | notrace static void do_realtime_coarse(struct timespec *ts) |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 226 | { |
| 227 | unsigned long seq; |
| 228 | do { |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 229 | seq = gtod_read_begin(gtod); |
| 230 | ts->tv_sec = gtod->wall_time_coarse_sec; |
| 231 | ts->tv_nsec = gtod->wall_time_coarse_nsec; |
| 232 | } while (unlikely(gtod_read_retry(gtod, seq))); |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 235 | notrace static void do_monotonic_coarse(struct timespec *ts) |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 236 | { |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 237 | unsigned long seq; |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 238 | do { |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 239 | seq = gtod_read_begin(gtod); |
| 240 | ts->tv_sec = gtod->monotonic_time_coarse_sec; |
| 241 | ts->tv_nsec = gtod->monotonic_time_coarse_nsec; |
| 242 | } while (unlikely(gtod_read_retry(gtod, seq))); |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Steven Rostedt | 23adec5 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 245 | notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 246 | { |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 247 | switch (clock) { |
| 248 | case CLOCK_REALTIME: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 249 | if (do_realtime(ts) == VCLOCK_NONE) |
| 250 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 251 | break; |
| 252 | case CLOCK_MONOTONIC: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 253 | if (do_monotonic(ts) == VCLOCK_NONE) |
| 254 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 255 | break; |
| 256 | case CLOCK_REALTIME_COARSE: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 257 | do_realtime_coarse(ts); |
| 258 | break; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 259 | case CLOCK_MONOTONIC_COARSE: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 260 | do_monotonic_coarse(ts); |
| 261 | break; |
| 262 | default: |
| 263 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 264 | } |
| 265 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 266 | return 0; |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 267 | fallback: |
| 268 | return vdso_fallback_gettime(clock, ts); |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 269 | } |
| 270 | int clock_gettime(clockid_t, struct timespec *) |
| 271 | __attribute__((weak, alias("__vdso_clock_gettime"))); |
| 272 | |
Steven Rostedt | 23adec5 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 273 | notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 274 | { |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 275 | if (likely(tv != NULL)) { |
Stefani Seibold | 0df1ea2 | 2014-03-17 23:22:06 +0100 | [diff] [blame] | 276 | if (unlikely(do_realtime((struct timespec *)tv) == VCLOCK_NONE)) |
| 277 | return vdso_fallback_gtod(tv, tz); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 278 | tv->tv_usec /= 1000; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 279 | } |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 280 | if (unlikely(tz != NULL)) { |
Stefani Seibold | 7c03156 | 2014-03-17 23:22:10 +0100 | [diff] [blame] | 281 | tz->tz_minuteswest = gtod->tz_minuteswest; |
| 282 | tz->tz_dsttime = gtod->tz_dsttime; |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 283 | } |
| 284 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 285 | return 0; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 286 | } |
| 287 | int gettimeofday(struct timeval *, struct timezone *) |
| 288 | __attribute__((weak, alias("__vdso_gettimeofday"))); |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 289 | |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 290 | /* |
| 291 | * This will break when the xtime seconds get inaccurate, but that is |
| 292 | * unlikely |
| 293 | */ |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 294 | notrace time_t __vdso_time(time_t *t) |
| 295 | { |
Stefani Seibold | 7a59ed4 | 2014-03-17 23:22:09 +0100 | [diff] [blame] | 296 | /* This is atomic on x86 so we don't need any locks. */ |
Stefani Seibold | af8c93d | 2014-03-17 23:22:05 +0100 | [diff] [blame] | 297 | time_t result = ACCESS_ONCE(gtod->wall_time_sec); |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 298 | |
| 299 | if (t) |
| 300 | *t = result; |
| 301 | return result; |
| 302 | } |
| 303 | int time(time_t *t) |
| 304 | __attribute__((weak, alias("__vdso_time"))); |