Linux 4.11-rc5
[linux/fpc-iii.git] / arch / x86 / entry / vsyscall / vsyscall_gtod.c
blob0fb3a104ac626b07e0a4e604a8ebf36764bea2cf
1 /*
2 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
3 * Copyright 2003 Andi Kleen, SuSE Labs.
5 * Modified for x86 32 bit architecture by
6 * Stefani Seibold <stefani@seibold.net>
7 * sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany
9 * Thanks to hpa@transmeta.com for some useful hint.
10 * Special thanks to Ingo Molnar for his early experience with
11 * a different vsyscall implementation for Linux/IA32 and for the name.
15 #include <linux/timekeeper_internal.h>
16 #include <asm/vgtod.h>
17 #include <asm/vvar.h>
19 int vclocks_used __read_mostly;
21 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23 void update_vsyscall_tz(void)
25 vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest;
26 vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime;
29 void update_vsyscall(struct timekeeper *tk)
31 int vclock_mode = tk->tkr_mono.clock->archdata.vclock_mode;
32 struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data;
34 /* Mark the new vclock used. */
35 BUILD_BUG_ON(VCLOCK_MAX >= 32);
36 WRITE_ONCE(vclocks_used, READ_ONCE(vclocks_used) | (1 << vclock_mode));
38 gtod_write_begin(vdata);
40 /* copy vsyscall data */
41 vdata->vclock_mode = vclock_mode;
42 vdata->cycle_last = tk->tkr_mono.cycle_last;
43 vdata->mask = tk->tkr_mono.mask;
44 vdata->mult = tk->tkr_mono.mult;
45 vdata->shift = tk->tkr_mono.shift;
47 vdata->wall_time_sec = tk->xtime_sec;
48 vdata->wall_time_snsec = tk->tkr_mono.xtime_nsec;
50 vdata->monotonic_time_sec = tk->xtime_sec
51 + tk->wall_to_monotonic.tv_sec;
52 vdata->monotonic_time_snsec = tk->tkr_mono.xtime_nsec
53 + ((u64)tk->wall_to_monotonic.tv_nsec
54 << tk->tkr_mono.shift);
55 while (vdata->monotonic_time_snsec >=
56 (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
57 vdata->monotonic_time_snsec -=
58 ((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
59 vdata->monotonic_time_sec++;
62 vdata->wall_time_coarse_sec = tk->xtime_sec;
63 vdata->wall_time_coarse_nsec = (long)(tk->tkr_mono.xtime_nsec >>
64 tk->tkr_mono.shift);
66 vdata->monotonic_time_coarse_sec =
67 vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
68 vdata->monotonic_time_coarse_nsec =
69 vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
71 while (vdata->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
72 vdata->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
73 vdata->monotonic_time_coarse_sec++;
76 gtod_write_end(vdata);