Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3612299imm; Tue, 29 May 2018 10:09:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrmCejtKiFxGNVgUsFmK8wuvOZ2uTfzbgfC6aKL4NJvLhR3xMALS6XOoxYoxVSjp9Dettgl X-Received: by 2002:a17:902:5597:: with SMTP id g23-v6mr18036452pli.99.1527613795221; Tue, 29 May 2018 10:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527613795; cv=none; d=google.com; s=arc-20160816; b=zmLEwuOgKxE3XFBoyT1CzxMSVJnw4zpvzGCA31StvqtSchKR6nun8rSgAkhwcc9Ie5 L0QZOUGJ8ZipaP0kxATF6cnOsTfcFcmkVlbBmXW9b7G2nJjgD0vMHNhMFrH5vOrak5Q8 GGET7lIzTpWpTzmh3qRWasOKlOa0sg3h2fdrDVPLO8YDDyyMVJFNYlNWD+O7w2t5OaaN dScCzTN74ypHvVcZDZ2tO5OLQjkyTiOq22pDaQoKTYHQ2imM8f9PG4AX4qFgJKvI336i NmG1OBNzATECYLcuI6HNxYIJZHUilmfuvR5cht5IIoF/17dfIjV/S1VH/xWhxMe1oMwG iqmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=Hf3iwamSet9xjvtZ38dmhWS+gOMPA1R3BoVBGTejlFY=; b=o/EixUZqjavLVX2xE86FqQpviJyvIMBciDMGtax3owkg2ynVaySsCshgOzlQFcITBg z+1BaC3XilbN26T6tSO+q/rvdMKIHPB7c5fCmRzwWz6N8ARuB6DkRSgsXVrqA+1Mnamc 5JIwaRTKXEFkMKZFRfBX5eHg/CWI75ebiASXTjqr0LlAEKwTUJV8KbHB07D+y+n9tnyH /hZHvicc8IEBXPER1SqAW7sLxT7QfnAACjh5HW06pYnjt3Trtc7s3dT58iuZLrZUcgNt i8j/lJ+h3DkHjUOsARsiTWWzWRwR1eqloLeofxwcTzbAdlc9kL18Hj7cfCEscM0+t7+f AQTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hx20D503; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24-v6si8985485pgw.213.2018.05.29.10.09.41; Tue, 29 May 2018 10:09:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hx20D503; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965278AbeE2RI5 (ORCPT + 99 others); Tue, 29 May 2018 13:08:57 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36981 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936821AbeE2RIw (ORCPT ); Tue, 29 May 2018 13:08:52 -0400 Received: by mail-wm0-f67.google.com with SMTP id l1-v6so42732740wmb.2; Tue, 29 May 2018 10:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:openpgp:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Hf3iwamSet9xjvtZ38dmhWS+gOMPA1R3BoVBGTejlFY=; b=hx20D5036x8dbcKn4vd6/UM95JCOI2wjyytRZfWRZ9zwI131ZZdSS3bBAVXz5C14U7 lNdeQrHMipoYFDzj+WJkzBh2HKKY751BqLkYhPlc9eREVBv9fi4fDucGE+bpNf8jaqy8 59S21bxY0Tf8gxJ99kneSllfqj1PB2Jr4D4D3ICP56buwCWxm/3eXobGLiZDc+HnuFQF jpo8lfqeK/ifobFZJERtHJPq1nnKnvwm0erPtEt62t6ek+9dZGo+XR3ioeHguK1W1ttq dY/B+2LgbUMzn/x3YkavWYYLCIfDszCD3Rx2q80TgZOXYaEDY5vQLmKnmDmfNyXempS+ hdpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:openpgp :autocrypt:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=Hf3iwamSet9xjvtZ38dmhWS+gOMPA1R3BoVBGTejlFY=; b=BH407Okg03gGeWBoPzR8K2r7G62TrzGb9yYe5IqmD721rGbUhSPl82Q63Xg/o7A+7f z32pAxlK+sk0SD22s17DZVaaJ/ZigvF/B71y8tU9R+yp+eFTuxO+u3TtC2pd6uKoGZVx YWNlnorXBrLF+v2n5v96K4mOiD0zEOMJQx1GOzplV+ooqEEQ5DJOGvvjVMHkcVzOXJ36 x8Bm89oKMAHbHgZJgn/sEjl5r1VJFXE3xITmsChE8/6LxxRILqIrmNrCvnIV3norVD2P MvZxqe1KtyN0TqEMjsYJGuxxKWOiMlvKsMTlztA/my5MQDXSKAtGB7fFxKcpcUPT2RaO SJhw== X-Gm-Message-State: ALKqPwdnS2dUAy9nfQf01WyYMbalrm+twmJowARSGqeq447pH6WI2yMp d2fpjEvN1CHQJINuQAJtcoghGR6b X-Received: by 2002:a1c:8ec1:: with SMTP id q184-v6mr5145428wmd.104.1527613730848; Tue, 29 May 2018 10:08:50 -0700 (PDT) Received: from [192.168.10.165] (dynamic-adsl-78-12-189-60.clienti.tiscali.it. [78.12.189.60]) by smtp.googlemail.com with ESMTPSA id n17-v6sm30581452wra.3.2018.05.29.10.08.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 10:08:49 -0700 (PDT) Subject: Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <1527576797-5738-1-git-send-email-wanpengli@tencent.com> <20180529142324.GA7819@flask> <20180529143102.GC7819@flask> From: Paolo Bonzini Openpgp: preference=signencrypt Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyRXGYO8oROiuh+RZ1lXp6AQ4ZjoyH8WLfTLf5g1EKCTc4C1sy1vQSdzIRu3rBIjAvnC tGZADei1IExLqB3uzXKzZ1BZ+Z8hnt2og9hb7H0y8diYfEk2w3R7wEr+Ehk5NQsT2MPI2QBd wEv1/Aj1DgUHZAHzG1QN9S8wNWQ6K9DqHZTBnI1hUlkp22zCSHK/6FwUCuYp1zcAEQEAAc0f UGFvbG8gQm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WU9iuE1P0wARAQABwsEzBBgBAgAJBQJUQnHuAhsMAAoJEH4VEAzNNmmxp1EO oJy0uZggJm7gZKeJ7iUpeX4eqUtqelUw6gU2daz2hE/jsxsTbC/w5piHmk1H1VWDKEM4bQBT uiJ0bfo55SWsUNN+c9hhIX+Y8LEe22izK3w7mRpvGcg+/ZRG4DEMHLP6JVsv5GMpoYwYOmHn plOzCXHvmdlW0i6SrMsBDl9rw4AtIa6bRwWLim1lQ6EM3PWifPrWSUPrPcw4OLSwFk0CPqC4 HYv/7ZnASVkR5EERFF3+6iaaVi5OgBd81F1TCvCX2BEyIDRZLJNvX3TOd5FEN+lIrl26xecz 876SvcOb5SL5SKg9/rCBufdPSjojkGFWGziHiFaYhbuI2E+NfWLJtd+ZvWAAV+O0d8vFFSvr iy9enJ8kxJwhC0ECbSKFY+W1eTIhMD3aeAKY90drozWEyHhENf4l/V+Ja5vOnW+gCDQkGt2Y 1lJAPPSIqZKvHzGShdh8DduC0U3xYkfbGAUvbxeepjgzp0uEnBXfPTy09JGpgWbg0w91GyfT /ujKaGd4vxG2Ei+MMNDmS1SMx7wu0evvQ5kT9NPzyq8R2GIhVSiAd2jioGuTjX6AZCFv3ToO 53DliFMkVTecLptsXaesuUHgL9dKIfvpm+rNXRn9wAwGjk0X/A== Message-ID: Date: Tue, 29 May 2018 19:08:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180529143102.GC7819@flask> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>> >>> '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 >>> Cc: Radim Krčmář >>> Signed-off-by: Wanpeng Li >>> --- >>> 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