Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3945805imm; Tue, 29 May 2018 17:46:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKITPO8Eux9Q0SgP2PMEukCTZI0wNMhBIAq/IWFbQDmaLew0M7LSgMtApYpPPYcjhFxKKbJi X-Received: by 2002:a17:902:6e4:: with SMTP id 91-v6mr612989plh.63.1527641214506; Tue, 29 May 2018 17:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527641214; cv=none; d=google.com; s=arc-20160816; b=tW40Ceh+4NMTA5vHm4Z9lOc3jel7Ojlaj1Ot+8fMewh/XgpCt3aFmKIHYbsP4yR7qa uqhAB9bLU28bcaSz2UIjFrpNfI0lWHxsWbBwPipE7n5jPTjfy3deaEG9xpapnKGT5CYE sBt0ja9CXXnDrV13pvu666ahBHiXiQAXrbgzFqyqi4OGsSr/M2/aXJ/2IhrlQ510YQo5 cckZ9gYlBlJ61GPZ88aq9778g5g6UTzG/yUwJ2Zk+jrq3PyqA2Ua+kMzsRee0aqPKs+1 YzDPajHhYpjnl7A6MuFwEwcDpnLNmIoMfzvLe/qyJmvhEqtnVR3wY0d7kziQx4o0EYQa 5qyw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=/XJNha/wJN/dCA9XaNvI4FKzNx9IvDns3Tqj0hPiR+0=; b=fuVbgqjpJG4WAuklZHh/sQBSDCrjDTchH57y7X0ikKk7zjnye7IGtvXb06IeIhUiOh BurnJQKQIMEi2A+5IYoerLVPXGrfucKDvBUAVsmdp3TiBiliYPhitnqjEo8CdJgkcGYp GRjXiXc1+HWp1hQjOc1GS8N7y7026N43geaRs9tMZgWIFIUZJLVSdlCrQ49RA4grWgWv hvZbcRGuZk0yaOW7i8gC5lHAGuURs9H/jqWj6Oh7zh9nxISNUrr9iMRbOETqMbj9up5/ qboyB7LFnbXlOwDWUgcYRHB9SWhr7RGpKXgYJnX+ep8cirzBODc+ts1Oay+/6hgmikS9 B2Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BZovHtV5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63-v6si33875664plb.566.2018.05.29.17.46.39; Tue, 29 May 2018 17:46:54 -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=pass header.i=@gmail.com header.s=20161025 header.b=BZovHtV5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968089AbeE3AqM (ORCPT + 99 others); Tue, 29 May 2018 20:46:12 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:34074 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965323AbeE3AqK (ORCPT ); Tue, 29 May 2018 20:46:10 -0400 Received: by mail-ot0-f193.google.com with SMTP id i5-v6so19197656otf.1; Tue, 29 May 2018 17:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/XJNha/wJN/dCA9XaNvI4FKzNx9IvDns3Tqj0hPiR+0=; b=BZovHtV51v+d0qUbf806oeM4kCT+WArMa9lAZ3XDDssXLug3Q3YmtjJ7kHRYxnajKg NE06IWgdjGNFlzY2qsGzDWNBh8jKBnxWlzZ3h2jD/3mHPqutMCW9UowsJfOaK5EIuFVB 0JTBqyLr/Lmkw5vxICt3ka6xWM9TzsqkLmfNhR7jRS+ePjgsn+j4JUcp4Dosa+wWdtSo GowD7bn0iawr+R7fbQpxqvzN+QPNQ3ydhPa/lKlaj5Yu2p9W7zPA2qciH/BHqaKypF7F WWQro6HYk2GTOxLYOLd6+Qx2z+nElE54duX7BVo8W8zqmDZHoDXpcYdEZ+3ODem+4LzS iWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=/XJNha/wJN/dCA9XaNvI4FKzNx9IvDns3Tqj0hPiR+0=; b=SrvJKC+C7cRvQxa6sZKE/KazuxyUq/ImEP9JvPglivV+JdPpEfZofPJL9oTr22oFEl wmQiOlLBi3CMRJLYtLnYwczNtfu9YCLE68kdvVo7CZpwG+O9fSDqBr5uFCTvAzjrerb/ eVBsEIvReSAFI1HI7d5aakXcEu6fce5Wdiqrup+thtVmcCfCzDiCDLTaoziv3R/O16Vq gWA75HGF92adZbVK7jYhuiBmToUQiktmcglXCJOIc01hvs7f0VPx1NdxzA8J4C1aeh++ G8cm4pp9tpouaQkb/0Jlw5fhIqR8OoLyvI/4AfsPOIrPFKXQ2QqKjxgFqvU7bHYeK7EF iJSw== X-Gm-Message-State: APt69E1GcOKOHv3Clq7qZpv8PNzVv46fedVpN8g48lB+HsqQOZ5tlcF4 qts2RrYa86XxLayX1E2y6z01da6deW72cuVHGhE= X-Received: by 2002:a9d:caf:: with SMTP id b44-v6mr402566otb.270.1527641170032; Tue, 29 May 2018 17:46:10 -0700 (PDT) MIME-Version: 1.0 References: <1527576797-5738-1-git-send-email-wanpengli@tencent.com> <20180529142324.GA7819@flask> <20180529143102.GC7819@flask> In-Reply-To: From: Wanpeng Li Date: Wed, 30 May 2018 08:46:11 +0800 Message-ID: Subject: Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency To: Paolo Bonzini Cc: Radim Krcmar , LKML , kvm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 30 May 2018 at 01:08, Paolo Bonzini wrote: > On 29/05/2018 16:31, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > > 2018-05-29 16:23+0200, Radim Kr=C4=8Dm=C3=A1=C5=99: > >> 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 testin= g > >>> busy waits. > >>> > >>> Cc: Paolo Bonzini > >>> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > >>> 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 =3D rdtsc(); > >>> guest_tscl =3D kvm_read_l1_tsc(vcpu, tscl); > >>> delta_tsc =3D max(guest_deadline_tsc, guest_tscl) - guest_tscl; > >>> + lapic_timer_advance_cycles =3D nsec_to_cycles(vcpu, lapic_timer_advance_ns); > >>> + if (delta_tsc > lapic_timer_advance_cycles) > >>> + delta_tsc -=3D lapic_timer_advance_cycles; > >>> + else > >>> + delta_tsc =3D 1; > >> > >> Why don't we just "return 1" to say that the timer has expired? > > > > This case might be rare, so setting delta_tsc =3D 0 would be safer. > Queued with this change. Indeed this case matches vmx_arm_hv_timer so > it's preferrable. Agreed, thanks. Regards, Wanpeng Li