* How to get to know vcpu status from outside
@ 2013-12-17 6:11 Arthur Chunqi Li
2013-12-17 11:21 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Arthur Chunqi Li @ 2013-12-17 6:11 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
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?
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?
Thanks very much,
Arthur
--
Arthur Chunqi Li
Department of Computer Science
School of EECS
Peking University
Beijing, China
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get to know vcpu status from outside
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
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2013-12-17 11:21 UTC (permalink / raw)
To: Arthur Chunqi Li; +Cc: kvm
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).
> 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).
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get to know vcpu status from outside
2013-12-17 11:21 ` Paolo Bonzini
@ 2013-12-17 11:43 ` Arthur Chunqi Li
2013-12-17 12:28 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Arthur Chunqi Li @ 2013-12-17 11:43 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
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?
>
>> 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?
>
> Paolo
>
Besides, can I pin a vcpu to a pcpu? That is to say, I assigned a pcpu
only for a vcpu and pcpu can only run this vcpu?
Thanks,
Arthur
--
Arthur Chunqi Li
Department of Computer Science
School of EECS
Peking University
Beijing, China
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get to know vcpu status from outside
2013-12-17 11:43 ` Arthur Chunqi Li
@ 2013-12-17 12:28 ` Paolo Bonzini
2013-12-20 8:05 ` Arthur Chunqi Li
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2013-12-17 12:28 UTC (permalink / raw)
To: Arthur Chunqi Li; +Cc: kvm
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get to know vcpu status from outside
2013-12-17 12:28 ` Paolo Bonzini
@ 2013-12-20 8:05 ` Arthur Chunqi Li
2013-12-20 11:57 ` Paolo Bonzini
0 siblings, 1 reply; 6+ messages in thread
From: Arthur Chunqi Li @ 2013-12-20 8:05 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
Hi Paolo,
On Tue, Dec 17, 2013 at 8:28 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 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.
I failed to kvm_vcpu_kick inactive vcpus at the beginning of the boot
time (from power up to grub) of a VM. I think this may because other
vcpus are not activated by SMP system at boot time, right? How can I
distinguish vcpus in such status?
Thanks,
Arthur
>
> Paolo
--
Arthur Chunqi Li
Department of Computer Science
School of EECS
Peking University
Beijing, China
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get to know vcpu status from outside
2013-12-20 8:05 ` Arthur Chunqi Li
@ 2013-12-20 11:57 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2013-12-20 11:57 UTC (permalink / raw)
To: Arthur Chunqi Li; +Cc: kvm
Il 20/12/2013 09:05, Arthur Chunqi Li ha scritto:
> I failed to kvm_vcpu_kick inactive vcpus at the beginning of the boot
> time (from power up to grub) of a VM. I think this may because other
> vcpus are not activated by SMP system at boot time, right? How can I
> distinguish vcpus in such status?
Their vcpu->arch.mp_state is KVM_MP_STATE_UNINITIALIZED.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-12-20 11:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-12-20 8:05 ` Arthur Chunqi Li
2013-12-20 11:57 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox