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 | * |
| 7 | * The code should have no internal unresolved relocations. |
| 8 | * Check with readelf after changing. |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Ingo Molnar | 2b7d039 | 2008-11-12 13:17:38 +0100 | [diff] [blame] | 11 | /* Disable profiling for userspace code: */ |
Steven Rostedt | 2ed84ee | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 12 | #define DISABLE_BRANCH_PROFILING |
Ingo Molnar | 2b7d039 | 2008-11-12 13:17:38 +0100 | [diff] [blame] | 13 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/posix-timers.h> |
| 16 | #include <linux/time.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <asm/vsyscall.h> |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 19 | #include <asm/fixmap.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 20 | #include <asm/vgtod.h> |
| 21 | #include <asm/timex.h> |
| 22 | #include <asm/hpet.h> |
| 23 | #include <asm/unistd.h> |
| 24 | #include <asm/io.h> |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 25 | #include <asm/pvclock.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 26 | |
Andy Lutomirski | 8c49d9a | 2011-05-23 09:31:24 -0400 | [diff] [blame] | 27 | #define gtod (&VVAR(vsyscall_gtod_data)) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 28 | |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 29 | static notrace cycle_t vread_hpet(void) |
| 30 | { |
Satoru Takeuchi | 36dfbbf | 2013-02-15 16:58:14 +0900 | [diff] [blame] | 31 | return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + HPET_COUNTER); |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 34 | notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) |
| 35 | { |
| 36 | long ret; |
| 37 | asm("syscall" : "=a" (ret) : |
| 38 | "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : "memory"); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) |
| 43 | { |
| 44 | long ret; |
| 45 | |
| 46 | asm("syscall" : "=a" (ret) : |
| 47 | "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory"); |
| 48 | return ret; |
| 49 | } |
| 50 | |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 51 | #ifdef CONFIG_PARAVIRT_CLOCK |
| 52 | |
| 53 | static notrace const struct pvclock_vsyscall_time_info *get_pvti(int cpu) |
| 54 | { |
| 55 | const struct pvclock_vsyscall_time_info *pvti_base; |
| 56 | int idx = cpu / (PAGE_SIZE/PVTI_SIZE); |
| 57 | int offset = cpu % (PAGE_SIZE/PVTI_SIZE); |
| 58 | |
| 59 | BUG_ON(PVCLOCK_FIXMAP_BEGIN + idx > PVCLOCK_FIXMAP_END); |
| 60 | |
| 61 | pvti_base = (struct pvclock_vsyscall_time_info *) |
| 62 | __fix_to_virt(PVCLOCK_FIXMAP_BEGIN+idx); |
| 63 | |
| 64 | return &pvti_base[offset]; |
| 65 | } |
| 66 | |
| 67 | static notrace cycle_t vread_pvclock(int *mode) |
| 68 | { |
| 69 | const struct pvclock_vsyscall_time_info *pvti; |
| 70 | cycle_t ret; |
| 71 | u64 last; |
| 72 | u32 version; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 73 | u8 flags; |
| 74 | unsigned cpu, cpu1; |
| 75 | |
| 76 | |
| 77 | /* |
Marcelo Tosatti | e04c5d7 | 2013-07-10 22:21:57 -0300 | [diff] [blame] | 78 | * Note: hypervisor must guarantee that: |
| 79 | * 1. cpu ID number maps 1:1 to per-CPU pvclock time info. |
| 80 | * 2. that per-CPU pvclock time info is updated if the |
| 81 | * underlying CPU changes. |
| 82 | * 3. that version is increased whenever underlying CPU |
| 83 | * changes. |
| 84 | * |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 85 | */ |
| 86 | do { |
| 87 | cpu = __getcpu() & VGETCPU_CPU_MASK; |
| 88 | /* TODO: We can put vcpu id into higher bits of pvti.version. |
| 89 | * This will save a couple of cycles by getting rid of |
| 90 | * __getcpu() calls (Gleb). |
| 91 | */ |
| 92 | |
| 93 | pvti = get_pvti(cpu); |
| 94 | |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 95 | version = __pvclock_read_cycles(&pvti->pvti, &ret, &flags); |
| 96 | |
| 97 | /* |
| 98 | * Test we're still on the cpu as well as the version. |
| 99 | * We could have been migrated just after the first |
| 100 | * vgetcpu but before fetching the version, so we |
| 101 | * wouldn't notice a version change. |
| 102 | */ |
| 103 | cpu1 = __getcpu() & VGETCPU_CPU_MASK; |
| 104 | } while (unlikely(cpu != cpu1 || |
| 105 | (pvti->pvti.version & 1) || |
Marcelo Tosatti | e04c5d7 | 2013-07-10 22:21:57 -0300 | [diff] [blame] | 106 | pvti->pvti.version != version)); |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 107 | |
| 108 | if (unlikely(!(flags & PVCLOCK_TSC_STABLE_BIT))) |
| 109 | *mode = VCLOCK_NONE; |
| 110 | |
| 111 | /* refer to tsc.c read_tsc() comment for rationale */ |
Stefani Seibold | af8c93d | 2014-03-17 23:22:05 +0100 | [diff] [blame] | 112 | last = gtod->clock.cycle_last; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 113 | |
| 114 | if (likely(ret >= last)) |
| 115 | return ret; |
| 116 | |
| 117 | return last; |
| 118 | } |
| 119 | #endif |
| 120 | |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 121 | notrace static cycle_t vread_tsc(void) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 122 | { |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 123 | cycle_t ret; |
| 124 | u64 last; |
| 125 | |
| 126 | /* |
| 127 | * Empirically, a fence (of type that depends on the CPU) |
| 128 | * before rdtsc is enough to ensure that rdtsc is ordered |
| 129 | * with respect to loads. The various CPU manuals are unclear |
| 130 | * as to whether rdtsc can be reordered with later loads, |
| 131 | * but no one has ever seen it happen. |
| 132 | */ |
| 133 | rdtsc_barrier(); |
| 134 | ret = (cycle_t)vget_cycles(); |
| 135 | |
Stefani Seibold | af8c93d | 2014-03-17 23:22:05 +0100 | [diff] [blame] | 136 | last = gtod->clock.cycle_last; |
Stefani Seibold | 411f790 | 2014-03-17 23:22:03 +0100 | [diff] [blame] | 137 | |
| 138 | if (likely(ret >= last)) |
| 139 | return ret; |
| 140 | |
| 141 | /* |
| 142 | * GCC likes to generate cmov here, but this branch is extremely |
| 143 | * predictable (it's just a funciton of time and the likely is |
| 144 | * very likely) and there's a data dependence, so force GCC |
| 145 | * to generate a branch instead. I don't barrier() because |
| 146 | * we don't actually need a barrier, and if this function |
| 147 | * ever gets inlined it will generate worse code. |
| 148 | */ |
| 149 | asm volatile (""); |
| 150 | return last; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 153 | notrace static inline u64 vgetsns(int *mode) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 154 | { |
Andi Kleen | 95b0867 | 2007-09-11 14:02:09 +0200 | [diff] [blame] | 155 | long v; |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 156 | cycles_t cycles; |
| 157 | if (gtod->clock.vclock_mode == VCLOCK_TSC) |
| 158 | cycles = vread_tsc(); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 159 | else if (gtod->clock.vclock_mode == VCLOCK_HPET) |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 160 | cycles = vread_hpet(); |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 161 | #ifdef CONFIG_PARAVIRT_CLOCK |
| 162 | else if (gtod->clock.vclock_mode == VCLOCK_PVCLOCK) |
| 163 | cycles = vread_pvclock(mode); |
| 164 | #endif |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 165 | else |
| 166 | return 0; |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 167 | v = (cycles - gtod->clock.cycle_last) & gtod->clock.mask; |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 168 | return v * gtod->clock.mult; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Andy Lutomirski | 5f29347 | 2012-03-22 21:15:52 -0700 | [diff] [blame] | 171 | /* Code size doesn't matter (vdso is 4k anyway) and this is faster. */ |
| 172 | notrace static int __always_inline do_realtime(struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 173 | { |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 174 | unsigned long seq; |
| 175 | u64 ns; |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 176 | int mode; |
| 177 | |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 178 | ts->tv_nsec = 0; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 179 | do { |
John Stultz | 0c3351d | 2014-01-02 15:11:13 -0800 | [diff] [blame] | 180 | seq = raw_read_seqcount_begin(>od->seq); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 181 | mode = gtod->clock.vclock_mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 182 | ts->tv_sec = gtod->wall_time_sec; |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 183 | ns = gtod->wall_time_snsec; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 184 | ns += vgetsns(&mode); |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 185 | ns >>= gtod->clock.shift; |
Thomas Gleixner | 2ab5165 | 2012-02-28 19:46:04 +0000 | [diff] [blame] | 186 | } while (unlikely(read_seqcount_retry(>od->seq, seq))); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 187 | |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 188 | timespec_add_ns(ts, ns); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 189 | return mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Andy Lutomirski | 5f29347 | 2012-03-22 21:15:52 -0700 | [diff] [blame] | 192 | notrace static int do_monotonic(struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 193 | { |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 194 | unsigned long seq; |
| 195 | u64 ns; |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 196 | int mode; |
| 197 | |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 198 | ts->tv_nsec = 0; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 199 | do { |
John Stultz | 0c3351d | 2014-01-02 15:11:13 -0800 | [diff] [blame] | 200 | seq = raw_read_seqcount_begin(>od->seq); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 201 | mode = gtod->clock.vclock_mode; |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 202 | ts->tv_sec = gtod->monotonic_time_sec; |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 203 | ns = gtod->monotonic_time_snsec; |
Marcelo Tosatti | 51c19b4 | 2012-11-27 23:28:57 -0200 | [diff] [blame] | 204 | ns += vgetsns(&mode); |
John Stultz | 650ea02 | 2012-09-04 16:14:46 -0400 | [diff] [blame] | 205 | ns >>= gtod->clock.shift; |
Thomas Gleixner | 2ab5165 | 2012-02-28 19:46:04 +0000 | [diff] [blame] | 206 | } while (unlikely(read_seqcount_retry(>od->seq, seq))); |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 207 | timespec_add_ns(ts, ns); |
Andy Lutomirski | 0f51f28 | 2011-05-23 09:31:27 -0400 | [diff] [blame] | 208 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 209 | return mode; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 212 | notrace static void do_realtime_coarse(struct timespec *ts) |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 213 | { |
| 214 | unsigned long seq; |
| 215 | do { |
John Stultz | 0c3351d | 2014-01-02 15:11:13 -0800 | [diff] [blame] | 216 | seq = raw_read_seqcount_begin(>od->seq); |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 217 | ts->tv_sec = gtod->wall_time_coarse.tv_sec; |
| 218 | ts->tv_nsec = gtod->wall_time_coarse.tv_nsec; |
Thomas Gleixner | 2ab5165 | 2012-02-28 19:46:04 +0000 | [diff] [blame] | 219 | } while (unlikely(read_seqcount_retry(>od->seq, seq))); |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 222 | notrace static void do_monotonic_coarse(struct timespec *ts) |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 223 | { |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 224 | unsigned long seq; |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 225 | do { |
John Stultz | 0c3351d | 2014-01-02 15:11:13 -0800 | [diff] [blame] | 226 | seq = raw_read_seqcount_begin(>od->seq); |
Andy Lutomirski | 91ec87d | 2012-03-22 21:15:51 -0700 | [diff] [blame] | 227 | ts->tv_sec = gtod->monotonic_time_coarse.tv_sec; |
| 228 | ts->tv_nsec = gtod->monotonic_time_coarse.tv_nsec; |
Thomas Gleixner | 2ab5165 | 2012-02-28 19:46:04 +0000 | [diff] [blame] | 229 | } while (unlikely(read_seqcount_retry(>od->seq, seq))); |
john stultz | da15cfd | 2009-08-19 19:13:34 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Steven Rostedt | 23adec5 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 232 | notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 233 | { |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 234 | switch (clock) { |
| 235 | case CLOCK_REALTIME: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 236 | if (do_realtime(ts) == VCLOCK_NONE) |
| 237 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 238 | break; |
| 239 | case CLOCK_MONOTONIC: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 240 | if (do_monotonic(ts) == VCLOCK_NONE) |
| 241 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 242 | break; |
| 243 | case CLOCK_REALTIME_COARSE: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 244 | do_realtime_coarse(ts); |
| 245 | break; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 246 | case CLOCK_MONOTONIC_COARSE: |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 247 | do_monotonic_coarse(ts); |
| 248 | break; |
| 249 | default: |
| 250 | goto fallback; |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 251 | } |
| 252 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 253 | return 0; |
Stefani Seibold | ce39c64 | 2014-03-17 23:22:04 +0100 | [diff] [blame] | 254 | fallback: |
| 255 | return vdso_fallback_gettime(clock, ts); |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 256 | } |
| 257 | int clock_gettime(clockid_t, struct timespec *) |
| 258 | __attribute__((weak, alias("__vdso_clock_gettime"))); |
| 259 | |
Steven Rostedt | 23adec5 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 260 | notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 261 | { |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 262 | if (likely(tv != NULL)) { |
| 263 | BUILD_BUG_ON(offsetof(struct timeval, tv_usec) != |
| 264 | offsetof(struct timespec, tv_nsec) || |
| 265 | sizeof(*tv) != sizeof(struct timespec)); |
Stefani Seibold | 0df1ea2 | 2014-03-17 23:22:06 +0100 | [diff] [blame^] | 266 | if (unlikely(do_realtime((struct timespec *)tv) == VCLOCK_NONE)) |
| 267 | return vdso_fallback_gtod(tv, tz); |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 268 | tv->tv_usec /= 1000; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 269 | } |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 270 | if (unlikely(tz != NULL)) { |
| 271 | /* Avoid memcpy. Some old compilers fail to inline it */ |
| 272 | tz->tz_minuteswest = gtod->sys_tz.tz_minuteswest; |
| 273 | tz->tz_dsttime = gtod->sys_tz.tz_dsttime; |
| 274 | } |
| 275 | |
John Stultz | a939e81 | 2012-03-01 22:11:09 -0800 | [diff] [blame] | 276 | return 0; |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 277 | } |
| 278 | int gettimeofday(struct timeval *, struct timezone *) |
| 279 | __attribute__((weak, alias("__vdso_gettimeofday"))); |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 280 | |
Andy Lutomirski | 0d7b854 | 2011-06-05 13:50:20 -0400 | [diff] [blame] | 281 | /* |
| 282 | * This will break when the xtime seconds get inaccurate, but that is |
| 283 | * unlikely |
| 284 | */ |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 285 | notrace time_t __vdso_time(time_t *t) |
| 286 | { |
Andy Lutomirski | 973aa81 | 2011-05-23 09:31:31 -0400 | [diff] [blame] | 287 | /* This is atomic on x86_64 so we don't need any locks. */ |
Stefani Seibold | af8c93d | 2014-03-17 23:22:05 +0100 | [diff] [blame] | 288 | time_t result = ACCESS_ONCE(gtod->wall_time_sec); |
Andy Lutomirski | f144a6b | 2011-05-23 09:31:30 -0400 | [diff] [blame] | 289 | |
| 290 | if (t) |
| 291 | *t = result; |
| 292 | return result; |
| 293 | } |
| 294 | int time(time_t *t) |
| 295 | __attribute__((weak, alias("__vdso_time"))); |