public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Longpeng (Mike)" <longpeng2@huawei.com>
To: Cornelia Huck <cohuck@redhat.com>, David Hildenbrand <david@redhat.com>
Cc: <pbonzini@redhat.com>, <rkrcmar@redhat.com>, <agraf@suse.com>,
	<borntraeger@de.ibm.com>, <christoffer.dall@linaro.org>,
	<marc.zyngier@arm.com>, <james.hogan@imgtec.com>,
	<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<weidong.huang@huawei.com>, <arei.gonglei@huawei.com>,
	<wangxinxin.wang@huawei.com>, <longpeng.mike@gmail.com>
Subject: Re: [RFC] KVM: optimize the kvm_vcpu_on_spin
Date: Mon, 31 Jul 2017 21:01:59 +0800	[thread overview]
Message-ID: <597F2A47.4020209@huawei.com> (raw)
In-Reply-To: <20170731143155.30a1b0dd@gondolin>



On 2017/7/31 20:31, Cornelia Huck wrote:

> On Mon, 31 Jul 2017 20:08:14 +0800
> "Longpeng (Mike)" <longpeng2@huawei.com> wrote:
> 
>> Hi David,
>>
>> On 2017/7/31 19:31, David Hildenbrand wrote:
> 
>>>> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
>>>> index 648b34c..f8f0d74 100644
>>>> --- a/include/linux/kvm_host.h
>>>> +++ b/include/linux/kvm_host.h
>>>> @@ -272,6 +272,9 @@ struct kvm_vcpu {
>>>>  	} spin_loop;
>>>>  #endif
>>>>  	bool preempted;
>>>> +	/* If vcpu is in kernel-mode when preempted */
>>>> +	bool in_kernmode;
>>>> +  
>>>
>>> Why do you have to store that ...
>>>   
>>
>>> [...]> +	me->in_kernmode = kvm_arch_vcpu_spin_kernmode(me);
>>>>  	kvm_vcpu_set_in_spin_loop(me, true);
>>>>  	/*
>>>>  	 * We boost the priority of a VCPU that is runnable but not
>>>> @@ -2351,6 +2353,8 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me)
>>>>  				continue;
>>>>  			if (swait_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
>>>>  				continue;
>>>> +			if (me->in_kernmode && !vcpu->in_kernmode)  
>>>
>>> Wouldn't it be easier to simply have
>>>
>>> in_kernel = kvm_arch_vcpu_in_kernel(me);
>>> ...
>>> if (in_kernel && !kvm_arch_vcpu_in_kernel(vcpu))
>>> ...
>>>   
>>
>> I'm not sure whether the operation of get the vcpu's priority-level is
>> expensive on all architectures, so I record it in kvm_sched_out() for
>> minimal the extra cycles cost in kvm_vcpu_on_spin().
> 
> As it is now, this handling looks a bit inconsistent. You only update
> the field on sched-out via preemption _or_ if kvm_vcpu_on_spin is
> called for the vcpu. In most contexts, this field will have stale
> content.
> 
> Also, would checking for kernel mode be more expensive than the various
> other checks already done in this function?
> 

> [I like David's suggestion.]
> 


Hi Cornelia & David,

I'll take your suggestion, thanks :)

>>
>>>> +				continue;
>>>>  			if (!kvm_vcpu_eligible_for_directed_yield(vcpu))
>>>>  				continue;
>>>>  
> 
> .
> 


-- 
Regards,
Longpeng(Mike)

  reply	other threads:[~2017-07-31 13:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-29  6:22 [RFC] KVM: optimize the kvm_vcpu_on_spin Longpeng(Mike)
2017-07-31 11:31 ` David Hildenbrand
2017-07-31 12:08   ` Longpeng (Mike)
2017-07-31 12:27     ` David Hildenbrand
2017-07-31 13:20       ` Paolo Bonzini
2017-08-01  3:26         ` Longpeng (Mike)
2017-08-01  8:32           ` Paolo Bonzini
2017-07-31 12:31     ` Cornelia Huck
2017-07-31 13:01       ` Longpeng (Mike) [this message]
2017-07-31 13:22 ` Christoffer Dall
2017-07-31 17:32   ` David Hildenbrand
2017-08-01  6:51     ` Cornelia Huck
2017-08-01  2:24   ` Longpeng (Mike)
2017-07-31 13:42 ` Marc Zyngier
2017-07-31 14:23   ` 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=597F2A47.4020209@huawei.com \
    --to=longpeng2@huawei.com \
    --cc=agraf@suse.com \
    --cc=arei.gonglei@huawei.com \
    --cc=borntraeger@de.ibm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=james.hogan@imgtec.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longpeng.mike@gmail.com \
    --cc=marc.zyngier@arm.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=wangxinxin.wang@huawei.com \
    --cc=weidong.huang@huawei.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