From: Eduardo Habkost <ehabkost@redhat.com> To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, "Michael S. Tsirkin" <mst@redhat.com>, afaerber@suse.de, Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org Subject: Re: [PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate Date: Mon, 16 Nov 2015 13:35:21 -0200 [thread overview] Message-ID: <20151116153521.GY4180@thinpad.lan.raisama.net> (raw) In-Reply-To: <20151116143008.GA22212@hzzhang-OptiPlex-9020.sh.intel.com> On Mon, Nov 16, 2015 at 10:30:08PM +0800, Haozhong Zhang wrote: > On 11/16/15 11:43, Eduardo Habkost wrote: > > On Mon, Nov 16, 2015 at 04:04:08PM +0800, Haozhong Zhang wrote: > > > This patch enables migrating vcpu's TSC rate. If KVM on the destination > > > machine supports TSC scaling, guest programs will observe a consistent > > > TSC rate across the migration. > > > > > > If TSC scaling is not supported on the destination machine, the > > > migration will not be aborted and QEMU on the destination will not set > > > vcpu's TSC rate to the migrated value. > > > > > > If vcpu's TSC rate specified by CPU option 'tsc-freq' on the destination > > > machine is inconsistent with the migrated TSC rate, the migration will > > > be aborted. > > > > > > For backwards compatibility, the migration of vcpu's TSC rate is > > > disabled on pc-*-2.4 and older machine types. > > > > > > Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com> [...] > > > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > > > index 9084b29..8448248 100644 > > > --- a/target-i386/kvm.c > > > +++ b/target-i386/kvm.c > > > @@ -2334,8 +2334,30 @@ static void kvm_arch_set_tsc_khz(CPUState *cs) > > > int r; > > > > > > /* > > > - * If no user-specified TSC frequency is present, we will try to > > > - * set env->tsc_khz to the value used by KVM. > > > + * For other cases of env->tsc_khz and env->user_tsc_khz: > > > + * > > > + * - We have eliminated all cases that satisfy > > > + * env->tsc_khz && env->user_tsc_khz && > > > + * env->tsc_khz != env->user_tsc_khz > > > + * in cpu_post_load(). > > > + * > > > + * - If env->user_tsc_khz is not zero, then it must be equal to > > > + * env->tsc_khz (if the latter is not zero) and has been set in > > > + * kvm_arch_init_vcpu(). > > > + */ > > > + if (env->tsc_khz && !env->user_tsc_khz) { > > > + r = kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL) ? > > > + kvm_vcpu_ioctl(cs, KVM_SET_TSC_KHZ, env->tsc_khz) : -ENOTSUP; > > > > Please don't duplicate the code from kvm_arch_init_vcpu(). We can > > handle both cases in kvm_arch_put_registers(KVM_PUT_FULL_STATE), > > can't we? > > > > No. If KVM_SET_TSC_KHZ fails in kvm_arch_init_vcpu(), QEMU will > exit. But if KVM_SET_TSC_KHZ fails in the migration, QEMU will not > abort. And because the return value of > kvm_arch_put_registers(KVM_PUT_FULL_STATE) is not checked by its > caller do_kvm_cpu_synchronize_post_init(), I have to handle them in > different ways. Reporting errors back in kvm_put_registers() may be difficult, I see, so handling user-provided TSC frequency in kvm_arch_init_vcpu() makes sense. But you can still avoid code duplication. Just reuse the same function in kvm_arch_init_vcpu() and kvm_put_registers(), but return errors back to the caller in kvm_arch_init_vcpu() in case env->user_tsc_khz is set. kvm_put_registers() can ignore the error, and just print a warning. But (on both cases) we should print a warning only if env->tsc_khz doesn't match KVM_GET_TSC_KHZ, because we don't want to print spurious warnings on every migration when TSC scaling isn't supported. (You even suggested changes to the example code that does that, at Message-ID: <20151106023244.GB24388@hzzhang-OptiPlex-9020.sh.intel.com>). Also, I believe it won't be a problem if we call KVM_SET_TSC_KHZ twice in the case of incoming migration, so there's no need to check user_tsc_khz in the kvm_arch_put_registers() path. Keeping the code simple is more important than avoiding one extra ioctl() on incoming migration, IMO. -- Eduardo
WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Habkost <ehabkost@redhat.com> To: qemu-devel@nongnu.org, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, "Michael S. Tsirkin" <mst@redhat.com>, afaerber@suse.de, Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org Subject: Re: [Qemu-devel] [PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate Date: Mon, 16 Nov 2015 13:35:21 -0200 [thread overview] Message-ID: <20151116153521.GY4180@thinpad.lan.raisama.net> (raw) In-Reply-To: <20151116143008.GA22212@hzzhang-OptiPlex-9020.sh.intel.com> On Mon, Nov 16, 2015 at 10:30:08PM +0800, Haozhong Zhang wrote: > On 11/16/15 11:43, Eduardo Habkost wrote: > > On Mon, Nov 16, 2015 at 04:04:08PM +0800, Haozhong Zhang wrote: > > > This patch enables migrating vcpu's TSC rate. If KVM on the destination > > > machine supports TSC scaling, guest programs will observe a consistent > > > TSC rate across the migration. > > > > > > If TSC scaling is not supported on the destination machine, the > > > migration will not be aborted and QEMU on the destination will not set > > > vcpu's TSC rate to the migrated value. > > > > > > If vcpu's TSC rate specified by CPU option 'tsc-freq' on the destination > > > machine is inconsistent with the migrated TSC rate, the migration will > > > be aborted. > > > > > > For backwards compatibility, the migration of vcpu's TSC rate is > > > disabled on pc-*-2.4 and older machine types. > > > > > > Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com> [...] > > > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > > > index 9084b29..8448248 100644 > > > --- a/target-i386/kvm.c > > > +++ b/target-i386/kvm.c > > > @@ -2334,8 +2334,30 @@ static void kvm_arch_set_tsc_khz(CPUState *cs) > > > int r; > > > > > > /* > > > - * If no user-specified TSC frequency is present, we will try to > > > - * set env->tsc_khz to the value used by KVM. > > > + * For other cases of env->tsc_khz and env->user_tsc_khz: > > > + * > > > + * - We have eliminated all cases that satisfy > > > + * env->tsc_khz && env->user_tsc_khz && > > > + * env->tsc_khz != env->user_tsc_khz > > > + * in cpu_post_load(). > > > + * > > > + * - If env->user_tsc_khz is not zero, then it must be equal to > > > + * env->tsc_khz (if the latter is not zero) and has been set in > > > + * kvm_arch_init_vcpu(). > > > + */ > > > + if (env->tsc_khz && !env->user_tsc_khz) { > > > + r = kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL) ? > > > + kvm_vcpu_ioctl(cs, KVM_SET_TSC_KHZ, env->tsc_khz) : -ENOTSUP; > > > > Please don't duplicate the code from kvm_arch_init_vcpu(). We can > > handle both cases in kvm_arch_put_registers(KVM_PUT_FULL_STATE), > > can't we? > > > > No. If KVM_SET_TSC_KHZ fails in kvm_arch_init_vcpu(), QEMU will > exit. But if KVM_SET_TSC_KHZ fails in the migration, QEMU will not > abort. And because the return value of > kvm_arch_put_registers(KVM_PUT_FULL_STATE) is not checked by its > caller do_kvm_cpu_synchronize_post_init(), I have to handle them in > different ways. Reporting errors back in kvm_put_registers() may be difficult, I see, so handling user-provided TSC frequency in kvm_arch_init_vcpu() makes sense. But you can still avoid code duplication. Just reuse the same function in kvm_arch_init_vcpu() and kvm_put_registers(), but return errors back to the caller in kvm_arch_init_vcpu() in case env->user_tsc_khz is set. kvm_put_registers() can ignore the error, and just print a warning. But (on both cases) we should print a warning only if env->tsc_khz doesn't match KVM_GET_TSC_KHZ, because we don't want to print spurious warnings on every migration when TSC scaling isn't supported. (You even suggested changes to the example code that does that, at Message-ID: <20151106023244.GB24388@hzzhang-OptiPlex-9020.sh.intel.com>). Also, I believe it won't be a problem if we call KVM_SET_TSC_KHZ twice in the case of incoming migration, so there's no need to check user_tsc_khz in the kvm_arch_put_registers() path. Keeping the code simple is more important than avoiding one extra ioctl() on incoming migration, IMO. -- Eduardo
next prev parent reply other threads:[~2015-11-16 15:35 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-11-16 8:04 [PATCH v4 0/2] target-i386: save/restore vcpu's TSC rate during migration Haozhong Zhang 2015-11-16 8:04 ` [Qemu-devel] " Haozhong Zhang 2015-11-16 8:04 ` [PATCH v4 1/2] target-i386: fallback vcpu's TSC rate to value returned by KVM Haozhong Zhang 2015-11-16 8:04 ` [Qemu-devel] " Haozhong Zhang 2015-11-16 13:39 ` Eduardo Habkost 2015-11-16 13:39 ` [Qemu-devel] " Eduardo Habkost 2015-11-16 14:30 ` Haozhong Zhang 2015-11-16 14:30 ` [Qemu-devel] " Haozhong Zhang 2015-11-16 8:04 ` [PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate Haozhong Zhang 2015-11-16 8:04 ` [Qemu-devel] " Haozhong Zhang 2015-11-16 13:43 ` Eduardo Habkost 2015-11-16 13:43 ` [Qemu-devel] " Eduardo Habkost 2015-11-16 14:30 ` Haozhong Zhang 2015-11-16 14:30 ` [Qemu-devel] " Haozhong Zhang 2015-11-16 15:35 ` Eduardo Habkost [this message] 2015-11-16 15:35 ` Eduardo Habkost 2015-11-17 5:24 ` Haozhong Zhang 2015-11-17 5:24 ` [Qemu-devel] " Haozhong Zhang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20151116153521.GY4180@thinpad.lan.raisama.net \ --to=ehabkost@redhat.com \ --cc=afaerber@suse.de \ --cc=dgilbert@redhat.com \ --cc=kvm@vger.kernel.org \ --cc=mst@redhat.com \ --cc=mtosatti@redhat.com \ --cc=pbonzini@redhat.com \ --cc=qemu-devel@nongnu.org \ --cc=rth@twiddle.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.