hugetlb: introduce generic version of hugetlb_free_pgd_range
[linux/fpc-iii.git] / arch / x86 / entry / vsyscall / vsyscall_gtod.c
blobcfcdba082feb9f61e31c02ea260725b4d6ac7262
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
4 * Copyright 2003 Andi Kleen, SuSE Labs.
6 * Modified for x86 32 bit architecture by
7 * Stefani Seibold <stefani@seibold.net>
8 * sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany
10 * Thanks to hpa@transmeta.com for some useful hint.
11 * Special thanks to Ingo Molnar for his early experience with
12 * a different vsyscall implementation for Linux/IA32 and for the name.
16 #include <linux/timekeeper_internal.h>
17 #include <asm/vgtod.h>
18 #include <asm/vvar.h>
20 int vclocks_used __read_mostly;
22 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24 void update_vsyscall_tz(void)
26 vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest;
27 vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime;
30 void update_vsyscall(struct timekeeper *tk)
32 int vclock_mode = tk->tkr_mono.clock->archdata.vclock_mode;
33 struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data;
34 struct vgtod_ts *base;
35 u64 nsec;
37 /* Mark the new vclock used. */
38 BUILD_BUG_ON(VCLOCK_MAX >= 32);
39 WRITE_ONCE(vclocks_used, READ_ONCE(vclocks_used) | (1 << vclock_mode));
41 gtod_write_begin(vdata);
43 /* copy vsyscall data */
44 vdata->vclock_mode = vclock_mode;
45 vdata->cycle_last = tk->tkr_mono.cycle_last;
46 vdata->mask = tk->tkr_mono.mask;
47 vdata->mult = tk->tkr_mono.mult;
48 vdata->shift = tk->tkr_mono.shift;
50 base = &vdata->basetime[CLOCK_REALTIME];
51 base->sec = tk->xtime_sec;
52 base->nsec = tk->tkr_mono.xtime_nsec;
54 base = &vdata->basetime[CLOCK_TAI];
55 base->sec = tk->xtime_sec + (s64)tk->tai_offset;
56 base->nsec = tk->tkr_mono.xtime_nsec;
58 base = &vdata->basetime[CLOCK_MONOTONIC];
59 base->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
60 nsec = tk->tkr_mono.xtime_nsec;
61 nsec += ((u64)tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
62 while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
63 nsec -= ((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
64 base->sec++;
66 base->nsec = nsec;
68 base = &vdata->basetime[CLOCK_REALTIME_COARSE];
69 base->sec = tk->xtime_sec;
70 base->nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
72 base = &vdata->basetime[CLOCK_MONOTONIC_COARSE];
73 base->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
74 nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
75 nsec += tk->wall_to_monotonic.tv_nsec;
76 while (nsec >= NSEC_PER_SEC) {
77 nsec -= NSEC_PER_SEC;
78 base->sec++;
80 base->nsec = nsec;
82 gtod_write_end(vdata);