From: Sheng Yang <sheng@linux.intel.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Ensure the exit frequency to QEmu for coalesced MMIO
Date: Wed, 20 Jan 2010 16:38:23 +0800 [thread overview]
Message-ID: <201001201638.23942.sheng@linux.intel.com> (raw)
In-Reply-To: <1263976559-15480-1-git-send-email-sheng@linux.intel.com>
On Wednesday 20 January 2010 16:35:59 Sheng Yang wrote:
> The default action of calesced MMIO is, cache the writing in buffer, until:
> 1. The buffer is full.
> 2. Or the exit to QEmu due to other reasons.
>
> But this would result in a very late writing in some condition.
> 1. The each time write to MMIO content is small.
> 2. The writing interval is big.
> 3. No need for input or accessing other devices frequently.
"No need for exiting to the QEmu in a period" should be more precise...
--
regards
Yang, Sheng
>
> This issue was observed in a experimental embbed system. The test image
> simply print "test" every 1 seconds. The output in QEmu meets expectation,
> but the output in KVM is delayed for seconds.
>
> To solve this issue, a timeout is added, to ensure userspace exit freqency
> is high enough(mostly target for video now) to write the buffered MMIO
> data. Current the maximum exit interval is 1/25s(so 25 times exit to
> userspace per second at least, pretty low compared to normal environment),
> and reused KVM_EXIT_IRQ_WINDOW_OPEN as exit reason, for it would doing
> nothing at all in userspace handler.
>
> Signed-off-by: Sheng Yang <sheng@linux.intel.com>
> ---
> arch/x86/include/asm/kvm_host.h | 2 ++
> arch/x86/kvm/x86.c | 31 +++++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h
> b/arch/x86/include/asm/kvm_host.h index a1f0b5d..eb8bb20 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -365,6 +365,8 @@ struct kvm_vcpu_arch {
> unsigned long singlestep_rip;
> /* fields used by HYPER-V emulation */
> u64 hv_vapic;
> +
> + ktime_t latest_userspace_exit_time;
> };
>
> struct kvm_mem_alias {
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 56a90a6..0b05f11 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4339,6 +4339,20 @@ out:
> return r;
> }
>
> +#ifdef CONFIG_KVM_MMIO
> +
> +#define KVM_USERSPACE_MMIO_MAX_INTERVAL (NSEC_PER_SEC / 25)
> +static bool mmio_need_exit_to_userspace(struct kvm_vcpu *vcpu)
> +{
> + ktime_t gap, now = ktime_get();
> +
> + gap = ktime_sub(now, vcpu->arch.latest_userspace_exit_time);
> + if (ktime_to_ns(gap) > KVM_USERSPACE_MMIO_MAX_INTERVAL)
> + return true;
> +
> + return false;
> +}
> +#endif
>
> static int __vcpu_run(struct kvm_vcpu *vcpu)
> {
> @@ -4404,6 +4418,10 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
> kvm_resched(vcpu);
> vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
> }
> +#ifdef CONFIG_KVM_MMIO
> + if (mmio_need_exit_to_userspace(vcpu))
> + r = 0;
> +#endif
> }
>
> srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
> @@ -4463,6 +4481,16 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu,
> struct kvm_run *kvm_run)
>
> r = __vcpu_run(vcpu);
>
> +#ifdef CONFIG_KVM_MMIO
> + if (mmio_need_exit_to_userspace(vcpu)) {
> + /* Use KVM_EXIT_IRQ_WINDOW_OPEN because userspace would do
> + * nothing to handle it */
> + kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
> + r = 0;
> + }
> + vcpu->arch.latest_userspace_exit_time = ktime_get();
> +#endif
> +
> out:
> if (vcpu->sigset_active)
> sigprocmask(SIG_SETMASK, &sigsaved, NULL);
> @@ -5455,6 +5483,9 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> goto fail_mmu_destroy;
> }
> vcpu->arch.mcg_cap = KVM_MAX_MCE_BANKS;
> +#ifdef CONFIG_KVM_MMIO
> + vcpu->arch.latest_userspace_exit_time = ktime_get();
> +#endif
>
> return 0;
>
next prev parent reply other threads:[~2010-01-20 8:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-20 8:35 [PATCH] KVM: Ensure the exit frequency to QEmu for coalesced MMIO Sheng Yang
2010-01-20 8:38 ` Sheng Yang [this message]
2010-01-20 9:11 ` Avi Kivity
2010-01-20 9:34 ` Sheng Yang
2010-01-20 9:47 ` Avi Kivity
2010-01-20 9:57 ` Sheng Yang
2010-01-20 11:04 ` Avi Kivity
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=201001201638.23942.sheng@linux.intel.com \
--to=sheng@linux.intel.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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