Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Thomas Gleixner. |
| 4 | * Copyright (C) 2016-2017 Christoph Hellwig. |
| 5 | */ |
Christoph Hellwig | 5e385a6 | 2016-07-04 17:39:27 +0900 | [diff] [blame] | 6 | #include <linux/interrupt.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/cpu.h> |
| 10 | |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 11 | static void irq_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, |
| 12 | int cpus_per_vec) |
| 13 | { |
| 14 | const struct cpumask *siblmsk; |
| 15 | int cpu, sibl; |
| 16 | |
| 17 | for ( ; cpus_per_vec > 0; ) { |
| 18 | cpu = cpumask_first(nmsk); |
| 19 | |
| 20 | /* Should not happen, but I'm too lazy to think about it */ |
| 21 | if (cpu >= nr_cpu_ids) |
| 22 | return; |
| 23 | |
| 24 | cpumask_clear_cpu(cpu, nmsk); |
| 25 | cpumask_set_cpu(cpu, irqmsk); |
| 26 | cpus_per_vec--; |
| 27 | |
| 28 | /* If the cpu has siblings, use them first */ |
| 29 | siblmsk = topology_sibling_cpumask(cpu); |
| 30 | for (sibl = -1; cpus_per_vec > 0; ) { |
| 31 | sibl = cpumask_next(sibl, siblmsk); |
| 32 | if (sibl >= nr_cpu_ids) |
| 33 | break; |
| 34 | if (!cpumask_test_and_clear_cpu(sibl, nmsk)) |
| 35 | continue; |
| 36 | cpumask_set_cpu(sibl, irqmsk); |
| 37 | cpus_per_vec--; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 42 | static cpumask_var_t *alloc_node_to_cpumask(void) |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 43 | { |
| 44 | cpumask_var_t *masks; |
| 45 | int node; |
| 46 | |
| 47 | masks = kcalloc(nr_node_ids, sizeof(cpumask_var_t), GFP_KERNEL); |
| 48 | if (!masks) |
| 49 | return NULL; |
| 50 | |
| 51 | for (node = 0; node < nr_node_ids; node++) { |
| 52 | if (!zalloc_cpumask_var(&masks[node], GFP_KERNEL)) |
| 53 | goto out_unwind; |
| 54 | } |
| 55 | |
| 56 | return masks; |
| 57 | |
| 58 | out_unwind: |
| 59 | while (--node >= 0) |
| 60 | free_cpumask_var(masks[node]); |
| 61 | kfree(masks); |
| 62 | return NULL; |
| 63 | } |
| 64 | |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 65 | static void free_node_to_cpumask(cpumask_var_t *masks) |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 66 | { |
| 67 | int node; |
| 68 | |
| 69 | for (node = 0; node < nr_node_ids; node++) |
| 70 | free_cpumask_var(masks[node]); |
| 71 | kfree(masks); |
| 72 | } |
| 73 | |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 74 | static void build_node_to_cpumask(cpumask_var_t *masks) |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 75 | { |
| 76 | int cpu; |
| 77 | |
Christoph Hellwig | 84676c1 | 2018-01-12 10:53:05 +0800 | [diff] [blame] | 78 | for_each_possible_cpu(cpu) |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 79 | cpumask_set_cpu(cpu, masks[cpu_to_node(cpu)]); |
| 80 | } |
| 81 | |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 82 | static int get_nodes_in_cpumask(cpumask_var_t *node_to_cpumask, |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 83 | const struct cpumask *mask, nodemask_t *nodemsk) |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 84 | { |
Guilherme G. Piccoli | c0af524 | 2016-12-14 16:01:12 -0200 | [diff] [blame] | 85 | int n, nodes = 0; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 86 | |
| 87 | /* Calculate the number of nodes in the supplied affinity mask */ |
Christoph Hellwig | 9a0ef98 | 2017-06-20 01:37:55 +0200 | [diff] [blame] | 88 | for_each_node(n) { |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 89 | if (cpumask_intersects(mask, node_to_cpumask[n])) { |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 90 | node_set(n, *nodemsk); |
| 91 | nodes++; |
| 92 | } |
| 93 | } |
| 94 | return nodes; |
| 95 | } |
| 96 | |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 97 | static int __irq_build_affinity_masks(const struct irq_affinity *affd, |
Thomas Gleixner | c2899c3 | 2018-12-18 16:06:53 +0100 | [diff] [blame] | 98 | int startvec, int numvecs, int firstvec, |
| 99 | cpumask_var_t *node_to_cpumask, |
| 100 | const struct cpumask *cpu_mask, |
| 101 | struct cpumask *nmsk, |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 102 | struct irq_affinity_desc *masks) |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 103 | { |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 104 | int n, nodes, cpus_per_vec, extra_vecs, done = 0; |
Ming Lei | 060746d | 2018-11-02 22:59:50 +0800 | [diff] [blame] | 105 | int last_affv = firstvec + numvecs; |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 106 | int curvec = startvec; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 107 | nodemask_t nodemsk = NODE_MASK_NONE; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 108 | |
Ming Lei | d305681 | 2018-03-08 18:53:58 +0800 | [diff] [blame] | 109 | if (!cpumask_weight(cpu_mask)) |
| 110 | return 0; |
| 111 | |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 112 | nodes = get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 113 | |
| 114 | /* |
Guilherme G. Piccoli | c0af524 | 2016-12-14 16:01:12 -0200 | [diff] [blame] | 115 | * If the number of nodes in the mask is greater than or equal the |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 116 | * number of vectors we just spread the vectors across the nodes. |
| 117 | */ |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 118 | if (numvecs <= nodes) { |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 119 | for_each_node_mask(n, nodemsk) { |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 120 | cpumask_or(&masks[curvec].mask, |
| 121 | &masks[curvec].mask, |
| 122 | node_to_cpumask[n]); |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 123 | if (++curvec == last_affv) |
Ming Lei | 060746d | 2018-11-02 22:59:50 +0800 | [diff] [blame] | 124 | curvec = firstvec; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 125 | } |
Long Li | b825921 | 2018-11-02 18:02:48 +0000 | [diff] [blame] | 126 | done = numvecs; |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 127 | goto out; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 130 | for_each_node_mask(n, nodemsk) { |
Keith Busch | 7bf8222 | 2017-04-03 15:25:53 -0400 | [diff] [blame] | 131 | int ncpus, v, vecs_to_assign, vecs_per_node; |
| 132 | |
| 133 | /* Spread the vectors per node */ |
Ming Lei | 060746d | 2018-11-02 22:59:50 +0800 | [diff] [blame] | 134 | vecs_per_node = (numvecs - (curvec - firstvec)) / nodes; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 135 | |
| 136 | /* Get the cpus on this node which are in the mask */ |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 137 | cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 138 | |
| 139 | /* Calculate the number of cpus per vector */ |
| 140 | ncpus = cpumask_weight(nmsk); |
Keith Busch | 7bf8222 | 2017-04-03 15:25:53 -0400 | [diff] [blame] | 141 | vecs_to_assign = min(vecs_per_node, ncpus); |
| 142 | |
| 143 | /* Account for rounding errors */ |
Keith Busch | 3412386 | 2017-04-13 13:28:12 -0400 | [diff] [blame] | 144 | extra_vecs = ncpus - vecs_to_assign * (ncpus / vecs_to_assign); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 145 | |
Christoph Hellwig | bfe1307 | 2016-11-15 10:12:58 +0100 | [diff] [blame] | 146 | for (v = 0; curvec < last_affv && v < vecs_to_assign; |
| 147 | curvec++, v++) { |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 148 | cpus_per_vec = ncpus / vecs_to_assign; |
| 149 | |
| 150 | /* Account for extra vectors to compensate rounding errors */ |
| 151 | if (extra_vecs) { |
| 152 | cpus_per_vec++; |
Keith Busch | 7bf8222 | 2017-04-03 15:25:53 -0400 | [diff] [blame] | 153 | --extra_vecs; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 154 | } |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 155 | irq_spread_init_one(&masks[curvec].mask, nmsk, |
| 156 | cpus_per_vec); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 159 | done += v; |
| 160 | if (done >= numvecs) |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 161 | break; |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 162 | if (curvec >= last_affv) |
Ming Lei | 060746d | 2018-11-02 22:59:50 +0800 | [diff] [blame] | 163 | curvec = firstvec; |
Keith Busch | 7bf8222 | 2017-04-03 15:25:53 -0400 | [diff] [blame] | 164 | --nodes; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 167 | out: |
Ming Lei | 1a2d091 | 2018-03-08 18:53:57 +0800 | [diff] [blame] | 168 | return done; |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 169 | } |
| 170 | |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 171 | /* |
| 172 | * build affinity in two stages: |
| 173 | * 1) spread present CPU on these vectors |
| 174 | * 2) spread other possible CPUs on these vectors |
| 175 | */ |
| 176 | static int irq_build_affinity_masks(const struct irq_affinity *affd, |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 177 | int startvec, int numvecs, int firstvec, |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 178 | cpumask_var_t *node_to_cpumask, |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 179 | struct irq_affinity_desc *masks) |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 180 | { |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 181 | int curvec = startvec, nr_present, nr_others; |
| 182 | int ret = -ENOMEM; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 183 | cpumask_var_t nmsk, npresmsk; |
| 184 | |
| 185 | if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) |
Thomas Gleixner | c2899c3 | 2018-12-18 16:06:53 +0100 | [diff] [blame] | 186 | return ret; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 187 | |
| 188 | if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL)) |
Thomas Gleixner | c2899c3 | 2018-12-18 16:06:53 +0100 | [diff] [blame] | 189 | goto fail; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 190 | |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 191 | ret = 0; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 192 | /* Stabilize the cpumasks */ |
| 193 | get_online_cpus(); |
| 194 | build_node_to_cpumask(node_to_cpumask); |
| 195 | |
| 196 | /* Spread on present CPUs starting from affd->pre_vectors */ |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 197 | nr_present = __irq_build_affinity_masks(affd, curvec, numvecs, |
| 198 | firstvec, node_to_cpumask, |
| 199 | cpu_present_mask, nmsk, masks); |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * Spread on non present CPUs starting from the next vector to be |
| 203 | * handled. If the spreading of present CPUs already exhausted the |
| 204 | * vector space, assign the non present CPUs to the already spread |
| 205 | * out vectors. |
| 206 | */ |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 207 | if (nr_present >= numvecs) |
| 208 | curvec = firstvec; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 209 | else |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 210 | curvec = firstvec + nr_present; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 211 | cpumask_andnot(npresmsk, cpu_possible_mask, cpu_present_mask); |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 212 | nr_others = __irq_build_affinity_masks(affd, curvec, numvecs, |
| 213 | firstvec, node_to_cpumask, |
| 214 | npresmsk, nmsk, masks); |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 215 | put_online_cpus(); |
| 216 | |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 217 | if (nr_present < numvecs) |
Thomas Gleixner | c2899c3 | 2018-12-18 16:06:53 +0100 | [diff] [blame] | 218 | WARN_ON(nr_present + nr_others < numvecs); |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 219 | |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 220 | free_cpumask_var(npresmsk); |
| 221 | |
| 222 | fail: |
| 223 | free_cpumask_var(nmsk); |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 224 | return ret; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 225 | } |
| 226 | |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 227 | /** |
| 228 | * irq_create_affinity_masks - Create affinity masks for multiqueue spreading |
| 229 | * @nvecs: The total number of vectors |
| 230 | * @affd: Description of the affinity requirements |
| 231 | * |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 232 | * Returns the irq_affinity_desc pointer or NULL if allocation failed. |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 233 | */ |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 234 | struct irq_affinity_desc * |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 235 | irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd) |
| 236 | { |
Ming Lei | d305681 | 2018-03-08 18:53:58 +0800 | [diff] [blame] | 237 | int affvecs = nvecs - affd->pre_vectors - affd->post_vectors; |
| 238 | int curvec, usedvecs; |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 239 | cpumask_var_t *node_to_cpumask; |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 240 | struct irq_affinity_desc *masks = NULL; |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 241 | int i, nr_sets; |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 242 | |
| 243 | /* |
| 244 | * If there aren't any vectors left after applying the pre/post |
| 245 | * vectors don't bother with assigning affinity. |
| 246 | */ |
| 247 | if (nvecs == affd->pre_vectors + affd->post_vectors) |
| 248 | return NULL; |
| 249 | |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 250 | node_to_cpumask = alloc_node_to_cpumask(); |
| 251 | if (!node_to_cpumask) |
Ming Lei | 5c903e10 | 2018-11-02 22:59:49 +0800 | [diff] [blame] | 252 | return NULL; |
Ming Lei | b3e6aaa | 2018-03-08 18:53:56 +0800 | [diff] [blame] | 253 | |
| 254 | masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL); |
| 255 | if (!masks) |
| 256 | goto outnodemsk; |
| 257 | |
| 258 | /* Fill out vectors at the beginning that don't need affinity */ |
| 259 | for (curvec = 0; curvec < affd->pre_vectors; curvec++) |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 260 | cpumask_copy(&masks[curvec].mask, irq_default_affinity); |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 261 | /* |
| 262 | * Spread on present CPUs starting from affd->pre_vectors. If we |
| 263 | * have multiple sets, build each sets affinity mask separately. |
| 264 | */ |
| 265 | nr_sets = affd->nr_sets; |
| 266 | if (!nr_sets) |
| 267 | nr_sets = 1; |
| 268 | |
| 269 | for (i = 0, usedvecs = 0; i < nr_sets; i++) { |
| 270 | int this_vecs = affd->sets ? affd->sets[i] : affvecs; |
| 271 | int ret; |
| 272 | |
| 273 | ret = irq_build_affinity_masks(affd, curvec, this_vecs, |
| 274 | curvec, node_to_cpumask, masks); |
| 275 | if (ret) { |
Thomas Gleixner | c2899c3 | 2018-12-18 16:06:53 +0100 | [diff] [blame] | 276 | kfree(masks); |
| 277 | masks = NULL; |
| 278 | goto outnodemsk; |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 279 | } |
| 280 | curvec += this_vecs; |
| 281 | usedvecs += this_vecs; |
| 282 | } |
Christoph Hellwig | 67c93c2 | 2016-11-08 17:15:03 -0800 | [diff] [blame] | 283 | |
| 284 | /* Fill out vectors at the end that don't need affinity */ |
Ming Lei | d305681 | 2018-03-08 18:53:58 +0800 | [diff] [blame] | 285 | if (usedvecs >= affvecs) |
| 286 | curvec = affd->pre_vectors + affvecs; |
| 287 | else |
| 288 | curvec = affd->pre_vectors + usedvecs; |
Christoph Hellwig | 67c93c2 | 2016-11-08 17:15:03 -0800 | [diff] [blame] | 289 | for (; curvec < nvecs; curvec++) |
Dou Liyang | bec0403 | 2018-12-04 23:51:20 +0800 | [diff] [blame] | 290 | cpumask_copy(&masks[curvec].mask, irq_default_affinity); |
Ming Lei | d305681 | 2018-03-08 18:53:58 +0800 | [diff] [blame] | 291 | |
Dou Liyang | c410abbb | 2018-12-04 23:51:21 +0800 | [diff] [blame^] | 292 | /* Mark the managed interrupts */ |
| 293 | for (i = affd->pre_vectors; i < nvecs - affd->post_vectors; i++) |
| 294 | masks[i].is_managed = 1; |
| 295 | |
Thomas Gleixner | 0211e12 | 2018-04-04 12:40:07 +0200 | [diff] [blame] | 296 | outnodemsk: |
Ming Lei | 47778f33 | 2018-03-08 18:53:55 +0800 | [diff] [blame] | 297 | free_node_to_cpumask(node_to_cpumask); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 298 | return masks; |
| 299 | } |
| 300 | |
| 301 | /** |
Christoph Hellwig | 212bd84 | 2016-11-08 17:15:02 -0800 | [diff] [blame] | 302 | * irq_calc_affinity_vectors - Calculate the optimal number of vectors |
Michael Hernandez | 6f9a22b | 2017-05-18 10:47:47 -0700 | [diff] [blame] | 303 | * @minvec: The minimum number of vectors available |
Christoph Hellwig | 212bd84 | 2016-11-08 17:15:02 -0800 | [diff] [blame] | 304 | * @maxvec: The maximum number of vectors available |
| 305 | * @affd: Description of the affinity requirements |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 306 | */ |
Michael Hernandez | 6f9a22b | 2017-05-18 10:47:47 -0700 | [diff] [blame] | 307 | int irq_calc_affinity_vectors(int minvec, int maxvec, const struct irq_affinity *affd) |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 308 | { |
Christoph Hellwig | 212bd84 | 2016-11-08 17:15:02 -0800 | [diff] [blame] | 309 | int resv = affd->pre_vectors + affd->post_vectors; |
| 310 | int vecs = maxvec - resv; |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 311 | int set_vecs; |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 312 | |
Michael Hernandez | 6f9a22b | 2017-05-18 10:47:47 -0700 | [diff] [blame] | 313 | if (resv > minvec) |
| 314 | return 0; |
| 315 | |
Jens Axboe | 6da4b3a | 2018-11-02 22:59:51 +0800 | [diff] [blame] | 316 | if (affd->nr_sets) { |
| 317 | int i; |
| 318 | |
| 319 | for (i = 0, set_vecs = 0; i < affd->nr_sets; i++) |
| 320 | set_vecs += affd->sets[i]; |
| 321 | } else { |
| 322 | get_online_cpus(); |
| 323 | set_vecs = cpumask_weight(cpu_possible_mask); |
| 324 | put_online_cpus(); |
| 325 | } |
| 326 | |
| 327 | return resv + min(set_vecs, vecs); |
Thomas Gleixner | 34c3d98 | 2016-09-14 16:18:48 +0200 | [diff] [blame] | 328 | } |