Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2399499ybi; Thu, 4 Jul 2019 10:16:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwquAMNYpeiJ10FdPlIXF5QankJ1GcD5Y9xfG8tBVzblpcOGnTq+ElE6dh5qfqg5e+SK3Aa X-Received: by 2002:a63:460c:: with SMTP id t12mr41561633pga.69.1562260603186; Thu, 04 Jul 2019 10:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562260603; cv=none; d=google.com; s=arc-20160816; b=lgR2bcY/zHISLD4C/pkkQWLWTsQcixgKywpRwi1YBwPasFP9DmBA+gJ9+WulOuS4kp plUd0V6QkwrQ6MG9XSfIuROJ+HYKpGiqsuqn/Hipadb0l4LBaYtuSp1ApaT/oLVzQvBz kH7xU+UbVpU/aXB96bq3crKUyvuBnVcHFPX8U6KUeh8KGLt0jLUPyukj/xKogCSlZhzz J7BywMIA0fBwtBvU+xb6sCmlC3PHdEquko+DNJdgWaHmFP6gLMfU/Wdq0O/Iios56+kt MKk+7flou4hfcQW0Aa3gqbCVNYChTsrK6yElhMVR8qb13sG6c93F6S/WVLlmHe5d3JB5 JWyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=/RO5XDNTE6EfEMGRKwrdUCOxyHVvXblXRCAwFikHQlg=; b=UezurytBDDlapl7LoxoKMcd7/ys6vlxVqTBiZzu08fDbOGjj+6xjwb32MrJbHCNyxT wk7yScOrRP0oL9Rh8IkwKaOkLWGxvX8+rTR/qui/s0EPJizfBdMpiEO5LHc5W/1uyVq+ CWAnAVoczlQKL0a6qZDZgVv4eDRjoXe1/QyelvNx03Fjj1riv53S8cHU4lw0D0aCY4aK Hzvkm5arDs+MmOtN22CILRAik2gM/dNMgR8rU5NSQR/y4d7aVJU/8kN78KOXUGNL67HN RRasqkErrk6E3tBhmvOFlfzrK1vbclBsgkFjcp7uhvRn5+pLpd+8BmcxNOgY5wxhKbYW +2HA== 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 k191si6023369pgd.25.2019.07.04.10.16.28; Thu, 04 Jul 2019 10:16:43 -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 S1727587AbfGDQet (ORCPT + 99 others); Thu, 4 Jul 2019 12:34:49 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59741 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727416AbfGDQeL (ORCPT ); Thu, 4 Jul 2019 12:34:11 -0400 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1hj4gT-0005iE-1h; Thu, 04 Jul 2019 18:34:09 +0200 Message-Id: <20190704155610.325211809@linutronix.de> User-Agent: quilt/0.65 Date: Thu, 04 Jul 2019 17:52:06 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Nadav Amit , Ricardo Neri , Stephane Eranian , Feng Tang Subject: [patch V2 21/25] x86/smp: Enhance native_send_call_func_ipi() References: <20190704155145.617706117@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nadav noticed that the cpumask allocations in native_send_call_func_ipi() are noticeable in microbenchmarks. Use the new cpumask_or_equal() function to simplify the decision whether the supplied target CPU mask is either equal to cpu_online_mask or equal to cpu_online_mask except for the CPU on which the function is invoked. cpumask_or_equal() or's the target mask and the cpumask of the current CPU together and compares it to cpu_online_mask. If the result is false, use the mask based IPI function, otherwise check whether the current CPU is set in the target mask and invoke either the send_IPI_all() or the send_IPI_allbutselt() APIC callback. Make the shorthand decision also depend on the static key which enables shorthand mode. That allows to remove the extra cpumask comparison with cpu_callout_mask. Reported-by: Nadav Amit Signed-off-by: Thomas Gleixner --- V2: New patch --- arch/x86/kernel/apic/ipi.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -83,23 +83,21 @@ void native_send_call_func_single_ipi(in void native_send_call_func_ipi(const struct cpumask *mask) { - cpumask_var_t allbutself; + if (static_branch_likely(&apic_use_ipi_shorthand)) { + unsigned int cpu = smp_processor_id(); - if (!alloc_cpumask_var(&allbutself, GFP_ATOMIC)) { - apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR); + if (!cpumask_or_equal(mask, cpumask_of(cpu), cpu_online_mask)) + goto sendmask; + + if (cpumask_test_cpu(cpu, mask)) + apic->send_IPI_all(CALL_FUNCTION_VECTOR); + else if (num_online_cpus() > 1) + apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR); return; } - cpumask_copy(allbutself, cpu_online_mask); - cpumask_clear_cpu(smp_processor_id(), allbutself); - - if (cpumask_equal(mask, allbutself) && - cpumask_equal(cpu_online_mask, cpu_callout_mask)) - apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR); - else - apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR); - - free_cpumask_var(allbutself); +sendmask: + apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR); } #endif /* CONFIG_SMP */