Skip to content

Commit 8ffe4e6

Browse files
douliyangKAGA-KOKO
authored andcommitted
irq/matrix: Split out the CPU selection code into a helper
Linux finds the CPU which has the lowest vector allocation count to spread out the non managed interrupts across the possible target CPUs, but does not do so for managed interrupts. Split out the CPU selection code into a helper function for reuse. No functional change. Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/20180908175838.14450-1-dou_liyang@163.com
1 parent 7876320 commit 8ffe4e6

1 file changed

Lines changed: 38 additions & 27 deletions

File tree

‎kernel/irq/matrix.c‎

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ static unsigned int matrix_alloc_area(struct irq_matrix *m, struct cpumap *cm,
124124
return area;
125125
}
126126

127+
/* Find the best CPU which has the lowest vector allocation count */
128+
static unsigned int matrix_find_best_cpu(struct irq_matrix *m,
129+
const struct cpumask *msk)
130+
{
131+
unsigned int cpu, best_cpu, maxavl = 0;
132+
struct cpumap *cm;
133+
134+
best_cpu = UINT_MAX;
135+
136+
for_each_cpu(cpu, msk) {
137+
cm = per_cpu_ptr(m->maps, cpu);
138+
139+
if (!cm->online || cm->available <= maxavl)
140+
continue;
141+
142+
best_cpu = cpu;
143+
maxavl = cm->available;
144+
}
145+
return best_cpu;
146+
}
147+
127148
/**
128149
* irq_matrix_assign_system - Assign system wide entry in the matrix
129150
* @m: Matrix pointer
@@ -322,37 +343,27 @@ void irq_matrix_remove_reserved(struct irq_matrix *m)
322343
int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk,
323344
bool reserved, unsigned int *mapped_cpu)
324345
{
325-
unsigned int cpu, best_cpu, maxavl = 0;
346+
unsigned int cpu, bit;
326347
struct cpumap *cm;
327-
unsigned int bit;
328348

329-
best_cpu = UINT_MAX;
330-
for_each_cpu(cpu, msk) {
331-
cm = per_cpu_ptr(m->maps, cpu);
332-
333-
if (!cm->online || cm->available <= maxavl)
334-
continue;
349+
cpu = matrix_find_best_cpu(m, msk);
350+
if (cpu == UINT_MAX)
351+
return -ENOSPC;
335352

336-
best_cpu = cpu;
337-
maxavl = cm->available;
338-
}
353+
cm = per_cpu_ptr(m->maps, cpu);
354+
bit = matrix_alloc_area(m, cm, 1, false);
355+
if (bit >= m->alloc_end)
356+
return -ENOSPC;
357+
cm->allocated++;
358+
cm->available--;
359+
m->total_allocated++;
360+
m->global_available--;
361+
if (reserved)
362+
m->global_reserved--;
363+
*mapped_cpu = cpu;
364+
trace_irq_matrix_alloc(bit, cpu, m, cm);
365+
return bit;
339366

340-
if (maxavl) {
341-
cm = per_cpu_ptr(m->maps, best_cpu);
342-
bit = matrix_alloc_area(m, cm, 1, false);
343-
if (bit < m->alloc_end) {
344-
cm->allocated++;
345-
cm->available--;
346-
m->total_allocated++;
347-
m->global_available--;
348-
if (reserved)
349-
m->global_reserved--;
350-
*mapped_cpu = best_cpu;
351-
trace_irq_matrix_alloc(bit, best_cpu, m, cm);
352-
return bit;
353-
}
354-
}
355-
return -ENOSPC;
356367
}
357368

358369
/**

0 commit comments

Comments
 (0)