]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.27/irq-matrix-split-out-the-cpu-selection-code-into-a-h.patch
Linux 4.14.105
[thirdparty/kernel/stable-queue.git] / releases / 4.19.27 / irq-matrix-split-out-the-cpu-selection-code-into-a-h.patch
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
5
6 [ Upstream commit 8ffe4e61c06a48324cfd97f1199bb9838acce2f2 ]
7
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.
11
12 Split out the CPU selection code into a helper function for reuse. No
13 functional change.
14
15 Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
16 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
17 Cc: hpa@zytor.com
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>
21 ---
22 kernel/irq/matrix.c | 65 ++++++++++++++++++++++++++++++----------------------
23 1 file changed, 38 insertions(+), 27 deletions(-)
24
25 --- a/kernel/irq/matrix.c
26 +++ b/kernel/irq/matrix.c
27 @@ -124,6 +124,27 @@ static unsigned int matrix_alloc_area(st
28 return area;
29 }
30
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)
34 +{
35 + unsigned int cpu, best_cpu, maxavl = 0;
36 + struct cpumap *cm;
37 +
38 + best_cpu = UINT_MAX;
39 +
40 + for_each_cpu(cpu, msk) {
41 + cm = per_cpu_ptr(m->maps, cpu);
42 +
43 + if (!cm->online || cm->available <= maxavl)
44 + continue;
45 +
46 + best_cpu = cpu;
47 + maxavl = cm->available;
48 + }
49 + return best_cpu;
50 +}
51 +
52 /**
53 * irq_matrix_assign_system - Assign system wide entry in the matrix
54 * @m: Matrix pointer
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)
58 {
59 - unsigned int cpu, best_cpu, maxavl = 0;
60 + unsigned int cpu, bit;
61 struct cpumap *cm;
62 - unsigned int bit;
63
64 - best_cpu = UINT_MAX;
65 - for_each_cpu(cpu, msk) {
66 - cm = per_cpu_ptr(m->maps, cpu);
67 -
68 - if (!cm->online || cm->available <= maxavl)
69 - continue;
70 + cpu = matrix_find_best_cpu(m, msk);
71 + if (cpu == UINT_MAX)
72 + return -ENOSPC;
73
74 - best_cpu = cpu;
75 - maxavl = cm->available;
76 - }
77 + cm = per_cpu_ptr(m->maps, cpu);
78 + bit = matrix_alloc_area(m, cm, 1, false);
79 + if (bit >= m->alloc_end)
80 + return -ENOSPC;
81 + cm->allocated++;
82 + cm->available--;
83 + m->total_allocated++;
84 + m->global_available--;
85 + if (reserved)
86 + m->global_reserved--;
87 + *mapped_cpu = cpu;
88 + trace_irq_matrix_alloc(bit, cpu, m, cm);
89 + return bit;
90
91 - if (maxavl) {
92 - cm = per_cpu_ptr(m->maps, best_cpu);
93 - bit = matrix_alloc_area(m, cm, 1, false);
94 - if (bit < m->alloc_end) {
95 - cm->allocated++;
96 - cm->available--;
97 - m->total_allocated++;
98 - m->global_available--;
99 - if (reserved)
100 - m->global_reserved--;
101 - *mapped_cpu = best_cpu;
102 - trace_irq_matrix_alloc(bit, best_cpu, m, cm);
103 - return bit;
104 - }
105 - }
106 - return -ENOSPC;
107 }
108
109 /**