Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6575493yba; Tue, 14 May 2019 09:46:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj5SbmxhdqUwLfevQD9wkP/4DGIhQfB7Wi660hcc0PhlsEpuVUsoh6Ma4itaio3KtS675i X-Received: by 2002:a17:902:8c8c:: with SMTP id t12mr39107560plo.116.1557852401918; Tue, 14 May 2019 09:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557852401; cv=none; d=google.com; s=arc-20160816; b=LF315L05/8oZd7CDnI7XL2Yl8n0LKJ5xFsJbhYl1V7zwqGRwN1HXSGtNUHgXy8QYLz vjDRJ7DoRG3KUVFwFLEam+fSByw0yV5XRZl7uhG4PjfFWlSfffoiiGyfl9gA0Ox9pjSb jjc/d41RP2rECOqMwtWtRCKXDOxLiDvi/0penFuhtCj1GsEJOgG5+z4fii/x5iqrGgbs AYnInoLvwGMZJmBl06TgpzUU0aQOWi674SN7CzXYB9Hd9MsXjYAk9B8427NWlbx8dDXC fkpwtz0sIxawrrQBygdeAIx7fVoPvp7Waj+0dnZkYeT+we5NGfYViZtukDjnXd0Sm0RH k2WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mJbK53euPZUoHHCuZHDyNYM2Ed4widHILUpTmOFLON0=; b=GmwL1Dxn9v8decnjQgiPSa6NczAG2yLJaB+mVcRx1FDKFdWXIrOeFCnSHXTi8IOsJR kR6O/Am74Qg+vWylK8TO7g3zZmcSx4lchjgASSGg/gpn5+SfPJ2YXgPEBLGCzvr5g5SA JptWaPyinXDs9ak3EJOxzUYVmmHR2jj9vYAeOE3UtjpbHquBIBw7pii88jrvmfV/BijS 3UDPYLInNrVyvD3obpOQniM1ZotBUegosgogWBu0OwGY+J1lVUq16vY5XdD/kzH4+sJX p9ST8+PLAXYHG0CUm4cN9YValA+0HltdHc2LhcB5oKTvaIbK77PuPaDV6I4Ekw+mb1o6 XhDg== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si12145241plb.147.2019.05.14.09.46.26; Tue, 14 May 2019 09:46:41 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbfENQpE (ORCPT + 99 others); Tue, 14 May 2019 12:45:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:55352 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726013AbfENQpE (ORCPT ); Tue, 14 May 2019 12:45:04 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 09:45:03 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by orsmga001.jf.intel.com with ESMTP; 14 May 2019 09:45:03 -0700 Date: Tue, 14 May 2019 09:45:03 -0700 From: Sean Christopherson To: Wanpeng Li Cc: LKML , kvm , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Liran Alon Subject: Re: [PATCH 3/3] KVM: LAPIC: Optimize timer latency further Message-ID: <20190514164503.GA1668@linux.intel.com> References: <1557401361-3828-1-git-send-email-wanpengli@tencent.com> <1557401361-3828-4-git-send-email-wanpengli@tencent.com> <20190513195417.GM28561@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 14, 2019 at 06:56:04PM +0800, Wanpeng Li wrote: > On Tue, 14 May 2019 at 09:45, Wanpeng Li wrote: > > > > On Tue, 14 May 2019 at 03:54, Sean Christopherson > > wrote: > > > Rather than reinvent the wheel, can we simply move the call to > > > wait_lapic_expire() into vmx.c and svm.c? For VMX we'd probably want to > > > support the advancement if enable_unrestricted_guest=true so that we avoid > > > the emulation_required case, but other than that I don't see anything that > > > requires wait_lapic_expire() to be called where it is. > > > > I also considered to move wait_lapic_expire() into vmx.c and svm.c > > before, what do you think, Paolo, Radim? > > However, guest_enter_irqoff() also prevents this. Otherwise, we will > account busy wait time as guest time. How about sampling several times > and get the average value or conservative min value to handle Sean's > concern? Hmm, looking at the history, wait_lapic_expire() was originally called immediately before kvm_x86_ops->run()[1]. The call was moved above guest_enter_irqoff() because of its tracepoint, which violated the RCU extended quiescent state invoked by guest_enter_irqoff()[2][3]. In other words, I don't think there is a fundamental issue with accounting the busy wait time to the guest rather than the host. Assuming the tracepoint was added to help tune the advancement time, I think we can simply remove the tracepoint, which would allow moving wait_lapic_expire(). Now that the advancement time is tracked per-vCPU, realizing a change in the advancement time requires creating a new VM. For all intents and purposes this makes it impractical to hand tune the advancement in real time using the tracepoint as the feedback mechanism. If we want to expose the per-vCPU advancement time to the user, a debugfs entry is likely sufficient given that the advancement time is automatically adjusted. [1] Commit d0659d946be0 ("KVM: x86: add option to advance tscdeadline hrtimer expiration") [2] Commit 8b89fe1f6c43 ("kvm: x86: move tracepoints outside extended quiescent state") [3] https://patchwork.kernel.org/patch/7821111/