All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Yacine <y_hebbal@esi.dz>, kvm@vger.kernel.org
Subject: Re: Difference between vcpu_load and kvm_sched_in ?
Date: Tue, 20 Oct 2015 17:44:53 +0200	[thread overview]
Message-ID: <56266175.4030409@redhat.com> (raw)
In-Reply-To: <loom.20151020T115351-372@post.gmane.org>



On 20/10/2015 11:57, Yacine wrote:
> vcpu_load; start cr3 trapping; vcpu_put
> 
> it worked correctly (in my logs I see that vcpu.cpu become equal to "cpu =
> raw_smp_processor_id();") but the VM blocks for a lot of time due to mutex
> in vcpu_load (up to serveral seconds and sometimes minutes !)

Right, that's because while the CPU is running the mutex is taken.  If
the VCPU doesn't exit, the mutex is held.

> I replaced vcpu_load with kvm_sched_in, now everything works perfectly and
> the VM doesn't block at all (logs here: http://pastebin.com/h5XNNMcb).
> 
> So, what I want to know is: what is the difference between vcpu_load and
> kvm_sched_in ? both of this functions call kvm_arch_vcpu_loadbut the latter
> one does it without doing a mutex

kvm_sched_out and kvm_sched_in are part of KVM's preemption hooks.  The
hooks are registered only between vcpu_load and vcpu_put, therefore they
know that the mutex is taken.  The sequence will go like this:

    vcpu_load
    kvm_sched_out
    kvm_sched_in
    kvm_sched_out
    kvm_sched_in
    ...
    vcpu_put

and it will all happen with the mutex held.

> Is there a problem in using kvm_sched_in instead of vcpu_load for my use case ?

Yes, unfortunately it is a problem: you are loading the same VMCS on two
processors, which has undefined results.

To fix the problem, wrap the ioctl into a function and pass the function
to QEMU's "run_on_cpu" function.  It will send the ioctl from the right
thread, so that the kernel will not be holding the vcpu mutex.

Paolo

  reply	other threads:[~2015-10-20 15:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20  9:57 Difference between vcpu_load and kvm_sched_in ? Yacine
2015-10-20 15:44 ` Paolo Bonzini [this message]
2015-10-20 22:57   ` Wanpeng Li
2015-10-21  6:46     ` Paolo Bonzini
2015-10-21 10:20       ` Yacine HEBBAL
2015-10-22  7:33       ` Wanpeng Li
     [not found]   ` <CACEoar52w8qU2bbSTGKJdq++jz3gppLQ0N-xqsS-pnYMNnaK3Q@mail.gmail.com>
2015-10-21 10:25     ` Paolo Bonzini
2015-10-21 17:21       ` Yacine HEBBAL
2015-10-22  9:37         ` Paolo Bonzini

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=56266175.4030409@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=y_hebbal@esi.dz \
    /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 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.