On Tue, Dec 10, 2013 at 10:23:17PM +1100, Vadim Rozenfeld wrote:
> On Mon, 2013-12-09 at 15:32 +0100, Paolo Bonzini wrote:
> > Il 08/12/2013 12:33, Vadim Rozenfeld ha scritto:
> > > +         tsc_ref.tsc_sequence =
> > > +                 boot_cpu_has(X86_FEATURE_CONSTANT_TSC) ? 1 : 0;
> > > +         tsc_ref.tsc_scale =
> > > +                 ((10000LL << 32) / vcpu->arch.virtual_tsc_khz) << 32;
> > > +         tsc_ref.tsc_offset = 0;
> > >           if (__copy_to_user((void __user *)addr, &tsc_ref, 
> > > sizeof(tsc_ref)))
> > >                   return 1;
> > >           mark_page_dirty(kvm, gfn);
> > >           kvm->arch.hv_tsc_page = data;
> > > +         kvm->arch.hv_ref_count = 0;
> > >           break;
> > >   }
> > >   default:
> > > @@ -3879,6 +3884,19 @@ long kvm_arch_vm_ioctl(struct file *filp,
> > >           local_irq_enable();
> > >           kvm->arch.kvmclock_offset = delta;
> > >           kvm_gen_update_masterclock(kvm);
> > > +
> > > +         if (kvm->arch.hv_tsc_page & HV_X64_MSR_TSC_REFERENCE_ENABLE) {
> > > +                 HV_REFERENCE_TSC_PAGE* tsc_ref;
> > > +                 u64 curr_time;
> > > +                 tsc_ref = (HV_REFERENCE_TSC_PAGE*)gfn_to_hva(kvm, 
> > > +                         kvm->arch.hv_tsc_page >> 
> > > HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);
> > > +                 tsc_ref->tsc_sequence =
> > > +                         boot_cpu_has(X86_FEATURE_CONSTANT_TSC) ? 
> > > tsc_ref->tsc_sequence + 1 : 0;
> > > +                 tsc_ref->tsc_scale = ((10000LL << 32) / 
> > > __get_cpu_var(cpu_tsc_khz)) << 32;
> > 
> > Why shouldn't this be vcpu->arch.virtual_tsc_khz?
> Yeah, I was thinking about that, but we need a vcpu instance for this.

Move it to kvm_guest_time_update time (which is necessary anyway for the
pvclock gtod notifier changes etc).

> > > +                 curr_time = (((tsc_ref->tsc_scale >> 32) * 
> > > native_read_tsc()) >> 32) + 
> > > +                         tsc_ref->tsc_offset;
> > > +                 tsc_ref->tsc_offset = kvm->arch.hv_ref_time - curr_time;
> > > +         }
> > 
> > The difference in setting tsc_ref->tsc_scale is the only important
> > change between the two occurrences.  If you can avoid that difference
> > and you move this to a separate function, you can reuse that new
> > function in set_msr_hyperv_pw as well.
> 
> Do you mean between HV_X64_MSR_REFERENCE_TSC which happens during
> partition creation time and KVM_SET_CLOCK which happens during resume 
> after partition pause? If so - there are several differences, where
> the offset calculation probably is the most important one.
> 
> Vadim.
> 
> > 
> > Also, kvm_set_tsc_khz should recompute the reference page's values as
> > well, so you'd have three uses.
> > 
> > Paolo
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to