Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 297173
b: refs/heads/master
c: 02626b6
h: refs/heads/master
i:
  297171: 8f89785
v: v3
  • Loading branch information
Marcelo Tosatti authored and Avi Kivity committed Mar 20, 2012
1 parent a7dbe3e commit 4a5c3fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b74f05d61b73af584d0c39121980171389ecfaaa
refs/heads/master: 02626b6af5d2bc62db3bb85fc2891b2725535d44
19 changes: 10 additions & 9 deletions trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,26 +1025,27 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data)
struct kvm *kvm = vcpu->kvm;
u64 offset, ns, elapsed;
unsigned long flags;
s64 nsdiff;
s64 usdiff;

raw_spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags);
offset = kvm_x86_ops->compute_tsc_offset(vcpu, data);
ns = get_kernel_ns();
elapsed = ns - kvm->arch.last_tsc_nsec;

/* n.b - signed multiplication and division required */
nsdiff = data - kvm->arch.last_tsc_write;
usdiff = data - kvm->arch.last_tsc_write;
#ifdef CONFIG_X86_64
nsdiff = (nsdiff * 1000) / vcpu->arch.virtual_tsc_khz;
usdiff = (usdiff * 1000) / vcpu->arch.virtual_tsc_khz;
#else
/* do_div() only does unsigned */
asm("idivl %2; xor %%edx, %%edx"
: "=A"(nsdiff)
: "A"(nsdiff * 1000), "rm"(vcpu->arch.virtual_tsc_khz));
: "=A"(usdiff)
: "A"(usdiff * 1000), "rm"(vcpu->arch.virtual_tsc_khz));
#endif
nsdiff -= elapsed;
if (nsdiff < 0)
nsdiff = -nsdiff;
do_div(elapsed, 1000);
usdiff -= elapsed;
if (usdiff < 0)
usdiff = -usdiff;

/*
* Special case: TSC write with a small delta (1 second) of virtual
Expand All @@ -1056,7 +1057,7 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data)
* compensation code attempt to catch up if we fall behind, but
* it's better to try to match offsets from the beginning.
*/
if (nsdiff < NSEC_PER_SEC &&
if (usdiff < USEC_PER_SEC &&
vcpu->arch.virtual_tsc_khz == kvm->arch.last_tsc_khz) {
if (!check_tsc_unstable()) {
offset = kvm->arch.cur_tsc_offset;
Expand Down

0 comments on commit 4a5c3fe

Please sign in to comment.