Received: by 10.223.176.5 with SMTP id f5csp761162wra; Fri, 9 Feb 2018 06:49:54 -0800 (PST) X-Google-Smtp-Source: AH8x226hq23jeWOEX4M35Dt4j8ZZy5anwQ19g2A/aneJPOHGaYU9trvcGLXJN4kdyeSTqP2kT+ya X-Received: by 10.99.60.86 with SMTP id i22mr2530415pgn.399.1518187794335; Fri, 09 Feb 2018 06:49:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187794; cv=none; d=google.com; s=arc-20160816; b=Zj6lIY/MSAcK6GhcpNu7E2RAM0wYyZtQcecLFZZ5M9/rHye81KdT7Q9L4LnjFp8vVQ /x7B4NJQplFGU7QoKNcCYL147YATDQP3zuOgSMZsZYgivADMQNJakrsyBiTFW6kb6ouE lyneI2tTe6i3nCflCjVJyYNbRRnckyVcE6Yqz/Wx7S3gZ5TL9PbMW1AbcHkA3slqysD7 QAjQTYkXejZRugID2GCfn64flSALYbA0sDlcuBx0IInGUicSh2jUK+lZtfvrTRo6Upm5 QHtX3CYFVHLpkXO1Rp2FpnkzJTRRKKlbgZ8zqBNPKRKgeFDOKe1IGojfRDO0XROJjUT1 nbng== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3l8Dl3EcdBLruIunXS4Y6Y//HS+nE4x8+L91yMrHxcc=; b=o7hDe/333PX99NIi9FugywhKGc1PRpZ1d/ws9kYPs2bj7CJpWgmJjSWFomDLhNEb+z svGp+GeNK1Fgac4AaiJH3uVY3+9T/3fzMLFTAJCHzb1HibHcx1eSEdpM8itr/KQ/nKdd tD8G7moognzcbmZZenVSnoFINa/HKlFvzDFYq74MtGDVbu/iHCX45ixpHkZwXUvW6doQ aurwlKkwq1/e9TZNeggcgLHwO5nOpXAUyU88p4vxWWK7YiCYm5RTGC5G3FUfaJST2EEo zvpk1cX5HdW5XBA+aQF3Z0lvpPpgigCnhxD7UrsV7doAdjSjAxsu0POJrfv1jEo3KYSk uhjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IJ5ra4Dc; 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=QUARANTINE 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 l64si1796933pfi.388.2018.02.09.06.49.40; Fri, 09 Feb 2018 06:49:54 -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=IJ5ra4Dc; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751122AbeBIOtC (ORCPT + 99 others); Fri, 9 Feb 2018 09:49:02 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:45877 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751004AbeBIOtA (ORCPT ); Fri, 9 Feb 2018 09:49:00 -0500 Received: by mail-pg0-f65.google.com with SMTP id m136so3748563pga.12; Fri, 09 Feb 2018 06:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3l8Dl3EcdBLruIunXS4Y6Y//HS+nE4x8+L91yMrHxcc=; b=IJ5ra4DcC8q3ipKZVEf+nMLdZbz39Wr0LPWl6PN1v0PKlM9xQjSQ6Yj2qInWXPomJt YmFJ2NdYfcRvZxlJ2a6jkOBl+F4UAdyh+BTddG7b6H9oX4WFebg4XyYqG0hquYwu/Hmh cxQb1wvFDP+PAKRc9GlELF61Bz+rQvhxT/5X3UU6qGe8LGvG+M/9tanAfE+OLX0PGNNr CzA7kXzc1OnLqJA0oL3YZIGlDmraqbYsbxKWWbizW4dZO5plJ6Fl+wzfOMY8yNBWWJcS gBGEgKucpO/19ONJFet/hJLi5Prb2qgBgOkLSkcn+e/3mRfLsmM2i/poDHNk0YbJT6x6 Y80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3l8Dl3EcdBLruIunXS4Y6Y//HS+nE4x8+L91yMrHxcc=; b=W/rPPXiyJDC7JeporFS7g3/AFpx7zGLQnUKEKU/7BmfG2LbO+0gaQoawFAt4xs0avm bEGTXAWQuy88cvw4HGWkdQUNIse3x0HsC7zjXzedsLwrbrbh/YZp2hzEwz14TgThXb/o /T6PZIC9q2HhRX0HaRSSgpY0tCucL6M0vKyiX4nAq7pVaOXU76Un8auJQ1f7wGTS1Hnl J9fVSewS4MLrnHZME9xAxU2rm9A6X5i9GK0v1klUbPGS6MzwGuJDVBIQnlcRs0yI7zFX UJsY2PFi08Ke+bYv6hya9CALe9OFNf2MYGpLxo5YikGH36p+lkxjNKowQfwLc23/+h7C tFhg== X-Gm-Message-State: APf1xPCRyojfP2Ey9Mv93ygRhiL6sQpH1Mx05Bt5IrmmijGsYB6FVXyT DS/+ngE86NOyXIO9Jbn69Y/w2Q== X-Received: by 10.99.65.65 with SMTP id o62mr2536199pga.392.1518187739328; Fri, 09 Feb 2018 06:48:59 -0800 (PST) Received: from localhost.localdomain ([45.248.77.205]) by smtp.googlemail.com with ESMTPSA id o63sm8098682pfa.101.2018.02.09.06.48.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:48:58 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Eduardo Habkost Subject: [PATCH v2 1/2] KVM: x86: Add dedicated vCPU hint KVM_HINTS_DEDICATED Date: Fri, 9 Feb 2018 06:47:52 -0800 Message-Id: <1518187673-70832-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Waiman Long mentioned that: Generally speaking, unfair lock performs well for VMs with a small number of vCPUs. Native qspinlock may perform better than pvqspinlock if there is vCPU pinning and there is no vCPU over-commitment. This patch adds a performance hint to allow hypervisor admin to choose the qspinlock to be used when a dedicated pCPU is available. PV_DEDICATED = 1, PV_UNHALT = anything: default is qspinlock PV_DEDICATED = 0, PV_UNHALT = 1: default is Hybrid PV queued/unfair lock PV_DEDICATED = 0, PV_UNHALT = 0: default is tas Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Eduardo Habkost Signed-off-by: Wanpeng Li --- v1 -> v2: * update to KVM_HINTS_DEDICATED Documentation/virtual/kvm/cpuid.txt | 6 ++++++ arch/x86/include/uapi/asm/kvm_para.h | 2 ++ arch/x86/kernel/kvm.c | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt index 87a7506..d54cc79 100644 --- a/Documentation/virtual/kvm/cpuid.txt +++ b/Documentation/virtual/kvm/cpuid.txt @@ -66,3 +66,9 @@ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock. ------------------------------------------------------------------------------ +KVM_HINTS_DEDICATED || 0 || guest checks this feature bit + || || to determine if they run on + || || dedicated vCPUs, allowing opti- + || || mizations such as usage of + || || qspinlocks. +------------------------------------------------------------------------------ diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 6cfa9c8..d65b16b 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -28,6 +28,8 @@ #define KVM_FEATURE_PV_TLB_FLUSH 9 #define KVM_FEATURE_ASYNC_PF_VMEXIT 10 +#define KVM_HINTS_DEDICATED 0 + /* 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 971babe..7f4c92d 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -724,6 +724,12 @@ void __init kvm_spinlock_init(void) { if (!kvm_para_available()) return; + + if (kvm_para_has_feature(KVM_HINTS_DEDICATED)) { + static_branch_disable(&virt_spin_lock_key); + return; + } + /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return; -- 2.7.4