~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/pvclock.h

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _ASM_X86_PVCLOCK_H
  3 #define _ASM_X86_PVCLOCK_H
  4 
  5 #include <linux/clocksource.h>
  6 #include <asm/pvclock-abi.h>
  7 
  8 /* some helper functions for xen and kvm pv clock sources */
  9 u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
 10 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src);
 11 void pvclock_set_flags(u8 flags);
 12 unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
 13 void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
 14                             struct pvclock_vcpu_time_info *vcpu,
 15                             struct timespec *ts);
 16 void pvclock_resume(void);
 17 
 18 void pvclock_touch_watchdogs(void);
 19 
 20 static __always_inline
 21 unsigned pvclock_read_begin(const struct pvclock_vcpu_time_info *src)
 22 {
 23         unsigned version = src->version & ~1;
 24         /* Make sure that the version is read before the data. */
 25         virt_rmb();
 26         return version;
 27 }
 28 
 29 static __always_inline
 30 bool pvclock_read_retry(const struct pvclock_vcpu_time_info *src,
 31                         unsigned version)
 32 {
 33         /* Make sure that the version is re-read after the data. */
 34         virt_rmb();
 35         return unlikely(version != src->version);
 36 }
 37 
 38 /*
 39  * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
 40  * yielding a 64-bit result.
 41  */
 42 static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
 43 {
 44         u64 product;
 45 #ifdef __i386__
 46         u32 tmp1, tmp2;
 47 #else
 48         ulong tmp;
 49 #endif
 50 
 51         if (shift < 0)
 52                 delta >>= -shift;
 53         else
 54                 delta <<= shift;
 55 
 56 #ifdef __i386__
 57         __asm__ (
 58                 "mul  %5       ; "
 59                 "mov  %4,%%eax ; "
 60                 "mov  %%edx,%4 ; "
 61                 "mul  %5       ; "
 62                 "xor  %5,%5    ; "
 63                 "add  %4,%%eax ; "
 64                 "adc  %5,%%edx ; "
 65                 : "=A" (product), "=r" (tmp1), "=r" (tmp2)
 66                 : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
 67 #elif defined(__x86_64__)
 68         __asm__ (
 69                 "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
 70                 : [lo]"=a"(product),
 71                   [hi]"=d"(tmp)
 72                 : ""(delta),
 73                   [mul_frac]"rm"((u64)mul_frac));
 74 #else
 75 #error implement me!
 76 #endif
 77 
 78         return product;
 79 }
 80 
 81 static __always_inline
 82 u64 __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src, u64 tsc)
 83 {
 84         u64 delta = tsc - src->tsc_timestamp;
 85         u64 offset = pvclock_scale_delta(delta, src->tsc_to_system_mul,
 86                                              src->tsc_shift);
 87         return src->system_time + offset;
 88 }
 89 
 90 struct pvclock_vsyscall_time_info {
 91         struct pvclock_vcpu_time_info pvti;
 92 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
 93 
 94 #define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
 95 
 96 #ifdef CONFIG_PARAVIRT_CLOCK
 97 void pvclock_set_pvti_cpu0_va(struct pvclock_vsyscall_time_info *pvti);
 98 struct pvclock_vsyscall_time_info *pvclock_get_pvti_cpu0_va(void);
 99 #else
100 static inline struct pvclock_vsyscall_time_info *pvclock_get_pvti_cpu0_va(void)
101 {
102         return NULL;
103 }
104 #endif
105 
106 #endif /* _ASM_X86_PVCLOCK_H */
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp