Received: by 10.223.164.202 with SMTP id h10csp342523wrb; Thu, 9 Nov 2017 07:12:24 -0800 (PST) X-Google-Smtp-Source: ABhQp+QrZ8HVg3fnlARRBjahIKKJKKPJ0OfaZvYeWiNfG1sfI+32xQnKuUXY3J8mAGJSStZst1dd X-Received: by 10.84.130.33 with SMTP id 30mr768839plc.131.1510240344211; Thu, 09 Nov 2017 07:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510240344; cv=none; d=google.com; s=arc-20160816; b=yM7aARZnqlShe4H8yHG/eDMNaaFPc21DkPSF7ZQj63as4wVu1hAKU/2QmgxKlJYl7P Lmmr5fvOp1ab6Bt35IS7zRf7Q3rpvef5MY3nRXiNQbxYMkZ8WEwNM80Yx5BlFKnwlIRP P5nxO8PmKAncTB+46QHEITC1PO1eTIB5aD/0WrIOrx3rwAzlPDhQoiDl0Zx3tXU9tlU4 /3xKMuE8Xvty77NsipmKMysxzlcXhj5T8oeSa80xXS//d32DMBhDxCoR1PfsPnYvfZ/D T8fMNr+A5irWqBhmN0m/tDP2zx9vuc1tSIAnHwKQQQ2fs8tCLW//Nt+JpqAixDAJTri6 r2Xw== 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=sRR1P5S2tGFFKOziA02UaXZFru09NpBjfm1x7Sw1qMY=; b=n+MLG5/QGiKeeH3wNo4+Q/MPhucqmCad77AnygRerCnSDHwhkvBQ3Rp0xNrCpe2trB 2PjpW0ckgspAjh20WzF3XarBDRunyBE5PQh4b50pZtiSOzSzmrScucIs/axEWJVGIy8V 917hd8MRaHKjOIWzZN+3uYRSjBOxhhLfYrDCWw3Wgxkfa/9LwH00EJPc1Xc8U/XZPhqV OQZlRn48L9XMFV0FRbjW9Dg1oLCYAf29pfs5QFFKXKoaXAaDeBzS51fDl5xvsN+u6cIx +F3/EckAGSNiN3DQXMiXmiZwg2R50fnFd/dfdUZ42XhInjsV8HKTXstSeyUNVz+3/0lL R7uQ== 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 1si6480118pli.110.2017.11.09.07.12.12; Thu, 09 Nov 2017 07:12:24 -0800 (PST) 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 S1752745AbdKIPLI (ORCPT + 80 others); Thu, 9 Nov 2017 10:11:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41096 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbdKIPLF (ORCPT ); Thu, 9 Nov 2017 10:11:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A571E5D9FA; Thu, 9 Nov 2017 15:11:05 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 2CE2462460; Thu, 9 Nov 2017 15:11:03 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 09 Nov 2017 16:11:02 +0100 Date: Thu, 9 Nov 2017 16:11:02 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li Subject: Re: [PATCH RESEND 2/3] KVM: Add paravirt remote TLB flush Message-ID: <20171109151101.GB20859@flask> References: <1510192934-5369-1-git-send-email-wanpeng.li@hotmail.com> <1510192934-5369-3-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1510192934-5369-3-git-send-email-wanpeng.li@hotmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Nov 2017 15:11:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-08 18:02-0800, Wanpeng Li: > From: Wanpeng Li > > Remote flushing api's does a busy wait which is fine in bare-metal > scenario. But with-in the guest, the vcpus might have been pre-empted > or blocked. In this scenario, the initator vcpu would end up > busy-waiting for a long amount of time. > > This patch set implements para-virt flush tlbs making sure that it > does not wait for vcpus that are sleeping. And all the sleeping vcpus > flush the tlb on guest enter. > > The best result is achieved when we're overcommiting the host by running > multiple vCPUs on each pCPU. In this case PV tlb flush avoids touching > vCPUs which are not scheduled and avoid the wait on the main CPU. > > Test on a Haswell i7 desktop 4 cores (2HT), so 8 pCPUs, running ebizzy in > one linux guest. > > ebizzy -M > vanilla optimized boost > 8 vCPUs 10152 10083 -0.68% > 16 vCPUs 1224 4866 297.5% > 24 vCPUs 1109 3871 249% > 32 vCPUs 1025 3375 229.3% > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > @@ -465,6 +465,33 @@ static void __init kvm_apf_trap_init(void) > update_intr_gate(X86_TRAP_PF, async_page_fault); > } > > +static void kvm_flush_tlb_others(const struct cpumask *cpumask, > + const struct flush_tlb_info *info) > +{ > + u8 state; > + int cpu; > + struct kvm_steal_time *src; > + cpumask_t flushmask; > + > + > + cpumask_copy(&flushmask, cpumask); > + /* > + * We have to call flush only on online vCPUs. And > + * queue flush_on_enter for pre-empted vCPUs > + */ > + for_each_cpu(cpu, cpumask) { > + src = &per_cpu(steal_time, cpu); > + state = src->preempted; > + if ((state & KVM_VCPU_PREEMPTED)) { > + if (cmpxchg(&src->preempted, state, state | 1 << > + KVM_VCPU_SHOULD_FLUSH)) We won't be flushing unless the last argument reads 'state | KVM_VCPU_SHOULD_FLUSH' and the result will be the original value that should be compared with state to avoid a race that would drop running VCPU: if (cmpxchg(&src->preempted, state, state | KVM_VCPU_SHOULD_FLUSH) == state) > + cpumask_clear_cpu(cpu, &flushmask); > + } > + } > + > + native_flush_tlb_others(&flushmask, info); > +} > + > void __init kvm_guest_init(void) > { > int i; From 1583586515532623214@xxx Thu Nov 09 11:09:47 +0000 2017 X-GM-THRID: 1583551558691477552 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread