Merge branches 'pm-opp-fixes', 'pm-cpufreq-fixes' and 'pm-cpuidle-fixes'
[deliverable/linux.git] / arch / x86 / include / asm / vgtod.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_VGTOD_H
2#define _ASM_X86_VGTOD_H
2aae950b 3
7c03156f 4#include <linux/compiler.h>
2aae950b
AK
5#include <linux/clocksource.h>
6
7c03156f
SS
7#ifdef BUILD_VDSO32_64
8typedef u64 gtod_long_t;
9#else
10typedef unsigned long gtod_long_t;
11#endif
12/*
13 * vsyscall_gtod_data will be accessed by 32 and 64 bit code at the same time
14 * so be carefull by modifying this structure.
15 */
2aae950b 16struct vsyscall_gtod_data {
7c03156f 17 unsigned seq;
2aae950b 18
7c03156f
SS
19 int vclock_mode;
20 cycle_t cycle_last;
21 cycle_t mask;
22 u32 mult;
23 u32 shift;
91ec87d5
AL
24
25 /* open coded 'struct timespec' */
650ea024 26 u64 wall_time_snsec;
7c03156f
SS
27 gtod_long_t wall_time_sec;
28 gtod_long_t monotonic_time_sec;
650ea024 29 u64 monotonic_time_snsec;
7c03156f
SS
30 gtod_long_t wall_time_coarse_sec;
31 gtod_long_t wall_time_coarse_nsec;
32 gtod_long_t monotonic_time_coarse_sec;
33 gtod_long_t monotonic_time_coarse_nsec;
91ec87d5 34
7c03156f
SS
35 int tz_minuteswest;
36 int tz_dsttime;
2aae950b 37};
2aae950b
AK
38extern struct vsyscall_gtod_data vsyscall_gtod_data;
39
bd902c53
AL
40extern int vclocks_used;
41static inline bool vclock_was_used(int vclock)
42{
43 return READ_ONCE(vclocks_used) & (1 << vclock);
44}
45
7c03156f
SS
46static inline unsigned gtod_read_begin(const struct vsyscall_gtod_data *s)
47{
48 unsigned ret;
49
50repeat:
51 ret = ACCESS_ONCE(s->seq);
52 if (unlikely(ret & 1)) {
53 cpu_relax();
54 goto repeat;
55 }
56 smp_rmb();
57 return ret;
58}
59
60static inline int gtod_read_retry(const struct vsyscall_gtod_data *s,
61 unsigned start)
62{
63 smp_rmb();
64 return unlikely(s->seq != start);
65}
66
67static inline void gtod_write_begin(struct vsyscall_gtod_data *s)
68{
69 ++s->seq;
70 smp_wmb();
71}
72
73static inline void gtod_write_end(struct vsyscall_gtod_data *s)
74{
75 smp_wmb();
76 ++s->seq;
77}
78
e76b027e
AL
79#ifdef CONFIG_X86_64
80
81#define VGETCPU_CPU_MASK 0xfff
82
83static inline unsigned int __getcpu(void)
84{
85 unsigned int p;
86
87 /*
88 * Load per CPU data from GDT. LSL is faster than RDTSCP and
1ddf0b1b
AL
89 * works on all CPUs. This is volatile so that it orders
90 * correctly wrt barrier() and to keep gcc from cleverly
91 * hoisting it out of the calling function.
e76b027e 92 */
1ddf0b1b 93 asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
e76b027e
AL
94
95 return p;
96}
97
98#endif /* CONFIG_X86_64 */
99
1965aae3 100#endif /* _ASM_X86_VGTOD_H */
This page took 0.559043 seconds and 5 git commands to generate.