From: Dor Laor <dor.laor@gmail.com>
To: Marcelo Tosatti <marcelo@kvack.org>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>,
Avi Kivity <avi@qumranet.com>
Subject: Re: [RFC] QEMU/KVM: dedicated IO thread
Date: Thu, 27 Mar 2008 00:06:53 +0200 [thread overview]
Message-ID: <1206569213.2360.32.camel@localhost.localdomain> (raw)
In-Reply-To: <20080326181421.GB21800@dmt>
On Wed, 2008-03-26 at 15:14 -0300, Marcelo Tosatti wrote:
> On Wed, Mar 26, 2008 at 06:57:04PM +0200, Avi Kivity wrote:
> > Marcelo Tosatti wrote:
> > >
> > >>> QEMU/KVM: separate thread for IO handling
> > >>>
> > >>> Move IO processing from vcpu0 to a dedicated thread.
> > >>>
> > >>> This removes load on vcpu0 by allowing better cache locality and also
> > >>> improves latency.
> > >>>
> > >>> We can now block signal handling for IO events, so sigtimedwait won't
> > >>> race with handlers:
> > >>>
> > >>> - Currently the SIGALRM handler fails to set CPU_INTERRUPT_EXIT because
> > >>> the "next_cpu" variable is not initialized in the KVM path, meaning that
> > >>> processing of timer expiration might be delayed until the next vcpu0 exit.
> > >>>
> > >>>
> > >> I think we call main_loop_wait() is called unconditionally after every
> > >> signal.
> > >>
> > >
> > > We exit the kvm_run() loop if CPU_INTERRUPT_EXIT is detected by pre_kvm_run().
> > >
> > >
> >
> > But why do we need to exit the kvm_run() loop? As I understand it, the
> > I/O thread wakes up when the signal is queued and calls main_loop_wait()
> > to process any events (through qemu_run_timers()). If a timer needs to
> > wake up a vcpu, it will raise an interrupt line which will wake the vcpu
> > up, either in the kernel or in userspace depending on -no-kvm-irqchip.
>
> In the current state of vcpu0 thread handling IO, kvm_run() loop must
> bail out for main_loop_wait->qemu_run_timers() to run.
>
> If using an userspace timer such as RTC (brought to attention by Dor's
> patches), the following will happen:
>
> - signal wakes up vcpu0 thread, goes back to userspace.
> - host_alarm_handler runs but fails to set CPU_INTERRUPT_EXIT
> because "next_cpu" is not initialized.
> - pre_kvm_run() checks for CPU_INTERRUPT_EXIT and determines
> its not necessary to exit kvm_run(), so vcpu0 thread goes
> back into kernel to enter guest mode.
>
> No interrupt was raised even though SIGALRM handler has executed.
>
But what if the host_alarm_handler to wake up the sleeping IO thread,
then it will run the timers and the irq will be triggered using ioctl.
You're right that if the designated vcpu was in userspace at that time
it might go back into the kernel but the time to do is decreases + the
following:
Every vcpu reads it's irq vector every time before vcpu_run so the guest
will receive the irq the next vmenter.
The lapic code sends kvm_vcpu_kick to the destination vcpu in order to
cause a vmexit so interrupt would be injected next time.
> AFAICS next_cpu is only initialized here:
>
> static int main_loop(void)
> {
> ...
> if (kvm_enabled()) {
> kvm_main_loop();
> cpu_disable_ticks();
> return 0;
> }
>
> cur_cpu = first_cpu;
> next_cpu = cur_cpu->next_cpu ?: first_cpu;
> for(;;) {
>
> See ? I pointed this out as it appears to be another factor in
> unreliable userspace timers.
>
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
prev parent reply other threads:[~2008-03-26 22:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-25 13:53 [RFC] QEMU/KVM: dedicated IO thread Marcelo Tosatti
2008-03-25 14:58 ` Avi Kivity
2008-03-25 16:00 ` Marcelo Tosatti
2008-03-26 16:57 ` Avi Kivity
2008-03-26 18:14 ` Marcelo Tosatti
2008-03-26 22:06 ` Dor Laor [this message]
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=1206569213.2360.32.camel@localhost.localdomain \
--to=dor.laor@gmail.com \
--cc=avi@qumranet.com \
--cc=dor.laor@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=marcelo@kvack.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