Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 372987
b: refs/heads/master
c: 03ba32c
h: refs/heads/master
i:
  372985: 63d49da
  372983: 96852f8
v: v3
  • Loading branch information
Marcelo Tosatti authored and Gleb Natapov committed Mar 12, 2013
1 parent 4aee992 commit fd47b5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 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: 0fa24ce3f57144e390a1566774c23434975a52a9
refs/heads/master: 03ba32cae66e3798d697e582633af2c7dd6907e5
29 changes: 18 additions & 11 deletions trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ static void kvm_set_tsc_khz(struct kvm_vcpu *vcpu, u32 this_tsc_khz)
u32 thresh_lo, thresh_hi;
int use_scaling = 0;

/* tsc_khz can be zero if TSC calibration fails */
if (this_tsc_khz == 0)
return;

/* Compute a scale to convert nanoseconds in TSC cycles */
kvm_get_time_scale(this_tsc_khz, NSEC_PER_SEC / 1000,
&vcpu->arch.virtual_tsc_shift,
Expand Down Expand Up @@ -1156,20 +1160,23 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr)
ns = get_kernel_ns();
elapsed = ns - kvm->arch.last_tsc_nsec;

/* n.b - signed multiplication and division required */
usdiff = data - kvm->arch.last_tsc_write;
if (vcpu->arch.virtual_tsc_khz) {
/* n.b - signed multiplication and division required */
usdiff = data - kvm->arch.last_tsc_write;
#ifdef CONFIG_X86_64
usdiff = (usdiff * 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"(usdiff)
: "A"(usdiff * 1000), "rm"(vcpu->arch.virtual_tsc_khz));
/* do_div() only does unsigned */
asm("idivl %2; xor %%edx, %%edx"
: "=A"(usdiff)
: "A"(usdiff * 1000), "rm"(vcpu->arch.virtual_tsc_khz));
#endif
do_div(elapsed, 1000);
usdiff -= elapsed;
if (usdiff < 0)
usdiff = -usdiff;
do_div(elapsed, 1000);
usdiff -= elapsed;
if (usdiff < 0)
usdiff = -usdiff;
} else
usdiff = USEC_PER_SEC; /* disable TSC match window below */

/*
* Special case: TSC write with a small delta (1 second) of virtual
Expand Down

0 comments on commit fd47b5a

Please sign in to comment.