Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp821178imm; Tue, 3 Jul 2018 00:06:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe9Ihofuk+aBgksnkHdzgM5cAjQOHZgorkACP+VyA7PPA8R77/GVZyZ0uxB1Lo3vMbIzz+q X-Received: by 2002:a65:498c:: with SMTP id r12-v6mr16044410pgs.112.1530601583531; Tue, 03 Jul 2018 00:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530601583; cv=none; d=google.com; s=arc-20160816; b=vVdaDbaxzB5ubKRUhOE4uDBUEEmGT+L7lmxOI7YMeEYXCHfNcLOVUXWVDG7eVpbJc3 fCq9azMg4hyB4D5H63EEyWbYjzegYPufS6MXl+Km12c7VVsPlyTMtBxZapoxfp/DBfEl dyRhyaFFfN1QWkEGIpcXqSCspQrYZRD2peq4JKdn5WYU+O1oKlg+WauQSKvakx1toQKf AE0wDfDbnHSTrMn14stmEHvW9ODD1FxfjM72crLuXbGD77Aq9SF7cZvgWav2mcC74jgp UivONBKu0rTQHaFTl5hRdm1l2cIuEg+RqQyYqQp/m2SsrXFcfDxUAS4aD2rNpSwO/0g8 IalA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=TSX8b4phdHEgAZAds9q/JhlV5qTVfvJ+i4JFu64d0g4=; b=SIQk/8pOMjDAeuBGAsGkpBDSlIQyMDaUXXwkCwF4nU03ztX4IDZBkMQGUIR/E/0laJ T/tYo4LUKc8udAfYbCDVrbMtTJRqIkqQFFz2rXtpHjqzzR/46p5ss42nsdKpFoS3H3Vw ZpjrRB3rJuYfzde76Fl7DDYs9DQJRXu3OQdayDmU+MbLtCbIuVazrgFxJMr7PFqxCIJN wentZteN4GFyh6h7ESBpo1hd5OA1y9AJXM31w+Sw3r8iVHzAhGCP8iB0InU3cySCLcv6 vOGoJobcqJi9hfTQQCdycmSm8VLsuK2sIGsRhzc6ivcIVZ01gtJ/2/YKA0iBR4DTKNnW ZjBQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6-v6si440719plo.508.2018.07.03.00.06.09; Tue, 03 Jul 2018 00:06:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932169AbeGCHFJ (ORCPT + 99 others); Tue, 3 Jul 2018 03:05:09 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50925 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754671AbeGCHFB (ORCPT ); Tue, 3 Jul 2018 03:05:01 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6374rtL189888 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 3 Jul 2018 00:04:53 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6374raj189885; Tue, 3 Jul 2018 00:04:53 -0700 Date: Tue, 3 Jul 2018 00:04:53 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Vitaly Kuznetsov Message-ID: Cc: tglx@linutronix.de, kys@microsoft.com, Tianyu.Lan@microsoft.com, hpa@zytor.com, haiyangz@microsoft.com, mingo@kernel.org, linux-kernel@vger.kernel.org, Michael.H.Kelley@microsoft.com, vkuznets@redhat.com, sthemmin@microsoft.com, mikelley@microsoft.com Reply-To: hpa@zytor.com, Tianyu.Lan@microsoft.com, kys@microsoft.com, tglx@linutronix.de, haiyangz@microsoft.com, Michael.H.Kelley@microsoft.com, linux-kernel@vger.kernel.org, mingo@kernel.org, vkuznets@redhat.com, sthemmin@microsoft.com, mikelley@microsoft.com In-Reply-To: <20180622170625.30688-4-vkuznets@redhat.com> References: <20180622170625.30688-4-vkuznets@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/hyperv] x86/hyper-v: Use cheaper HVCALL_SEND_IPI hypercall when possible Git-Commit-ID: 4bd06060762bc7e4834ecf9daeb78834f7a29582 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 4bd06060762bc7e4834ecf9daeb78834f7a29582 Gitweb: https://git.kernel.org/tip/4bd06060762bc7e4834ecf9daeb78834f7a29582 Author: Vitaly Kuznetsov AuthorDate: Fri, 22 Jun 2018 19:06:24 +0200 Committer: Thomas Gleixner CommitDate: Tue, 3 Jul 2018 09:00:34 +0200 x86/hyper-v: Use cheaper HVCALL_SEND_IPI hypercall when possible When there is no need to send an IPI to a CPU with VP number > 64 we can do the job with fast HVCALL_SEND_IPI hypercall. Signed-off-by: Vitaly Kuznetsov Signed-off-by: Thomas Gleixner Reviewed-by: Michael Kelley Cc: devel@linuxdriverproject.org Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: "H. Peter Anvin" Cc: Tianyu Lan Cc: "Michael Kelley (EOSG)" Link: https://lkml.kernel.org/r/20180622170625.30688-4-vkuznets@redhat.com --- arch/x86/hyperv/hv_apic.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index 90055f89223b..ee962784d25b 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -99,6 +99,9 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector) int nr_bank = 0; int ret = 1; + if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) + return false; + local_irq_save(flags); arg = (struct ipi_arg_ex **)this_cpu_ptr(hyperv_pcpu_input_arg); @@ -140,8 +143,18 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector) if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR)) return false; - if ((ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) - return __send_ipi_mask_ex(mask, vector); + /* + * From the supplied CPU set we need to figure out if we can get away + * with cheaper HVCALL_SEND_IPI hypercall. This is possible when the + * highest VP number in the set is < 64. As VP numbers are usually in + * ascending order and match Linux CPU ids, here is an optimization: + * we check the VP number for the highest bit in the supplied set first + * so we can quickly find out if using HVCALL_SEND_IPI_EX hypercall is + * a must. We will also check all VP numbers when walking the supplied + * CPU set to remain correct in all cases. + */ + if (hv_cpu_number_to_vp_number(cpumask_last(mask)) >= 64) + goto do_ex_hypercall; ipi_arg.vector = vector; ipi_arg.cpu_mask = 0; @@ -153,16 +166,17 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector) * only target upto 64 CPUs. */ if (vcpu >= 64) - goto ipi_mask_done; + goto do_ex_hypercall; __set_bit(vcpu, (unsigned long *)&ipi_arg.cpu_mask); } ret = hv_do_fast_hypercall16(HVCALL_SEND_IPI, ipi_arg.vector, ipi_arg.cpu_mask); - -ipi_mask_done: return ((ret == 0) ? true : false); + +do_ex_hypercall: + return __send_ipi_mask_ex(mask, vector); } static bool __send_ipi_one(int cpu, int vector) @@ -218,10 +232,7 @@ static void hv_send_ipi_self(int vector) void __init hv_apic_init(void) { if (ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) { - if ((ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) - pr_info("Hyper-V: Using ext hypercalls for IPI\n"); - else - pr_info("Hyper-V: Using IPI hypercalls\n"); + pr_info("Hyper-V: Using IPI hypercalls\n"); /* * Set the IPI entry points. */