diff options
author | Zachary Amsden <zamsden@redhat.com> | 2010-08-20 04:07:29 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:51:24 -0400 |
commit | 347bb4448c2155eb2310923ccaa4be5677649003 (patch) | |
tree | 93f5592975413c00c6c647001d715324e27cf985 | |
parent | ca84d1a24c376e0841f35db08dab7b829c8c0b1e (diff) |
x86: pvclock: Move scale_delta into common header
The scale_delta function for shift / multiply with 31-bit
precision moves to a common header so it can be used by both
kernel and kvm module.
Signed-off-by: Zachary Amsden <zamsden@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r-- | arch/x86/include/asm/pvclock.h | 38 | ||||
-rw-r--r-- | arch/x86/kernel/pvclock.c | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h index cd02f324aa6b..7f7e577a0e39 100644 --- a/arch/x86/include/asm/pvclock.h +++ b/arch/x86/include/asm/pvclock.h | |||
@@ -12,4 +12,42 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall, | |||
12 | struct pvclock_vcpu_time_info *vcpu, | 12 | struct pvclock_vcpu_time_info *vcpu, |
13 | struct timespec *ts); | 13 | struct timespec *ts); |
14 | 14 | ||
15 | /* | ||
16 | * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, | ||
17 | * yielding a 64-bit result. | ||
18 | */ | ||
19 | static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift) | ||
20 | { | ||
21 | u64 product; | ||
22 | #ifdef __i386__ | ||
23 | u32 tmp1, tmp2; | ||
24 | #endif | ||
25 | |||
26 | if (shift < 0) | ||
27 | delta >>= -shift; | ||
28 | else | ||
29 | delta <<= shift; | ||
30 | |||
31 | #ifdef __i386__ | ||
32 | __asm__ ( | ||
33 | "mul %5 ; " | ||
34 | "mov %4,%%eax ; " | ||
35 | "mov %%edx,%4 ; " | ||
36 | "mul %5 ; " | ||
37 | "xor %5,%5 ; " | ||
38 | "add %4,%%eax ; " | ||
39 | "adc %5,%%edx ; " | ||
40 | : "=A" (product), "=r" (tmp1), "=r" (tmp2) | ||
41 | : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) ); | ||
42 | #elif defined(__x86_64__) | ||
43 | __asm__ ( | ||
44 | "mul %%rdx ; shrd $32,%%rdx,%%rax" | ||
45 | : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) ); | ||
46 | #else | ||
47 | #error implement me! | ||
48 | #endif | ||
49 | |||
50 | return product; | ||
51 | } | ||
52 | |||
15 | #endif /* _ASM_X86_PVCLOCK_H */ | 53 | #endif /* _ASM_X86_PVCLOCK_H */ |
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c index 239427ca02af..bab3b9e6f66d 100644 --- a/arch/x86/kernel/pvclock.c +++ b/arch/x86/kernel/pvclock.c | |||
@@ -82,7 +82,8 @@ static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) | |||
82 | static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow) | 82 | static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow) |
83 | { | 83 | { |
84 | u64 delta = native_read_tsc() - shadow->tsc_timestamp; | 84 | u64 delta = native_read_tsc() - shadow->tsc_timestamp; |
85 | return scale_delta(delta, shadow->tsc_to_nsec_mul, shadow->tsc_shift); | 85 | return pvclock_scale_delta(delta, shadow->tsc_to_nsec_mul, |
86 | shadow->tsc_shift); | ||
86 | } | 87 | } |
87 | 88 | ||
88 | /* | 89 | /* |