From: Shradha Gupta <shradhagupta@linux.microsoft.com>
To: Dexuan Cui <decui@microsoft.com>, Wei Liu <wei.liu@kernel.org>,
Haiyang Zhang <haiyangz@microsoft.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Konstantin Taranov <kotaranov@microsoft.com>,
Simon Horman <horms@kernel.org>,
Leon Romanovsky <leon@kernel.org>,
Maxim Levitsky <mlevitsk@redhat.com>,
Erni Sri Satya Vennela <ernis@linux.microsoft.com>,
Peter Zijlstra <peterz@infradead.org>,
Michael Kelley <mhklinux@outlook.com>
Cc: "Yury Norov" <yury.norov@gmail.com>,
linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, "Nipun Gupta" <nipun.gupta@amd.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Jonathan Cameron" <Jonathan.Cameron@huwei.com>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Shradha Gupta" <shradhagupta@linux.microsoft.com>,
"Kevin Tian" <kevin.tian@intel.com>,
"Long Li" <longli@microsoft.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Rob Herring" <robh@kernel.org>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Krzysztof Wilczy�~Dski" <kw@linux.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
"Paul Rosswurm" <paulros@microsoft.com>,
"Shradha Gupta" <shradhagupta@microsoft.com>
Subject: [PATCH v5 3/5] net: mana: explain irq_setup() algorithm
Date: Mon, 9 Jun 2025 06:49:24 -0700 [thread overview]
Message-ID: <1749476964-27606-1-git-send-email-shradhagupta@linux.microsoft.com> (raw)
In-Reply-To: <1749476901-27251-1-git-send-email-shradhagupta@linux.microsoft.com>
From: Yury Norov <yury.norov@gmail.com>
Commit 91bfe210e196 ("net: mana: add a function to spread IRQs per CPUs")
added the irq_setup() function that distributes IRQs on CPUs according
to a tricky heuristic. The corresponding commit message explains the
heuristic.
Duplicate it in the source code to make available for readers without
digging git in history. Also, add more detailed explanation about how
the heuristics is implemented.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
---
Changes in v5:
* Corrected the Authur of the patch
---
.../net/ethernet/microsoft/mana/gdma_main.c | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index 3504507477c6..6c4e143972a1 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -1288,6 +1288,47 @@ void mana_gd_free_res_map(struct gdma_resource *r)
r->size = 0;
}
+/*
+ * Spread on CPUs with the following heuristics:
+ *
+ * 1. No more than one IRQ per CPU, if possible;
+ * 2. NUMA locality is the second priority;
+ * 3. Sibling dislocality is the last priority.
+ *
+ * Let's consider this topology:
+ *
+ * Node 0 1
+ * Core 0 1 2 3
+ * CPU 0 1 2 3 4 5 6 7
+ *
+ * The most performant IRQ distribution based on the above topology
+ * and heuristics may look like this:
+ *
+ * IRQ Nodes Cores CPUs
+ * 0 1 0 0-1
+ * 1 1 1 2-3
+ * 2 1 0 0-1
+ * 3 1 1 2-3
+ * 4 2 2 4-5
+ * 5 2 3 6-7
+ * 6 2 2 4-5
+ * 7 2 3 6-7
+ *
+ * The heuristics is implemented as follows.
+ *
+ * The outer for_each() loop resets the 'weight' to the actual number
+ * of CPUs in the hop. Then inner for_each() loop decrements it by the
+ * number of sibling groups (cores) while assigning first set of IRQs
+ * to each group. IRQs 0 and 1 above are distributed this way.
+ *
+ * Now, because NUMA locality is more important, we should walk the
+ * same set of siblings and assign 2nd set of IRQs (2 and 3), and it's
+ * implemented by the medium while() loop. We do like this unless the
+ * number of IRQs assigned on this hop will not become equal to number
+ * of CPUs in the hop (weight == 0). Then we switch to the next hop and
+ * do the same thing.
+ */
+
static int irq_setup(unsigned int *irqs, unsigned int len, int node)
{
const struct cpumask *next, *prev = cpu_none_mask;
--
2.34.1
next prev parent reply other threads:[~2025-06-09 13:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 13:48 [PATCH v5 0/5] Allow dyn MSI-X vector allocation of MANA Shradha Gupta
2025-06-09 13:48 ` [PATCH v5 1/5] PCI/MSI: Export pci_msix_prepare_desc() for dynamic MSI-X allocations Shradha Gupta
2025-06-09 13:49 ` [PATCH v5 2/5] PCI: hv: Allow dynamic MSI-X vector allocation Shradha Gupta
2025-06-09 13:49 ` Shradha Gupta [this message]
2025-06-09 13:49 ` [PATCH v5 4/5] net: mana: Allow irq_setup() to skip cpus for affinity Shradha Gupta
2025-06-09 13:49 ` [PATCH v5 5/5] net: mana: Allocate MSI-X vectors dynamically Shradha Gupta
2025-06-10 21:40 ` [PATCH v5 0/5] Allow dyn MSI-X vector allocation of MANA Jakub Kicinski
2025-06-11 5:33 ` Shradha Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1749476964-27606-1-git-send-email-shradhagupta@linux.microsoft.com \
--to=shradhagupta@linux.microsoft.com \
--cc=Jonathan.Cameron@huwei.com \
--cc=andrew+netdev@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=ernis@linux.microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kotaranov@microsoft.com \
--cc=kuba@kernel.org \
--cc=kw@linux.com \
--cc=kys@microsoft.com \
--cc=leon@kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mhklinux@outlook.com \
--cc=mlevitsk@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=nipun.gupta@amd.com \
--cc=pabeni@redhat.com \
--cc=paulros@microsoft.com \
--cc=peterz@infradead.org \
--cc=robh@kernel.org \
--cc=shradhagupta@microsoft.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).