All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Sheng Yang <sheng@linux.intel.com>,
	Joerg Roedel <joerg.roedel@amd.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH 4/5] KVM: Lazify fpu activation and deactivation
Date: Wed, 06 Jan 2010 05:18:13 +0200	[thread overview]
Message-ID: <4B4400F5.2010309@redhat.com> (raw)
In-Reply-To: <20100106002529.GA11233@amt.cnet>

On 01/06/2010 02:25 AM, Marcelo Tosatti wrote:
> On Wed, Dec 30, 2009 at 06:25:41PM +0200, Avi Kivity wrote:
>    
>> Defer fpu deactivation as much as possible - if the guest fpu is loaded, keep
>> it loaded until the next heavyweight exit (where we are forced to unload it).
>> This reduces unnecessary exits.
>>
>> We also defer fpu activation on clts; while clts signals the intent to use the
>> fpu, we can't be sure the guest will actually use it.
>>
>> Signed-off-by: Avi Kivity<avi@redhat.com>
>>      
>    
>> +static void svm_fpu_deactivate(struct kvm_vcpu *vcpu)
>> +{
>> +	struct vcpu_svm *svm = to_svm(vcpu);
>> +
>> +	if (npt_enabled) {
>> +		/* hack: npt requires active fpu at this time */
>> +		vcpu->fpu_active = 1;
>> +		return;
>> +	}
>>      
> Why is that ?
>    

A guest context switch will involve setting cr0.ts and possibly issuing 
clts after the fpu is first used:

   _switch_to()
      unlazy_fpu()
         stts()

So we will get an exit on cr0 writes on every guest context switch until 
the fpu is loaded.  vmx avoids this by allowing writes that don't change 
important bits to proceed.

Hmm,  I see the write is conditional, so it may not be as bad as that.  
We'll have to test other guests to make sure they all do conditional stts().

Joerg, what was the reason the initial npt implementation did not do 
lazy fpu switching?

>>   void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
>>   {
>> -	kvm_x86_ops->vcpu_put(vcpu);
>>   	kvm_put_guest_fpu(vcpu);
>> +	kvm_x86_ops->vcpu_put(vcpu);
>>   }
>>      
> It might be possible to defer host FPU restoration to
> user-return-notifier/kernel_fpu_begin time, so you'd keep the guest FPU
> loaded across qemukvm->kernel task->qemukvm switches. Not sure if its
> worthwhile though.
>    

I have some vague plans to do that, as well as make kernel_fpu_begin() 
preemptable.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


  reply	other threads:[~2010-01-06  3:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30 16:25 [PATCH 0/5] Lazy fpu, cr0.ts Avi Kivity
2009-12-30 16:25 ` [PATCH 1/5] KVM: VMX: trace clts and lmsw instructions as cr accesses Avi Kivity
2009-12-30 16:25 ` [PATCH 2/5] KVM: Replace read accesses of vcpu->arch.cr0 by an accessor Avi Kivity
2009-12-30 16:25 ` [PATCH 3/5] KVM: VMX: Allow the guest to own some cr0 bits Avi Kivity
2009-12-30 16:25 ` [PATCH 4/5] KVM: Lazify fpu activation and deactivation Avi Kivity
2010-01-06  0:25   ` Marcelo Tosatti
2010-01-06  3:18     ` Avi Kivity [this message]
2010-01-06  6:21       ` Avi Kivity
2010-01-06 10:47       ` Joerg Roedel
2010-01-06 11:00         ` Avi Kivity
2010-01-14 13:11   ` Avi Kivity
2010-01-14 13:11     ` Avi Kivity
2010-01-14 14:34       ` Lucas Meneghel Rodrigues
2010-01-14 15:04         ` Avi Kivity
2009-12-30 16:25 ` [PATCH 5/5] KVM: VMX: Give the guest ownership of cr0.ts when the fpu is active Avi Kivity
2010-01-06  0:40   ` Marcelo Tosatti
2009-12-31  9:23 ` [PATCH 0/5] Lazy fpu, cr0.ts Sheng Yang

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=4B4400F5.2010309@redhat.com \
    --to=avi@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=sheng@linux.intel.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 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.