Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3190175imm; Fri, 19 Oct 2018 06:40:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV62ht2uhlH11dy2r/QO7N0tZ1vf5NszZcu7d+32TlHRDFQjo1EAx9ZcMKiQo7Z62XWPO2HIn X-Received: by 2002:a63:d805:: with SMTP id b5-v6mr32037137pgh.174.1539956452482; Fri, 19 Oct 2018 06:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539956452; cv=none; d=google.com; s=arc-20160816; b=08YFbbaEEMRjWOS/ick1VcTIxv67w2wBw5azcsVC6bUaxYAX72GKQ08GwkGG8srh2B kYh3zKubr1mbwF8P/qDiwZVAtSE4ymyPFnF2j8gQw2uzyoIF4fya0V4gBe9FDfBBj3mR mFRenrVSiA+WRk9nX2WXVlCQjsd308y3BqCexucVxoe4GOIrLEQYrpX6aFNQau82cP+O WlWWmsjfR1D7kk8d0jXzv8zsw/ir+vnrE0os1BDkK/DUL0K3alSlHfIM6HPz9a5kt9X3 hLiIay0C/eAwriMo1cBLs1/aHrZewFqDiGPY6GeMHEL1wWpMLxPbd8G7VDdH5LUkddcZ ACzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=1n3P0AReSiB1JyZqsrcw6u6tDGhBm20+iA+Quc4324M=; b=ReOP9GW81GoRrbCSYke04S6UmeKqXKSmjwx4nu1USoTIa/4kK+pObkZZb4pdKwYlLt C60XEsb7ePl/t0P4jQ3O9LipjZ6tgR7aQZHqya/F0dBY5LT+fMMkcFEQeD8g7aMztLLa BdVR/Rkxrd16FDH3HF0d/vhFflWjDnndSUjw+iPtMO4WPRkGFHrOUYOvZ8HNAVVPb31s fBDCJy4bN7y5lc7jEn5TsYbwVHp7sjqv+CBTFigEkCHf+Wg6WBsbBfL6w9KFi1Vb5Yvg CRkn6lyF03YS7NOvbmGKDl0UceAWSj1VFJlJRcSKU1oyjX6FmuLaGB959DThPuJEx0sR YVBQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si24694908pgh.542.2018.10.19.06.40.37; Fri, 19 Oct 2018 06:40:52 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727802AbeJSVqF (ORCPT + 99 others); Fri, 19 Oct 2018 17:46:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:23847 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727377AbeJSVqE (ORCPT ); Fri, 19 Oct 2018 17:46:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2018 06:39:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,400,1534834800"; d="scan'208";a="89603836" Received: from svm-s2600wft.bj.intel.com ([10.240.193.45]) by FMSMGA003.fm.intel.com with ESMTP; 19 Oct 2018 06:39:51 -0700 From: Yi Sun To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, jgross@suse.com, chao.p.peng@intel.com, chao.gao@intel.com, isaku.yamahata@intel.com, michael.h.kelley@microsoft.com, tianyu.lan@microsoft.com, Yi Sun , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" Subject: [PATCH v1 2/2] x86/hyperv: make HvNotifyLongSpinWait hypercall Date: Fri, 19 Oct 2018 21:13:55 +0800 Message-Id: <1539954835-34035-3-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539954835-34035-1-git-send-email-yi.y.sun@linux.intel.com> References: <1539954835-34035-1-git-send-email-yi.y.sun@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The HvNotifyLongSpinWait hypercall (HVCALL_NOTIFY_LONG_SPIN_WAIT) is used by a guest OS to notify the hypervisor that the calling virtual processor is attempting to acquire a resource that is potentially held by another virtual processor within the same Virtual Machine. This scheduling hint improves the scalability of VMs with more than one virtual processor on Hyper-V. Per MSFT TLFS, the retry number (SpinWaitInfo) is sent to hypervisor only when the retry number exceeds the recommended number. If recommended number is 0xFFFFFFFF, never retry. Signed-off-by: Yi Sun Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Thomas Gleixner Cc: Michael Kelley (EOSG) Cc: Juergen Gross --- arch/x86/hyperv/hv_spinlock.c | 18 ++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + kernel/locking/qspinlock_paravirt.h | 10 ++++++++++ 3 files changed, 29 insertions(+) diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c index a861b04..723dccb 100644 --- a/arch/x86/hyperv/hv_spinlock.c +++ b/arch/x86/hyperv/hv_spinlock.c @@ -18,6 +18,24 @@ static bool __initdata hv_pvspin = true; +bool hv_notify_long_spin_wait(int retry_num) +{ + /* + * Per MSFT TLFS, the SpinWaitInfo is sent to hypervisor only when + * the retry number exceeds the recommended number. + * + * If recommended number is 0xFFFFFFFF, never retry. + */ + if (ms_hyperv.num_spin_retry == HYPERV_SPINLOCK_RETRY_NEVER) + return false; + + if ((0 == retry_num % ms_hyperv.num_spin_retry) && retry_num) + hv_do_fast_hypercall8(HVCALL_NOTIFY_LONG_SPIN_WAIT, + retry_num); + + return true; +} + static void hv_qlock_kick(int cpu) { apic->send_IPI(cpu, X86_PLATFORM_IPI_VECTOR); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index f909365..bd87868 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -356,6 +356,7 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, void hv_apic_init(void); void __init hv_init_spinlocks(void); bool hv_vcpu_is_preempted(int vcpu); +bool hv_notify_long_spin_wait(int retry_num); #else static inline void hv_apic_init(void) {} #endif diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h index 0130e48..9e88c7e 100644 --- a/kernel/locking/qspinlock_paravirt.h +++ b/kernel/locking/qspinlock_paravirt.h @@ -7,6 +7,8 @@ #include #include +#include + /* * Implement paravirt qspinlocks; the general idea is to halt the vcpus instead * of spinning them. @@ -305,6 +307,10 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) wait_early = true; break; } +#if defined(CONFIG_X86_64) && defined(CONFIG_PARAVIRT_SPINLOCKS) && IS_ENABLED(CONFIG_HYPERV) + if (!hv_notify_long_spin_wait(SPIN_THRESHOLD - loop)) + break; +#endif cpu_relax(); } @@ -433,6 +439,10 @@ static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) for (loop = SPIN_THRESHOLD; loop; loop--) { if (trylock_clear_pending(lock)) goto gotlock; +#if defined(CONFIG_X86_64) && defined(CONFIG_PARAVIRT_SPINLOCKS) && IS_ENABLED(CONFIG_HYPERV) + if (!hv_notify_long_spin_wait(SPIN_THRESHOLD - loop)) + break; +#endif cpu_relax(); } clear_pending(lock); -- 1.9.1