From patchwork Tue Jan 9 10:51:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 186316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp27694dyi; Tue, 9 Jan 2024 02:53:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1XfJF2ukU0WrtKoH5L7UVG57pW1X2rM9zEFXx4AT056vUcb/jtJCMzIi+nVXE5AcbjeCW X-Received: by 2002:a7b:c5c5:0:b0:40d:3be5:c8b7 with SMTP id n5-20020a7bc5c5000000b0040d3be5c8b7mr1437158wmk.117.1704797626674; Tue, 09 Jan 2024 02:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704797626; cv=none; d=google.com; s=arc-20160816; b=bAaujR0IV0pQv833Bob5IjSi3HzfUpkCdIIsZY0kE64FcQepoF5iK2Ie21aaVftZjI hRdUDhrLD5qjUpJfe0o2xK8wSXpjCrrgqN/RO8HpFFKIbu3UNg4s0Z17yOco3shose8t DZbhu1fZghkqrVzFy3sMYYDzsHZ6CNr0xJF4Ekg5gx8BsM+nRtzKSQFDKQnzgnTuOyhi bozwHfETb4pjelY9q0BkU/Mb7mbuVpsvK2qNh30Xorlxcd0ZwDRcJhT8x+QXKZ1HeKv5 B0hjZkzlkY/ETyWMY5APIle6O3Cb1M+E34wgZtQ3KwIAB+2EVyQwiXmKYHbSilnKgzDu IYXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=BjA1llB0tV0DNKtNQwDzCat1URmop7G8PpQu5Aagoj4=; fh=i0uHiUPKHfc1dSxTUTgp1cL8PKSGIUKO6qVCzrDTDzE=; b=nGitTCa260KNE/32Myv+5nR6MD0ZMf2rNwvtBGmAAOMWBMf8JKFqNCgQIQznxYBbPF 2BUsSJ7Dwud5YMvw2HeKH9f7fzXlcimUOUDhz8zydmxTjqy+xU0ENisPFsJZx9prv216 0ReqIIC9SLCM1rqxzOcAHwkRhF4AfbVA53AGrZXldElaG3I81v8V5E2HIBzVwVjbriOv 4GjaPCr+1A/wC12hsXjrnp9xSYrBhUCjJ3nZao57vFlMDIKaSI1EnQtKTZipa92MbVVl vaggkKjI5BkQMjkW0saKAgwEahqO7HlBlsbo/deClzSRbSO1UbVaR3ZYxLxoAmOwIVKV affg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=YNAZu+v3; spf=pass (google.com: domain of linux-kernel+bounces-20731-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20731-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u22-20020a170906069600b00a2a2ad85e13si649554ejb.926.2024.01.09.02.53.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 02:53:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20731-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=YNAZu+v3; spf=pass (google.com: domain of linux-kernel+bounces-20731-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20731-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 470911F250BF for ; Tue, 9 Jan 2024 10:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AF0539852; Tue, 9 Jan 2024 10:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="YNAZu+v3" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25AE1381D6; Tue, 9 Jan 2024 10:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1099) id F252120B3CC2; Tue, 9 Jan 2024 02:51:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com F252120B3CC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1704797496; bh=BjA1llB0tV0DNKtNQwDzCat1URmop7G8PpQu5Aagoj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YNAZu+v3p4jhxsCl+dNOLV5ZCD7oKcv0KmwZforvUJgtpnAVrwmY5zXCykrDI7SM0 5qPsJwpcp8fMmt2KGvayIzMFDV2Je6kTsr9GFsBfsvnoLfUusVmBcZFAMofUQCNBcX JnjYnZxDIfX/8zx/JP/KF/Zn1HLvqXAK+xcEjDPQ= From: Souradeep Chakrabarti To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, longli@microsoft.com, yury.norov@gmail.com, leon@kernel.org, cai.huoqing@linux.dev, ssengar@linux.microsoft.com, vkuznets@redhat.com, tglx@linutronix.de, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Cc: schakrabarti@microsoft.com, paulros@microsoft.com, Souradeep Chakrabarti Subject: [PATCH 4/4 net-next] net: mana: Assigning IRQ affinity on HT cores Date: Tue, 9 Jan 2024 02:51:18 -0800 Message-Id: <1704797478-32377-5-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704797478-32377-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1704797478-32377-1-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787609764438613194 X-GMAIL-MSGID: 1787609876402517336 Existing MANA design assigns IRQ to every CPU, including sibling hyper-threads. This may cause multiple IRQs to be active simultaneously in the same core and may reduce the network performance. Improve the performance by assigning IRQ to non sibling CPUs in local NUMA node. The performance improvement we are getting using ntttcp with following patch is around 15 percent against existing design and approximately 11 percent, when trying to assign one IRQ in each core across NUMA nodes, if enough cores are present. Signed-off-by: Souradeep Chakrabarti --- .../net/ethernet/microsoft/mana/gdma_main.c | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 6a967d6be01e..6715d6939bc7 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1274,13 +1274,16 @@ static __maybe_unused int irq_setup(unsigned int *irqs, unsigned int len, int no static int mana_gd_setup_irqs(struct pci_dev *pdev) { - unsigned int max_queues_per_port = num_online_cpus(); struct gdma_context *gc = pci_get_drvdata(pdev); + unsigned int max_queues_per_port; struct gdma_irq_context *gic; unsigned int max_irqs, cpu; - int nvec, irq; + int start_irq_index = 1; + int nvec, *irqs, irq; int err, i = 0, j; + cpus_read_lock(); + max_queues_per_port = num_online_cpus(); if (max_queues_per_port > MANA_MAX_NUM_QUEUES) max_queues_per_port = MANA_MAX_NUM_QUEUES; @@ -1288,8 +1291,18 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) max_irqs = max_queues_per_port + 1; nvec = pci_alloc_irq_vectors(pdev, 2, max_irqs, PCI_IRQ_MSIX); - if (nvec < 0) + if (nvec < 0) { + cpus_read_unlock(); return nvec; + } + if (nvec <= num_online_cpus()) + start_irq_index = 0; + + irqs = kmalloc_array((nvec - start_irq_index), sizeof(int), GFP_KERNEL); + if (!irqs) { + err = -ENOMEM; + goto free_irq_vector; + } gc->irq_contexts = kcalloc(nvec, sizeof(struct gdma_irq_context), GFP_KERNEL); @@ -1316,21 +1329,44 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) goto free_irq; } - err = request_irq(irq, mana_gd_intr, 0, gic->name, gic); - if (err) - goto free_irq; - - cpu = cpumask_local_spread(i, gc->numa_node); - irq_set_affinity_and_hint(irq, cpumask_of(cpu)); + if (!i) { + err = request_irq(irq, mana_gd_intr, 0, gic->name, gic); + if (err) + goto free_irq; + + /* If number of IRQ is one extra than number of online CPUs, + * then we need to assign IRQ0 (hwc irq) and IRQ1 to + * same CPU. + * Else we will use different CPUs for IRQ0 and IRQ1. + * Also we are using cpumask_local_spread instead of + * cpumask_first for the node, because the node can be + * mem only. + */ + if (start_irq_index) { + cpu = cpumask_local_spread(i, gc->numa_node); + irq_set_affinity_and_hint(irq, cpumask_of(cpu)); + } else { + irqs[start_irq_index] = irq; + } + } else { + irqs[i - start_irq_index] = irq; + err = request_irq(irqs[i - start_irq_index], mana_gd_intr, 0, + gic->name, gic); + if (err) + goto free_irq; + } } + err = irq_setup(irqs, (nvec - start_irq_index), gc->numa_node); + if (err) + goto free_irq; err = mana_gd_alloc_res_map(nvec, &gc->msix_resource); if (err) goto free_irq; gc->max_num_msix = nvec; gc->num_msix_usable = nvec; - + cpus_read_unlock(); return 0; free_irq: @@ -1343,8 +1379,10 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) } kfree(gc->irq_contexts); + kfree(irqs); gc->irq_contexts = NULL; free_irq_vector: + cpus_read_unlock(); pci_free_irq_vectors(pdev); return err; }