From patchwork Wed Sep 9 15:08:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Narayan Lal X-Patchwork-Id: 11765921 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E6CC92C for ; Wed, 9 Sep 2020 17:18:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59CDE2166E for ; Wed, 9 Sep 2020 17:18:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ELo1IuN3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730446AbgIIRRa (ORCPT ); Wed, 9 Sep 2020 13:17:30 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:32682 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730131AbgIIP2A (ORCPT ); Wed, 9 Sep 2020 11:28:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599665241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gs37dOVi+JtPJIOcRlbiuS4yc0tVwgOrDIKR6DvjZsg=; b=ELo1IuN3W69uOF1bLLhAiv0JEr7VDU6Uux4mX5t2cxEI48o4aoO9tqn2/5NYSt0sFE2BPv fehbmx3yZ3+WsinZUfwfMUbuCoY0/OzcMxIDRLhxOR8ToGiB/IB4VvoqTf/cJz9wy8nrFe w1iITctnUoSsk6sNK0HifwM2mDyZ74I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-TXrChhS4M9CSP5cyc0jy3Q-1; Wed, 09 Sep 2020 11:09:06 -0400 X-MC-Unique: TXrChhS4M9CSP5cyc0jy3Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96B2C873084; Wed, 9 Sep 2020 15:09:04 +0000 (UTC) Received: from wsfd-advnetlab06.anl.lab.eng.bos.redhat.com (wsfd-advnetlab06.anl.lab.eng.bos.redhat.com [10.19.107.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 277E027BD2; Wed, 9 Sep 2020 15:09:03 +0000 (UTC) From: Nitesh Narayan Lal To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, frederic@kernel.org, mtosatti@redhat.com, sassmann@redhat.com, jeffrey.t.kirsher@intel.com, jacob.e.keller@intel.com, jlelli@redhat.com, hch@infradead.org, bhelgaas@google.com, mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, thomas.lendacky@amd.com, jerinj@marvell.com, mathias.nyman@intel.com, jiri@nvidia.com Subject: [RFC][Patch v1 1/3] sched/isolation: API to get num of hosekeeping CPUs Date: Wed, 9 Sep 2020 11:08:16 -0400 Message-Id: <20200909150818.313699-2-nitesh@redhat.com> In-Reply-To: <20200909150818.313699-1-nitesh@redhat.com> References: <20200909150818.313699-1-nitesh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduce a new API num_housekeeping_cpus(), that can be used to retrieve the number of housekeeping CPUs by reading an atomic variable __num_housekeeping_cpus. This variable is set from housekeeping_setup(). This API is introduced for the purpose of drivers that were previously relying only on num_online_cpus() to determine the number of MSIX vectors to create. In an RT environment with large isolated but a fewer housekeeping CPUs this was leading to a situation where an attempt to move all of the vectors corresponding to isolated CPUs to housekeeping CPUs was failing due to per CPU vector limit. If there are no isolated CPUs specified then the API returns the number of all online CPUs. Signed-off-by: Nitesh Narayan Lal --- include/linux/sched/isolation.h | 7 +++++++ kernel/sched/isolation.c | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h index cc9f393e2a70..94c25d956d8a 100644 --- a/include/linux/sched/isolation.h +++ b/include/linux/sched/isolation.h @@ -25,6 +25,7 @@ extern bool housekeeping_enabled(enum hk_flags flags); extern void housekeeping_affine(struct task_struct *t, enum hk_flags flags); extern bool housekeeping_test_cpu(int cpu, enum hk_flags flags); extern void __init housekeeping_init(void); +extern unsigned int num_housekeeping_cpus(void); #else @@ -46,6 +47,12 @@ static inline bool housekeeping_enabled(enum hk_flags flags) static inline void housekeeping_affine(struct task_struct *t, enum hk_flags flags) { } static inline void housekeeping_init(void) { } + +static unsigned int num_housekeeping_cpus(void) +{ + return num_online_cpus(); +} + #endif /* CONFIG_CPU_ISOLATION */ static inline bool housekeeping_cpu(int cpu, enum hk_flags flags) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 5a6ea03f9882..7024298390b7 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -13,6 +13,7 @@ DEFINE_STATIC_KEY_FALSE(housekeeping_overridden); EXPORT_SYMBOL_GPL(housekeeping_overridden); static cpumask_var_t housekeeping_mask; static unsigned int housekeeping_flags; +static atomic_t __num_housekeeping_cpus __read_mostly; bool housekeeping_enabled(enum hk_flags flags) { @@ -20,6 +21,27 @@ bool housekeeping_enabled(enum hk_flags flags) } EXPORT_SYMBOL_GPL(housekeeping_enabled); +/* + * num_housekeeping_cpus() - Read the number of housekeeping CPUs. + * + * This function returns the number of available housekeeping CPUs + * based on __num_housekeeping_cpus which is of type atomic_t + * and is initialized at the time of the housekeeping setup. + */ +unsigned int num_housekeeping_cpus(void) +{ + unsigned int cpus; + + if (static_branch_unlikely(&housekeeping_overridden)) { + cpus = atomic_read(&__num_housekeeping_cpus); + /* We should always have at least one housekeeping CPU */ + BUG_ON(!cpus); + return cpus; + } + return num_online_cpus(); +} +EXPORT_SYMBOL_GPL(num_housekeeping_cpus); + int housekeeping_any_cpu(enum hk_flags flags) { int cpu; @@ -131,6 +153,7 @@ static int __init housekeeping_setup(char *str, enum hk_flags flags) housekeeping_flags |= flags; + atomic_set(&__num_housekeeping_cpus, cpumask_weight(housekeeping_mask)); free_bootmem_cpumask_var(non_housekeeping_mask); return 1; From patchwork Wed Sep 9 15:08:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Narayan Lal X-Patchwork-Id: 11765923 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16B26618 for ; Wed, 9 Sep 2020 17:18:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAE42206D4 for ; Wed, 9 Sep 2020 17:18:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JbR6/g1f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730304AbgIIRR3 (ORCPT ); Wed, 9 Sep 2020 13:17:29 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:21908 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730157AbgIIP2A (ORCPT ); Wed, 9 Sep 2020 11:28:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599665244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WiK+CLNHCkGtArM+EWzVkhYFO4V34cQn5Dk8gnAgqYI=; b=JbR6/g1fMBYV9guWPu7wh0TG7ODY66R4TBMd/PRPJpBkqvBxgr+YxSUJd8oC75tqlrvayU WoVCJGAJBCmRxJwaPOu1eg3LVejxU/GQM6umIxIazftZfqR4tAmSygZ/ZjkEhSHb5F57r8 GqqNo4Bqp5U4pl7Z7SxWeX0FrcVsy7M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-InbDKSgzP6WcdO2Nor3JbQ-1; Wed, 09 Sep 2020 11:09:10 -0400 X-MC-Unique: InbDKSgzP6WcdO2Nor3JbQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 323CB8015A5; Wed, 9 Sep 2020 15:09:06 +0000 (UTC) Received: from wsfd-advnetlab06.anl.lab.eng.bos.redhat.com (wsfd-advnetlab06.anl.lab.eng.bos.redhat.com [10.19.107.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id B667119C4F; Wed, 9 Sep 2020 15:09:04 +0000 (UTC) From: Nitesh Narayan Lal To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, frederic@kernel.org, mtosatti@redhat.com, sassmann@redhat.com, jeffrey.t.kirsher@intel.com, jacob.e.keller@intel.com, jlelli@redhat.com, hch@infradead.org, bhelgaas@google.com, mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, thomas.lendacky@amd.com, jerinj@marvell.com, mathias.nyman@intel.com, jiri@nvidia.com Subject: [RFC][Patch v1 2/3] i40e: limit msix vectors based on housekeeping CPUs Date: Wed, 9 Sep 2020 11:08:17 -0400 Message-Id: <20200909150818.313699-3-nitesh@redhat.com> In-Reply-To: <20200909150818.313699-1-nitesh@redhat.com> References: <20200909150818.313699-1-nitesh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In a realtime environment, it is essential to isolate unwanted IRQs from isolated CPUs to prevent latency overheads. Creating MSIX vectors only based on the online CPUs could lead to a potential issue on an RT setup that has several isolated CPUs but a very few housekeeping CPUs. This is because in these kinds of setups an attempt to move the IRQs to the limited housekeeping CPUs from isolated CPUs might fail due to the per CPU vector limit. This could eventually result in latency spikes because of the IRQ threads that we fail to move from isolated CPUs. This patch prevents i40e to add vectors only based on available housekeeping CPUs by using num_housekeeping_cpus(). Signed-off-by: Nitesh Narayan Lal Reviewed-by: Marcelo Tosatti Acked-by: Jesse Brandeburg --- drivers/net/ethernet/intel/i40e/i40e_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 2e433fdbf2c3..3b4cd4b3de85 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include /* Local includes */ @@ -11002,7 +11003,7 @@ static int i40e_init_msix(struct i40e_pf *pf) * will use any remaining vectors to reach as close as we can to the * number of online CPUs. */ - cpus = num_online_cpus(); + cpus = num_housekeeping_cpus(); pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); vectors_left -= pf->num_lan_msix; From patchwork Wed Sep 9 15:08:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Narayan Lal X-Patchwork-Id: 11765925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33049618 for ; Wed, 9 Sep 2020 17:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FEA121919 for ; Wed, 9 Sep 2020 17:18:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UXJ67XSB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730206AbgIIRR3 (ORCPT ); Wed, 9 Sep 2020 13:17:29 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39855 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730168AbgIIP2A (ORCPT ); Wed, 9 Sep 2020 11:28:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599665250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+BCz3wPlVfUrMQm65Je9XbtrGnOGZT7lnY6dkRWqnmM=; b=UXJ67XSBfhoW0sPqHv+AhMU4/udt5w6wdlmNsoq3DelZA8V0qJ9aAfSToWCRfkoohT9P5+ 0kYs0ZATv8JkqR96BvTwzn9zyH/MDNqmcpUH9nlWEJKP+RkRal8wlcUlQfUnNTYPlSGcSF Id2BmOGmwj9mbTNZbfCLjmnU891/WgU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-6B6-ByPUO9KRZAKC5KxUow-1; Wed, 09 Sep 2020 11:09:14 -0400 X-MC-Unique: 6B6-ByPUO9KRZAKC5KxUow-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D82318BA290; Wed, 9 Sep 2020 15:09:12 +0000 (UTC) Received: from wsfd-advnetlab06.anl.lab.eng.bos.redhat.com (wsfd-advnetlab06.anl.lab.eng.bos.redhat.com [10.19.107.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5242A19C4F; Wed, 9 Sep 2020 15:09:06 +0000 (UTC) From: Nitesh Narayan Lal To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, frederic@kernel.org, mtosatti@redhat.com, sassmann@redhat.com, jeffrey.t.kirsher@intel.com, jacob.e.keller@intel.com, jlelli@redhat.com, hch@infradead.org, bhelgaas@google.com, mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, thomas.lendacky@amd.com, jerinj@marvell.com, mathias.nyman@intel.com, jiri@nvidia.com Subject: [RFC][Patch v1 3/3] PCI: Limit pci_alloc_irq_vectors as per housekeeping CPUs Date: Wed, 9 Sep 2020 11:08:18 -0400 Message-Id: <20200909150818.313699-4-nitesh@redhat.com> In-Reply-To: <20200909150818.313699-1-nitesh@redhat.com> References: <20200909150818.313699-1-nitesh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch limits the pci_alloc_irq_vectors max vectors that is passed on by the caller based on the available housekeeping CPUs by only using the minimum of the two. A minimum of the max_vecs passed and available housekeeping CPUs is derived to ensure that we don't create excess vectors which can be problematic specifically in an RT environment. This is because for an RT environment unwanted IRQs are moved to the housekeeping CPUs from isolated CPUs to keep the latency overhead to a minimum. If the number of housekeeping CPUs are significantly lower than that of the isolated CPUs we can run into failures while moving these IRQs to housekeeping due to per CPU vector limit. Signed-off-by: Nitesh Narayan Lal --- include/linux/pci.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 835530605c0d..750ba927d963 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -1797,6 +1798,21 @@ static inline int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, unsigned int max_vecs, unsigned int flags) { + unsigned int num_housekeeping = num_housekeeping_cpus(); + unsigned int num_online = num_online_cpus(); + + /* + * Try to be conservative and at max only ask for the same number of + * vectors as there are housekeeping CPUs. However, skip any + * modification to the of max vectors in two conditions: + * 1. If the min_vecs requested are higher than that of the + * housekeeping CPUs as we don't want to prevent the initialization + * of a device. + * 2. If there are no isolated CPUs as in this case the driver should + * already have taken online CPUs into consideration. + */ + if (min_vecs < num_housekeeping && num_housekeeping != num_online) + max_vecs = min_t(int, max_vecs, num_housekeeping); return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags, NULL); }