Skip to content

Commit 6da4b3a

Browse files
axboeKAGA-KOKO
authored andcommitted
genirq/affinity: Add support for allocating interrupt sets
A driver may have a need to allocate multiple sets of MSI/MSI-X interrupts, and have them appropriately affinitized. Add support for defining a number of sets in the irq_affinity structure, of varying sizes, and get each set affinitized correctly across the machine. [ tglx: Minor changelog tweaks ] Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Keith Busch <keith.busch@intel.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Cc: linux-block@vger.kernel.org Link: https://lkml.kernel.org/r/20181102145951.31979-5-ming.lei@redhat.com
1 parent 060746d commit 6da4b3a

File tree

3 files changed

+72
-23
lines changed

3 files changed

+72
-23
lines changed

drivers/pci/msi.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,13 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
10361036
if (maxvec < minvec)
10371037
return -ERANGE;
10381038

1039+
/*
1040+
* If the caller is passing in sets, we can't support a range of
1041+
* vectors. The caller needs to handle that.
1042+
*/
1043+
if (affd && affd->nr_sets && minvec != maxvec)
1044+
return -EINVAL;
1045+
10391046
if (WARN_ON_ONCE(dev->msi_enabled))
10401047
return -EINVAL;
10411048

@@ -1087,6 +1094,13 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
10871094
if (maxvec < minvec)
10881095
return -ERANGE;
10891096

1097+
/*
1098+
* If the caller is passing in sets, we can't support a range of
1099+
* supported vectors. The caller needs to handle that.
1100+
*/
1101+
if (affd && affd->nr_sets && minvec != maxvec)
1102+
return -EINVAL;
1103+
10901104
if (WARN_ON_ONCE(dev->msix_enabled))
10911105
return -EINVAL;
10921106

include/linux/interrupt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,14 @@ struct irq_affinity_notify {
247247
* the MSI(-X) vector space
248248
* @post_vectors: Don't apply affinity to @post_vectors at end of
249249
* the MSI(-X) vector space
250+
* @nr_sets: Length of passed in *sets array
251+
* @sets: Number of affinitized sets
250252
*/
251253
struct irq_affinity {
252254
int pre_vectors;
253255
int post_vectors;
256+
int nr_sets;
257+
int *sets;
254258
};
255259

256260
#if defined(CONFIG_SMP)

kernel/irq/affinity.c

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,52 +171,54 @@ static int __irq_build_affinity_masks(const struct irq_affinity *affd,
171171
* 2) spread other possible CPUs on these vectors
172172
*/
173173
static int irq_build_affinity_masks(const struct irq_affinity *affd,
174-
int startvec, int numvecs,
174+
int startvec, int numvecs, int firstvec,
175175
cpumask_var_t *node_to_cpumask,
176176
struct cpumask *masks)
177177
{
178-
int curvec = startvec, usedvecs = -1;
178+
int curvec = startvec, nr_present, nr_others;
179+
int ret = -ENOMEM;
179180
cpumask_var_t nmsk, npresmsk;
180181

181182
if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
182-
return usedvecs;
183+
return ret;
183184

184185
if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL))
185186
goto fail;
186187

188+
ret = 0;
187189
/* Stabilize the cpumasks */
188190
get_online_cpus();
189191
build_node_to_cpumask(node_to_cpumask);
190192

191193
/* Spread on present CPUs starting from affd->pre_vectors */
192-
usedvecs = __irq_build_affinity_masks(affd, curvec, numvecs,
193-
affd->pre_vectors,
194-
node_to_cpumask,
195-
cpu_present_mask, nmsk, masks);
194+
nr_present = __irq_build_affinity_masks(affd, curvec, numvecs,
195+
firstvec, node_to_cpumask,
196+
cpu_present_mask, nmsk, masks);
196197

197198
/*
198199
* Spread on non present CPUs starting from the next vector to be
199200
* handled. If the spreading of present CPUs already exhausted the
200201
* vector space, assign the non present CPUs to the already spread
201202
* out vectors.
202203
*/
203-
if (usedvecs >= numvecs)
204-
curvec = affd->pre_vectors;
204+
if (nr_present >= numvecs)
205+
curvec = firstvec;
205206
else
206-
curvec = affd->pre_vectors + usedvecs;
207+
curvec = firstvec + nr_present;
207208
cpumask_andnot(npresmsk, cpu_possible_mask, cpu_present_mask);
208-
usedvecs += __irq_build_affinity_masks(affd, curvec, numvecs,
209-
affd->pre_vectors,
210-
node_to_cpumask, npresmsk,
211-
nmsk, masks);
209+
nr_others = __irq_build_affinity_masks(affd, curvec, numvecs,
210+
firstvec, node_to_cpumask,
211+
npresmsk, nmsk, masks);
212212
put_online_cpus();
213213

214+
if (nr_present < numvecs)
215+
WARN_ON(nr_present + nr_others < numvecs);
216+
214217
free_cpumask_var(npresmsk);
215218

216219
fail:
217220
free_cpumask_var(nmsk);
218-
219-
return usedvecs;
221+
return ret;
220222
}
221223

222224
/**
@@ -233,6 +235,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
233235
int curvec, usedvecs;
234236
cpumask_var_t *node_to_cpumask;
235237
struct cpumask *masks = NULL;
238+
int i, nr_sets;
236239

237240
/*
238241
* If there aren't any vectors left after applying the pre/post
@@ -253,8 +256,28 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
253256
for (curvec = 0; curvec < affd->pre_vectors; curvec++)
254257
cpumask_copy(masks + curvec, irq_default_affinity);
255258

256-
usedvecs = irq_build_affinity_masks(affd, curvec, affvecs,
257-
node_to_cpumask, masks);
259+
/*
260+
* Spread on present CPUs starting from affd->pre_vectors. If we
261+
* have multiple sets, build each sets affinity mask separately.
262+
*/
263+
nr_sets = affd->nr_sets;
264+
if (!nr_sets)
265+
nr_sets = 1;
266+
267+
for (i = 0, usedvecs = 0; i < nr_sets; i++) {
268+
int this_vecs = affd->sets ? affd->sets[i] : affvecs;
269+
int ret;
270+
271+
ret = irq_build_affinity_masks(affd, curvec, this_vecs,
272+
curvec, node_to_cpumask, masks);
273+
if (ret) {
274+
kfree(masks);
275+
masks = NULL;
276+
goto outnodemsk;
277+
}
278+
curvec += this_vecs;
279+
usedvecs += this_vecs;
280+
}
258281

259282
/* Fill out vectors at the end that don't need affinity */
260283
if (usedvecs >= affvecs)
@@ -279,13 +302,21 @@ int irq_calc_affinity_vectors(int minvec, int maxvec, const struct irq_affinity
279302
{
280303
int resv = affd->pre_vectors + affd->post_vectors;
281304
int vecs = maxvec - resv;
282-
int ret;
305+
int set_vecs;
283306

284307
if (resv > minvec)
285308
return 0;
286309

287-
get_online_cpus();
288-
ret = min_t(int, cpumask_weight(cpu_possible_mask), vecs) + resv;
289-
put_online_cpus();
290-
return ret;
310+
if (affd->nr_sets) {
311+
int i;
312+
313+
for (i = 0, set_vecs = 0; i < affd->nr_sets; i++)
314+
set_vecs += affd->sets[i];
315+
} else {
316+
get_online_cpus();
317+
set_vecs = cpumask_weight(cpu_possible_mask);
318+
put_online_cpus();
319+
}
320+
321+
return resv + min(set_vecs, vecs);
291322
}

0 commit comments

Comments
 (0)