Linux 4.1.18
[linux/fpc-iii.git] / arch / x86 / kernel / vsyscall_gtod.c
blob51e3304169951619362ea4a1494716e4f20696bf
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 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21 void update_vsyscall_tz(void)
23 vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest;
24 vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime;
27 void update_vsyscall(struct timekeeper *tk)
29 struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data;
31 gtod_write_begin(vdata);
33 /* copy vsyscall data */
34 vdata->vclock_mode = tk->tkr_mono.clock->archdata.vclock_mode;
35 vdata->cycle_last = tk->tkr_mono.cycle_last;
36 vdata->mask = tk->tkr_mono.mask;
37 vdata->mult = tk->tkr_mono.mult;
38 vdata->shift = tk->tkr_mono.shift;
40 vdata->wall_time_sec = tk->xtime_sec;
41 vdata->wall_time_snsec = tk->tkr_mono.xtime_nsec;
43 vdata->monotonic_time_sec = tk->xtime_sec
44 + tk->wall_to_monotonic.tv_sec;
45 vdata->monotonic_time_snsec = tk->tkr_mono.xtime_nsec
46 + ((u64)tk->wall_to_monotonic.tv_nsec
47 << tk->tkr_mono.shift);
48 while (vdata->monotonic_time_snsec >=
49 (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
50 vdata->monotonic_time_snsec -=
51 ((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
52 vdata->monotonic_time_sec++;
55 vdata->wall_time_coarse_sec = tk->xtime_sec;
56 vdata->wall_time_coarse_nsec = (long)(tk->tkr_mono.xtime_nsec >>
57 tk->tkr_mono.shift);
59 vdata->monotonic_time_coarse_sec =
60 vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
61 vdata->monotonic_time_coarse_nsec =
62 vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
64 while (vdata->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
65 vdata->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
66 vdata->monotonic_time_coarse_sec++;
69 gtod_write_end(vdata);