All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	netdev@vger.kernel.org, linux-pci@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Jesse Brandeburg <jesse.brandeburg@intel.com>,
	Nitesh Lal <nilal@redhat.com>
Subject: [RFC] genirq: Add effective CPU index retrieving interface
Date: Mon, 7 Jun 2021 15:33:02 +0800	[thread overview]
Message-ID: <YL3LrgAzMNI2hp5i@syu-laptop> (raw)

Most driver's IRQ spreading scheme is naive compared to the IRQ spreading
scheme introduced since IRQ subsystem rework, so it better to rely
request_irq() to spread IRQ out.

However, drivers that care about performance enough also tends to try
allocating memory on the same NUMA node on which the IRQ handler will run.
For such driver to rely on request_irq() for IRQ spreading, we also need to
provide an interface to retrieve the CPU index after calling request_irq().

This should be the last missing piece of puzzle that allows removal of
calls to irq_set_affinity_hint() that were actually intended to spread out
IRQ.

Link: https://lore.kernel.org/lkml/CAFki+Lm0W_brLu31epqD3gAV+WNKOJfVDfX2M8ZM__aj3nv9uA@mail.gmail.com/
Link: https://lore.kernel.org/linux-api/87zgwo9u79.ffs@nanos.tec.linutronix.de/
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---

I've ask previously in another thread[1], but there doesn't seem to be one,
so hence this patch.

I apologize if there's anything glaringly wrong, it's my 1st time trying to
send a patch that deals with driver interface. Just let me know, and I'll
get it fixed.

Also, there's probably better a name for the interface but I can't think of
one.

1: https://lore.kernel.org/r/YK9yxQoBPeUfQG05@syu-laptop

---
 include/linux/interrupt.h |  1 +
 kernel/irq/manage.c       | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 2ed65b01c961..b67621ccde35 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -324,6 +324,7 @@ extern cpumask_var_t irq_default_affinity;
 
 extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
 extern int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask);
+extern int irq_get_effective_cpu(unsigned int irq);
 
 extern int irq_can_set_affinity(unsigned int irq);
 extern int irq_select_affinity(unsigned int irq);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index ef30b4762947..5e2a722c5d93 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -487,6 +487,23 @@ int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
 }
 EXPORT_SYMBOL_GPL(irq_force_affinity);
 
+/**
+ * irq_get_effective_cpu - Retrieve the effective CPU index
+ * @irq:	Target interrupt to retrieve effective CPU index
+ *
+ * When the effective affinity cpumask has multiple CPU toggled, it just
+ * returns the first CPU in the cpumask.
+ */
+int irq_get_effective_cpu(unsigned int irq)
+{
+	struct irq_data *data = irq_get_irq_data(irq);
+	struct cpumask *m;
+
+	m = irq_data_get_effective_affinity_mask(data);
+	return cpumask_first(m);
+}
+EXPORT_SYMBOL_GPL(irq_get_effective_cpu);
+
 int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m)
 {
 	unsigned long flags;
-- 
2.31.1


             reply	other threads:[~2021-06-07  7:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  7:33 Shung-Hsi Yu [this message]
2021-08-10 14:12 ` [RFC] genirq: Add effective CPU index retrieving interface Thomas Gleixner
2021-08-10 14:35   ` Nitesh Lal

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=YL3LrgAzMNI2hp5i@syu-laptop \
    --to=shung-hsi.yu@suse.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nilal@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.