@@ -1202,7 +1202,7 @@ void irq_matrix_assign_system(struct irq_matrix *m, unsigned int bit, bool repla
int irq_matrix_reserve_managed(struct irq_matrix *m, const struct cpumask *msk);
void irq_matrix_remove_managed(struct irq_matrix *m, const struct cpumask *msk);
int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk,
- unsigned int *mapped_cpu);
+ int node, unsigned int *mapped_cpu);
void irq_matrix_reserve(struct irq_matrix *m);
void irq_matrix_remove_reserved(struct irq_matrix *m);
int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk,
@@ -309,6 +309,7 @@ assign_managed_vector(struct irq_data *irqd, const struct cpumask *dest)
{
const struct cpumask *affmsk = irq_data_get_affinity_mask(irqd);
struct apic_chip_data *apicd = apic_chip_data(irqd);
+ int node = irq_data_get_node(irqd);
int vector, cpu;
cpumask_and(vector_searchmask, dest, affmsk);
@@ -317,7 +318,7 @@ assign_managed_vector(struct irq_data *irqd, const struct cpumask *dest)
if (apicd->vector && cpumask_test_cpu(apicd->cpu, vector_searchmask))
return 0;
vector = irq_matrix_alloc_managed(vector_matrix, vector_searchmask,
- &cpu);
+ node, &cpu);
trace_vector_alloc_managed(irqd->irq, vector, vector);
if (vector < 0)
return vector;
@@ -148,7 +148,8 @@ static unsigned int matrix_find_best_cpu(struct irq_matrix *m,
/* Find the best CPU which has the lowest number of managed IRQs allocated */
static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m,
- const struct cpumask *msk)
+ const struct cpumask *msk,
+ int node)
{
unsigned int cpu, best_cpu, allocated = UINT_MAX;
struct cpumap *cm;
@@ -156,6 +157,9 @@ static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m,
best_cpu = UINT_MAX;
for_each_cpu(cpu, msk) {
+ if (node != NUMA_NO_NODE && cpu_to_node(cpu) != node)
+ continue;
+
cm = per_cpu_ptr(m->maps, cpu);
if (!cm->online || cm->managed_allocated > allocated)
@@ -280,10 +284,12 @@ void irq_matrix_remove_managed(struct irq_matrix *m, const struct cpumask *msk)
/**
* irq_matrix_alloc_managed - Allocate a managed interrupt in a CPU map
* @m: Matrix pointer
- * @cpu: On which CPU the interrupt should be allocated
+ * @mask: The mask of CPUs on which the interrupt can be allocated
+ * @node: The preferred NUMA node
+ * @mapped_cpu: The resulting CPU on which the interrupt should be allocated
*/
int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk,
- unsigned int *mapped_cpu)
+ int node, unsigned int *mapped_cpu)
{
unsigned int bit, cpu, end = m->alloc_end;
struct cpumap *cm;
@@ -291,7 +297,9 @@ int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk,
if (cpumask_empty(msk))
return -EINVAL;
- cpu = matrix_find_best_cpu_managed(m, msk);
+ cpu = matrix_find_best_cpu_managed(m, msk, node);
+ if (cpu == UINT_MAX)
+ cpu = matrix_find_best_cpu_managed(m, msk, NUMA_NO_NODE);
if (cpu == UINT_MAX)
return -ENOSPC;
Select CPUs from the IRQ's NUMA node in preference over other CPUs. This ensures that managed IRQs are assigned to the same NUMA node as the device. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- include/linux/irq.h | 2 +- arch/x86/kernel/apic/vector.c | 3 ++- kernel/irq/matrix.c | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-)