1 From 504302562cb34ba1a9b73753f9735da29d8f5ef2 Mon Sep 17 00:00:00 2001
2 From: Dou Liyang <douly.fnst@cn.fujitsu.com>
3 Date: Sun, 9 Sep 2018 01:58:37 +0800
4 Subject: irq/matrix: Split out the CPU selection code into a helper
6 [ Upstream commit 8ffe4e61c06a48324cfd97f1199bb9838acce2f2 ]
8 Linux finds the CPU which has the lowest vector allocation count to spread
9 out the non managed interrupts across the possible target CPUs, but does
10 not do so for managed interrupts.
12 Split out the CPU selection code into a helper function for reuse. No
15 Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
16 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
18 Link: https://lkml.kernel.org/r/20180908175838.14450-1-dou_liyang@163.com
19 Signed-off-by: Sasha Levin <sashal@kernel.org>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 kernel/irq/matrix.c | 65 ++++++++++++++++++++++++++++++----------------------
23 1 file changed, 38 insertions(+), 27 deletions(-)
25 --- a/kernel/irq/matrix.c
26 +++ b/kernel/irq/matrix.c
27 @@ -124,6 +124,27 @@ static unsigned int matrix_alloc_area(st
31 +/* Find the best CPU which has the lowest vector allocation count */
32 +static unsigned int matrix_find_best_cpu(struct irq_matrix *m,
33 + const struct cpumask *msk)
35 + unsigned int cpu, best_cpu, maxavl = 0;
38 + best_cpu = UINT_MAX;
40 + for_each_cpu(cpu, msk) {
41 + cm = per_cpu_ptr(m->maps, cpu);
43 + if (!cm->online || cm->available <= maxavl)
47 + maxavl = cm->available;
53 * irq_matrix_assign_system - Assign system wide entry in the matrix
55 @@ -322,37 +343,27 @@ void irq_matrix_remove_reserved(struct i
56 int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk,
57 bool reserved, unsigned int *mapped_cpu)
59 - unsigned int cpu, best_cpu, maxavl = 0;
60 + unsigned int cpu, bit;
64 - best_cpu = UINT_MAX;
65 - for_each_cpu(cpu, msk) {
66 - cm = per_cpu_ptr(m->maps, cpu);
68 - if (!cm->online || cm->available <= maxavl)
70 + cpu = matrix_find_best_cpu(m, msk);
71 + if (cpu == UINT_MAX)
75 - maxavl = cm->available;
77 + cm = per_cpu_ptr(m->maps, cpu);
78 + bit = matrix_alloc_area(m, cm, 1, false);
79 + if (bit >= m->alloc_end)
83 + m->total_allocated++;
84 + m->global_available--;
86 + m->global_reserved--;
88 + trace_irq_matrix_alloc(bit, cpu, m, cm);
92 - cm = per_cpu_ptr(m->maps, best_cpu);
93 - bit = matrix_alloc_area(m, cm, 1, false);
94 - if (bit < m->alloc_end) {
97 - m->total_allocated++;
98 - m->global_available--;
100 - m->global_reserved--;
101 - *mapped_cpu = best_cpu;
102 - trace_irq_matrix_alloc(bit, best_cpu, m, cm);