Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3446708imm; Tue, 29 May 2018 07:25:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLDPKZee85uShqt7dH1JeZhlLPcUGKjSvJN9h9kBD3UQ8m5wTAJcxwAAMjmden2DNs12Ov9 X-Received: by 2002:a65:4c0e:: with SMTP id u14-v6mr6383671pgq.388.1527603902575; Tue, 29 May 2018 07:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527603902; cv=none; d=google.com; s=arc-20160816; b=YBs7et3ODxlZDmFg4lfwAaWU+mk5Ugheyu5RmeLkd4yO+wbUhYkn1oLfpegLS3fFLQ dquy+cc3ZqaIni2Om0bPNToCIo7eCZvUz8gl4RDbG+Xnmorqw7cSUN3IdhF0XRWkEW8j DYs7iPHNz/mFoBLaVZsCGc8cBY7H4MpBRRv0nfPFyLSU6rFi+eplScR6NPFSIkUml/Yn 68konbhOYGwE2f1cmGYGQHipfOgFkJog+R9Pl+KYnXKCSwgeWmIc7oIc1vKk9E987amm IF5ARaz3aa6dc/4MBPcQF+fYz7lR95gkBg0FElTmhbdoiIBDl/Te5Iq6opKhKHNiXDZB Bdrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=/TRUGKLZDdwm3GpaH5mS2OWAQVEKWZ5kKJhTaeq79Y0=; b=lPW2CeHmowHZLTym99hly1TYk6RFRHRBDINlkc71hYwT6imFOxKfuqTNNJgOCf65jV FdNxWTi7OqJn3s6AAaywsEwz8eY4vWPBV+AVXFNu56F6oFfx3j9nsEbTP2HxuE9sm+dL EOvv5HFSUgDrp0Am19/2ZDPiPF4z2KZqZpgRnW/MaIXaS4zoqX11hi3KCwd3PEjlDWTj Rpf6TxjrEkvNGPB51vK607MZzmtJZEgMqkZgwiokUvM9YlqfczO7oqVAlxfgUJjwH6EV v6XWeWspYrapgYUdmkRAEoycGYv4QGN0v8qWLsLZnsnRuf5OEZe0ECifS8vP2acT2Bon zjqA== ARC-Authentication-Results: i=1; mx.google.com; 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 f13-v6si26434162pgr.62.2018.05.29.07.24.48; Tue, 29 May 2018 07:25:02 -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; 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 S934981AbeE2OXa (ORCPT + 99 others); Tue, 29 May 2018 10:23:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50720 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934472AbeE2OX1 (ORCPT ); Tue, 29 May 2018 10:23:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F028D818BAF2; Tue, 29 May 2018 14:23:26 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 3556C210C6CE; Tue, 29 May 2018 14:23:25 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Tue, 29 May 2018 16:23:24 +0200 Date: Tue, 29 May 2018 16:23:24 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini Subject: Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency Message-ID: <20180529142324.GA7819@flask> References: <1527576797-5738-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1527576797-5738-1-git-send-email-wanpengli@tencent.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 14:23:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 14:23:27 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rkrcmar@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? I think "delta_tsc = 1" would just force an immediate VM exit and a re-entry, which seems wasteful as we could just be delaying the entry until the deadline has really passed, thanks.