mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yang Zhang <yang.zhang.wz@gmail.com>
To: David Matlack <dmatlack@google.com>
Cc: "Wanpeng Li" <kernellwp@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm list" <kvm@vger.kernel.org>,
	"Wanpeng Li" <wanpeng.li@hotmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>
Subject: Re: [PATCH v2] KVM: halt-polling: poll if emulated lapic timer will fire soon
Date: Mon, 23 May 2016 09:26:34 +0800	[thread overview]
Message-ID: <4b5e2981-17a3-788b-0dac-c2f125765de3@gmail.com> (raw)
In-Reply-To: <CALzav=fpWCt=9dKziT4XTt9YXWjZCVHJJuKim9_jJADHxrtqEQ@mail.gmail.com>

On 2016/5/21 2:37, David Matlack wrote:
> On Thu, May 19, 2016 at 7:04 PM, Yang Zhang <yang.zhang.wz@gmail.com> wrote:
>> On 2016/5/20 2:36, David Matlack wrote:
>>>
>>> On Thu, May 19, 2016 at 11:01 AM, David Matlack <dmatlack@google.com>
>>> wrote:
>>>>
>>>> On Thu, May 19, 2016 at 6:27 AM, Wanpeng Li <kernellwp@gmail.com> wrote:
>>>>>
>>>>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>>>>
>>>>> If an emulated lapic timer will fire soon(in the scope of 10us the
>>>>> base of dynamic halt-polling, lower-end of message passing workload
>>>>> latency TCP_RR's poll time < 10us) we can treat it as a short halt,
>>>>> and poll to wait it fire, the fire callback apic_timer_fn() will set
>>>>> KVM_REQ_PENDING_TIMER, and this flag will be check during busy poll.
>>>>> This can avoid context switch overhead and the latency which we wake
>>>>> up vCPU.
>>>>
>>>>
>>>> If I understand correctly, your patch aims to reduce the latency of
>>>> (APIC Timer expires) -> (Guest resumes execution) using halt-polling.
>>>> Let me know if I'm misunderstanding.
>>>>
>>>> In general, I don't think it makes sense to poll for timer interrupts.
>>>> We know when the timer interrupt is going to arrive. If we care about
>>>> the latency of delivering that interrupt to the guest, we should
>>>> program the hrtimer to wake us up slightly early, and then deliver the
>>>> virtual timer interrupt right on time (I think KVM's TSC Deadline
>>>> Timer emulation already does this).
>>>
>>>
>>> (It looks like the way to enable this feature is to set the module
>>> parameter lapic_timer_advance_ns and make sure your guest is using the
>>> TSC Deadline timer instead of the APIC Timer.)
>>
>>
>> This feature is slightly different from current advance expiration way.
>> Advance expiration rely on the VCPU is running(do polling before vmentry).
>> But in some cases, the timer interrupt may be blocked by other thread(i.e.,
>> IF bit is clear) and VCPU cannot be scheduled to run immediately. So even
>> advance the timer early, VCPU may still see the latency. But polling is
>> different, it ensures the VCPU to aware the timer expiration before schedule
>> out.
>>
>>>
>>>> I'm curious to know if this scheme
>>>> would give the same performance improvement to iperf as your patch.
>>>>
>>>> We discussed this a bit before on the mailing list before
>>>> (https://lkml.org/lkml/2016/3/29/680). I'd like to see halt-polling
>>>> and timer interrupts go in the opposite direction: if the next timer
>>>> event (from any timer) is less than vcpu->halt_poll_ns, don't poll at
>>>> all.
>>>>
>>>>>
>>>>> iperf TCP get ~6% bandwidth improvement.
>>>>
>>>>
>>>> Can you explain why your patch results in this bandwidth improvement?
>>
>>
>> It should be reasonable. I have seen the same improvement with ctx switch
>> benchmark: The latency is reduce from ~2600ns to ~2300ns with the similar
>> mechanism.(The same idea but different implementation)
>
> It's not obvious to me why polling for a timer interrupt would improve
> context switch latency. Can you explain a bit more?

We have a workload which using high resolution timer(less than 1ms) 
inside guest. It rely on the timer to wakeup itself. Sometimes the timer 
is expected to fired just after the VCPU is blocked due to execute halt 
instruction. But the thread who is running in the CPU will turn off the 
hardware interrupt for long time due to disk access. This will cause the 
timer interrupt been blocked until the interrupt is re-open.
For optimization, we let VCPU to poll for a while if the next timer will 
arrive soon before schedule out. And the result shows good when running 
several workloads inside guest.

-- 
best regards
yang

  reply	other threads:[~2016-05-23  1:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19 13:27 Wanpeng Li
2016-05-19 13:46 ` Christian Borntraeger
2016-05-19 13:57 ` Paolo Bonzini
2016-05-19 14:52   ` Christian Borntraeger
2016-05-19 14:56     ` Paolo Bonzini
2016-05-19 15:03       ` Christian Borntraeger
2016-05-19 15:06         ` Paolo Bonzini
2016-05-19 15:42           ` Christian Borntraeger
2016-05-24  2:48   ` Wanpeng Li
2016-05-19 18:01 ` David Matlack
2016-05-19 18:36   ` David Matlack
2016-05-20  2:04     ` Yang Zhang
2016-05-20  5:53       ` Wanpeng Li
2016-05-20 18:37       ` David Matlack
2016-05-23  1:26         ` Yang Zhang [this message]
2016-05-23 18:04           ` David Matlack
2016-05-24  1:13             ` Yang Zhang
2016-05-24  1:16               ` David Matlack
2016-05-24  2:55                 ` Yang Zhang

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=4b5e2981-17a3-788b-0dac-c2f125765de3@gmail.com \
    --to=yang.zhang.wz@gmail.com \
    --cc=borntraeger@de.ibm.com \
    --cc=dmatlack@google.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.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®