Received: by 10.223.164.202 with SMTP id h10csp388314wrb; Thu, 9 Nov 2017 07:54:51 -0800 (PST) X-Google-Smtp-Source: ABhQp+RiDDmuDEJPuDLUdmt8JDhO4/iPknxwnhUSZ8V45WcoKfuoqAyWXWmg4xBYPTInwwXwzGyz X-Received: by 10.99.56.82 with SMTP id h18mr884745pgn.281.1510242891897; Thu, 09 Nov 2017 07:54:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510242891; cv=none; d=google.com; s=arc-20160816; b=JoKfy7xGYgFdp+EKXyA2zArg41W/56SsK2JFbIXil9cDn9yIKlFTWAjjARNDKCJVwo OkPiaY0I99xc6MktIkAa7BrDx7y0rGJ/CeUqJEHEE28qZEBpWqVBe6hmlDE4scu5AV4X 44qS1ce/cB9HD793QERxz22IkiCB1TGCfE0Rr88DROJapp9myxFIEfxJE3Eg5FSeanLu NM6RAjlUTkO3XZu/sGAHAnTDjNX/QLHh4HYv2kLwRiATZBMYKZsy1h86Tjs9e9kHN2Mw 9WwodvI34Lxfe6puknGDpjIPDWv9Ga9T3UBok5IWBQg5hAPD7+THp8vvDTtpN3dL7tj5 4EsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:arc-authentication-results; bh=wwLn23j2lj76A+Nfq1IYND6ynUEV7t8laaYlDa4o2sk=; b=jGpmWhFian86MlKP3MSJF6WOkF+sdqmJoTYiQnDWwjtIUwGB6i1Lon9a6SiVQvNTRW f7lOyg6RqvkJy5/tBSlh9gFjNHco8b2aLCEQLhzYe4cgrClrW9v6y0gKL5y66hetWslI u7o0UOSJw6NLVjVQof1u/o+tQSEMjL9/E0H+5KwSU+W86niLFiPMM+KPvtPJpac6nBul 0LbUcbZ9oqLsu0eCOICXXt1GgTv8OKxhSNQmlLTu8VrgouuoRSrz7LHwAUdvRKQyX6aU VI6vYOkA8QhmCFlMMGtUAruovRiTrbNukyH0w5LuDaZoMBsudvJGyAkf5Le8MfMRfluU lz+Q== 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 d12si4242395pgn.478.2017.11.09.07.54.40; Thu, 09 Nov 2017 07:54:51 -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 S1753008AbdKIPx3 convert rfc822-to-8bit (ORCPT + 80 others); Thu, 9 Nov 2017 10:53:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49824 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752745AbdKIPx0 (ORCPT ); Thu, 9 Nov 2017 10:53:26 -0500 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 7B6E6883CE; Thu, 9 Nov 2017 15:53:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B1FE6375E; Thu, 9 Nov 2017 15:53:26 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EFEF21808870; Thu, 9 Nov 2017 15:53:25 +0000 (UTC) Date: Thu, 9 Nov 2017 10:53:25 -0500 (EST) From: Pankaj Gupta To: Wanpeng Li Cc: Eduardo Valentin , Paolo Bonzini , Radim Krcmar , Matt Wilson , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , the arch/x86 maintainers , Peter Zijlstra , Waiman Long , kvm , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, "Jan H . Schoenherr" , Anthony Liguori Message-ID: <789734192.29237413.1510242805535.JavaMail.zimbra@redhat.com> In-Reply-To: References: <1509999980-10828-1-git-send-email-eduval@amazon.com> Subject: Re: [PATCHv3 1/1] locking/qspinlock/x86: Avoid test-and-set when PV_DEDICATED is set MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.67.116.57, 10.4.195.3] Thread-Topic: locking/qspinlock/x86: Avoid test-and-set when PV_DEDICATED is set Thread-Index: WTMmuiUfWA0BcJGubqLqDJ8vhAU0ZQ== 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.26]); Thu, 09 Nov 2017 15:53:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 2017-11-07 4:26 GMT+08:00 Eduardo Valentin : > > Currently, the existing qspinlock implementation will fallback to > > test-and-set if the hypervisor has not set the PV_UNHALT flag. > > > > This patch gives the opportunity to guest kernels to select > > between test-and-set and the regular queueu fair lock implementation > > based on the PV_DEDICATED KVM feature flag. When the PV_DEDICATED > > flag is not set, the code will still fall back to test-and-set, > > but when the PV_DEDICATED flag is set, the code will use > > the regular queue spinlock implementation. > > > > With this patch, when in autoselect mode, the guest will > > use the default spinlock implementation based on host feature > > flags as follows: > > > > PV_DEDICATED = 1, PV_UNHALT = anything: default is qspinlock > > PV_DEDICATED = 0, PV_UNHALT = 1: default is pvqspinlock > > PV_DEDICATED = 0, PV_UNHALT = 0: default is tas > > > > Cc: Paolo Bonzini > > Cc: "Radim Krčmář" > > Cc: Jonathan Corbet > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: "H. Peter Anvin" > > Cc: x86@kernel.org > > Cc: Peter Zijlstra > > Cc: Waiman Long > > Cc: kvm@vger.kernel.org > > Cc: linux-doc@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Cc: Jan H. Schoenherr > > Cc: Anthony Liguori > > Suggested-by: Matt Wilson > > Signed-off-by: Eduardo Valentin > > --- > > V3: > > - When PV_DEDICATED is set (1), qspinlock is selected, > > regardless of the value of PV_UNHAULT. Suggested by Paolo Bonzini. > > - Refreshed on top of tip/master. > > V2: > > - rebase on top of tip/master > > > > Documentation/virtual/kvm/cpuid.txt | 6 ++++++ > > arch/x86/include/asm/qspinlock.h | 4 ++++ > > arch/x86/include/uapi/asm/kvm_para.h | 1 + > > arch/x86/kernel/kvm.c | 2 ++ > > 4 files changed, 13 insertions(+) > > > > diff --git a/Documentation/virtual/kvm/cpuid.txt > > b/Documentation/virtual/kvm/cpuid.txt > > index 3c65feb..117066a 100644 > > --- a/Documentation/virtual/kvm/cpuid.txt > > +++ b/Documentation/virtual/kvm/cpuid.txt > > @@ -54,6 +54,12 @@ KVM_FEATURE_PV_UNHALT || 7 || guest > > checks this feature bit > > || || before enabling > > || || paravirtualized > > || || spinlock support. > > ------------------------------------------------------------------------------ > > +KVM_FEATURE_PV_DEDICATED || 8 || guest checks this feature > > bit > > + || || to determine if they run on > > + || || dedicated vCPUs, allowing > > opti- > > + || || mizations such as usage of > > + || || qspinlocks. > > +------------------------------------------------------------------------------ > > KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no > > guest-side > > || || per-cpu warps are expected > > || || in > > || || kvmclock. > > diff --git a/arch/x86/include/asm/qspinlock.h > > b/arch/x86/include/asm/qspinlock.h > > index 5e16b5d..de42694 100644 > > --- a/arch/x86/include/asm/qspinlock.h > > +++ b/arch/x86/include/asm/qspinlock.h > > @@ -3,6 +3,8 @@ > > #define _ASM_X86_QSPINLOCK_H > > > > #include > > +#include > > + > > #include > > #include > > #include > > @@ -58,6 +60,8 @@ static inline bool virt_spin_lock(struct qspinlock *lock) > > if (!static_branch_likely(&virt_spin_lock_key)) > > return false; > > > > + if (kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) > > + return false; > > /* > > * On hypervisors without PARAVIRT_SPINLOCKS support we fall > > * back to a Test-and-Set spinlock, because fair locks have > > diff --git a/arch/x86/include/uapi/asm/kvm_para.h > > b/arch/x86/include/uapi/asm/kvm_para.h > > index 554aa8f..85a9875 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_STEAL_TIME 5 > > #define KVM_FEATURE_PV_EOI 6 > > #define KVM_FEATURE_PV_UNHALT 7 > > +#define KVM_FEATURE_PV_DEDICATED 8 > > > > /* The last 8 bits are used to indicate how to interpret the flags field > > * in pvclock structure. If no bits are set, all flags are ignored. > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > > index 8bb9594..dacd7cf 100644 > > --- a/arch/x86/kernel/kvm.c > > +++ b/arch/x86/kernel/kvm.c > > @@ -642,6 +642,8 @@ void __init kvm_spinlock_init(void) > > { > > if (!kvm_para_available()) > > return; > > + if (kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) > > + return; > > /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ > > if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) > > return; > > -- > > 2.7.4 > > > > You should also add a cpuid flag in kvm part. Also, I am thinking if PV_DEDICATED helps in performance and with conjunction with PV TLB patch in other thread. For use-case e.g KVM-RT where we don't overcommit vCPU's and pin vCPU:pCPU 1:1 we need a way from host side with which user can decide to enable PV_DEDICATED option. Such that if vCPU's are unlikely going to preempt or sleep we should avoid traversing the cpulist in PV TLB code. So, two things: 1] A way to configure PV_DEDICATED from host. 2] PV TLB should also behave as per option PV_DEDICATED for better performance. Or I am missing any context here? > > Regards, > Wanpeng Li > From 1583598396568057173@xxx Thu Nov 09 14:18:38 +0000 2017 X-GM-THRID: 1583352031107436177 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread