提交 67c93c21 编写于 作者: C Christoph Hellwig 提交者: Thomas Gleixner

genirq/affinity: Handle pre/post vectors in irq_create_affinity_masks()

Only calculate the affinity for the main I/O vectors, and skip the
pre or post vectors specified by struct irq_affinity.

Also remove the irq_affinity cpumask argument that has never been used.
If we ever need it in the future we can pass it through struct
irq_affinity.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NHannes Reinecke <hare@suse.com>
Acked-by: NBjorn Helgaas <bhelgaas@google.com>
Acked-by: NJens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Link: http://lkml.kernel.org/r/1478654107-7384-4-git-send-email-hch@lst.deSigned-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 212bd846
...@@ -553,12 +553,13 @@ static int populate_msi_sysfs(struct pci_dev *pdev) ...@@ -553,12 +553,13 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
static struct msi_desc * static struct msi_desc *
msi_setup_entry(struct pci_dev *dev, int nvec, bool affinity) msi_setup_entry(struct pci_dev *dev, int nvec, bool affinity)
{ {
static const struct irq_affinity default_affd;
struct cpumask *masks = NULL; struct cpumask *masks = NULL;
struct msi_desc *entry; struct msi_desc *entry;
u16 control; u16 control;
if (affinity) { if (affinity) {
masks = irq_create_affinity_masks(dev->irq_affinity, nvec); masks = irq_create_affinity_masks(nvec, &default_affd);
if (!masks) if (!masks)
pr_err("Unable to allocate affinity masks, ignoring\n"); pr_err("Unable to allocate affinity masks, ignoring\n");
} }
...@@ -692,12 +693,13 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base, ...@@ -692,12 +693,13 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,
struct msix_entry *entries, int nvec, struct msix_entry *entries, int nvec,
bool affinity) bool affinity)
{ {
static const struct irq_affinity default_affd;
struct cpumask *curmsk, *masks = NULL; struct cpumask *curmsk, *masks = NULL;
struct msi_desc *entry; struct msi_desc *entry;
int ret, i; int ret, i;
if (affinity) { if (affinity) {
masks = irq_create_affinity_masks(dev->irq_affinity, nvec); masks = irq_create_affinity_masks(nvec, &default_affd);
if (!masks) if (!masks)
pr_err("Unable to allocate affinity masks, ignoring\n"); pr_err("Unable to allocate affinity masks, ignoring\n");
} }
......
...@@ -290,7 +290,7 @@ extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); ...@@ -290,7 +290,7 @@ extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
extern int extern int
irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify); irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity, int nvec); struct cpumask *irq_create_affinity_masks(int nvec, const struct irq_affinity *affd);
int irq_calc_affinity_vectors(int maxvec, const struct irq_affinity *affd); int irq_calc_affinity_vectors(int maxvec, const struct irq_affinity *affd);
#else /* CONFIG_SMP */ #else /* CONFIG_SMP */
...@@ -325,7 +325,7 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) ...@@ -325,7 +325,7 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
} }
static inline struct cpumask * static inline struct cpumask *
irq_create_affinity_masks(const struct cpumask *affinity, int nvec) irq_create_affinity_masks(int nvec, const struct irq_affinity *affd)
{ {
return NULL; return NULL;
} }
......
...@@ -51,16 +51,16 @@ static int get_nodes_in_cpumask(const struct cpumask *mask, nodemask_t *nodemsk) ...@@ -51,16 +51,16 @@ static int get_nodes_in_cpumask(const struct cpumask *mask, nodemask_t *nodemsk)
/** /**
* irq_create_affinity_masks - Create affinity masks for multiqueue spreading * irq_create_affinity_masks - Create affinity masks for multiqueue spreading
* @affinity: The affinity mask to spread. If NULL cpu_online_mask * @nvecs: The total number of vectors
* is used * @affd: Description of the affinity requirements
* @nvecs: The number of vectors
* *
* Returns the masks pointer or NULL if allocation failed. * Returns the masks pointer or NULL if allocation failed.
*/ */
struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity, struct cpumask *
int nvec) irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
{ {
int n, nodes, vecs_per_node, cpus_per_vec, extra_vecs, curvec = 0; int n, nodes, vecs_per_node, cpus_per_vec, extra_vecs, curvec;
int affv = nvecs - affd->pre_vectors - affd->post_vectors;
nodemask_t nodemsk = NODE_MASK_NONE; nodemask_t nodemsk = NODE_MASK_NONE;
struct cpumask *masks; struct cpumask *masks;
cpumask_var_t nmsk; cpumask_var_t nmsk;
...@@ -68,46 +68,46 @@ struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity, ...@@ -68,46 +68,46 @@ struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity,
if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
return NULL; return NULL;
masks = kzalloc(nvec * sizeof(*masks), GFP_KERNEL); masks = kcalloc(nvecs, sizeof(*masks), GFP_KERNEL);
if (!masks) if (!masks)
goto out; goto out;
/* Fill out vectors at the beginning that don't need affinity */
for (curvec = 0; curvec < affd->pre_vectors; curvec++)
cpumask_copy(masks + curvec, cpu_possible_mask);
/* Stabilize the cpumasks */ /* Stabilize the cpumasks */
get_online_cpus(); get_online_cpus();
/* If the supplied affinity mask is NULL, use cpu online mask */ nodes = get_nodes_in_cpumask(cpu_online_mask, &nodemsk);
if (!affinity)
affinity = cpu_online_mask;
nodes = get_nodes_in_cpumask(affinity, &nodemsk);
/* /*
* If the number of nodes in the mask is less than or equal the * If the number of nodes in the mask is less than or equal the
* number of vectors we just spread the vectors across the nodes. * number of vectors we just spread the vectors across the nodes.
*/ */
if (nvec <= nodes) { if (affv <= nodes) {
for_each_node_mask(n, nodemsk) { for_each_node_mask(n, nodemsk) {
cpumask_copy(masks + curvec, cpumask_of_node(n)); cpumask_copy(masks + curvec, cpumask_of_node(n));
if (++curvec == nvec) if (++curvec == affv)
break; break;
} }
goto outonl; goto done;
} }
/* Spread the vectors per node */ /* Spread the vectors per node */
vecs_per_node = nvec / nodes; vecs_per_node = affv / nodes;
/* Account for rounding errors */ /* Account for rounding errors */
extra_vecs = nvec - (nodes * vecs_per_node); extra_vecs = affv - (nodes * vecs_per_node);
for_each_node_mask(n, nodemsk) { for_each_node_mask(n, nodemsk) {
int ncpus, v, vecs_to_assign = vecs_per_node; int ncpus, v, vecs_to_assign = vecs_per_node;
/* Get the cpus on this node which are in the mask */ /* Get the cpus on this node which are in the mask */
cpumask_and(nmsk, affinity, cpumask_of_node(n)); cpumask_and(nmsk, cpu_online_mask, cpumask_of_node(n));
/* Calculate the number of cpus per vector */ /* Calculate the number of cpus per vector */
ncpus = cpumask_weight(nmsk); ncpus = cpumask_weight(nmsk);
for (v = 0; curvec < nvec && v < vecs_to_assign; curvec++, v++) { for (v = 0; curvec < affv && v < vecs_to_assign; curvec++, v++) {
cpus_per_vec = ncpus / vecs_to_assign; cpus_per_vec = ncpus / vecs_to_assign;
/* Account for extra vectors to compensate rounding errors */ /* Account for extra vectors to compensate rounding errors */
...@@ -119,12 +119,16 @@ struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity, ...@@ -119,12 +119,16 @@ struct cpumask *irq_create_affinity_masks(const struct cpumask *affinity,
irq_spread_init_one(masks + curvec, nmsk, cpus_per_vec); irq_spread_init_one(masks + curvec, nmsk, cpus_per_vec);
} }
if (curvec >= nvec) if (curvec >= affv)
break; break;
} }
outonl: done:
put_online_cpus(); put_online_cpus();
/* Fill out vectors at the end that don't need affinity */
for (; curvec < nvecs; curvec++)
cpumask_copy(masks + curvec, cpu_possible_mask);
out: out:
free_cpumask_var(nmsk); free_cpumask_var(nmsk);
return masks; return masks;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册