Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1173961imm; Fri, 1 Jun 2018 17:25:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLi3CHEIor0kENxPKaSeC+Ngj3NHU+9GKXf2n0idx9arddXu4s6oNqjN2zlsJVc3WEueWQX X-Received: by 2002:a63:ba56:: with SMTP id l22-v6mr10547043pgu.161.1527899144622; Fri, 01 Jun 2018 17:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527899144; cv=none; d=google.com; s=arc-20160816; b=GYP7UmrGTPrLkPmFr2yx51btZrRSIsdKcAwjpktTBuXHLYEiqyQcDmGeffQCuFMcrV St3oPS/1KdXAaSG5w36jGX1b2tPB4iwIlqnDDI+30bEw3C5FO5bpmVw0KYu6LeyytZU1 YlWdXilKPWFEA1aLb4QhM75GYnidqY9Ix3gxJzvwnzHrKNIQx/LZM9q98Z2DAKXu3qy1 VYoLQrXbM8aSOwAxW0H3MmRgPWHTFSWY3EKoPJ/gXhELLOGDk2uu10hnhoo+FT9HyVLu E6ZIbBTLzEVs/qsU0VRDYJqgyCCeEMO+4Kd9iksMFQ52qVwVQ8GNWuDMz8y5FAmuD0mT 8/vQ== 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=CEXJ2pCNqfQvF2lHwTKHfbpezhCbhsD6nzZJILAPw1g=; b=FHwfD5BggiFXy6LUOyj1cEYhI9428f6TlNJV6R0rLcCJhQznez32BQI5GtVhN0aOWd Yw2mYNQ5/a2s2es7D+6NXra7D3NihtgeCWJwrPVtT+pwCQlOT0TZFzq8GxYe7nDlC7Q2 vhg24IwKIe81jpftP9ZMcmTxWN3iRSnrmG4PGgryRpFb1zF65O+MB8ym/2C5UaDZNSzQ W9JyxbMKgEkgwG3M7R7DaQpQRfDmc1wltSwkPQo38ZAGDzE+8aXtrrP3ADIevUkOIyoF ASomqIniboUmOEZlUamuq1V2vzd1j+zw87BtyN54UpN0+aEorVXzpC77E1tARPTXep0Q DsoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WyWtr1G7; 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 t200-v6si13360311pgb.553.2018.06.01.17.25.29; Fri, 01 Jun 2018 17:25:44 -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=WyWtr1G7; 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 S1751821AbeFBAZE (ORCPT + 99 others); Fri, 1 Jun 2018 20:25:04 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:38654 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbeFBAZA (ORCPT ); Fri, 1 Jun 2018 20:25:00 -0400 Received: by mail-ot0-f195.google.com with SMTP id n3-v6so31252421ota.5; Fri, 01 Jun 2018 17:24:59 -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=CEXJ2pCNqfQvF2lHwTKHfbpezhCbhsD6nzZJILAPw1g=; b=WyWtr1G7xqlPvbG8SsOC9FDAaH7V/YhNiV6LBpJgD1m0vvCEg2zEEBLTaPdXJ3QyVi xzXW89AnPWvdNB21UtTfE/OlTACPHeKOTyebzadBRu+7MIJqx0LX7RZUXXHP6HS3qMF2 dJikOsvyo1DdwTArJVBKJZSue2JqI3Ahym9HAF7MZ3XNXQ/MZi+zDZ60ncMQ8cBwifNJ FScN2SY7MZ2G5ElmrKru9EkYecZhWjqG1I0fwJ15FStsmowmcimiw28NdtY2VH/Nzy5z axgoySY580+FWHCmcPXdybJRwQvPjFqwVmRMVI1wxh0Tqjte9++GJqJ6VT3Gln3ZU5pp b1+g== 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=CEXJ2pCNqfQvF2lHwTKHfbpezhCbhsD6nzZJILAPw1g=; b=I8iM1lTyqstz0tS61gV3H6JkfeiHVPVylqEQT5dS6VTZsyymrj/ll6f5gpwaOt2iEw xNTNyqatbBkkXC/o93++uu5i3Ut/YY3yN8p1mC/PHeH8WclBUQKCCk5B6nqUZWlwNj5i VXtBjtEolMiqOnqRIistTsyej1i0dMrqrHN+m2/mueFKpVdtz8b9B82hL3ZW0JL1H/9m 3gLePfu96LLabsdvwd5OKTYGZxmEINAKffaQl2315ZQTnJVOaSL8MFD1OyQ+zIyOrEkg +P2keMNRXhjd+I2GbB+D/gFnbObLTYQUb6SEMTycIq8kSTl645rJTXhbjCGAB+lzwmAM 8VDw== X-Gm-Message-State: ALKqPwdZ/aHPagjUnZGUKoXacrWZlT9e4mZUC8QZ4iRbrud7GQ2Y0rZf s0fUgOmPdwrkdECJYHwmgSD81oz48m0hwabdN9U= X-Received: by 2002:a9d:2a45:: with SMTP id t63-v6mr8368345ota.389.1527899099623; Fri, 01 Jun 2018 17:24:59 -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: Sat, 2 Jun 2018 08:24:36 +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 tscdeadl= ine > >>> timer is emulated by VMX preemption timer to reduce the hypervisor > >>> lantency (handle_preemption_timer -> vmentry). clockevents infrastrut= ure > >>> 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_a= dvance_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 The patch description should also be updated in kvm/queue I think. Regards, Wanpeng Li