From: Paolo Bonzini <pbonzini@redhat.com>
To: Liang Li <liang.z.li@intel.com>, qemu-devel@nongnu.org
Cc: mtosatti@redhat.com, m.gibula@beyond.pl
Subject: Re: [Qemu-devel] [RESEND 1/2] kvmclock: use a light weight interface to update env->tsc.
Date: Mon, 2 Nov 2015 16:04:41 +0100 [thread overview]
Message-ID: <56377B89.1050808@redhat.com> (raw)
In-Reply-To: <1446106927-15490-2-git-send-email-liang.z.li@intel.com>
On 29/10/2015 09:22, Liang Li wrote:
> +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;
> + struct kvm_msr_entry *msrs = msr_data.entries;
> + int ret, i, n;
> +
> + n = 0;
> +
> + if (!env->tsc_valid) {
> + msrs[n++].index = MSR_IA32_TSC;
> + env->tsc_valid = !runstate_is_running();
> + }
> +
> + if (n == 0) {
> + return 0;
> + }
> +
> + msr_data.info = (struct kvm_msrs) {
> + .nmsrs = n,
> + };
> +
> + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
> + if (ret < 0) {
> + return ret;
> + }
> +
> + for (i = 0; i < ret; i++) {
> + uint32_t index = msrs[i].index;
> + switch (index) {
> + case MSR_IA32_TSC:
> + env->tsc = msrs[i].data;
> + break;
> + default:
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> +
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
next prev parent reply other threads:[~2015-11-02 15:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-29 8:22 [Qemu-devel] [RESEND 0/2] Optimze the env->tsc update operation Liang Li
2015-10-29 8:22 ` [Qemu-devel] [RESEND 1/2] kvmclock: use a light weight interface to update env->tsc Liang Li
2015-11-02 15:04 ` Paolo Bonzini [this message]
2015-11-02 15:11 ` Li, Liang Z
2015-10-29 8:22 ` [Qemu-devel] [RESEND 2/2] Revert "Introduce cpu_clean_all_dirty" Liang Li
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=56377B89.1050808@redhat.com \
--to=pbonzini@redhat.com \
--cc=liang.z.li@intel.com \
--cc=m.gibula@beyond.pl \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).