Received: by 10.223.164.202 with SMTP id h10csp1243781wrb; Fri, 10 Nov 2017 00:36:27 -0800 (PST) X-Google-Smtp-Source: ABhQp+Q6E9XI/8iV+9jeHkSh34LYiI7UUzBu1e0VArUNI2E0LwFYVCfGdRu31o4lhqhUtISxLhEj X-Received: by 10.84.246.195 with SMTP id j3mr3378201plt.7.1510302987246; Fri, 10 Nov 2017 00:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510302987; cv=none; d=google.com; s=arc-20160816; b=AQbdZv4QfgUiwmZ7t0gVM4VvTu2MNPbnvbihviBYjl2a0uSytLRpijy5QvnNCTJRoO 7a8PFZwxkvajss5HiGRlITvpl73Vw3iK8rFl1r0mCpg9dCHRLPgyXczQozfw7uVlQGgQ qUvSBjrEls26LbpHTOgDXJVIXFbK33He4N8RC/3AeH0EBlljMX8QjdejSLE/u591bcVr mXTQ1LrA5N/q11cXwcbQ76NdGWgHVoM5p66R1u5PdTSwSuSsmUjKU389zSYcc+HmK7tp AGpe5EtVfrZ5gBZ9bUr1AsTxuEugD75dbqMhcWuAbi8Z1qspQ3U54W186KOeWBY58smP SDDw== 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:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=7XVMHfS6GIMwIT5qDjguNcJJhyCciqpv8ELjR9ZctgA=; b=sgJ1x4W8kNbk8iXHYLdHtXJukaAjNpsLS+cnTeaQw9poxg9hU21yBkDUUOjQ0Cg0H7 5fQDtlIqy+tvKXq8B3SD57uSx64mdyMFARw3KzGkk9xt0hlxji+0RYzXZQfle2HmDd4m 88RxpFzbdtY+UlGOpcCvU/QEROc1HxiJpkd7rOOuy+oo87rdUXP15IksBuguon16kAku y9YmFOCt+VoGVE8OvIWZD36rVrVK31qONBRKZBoUkPIOO1mHyPRSK5joyPs5xNNDe+WU we1QYMZQnFZ5LPQ/Ei/wvPwo+L2yAHZ2IubDzRXeOt1sU4mkUDmmEU2i5sbPLCSVYmoj 9wMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rgayCSc7; 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=NONE 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 89si8364106plc.263.2017.11.10.00.36.13; Fri, 10 Nov 2017 00:36:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rgayCSc7; 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=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751375AbdKJIff (ORCPT + 82 others); Fri, 10 Nov 2017 03:35:35 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:47103 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbdKJIfd (ORCPT ); Fri, 10 Nov 2017 03:35:33 -0500 Received: by mail-ot0-f193.google.com with SMTP id o9so7601827ota.3; Fri, 10 Nov 2017 00:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7XVMHfS6GIMwIT5qDjguNcJJhyCciqpv8ELjR9ZctgA=; b=rgayCSc7o/PzGJPoTyBWcXIZSyYuchbwgivwhI5gp0l2wvMx7Alb/tNIyrplwsQaXM a0zNwZ7cSf/a9YlYzOAkYe4vn9rMsBig6qfWoJWe8T51g7OH4umK2dCNFyx+ERca2wGg 29DYK7u7r8XuMR712m3WDMxBE7qDdIvk28D7C8YGR2e4yYZxddFXeWLGq9bvSeOLeYWB aRwc+WEcoFChZAyjhOWAFEBf4VkU1NTsQ78Z86wAxbbjsShAm1GoqDK7fnrKD2ApWCiD 1CEwePgj/TxcXiss70lAk36xmQ7JQ/mezhmtyuLLXVO4LnI/7VQlC/4KEuSIKYXDaXag z9eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=7XVMHfS6GIMwIT5qDjguNcJJhyCciqpv8ELjR9ZctgA=; b=SfJcY8CZi0lJMurXmj1lCroVtNAc9BdnBJAyeqbFMA3Z4c+nBNp4S4MStWbiftCoVr 3LM635x6UEKGfR7A4yYIiKXkbhSWZa8l0BNfQT+YLCeAMX7SHXCl5MSRhXPI8hWgbs5W 1yGjzX/KgbSUlURelYgSuLneFZk8/A97LR6IgHUPbFO9mWFVVjNfHeb3XXXarGL6DP9H DaF3VqcvAq07O5XpEDGBlUF2tayOKPf9Xt9xnpsKGGhVgV0xuxf3HBwdDG1GbzMK952S pDaMWiW9fozvqEbjOeuffJ0xAPswOD+2KtcL5H2fbnrWO6uNAVwkRn/to+O791MnmHS9 F6AA== X-Gm-Message-State: AJaThX7m0AorYhMiSIr13kUw2r0X+olGR7CCjzVulj6MdXs/e1agc1pH qArIn5KmnMHMVZtkt8xFerZhS+v9SIKG+nLuiCU= X-Received: by 10.157.47.71 with SMTP id h65mr1920197otb.62.1510302932875; Fri, 10 Nov 2017 00:35:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Fri, 10 Nov 2017 00:35:32 -0800 (PST) In-Reply-To: References: <1510297497-10063-1-git-send-email-wanpeng.li@hotmail.com> <1510297497-10063-3-git-send-email-wanpeng.li@hotmail.com> <1a42f32f-3f2a-0c05-bd50-e6c3c710be85@redhat.com> From: Wanpeng Li Date: Fri, 10 Nov 2017 16:35:32 +0800 Message-ID: Subject: Re: [PATCH v2 2/4] KVM: Add paravirt remote TLB flush To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li 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 2017-11-10 16:33 GMT+08:00 Wanpeng Li : > 2017-11-10 16:24 GMT+08:00 Paolo Bonzini : >> On 10/11/2017 08:04, Wanpeng Li wrote: >>> 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 runnin= g >>> 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=C4=8Dm=C3=A1=C5=99 >>> Signed-off-by: Wanpeng Li >>> --- >>> Documentation/virtual/kvm/cpuid.txt | 4 ++++ >>> arch/x86/include/uapi/asm/kvm_para.h | 2 ++ >>> arch/x86/kernel/kvm.c | 31 ++++++++++++++++++++++++++++= +++ >>> 3 files changed, 37 insertions(+) >>> >>> diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtua= l/kvm/cpuid.txt >>> index 117066a..9693fcc 100644 >>> --- a/Documentation/virtual/kvm/cpuid.txt >>> +++ b/Documentation/virtual/kvm/cpuid.txt >>> @@ -60,6 +60,10 @@ KVM_FEATURE_PV_DEDICATED || 8 || guest= checks this feature bit >>> || || mizations such as usage= of >>> || || qspinlocks. >>> ----------------------------------------------------------------------= -------- >>> +KVM_FEATURE_PV_TLB_FLUSH || 9 || guest checks this featu= re bit >>> + || || before enabling paravir= tualized >>> + || || tlb flush. >>> +----------------------------------------------------------------------= -------- >>> KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no gu= est-side >>> || || per-cpu warps are expec= ted in >>> || || kvmclock. >>> diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/ua= pi/asm/kvm_para.h >>> index 9ead1ed..a028479 100644 >>> --- a/arch/x86/include/uapi/asm/kvm_para.h >>> +++ b/arch/x86/include/uapi/asm/kvm_para.h >>> @@ -25,6 +25,7 @@ >>> #define KVM_FEATURE_PV_EOI 6 >>> #define KVM_FEATURE_PV_UNHALT 7 >>> #define KVM_FEATURE_PV_DEDICATED 8 >>> +#define KVM_FEATURE_PV_TLB_FLUSH 9 >>> >>> /* The last 8 bits are used to indicate how to interpret the flags fie= ld >>> * in pvclock structure. If no bits are set, all flags are ignored. >>> @@ -53,6 +54,7 @@ struct kvm_steal_time { >>> >>> #define KVM_VCPU_NOT_PREEMPTED (0 << 0) >>> #define KVM_VCPU_PREEMPTED (1 << 0) >>> +#define KVM_VCPU_SHOULD_FLUSH (1 << 1) >>> >>> #define KVM_CLOCK_PAIRING_WALLCLOCK 0 >>> struct kvm_clock_pairing { >>> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c >>> index 66ed3bc..50f4b6a 100644 >>> --- 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 cpumask_t flushmask; >> >> Hi Wanpeng, >> >> are you going to send v3 with a percpu variable? > > Yeah, I just complete v3 according to Peterz's comments in another > guy's thread, I will send out them after completing the testing. This is how it looks it. https://pastebin.com/raw/L2vqu4cZ Regards, Wanpeng Li > > Regards, > Wanpeng Li > >> >> Paolo >> >>> +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_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 =3D &per_cpu(steal_time, cpu); >>> + state =3D src->preempted; >>> + if ((state & KVM_VCPU_PREEMPTED)) { >>> + if (cmpxchg(&src->preempted, state, state | >>> + KVM_VCPU_SHOULD_FLUSH) =3D=3D state) >>> + __cpumask_clear_cpu(cpu, &flushmask); >>> + } >>> + } >>> + >>> + native_flush_tlb_others(&flushmask, info); >>> +} >>> + >>> void __init kvm_guest_init(void) >>> { >>> int i; >>> @@ -484,6 +511,10 @@ void __init kvm_guest_init(void) >>> pv_time_ops.steal_clock =3D kvm_steal_clock; >>> } >>> >>> + if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && >>> + !kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) >>> + pv_mmu_ops.flush_tlb_others =3D kvm_flush_tlb_others; >>> + >>> if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) >>> apic_set_eoi_write(kvm_guest_apic_eoi_write); >>> >>> >> From 1583667350855343204@xxx Fri Nov 10 08:34:38 +0000 2017 X-GM-THRID: 1583661871160144366 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread