public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Arthur Chunqi Li <yzt356@gmail.com>
Cc: kvm <kvm@vger.kernel.org>
Subject: Re: How to get to know vcpu status from outside
Date: Tue, 17 Dec 2013 13:28:32 +0100	[thread overview]
Message-ID: <52B04370.1070208@redhat.com> (raw)
In-Reply-To: <CABpY8MLqx3Xo4Vkvp4+pGqkyPb_ZmoFLVfAibmArvi4Hdbp09w@mail.gmail.com>

Il 17/12/2013 12:43, Arthur Chunqi Li ha scritto:
> Hi Paolo,
> 
> Thanks very much. And...(see below)
> 
> On Tue, Dec 17, 2013 at 7:21 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Il 17/12/2013 07:11, Arthur Chunqi Li ha scritto:
>>> Hi Paolo,
>>>
>>> Since VCPU is managed the same as a process in kernel, how can I know
>>> the status (running, sleeping etc.) of a vcpu in kernel? Is there a
>>> variant in struct kvm_vcpu or something else indicate this?
>>
>> waitqueue_active(&vcpu->wq) means that the VCPU is sleeping in the
>> kernel (i.e. in a halted state).
>>
>> vcpu->mode == IN_GUEST_MODE means that the VCPU is running.
>>
>> Anything else means that the host is running some kind of "glue" code
>> (either kernel or userspace).
> 
> Another question about scheduler. When I have 4 vcpus and the workload
> of VM is low, and I noticed that it tends to activate only 1 or 2
> vcpus. Does this mean the other 2 vcpus are scheduled out or into
> sleeping status?

This depends on what the guest scheduler is doing.  The other 2 VCPUs
are probably running for so little time (a few microseconds every
1/100th of a second) that you do not see them, and they stay halted the
rest of the time.

Remember that KVM has no scheduler of its own.  What you see is the
combined result of the guest and host schedulers.
>>
>>> Besides, if vcpu1 is running on pcpu1, and a kernel thread running on
>>> pcpu0. Can the kernel thread send a message to force vcpu1 trap to
>>> VMM? How can I do this?
>>
>> Yes, with kvm_vcpu_kick.  KVM tracks internally which pcpu will run the
>> vcpu in vcpu->cpu, and kvm_vcpu_kick sends either a wakeup (if the vcpu
>> is sleeping) or an IPI (if it is running).
> 
> What is vcpu's action if kvm_vcpu_kick(vcpu)? What is the exit_reason
> of the kicked vcpu?

No exit reason, you just get a lightweight exit to the host kernel.  If
you want a userspace exit, you'd need to set a bit in vcpu->requests
before kvm_vcpu_kick (which you can do best with kvm_make_request), and
change that to a userspace exit in vcpu_enter_guest.  There's already an
example of that, search arch/x86/kvm/x86.c for KVM_REQ_TRIPLE_FAULT.

Paolo

  reply	other threads:[~2013-12-17 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17  6:11 How to get to know vcpu status from outside Arthur Chunqi Li
2013-12-17 11:21 ` Paolo Bonzini
2013-12-17 11:43   ` Arthur Chunqi Li
2013-12-17 12:28     ` Paolo Bonzini [this message]
2013-12-20  8:05       ` Arthur Chunqi Li
2013-12-20 11:57         ` 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=52B04370.1070208@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=yzt356@gmail.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