genirq: Add effective CPU index retrieving interface
Subsystems (5)
RFC 1/1 genirq: Add effective CPU index retrieving interface
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.
---
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(+)
include/linux/interrupt.h +1 -0
@@ -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);
kernel/irq/manage.c +17 -0
@@ -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;
Signature · 1 line
2.31.1
Quoted 9 lines · Shung-Hsi Yu
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 callingrequest_irq().
So if you are interested in the resulting NUMA node, then why exposing a random CPU out of the affinity mask instead of exposing a function to retrieve the NUMA node?
kernel/irq/manage.c int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask) · line 499
Quoted 10 lines
kernel/irq/manage.c +10
-0+/** +* 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);
This can be NULL.
kernel/irq/manage.c int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask) · line 504
Quoted 5 lines
kernel/irq/manage.c +5
-0+struct cpumask *m; + + m =irq_data_get_effective_affinity_mask (data); +return cpumask_first (m); +}
Thanks,
tglx
Quoted 12 lines · Thomas Gleixner
Quoted 9 lines · Shung-Hsi Yu
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 callingrequest_irq().
Quoted 3 lines
So if you are interested in the resulting NUMA node, then why exposing a random CPU out of the affinity mask instead of exposing a function to retrieve the NUMA node?
Agreed, probably it will make more sense for the drivers to pass either the local NUMA node index or NULL (in case they don't care about it) as a parameter then at the time of allocation, we only find the best-fit CPUs from that NUMA?
or, maybe we should do this by default, and if the local NUMA CPUs run out of available vectors then we go to the other NUMA node CPUs.
Quoted 24 lines
kernel/irq/manage.c int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask) · line 499
Quoted 11 lines
kernel/irq/manage.c +10
-0+/** +* 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);This can be NULL.
kernel/irq/manage.c int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask) · line 504
Quoted 5 lines
kernel/irq/manage.c +5
-0+struct cpumask *m; + + m =irq_data_get_effective_affinity_mask (data); +return cpumask_first (m); +}Thanks,
tglx
Signature · 2 lines
Thanks Nitesh