[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RESEND 1/2] kvmclock: use a light weight interface to
From: |
Li, Liang Z |
Subject: |
Re: [Qemu-devel] [RESEND 1/2] kvmclock: use a light weight interface to update env->tsc. |
Date: |
Mon, 2 Nov 2015 15:11:16 +0000 |
> This can be simplified a bit:
>
> int kvm_get_tsc(CPUState *cs)
> {
> X86CPU *cpu = X86_CPU(cs);
> CPUX86State *env = &cpu->env;
> struct {
> struct kvm_msrs info;
> struct kvm_msr_entry entries[1];
> } msr_data;
> int ret;
>
> if (env->tsc_valid) {
> return 0;
> }
>
> msr_data.info.nmsrs = 1;
> msr_data.entries[0].index = MSR_IA32_TSC;
> env->tsc_valid = !runstate_is_running();
>
> ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
> if (ret < 0) {
> return ret;
> }
>
> env->tsc = msr_data.entries[0].data;
> return 0;
> }
>
> >
> > + CPU_FOREACH(cpu) {
> > + ret = kvm_get_tsc(cpu);
> > + if (ret < 0) {
> > + fprintf(stderr, "KVM_GET_MSRS failed: %s\n",
> > strerror(ret));
> > + abort();
> > + return;
> > + }
> > + }
>
>
> This should be run in the appropriate thread using run_on_cpu. VCPU ioctls
> should only be invoked from the VCPU thread. So you should introduce a new
> function kvm_synchronize_all_tsc() or something like that.
>
> Otherwise, the idea behind the patches is fine. Thanks!
>
> Paolo
Thanks for your comments, I will send the v3.
Liang