mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>, "Wanpeng Li" <kernellwp@gmail.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency
Date: Tue, 29 May 2018 19:08:48 +0200	[thread overview]
Message-ID: <e85689ac-25be-a0ca-7618-51a918896ca4@redhat.com> (raw)
In-Reply-To: <20180529143102.GC7819@flask>

On 29/05/2018 16:31, Radim Krčmář wrote:
> 2018-05-29 16:23+0200, Radim Krčmář:
>> 2018-05-29 14:53+0800, Wanpeng Li:
>>> From: Wanpeng Li <wanpengli@tencent.com>
>>>
>>> 'Commit d0659d946be0 ("KVM: x86: add option to advance tscdeadline 
>>> hrtimer expiration")' advances the tscdeadline (the timer is emulated 
>>> by hrtimer) expiration in order that the latency which is incurred 
>>> by hypervisor (apic_timer_fn -> vmentry) can be avoided. This patch 
>>> adds the advance tscdeadline expiration support to which the tscdeadline 
>>> timer is emulated by VMX preemption timer to reduce the hypervisor 
>>> lantency (handle_preemption_timer -> vmentry). clockevents infrastruture 
>>> can program minimum delay if hrtimer feeds a expiration in the past, 
>>> we set delta_tsc to 1(which will be converted to 0 before vmentry) 
>>> which can lead to an immediately vmexit when delta_tsc is not bigger 
>>> than advance ns. 
>>>
>>> This patch can reduce ~63% latency (~4450 cycles to ~1660 cycles on 
>>> a haswell desktop) for kvm-unit-tests/tscdeadline_latency when testing
>>> busy waits.
>>>
>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>>> Cc: Radim Krčmář <rkrcmar@redhat.com>
>>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>>> ---
>>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>>> @@ -12444,6 +12444,12 @@ static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc)
>>>  	tscl = rdtsc();
>>>  	guest_tscl = kvm_read_l1_tsc(vcpu, tscl);
>>>  	delta_tsc = max(guest_deadline_tsc, guest_tscl) - guest_tscl;
>>> +	lapic_timer_advance_cycles = nsec_to_cycles(vcpu, lapic_timer_advance_ns);
>>> +	if (delta_tsc > lapic_timer_advance_cycles)
>>> +		delta_tsc -= lapic_timer_advance_cycles;
>>> +	else
>>> +		delta_tsc = 1;
>>
>> Why don't we just "return 1" to say that the timer has expired?
> 
> This case might be rare, so setting delta_tsc = 0 would be safer.

Queued with this change.  Indeed this case matches vmx_arm_hv_timer so
it's preferrable.

Paolo

  reply	other threads:[~2018-05-29 17:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29  6:53 Wanpeng Li
2018-05-29 14:23 ` Radim Krčmář
2018-05-29 14:31   ` Radim Krčmář
2018-05-29 17:08     ` Paolo Bonzini [this message]
2018-05-30  0:46       ` Wanpeng Li
2018-06-02  0:24       ` Wanpeng Li

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=e85689ac-25be-a0ca-7618-51a918896ca4@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rkrcmar@redhat.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

all inboxes | Powered by JetHome®