Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 248025
b: refs/heads/master
c: 1e99361
h: refs/heads/master
i:
  248023: feb618f
v: v3
  • Loading branch information
Joerg Roedel authored and Avi Kivity committed May 11, 2011
1 parent 59f4180 commit dbc430b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 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: fbc0db76b77125e0a5131fb886cbaafa1ec5c525
refs/heads/master: 1e993611d0dc879fde25515dc9867d1cfd4c5137
6 changes: 3 additions & 3 deletions trunk/arch/x86/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ struct kvm_vcpu_arch {
u64 last_kernel_ns;
u64 last_tsc_nsec;
u64 last_tsc_write;
u32 virtual_tsc_khz;
bool tsc_catchup;
u32 tsc_catchup_mult;
s8 tsc_catchup_shift;

bool nmi_pending;
bool nmi_injected;
Expand Down Expand Up @@ -466,9 +469,6 @@ struct kvm_arch {
u64 last_tsc_nsec;
u64 last_tsc_offset;
u64 last_tsc_write;
u32 virtual_tsc_khz;
u32 virtual_tsc_mult;
s8 virtual_tsc_shift;

struct kvm_xen_hvm_config xen_hvm_config;

Expand Down
25 changes: 15 additions & 10 deletions trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,14 @@ static inline int kvm_tsc_changes_freq(void)
return ret;
}

static u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu)
{
if (vcpu->arch.virtual_tsc_khz)
return vcpu->arch.virtual_tsc_khz;
else
return __this_cpu_read(cpu_tsc_khz);
}

static inline u64 nsec_to_cycles(u64 nsec)
{
u64 ret;
Expand All @@ -982,20 +990,19 @@ static inline u64 nsec_to_cycles(u64 nsec)
return ret;
}

static void kvm_arch_set_tsc_khz(struct kvm *kvm, u32 this_tsc_khz)
static void kvm_init_tsc_catchup(struct kvm_vcpu *vcpu, u32 this_tsc_khz)
{
/* Compute a scale to convert nanoseconds in TSC cycles */
kvm_get_time_scale(this_tsc_khz, NSEC_PER_SEC / 1000,
&kvm->arch.virtual_tsc_shift,
&kvm->arch.virtual_tsc_mult);
kvm->arch.virtual_tsc_khz = this_tsc_khz;
&vcpu->arch.tsc_catchup_shift,
&vcpu->arch.tsc_catchup_mult);
}

static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns)
{
u64 tsc = pvclock_scale_delta(kernel_ns-vcpu->arch.last_tsc_nsec,
vcpu->kvm->arch.virtual_tsc_mult,
vcpu->kvm->arch.virtual_tsc_shift);
vcpu->arch.tsc_catchup_mult,
vcpu->arch.tsc_catchup_shift);
tsc += vcpu->arch.last_tsc_write;
return tsc;
}
Expand Down Expand Up @@ -1062,8 +1069,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
local_irq_save(flags);
kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp);
kernel_ns = get_kernel_ns();
this_tsc_khz = __this_cpu_read(cpu_tsc_khz);

this_tsc_khz = vcpu_tsc_khz(v);
if (unlikely(this_tsc_khz == 0)) {
local_irq_restore(flags);
kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
Expand Down Expand Up @@ -6060,8 +6066,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
}
vcpu->arch.pio_data = page_address(page);

if (!kvm->arch.virtual_tsc_khz)
kvm_arch_set_tsc_khz(kvm, max_tsc_khz);
kvm_init_tsc_catchup(vcpu, max_tsc_khz);

r = kvm_mmu_create(vcpu);
if (r < 0)
Expand Down

0 comments on commit dbc430b

Please sign in to comment.