Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3415348ybi; Mon, 10 Jun 2019 09:53:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGjD+Q6ddvU7XFiGCPPpLweNxIbfJv13xzkcVqeT/+2TW+FCepnXDW6EvXl/hWspM5ZIDq X-Received: by 2002:aa7:8145:: with SMTP id d5mr76630718pfn.11.1560185590057; Mon, 10 Jun 2019 09:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560185590; cv=none; d=google.com; s=arc-20160816; b=LX9+RWCPkJ/K8dhNfVVvzYRnikilZwx/ABJSv1yWNJkqaHIo/euzbgLmnEA7SZlnk8 iBXvIsVnxRgffEIoCPNjgkI7IbjZXeHRY1r5xQ6depG8HNJ4qCqBlDRL4b/V7pIOpKoF HfOlhbQvdFv1ngwh3dXlJ28yC1veBaDoS5IQzTkx6IlHYhBCpP2u/2Bv/HGSe7CTfvGT SFZZMbsym69YNnOr5HQB9Ir+9beoau/ZGmVgB89WGdvbaJz30Ojelv7iOLpeTLke24cz WXAExVmt04Nn3JoQKeD3js6S0+NoChkdG6uR1vX4vK1nd1FYcLFRkVwNFYG5kiLGJFZJ 3BKg== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=6BJSPFIVmvc0CYFo6E7+ioRI9IIxk5nn7aQUhXzDTLY=; b=ZEBbc6dkUYA618OxxJsDszTW/r8IoYalPgcJDalht/bM7ECNyHDfMmn1TaffTYwotx jbpAFPNOrU20RAbl1CaTzv+Rc0zUfU/ECH1UX754i4K8O9IW2lWPSKWSGP87H1xECxoo sQYO71Ty/4+Od/vLn7pG/iPqDS54eEV0v1WWn7o3uZeSBstNfgXb21OB8ddhpGm/ijbq GmHHbVXG81KySxbqdY7iidUw9dsb3KBjezS3H4CpZXxd/KXQZoJkZmEM5J+HxjSfzlcB jEE2NGZ611nYhMIlGGyhYjsjuQRRYDKIGARTxyHF7P7S7Q19kG7rfrprFIBcpHbk3Igv txbQ== 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 a16si10351002pgl.242.2019.06.10.09.52.54; Mon, 10 Jun 2019 09:53:10 -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 S1728178AbfFJQva (ORCPT + 99 others); Mon, 10 Jun 2019 12:51:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49454 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725270AbfFJQva (ORCPT ); Mon, 10 Jun 2019 12:51:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56651308213B; Mon, 10 Jun 2019 16:51:30 +0000 (UTC) Received: from flask (unknown [10.43.2.83]) by smtp.corp.redhat.com (Postfix) with SMTP id 5CB085C1B4; Mon, 10 Jun 2019 16:51:28 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Mon, 10 Jun 2019 18:51:27 +0200 Date: Mon, 10 Jun 2019 18:51:27 +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 v2 2/3] KVM: LAPIC: lapic timer interrupt is injected by posted interrupt Message-ID: <20190610165127.GA8389@flask> References: <1559799086-13912-1-git-send-email-wanpengli@tencent.com> <1559799086-13912-3-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1559799086-13912-3-git-send-email-wanpengli@tencent.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 10 Jun 2019 16:51:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2019-06-06 13:31+0800, Wanpeng Li: > From: Wanpeng Li > > Dedicated instances are currently disturbed by unnecessary jitter due > to the emulated lapic timers fire on the same pCPUs which vCPUs resident. > There is no hardware virtual timer on Intel for guest like ARM. Both > programming timer in guest and the emulated timer fires incur vmexits. > This patch tries to avoid vmexit which is incurred by the emulated > timer fires in dedicated instance scenario. > > When nohz_full is enabled in dedicated instances scenario, the emulated > timers can be offload to the nearest busy housekeeping cpus since APICv > is really common in recent years. The guest timer interrupt is injected > by posted-interrupt which is delivered by housekeeping cpu once the emulated > timer fires. > > 3%~5% redis performance benefit can be observed on Skylake server. > > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/lapic.c | 32 +++++++++++++++++++++++++------- > arch/x86/kvm/x86.h | 5 +++++ > 2 files changed, 30 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 09b7387..c08e5a8 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -133,6 +133,12 @@ static inline bool posted_interrupt_inject_timer_enabled(struct kvm_vcpu *vcpu) > kvm_mwait_in_guest(vcpu->kvm); > } > > +static inline bool can_posted_interrupt_inject_timer(struct kvm_vcpu *vcpu) > +{ > + return posted_interrupt_inject_timer_enabled(vcpu) && > + !vcpu_halt_in_guest(vcpu); It would make more sense to have a condition for general blocking in KVM, but keep in mind that we're not running on the same cpu anymore, so any code like that has to be properly protected against VM entries under our hands. (The VCPU could appear halted here, but before we get make the timer pending, the VCPU would enter and potentially never check the interrupt.) I think we should be able to simply do if (posted_interrupt_inject_timer_enabled(vcpu)) kvm_inject_apic_timer_irqs(); directly in the apic_timer_expired() as the injection will wake up the target if necessary. It's going to be a bit slow for timer callback in those (too slow to warrant special handling?), but there hopefully aren't any context restrictions in place. Thanks.