Skip to content

Commit

Permalink
genirq/affinity: Improve __irq_build_affinity_masks()
Browse files Browse the repository at this point in the history
One invariant of __irq_build_affinity_masks() is that all CPUs in the
specified masks (cpu_mask AND node_to_cpumask for each node) should be
covered during the spread. Even though all requested vectors have been
reached, it's still required to spread vectors among remained CPUs. A
similar policy has been taken in case of 'numvecs <= nodes' already.

So remove the following check inside the loop:

	if (done >= numvecs)
		break;

Meantime assign at least 1 vector for remaining nodes if 'numvecs' vectors
have been handled already.

Also, if the specified cpumask for one numa node is empty, simply do not
spread vectors on this node.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190816022849.14075-2-ming.lei@redhat.com
  • Loading branch information
Ming Lei authored and Thomas Gleixner committed Aug 27, 2019
1 parent b6a32bb commit 53c1788
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions kernel/irq/affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,26 @@ static int __irq_build_affinity_masks(unsigned int startvec,
for_each_node_mask(n, nodemsk) {
unsigned int ncpus, v, vecs_to_assign, vecs_per_node;

/* Spread the vectors per node */
vecs_per_node = (numvecs - (curvec - firstvec)) / nodes;

/* Get the cpus on this node which are in the mask */
cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]);

/* Calculate the number of cpus per vector */
ncpus = cpumask_weight(nmsk);
if (!ncpus)
continue;

/*
* Calculate the number of cpus per vector
*
* Spread the vectors evenly per node. If the requested
* vector number has been reached, simply allocate one
* vector for each remaining node so that all nodes can
* be covered
*/
if (numvecs > done)
vecs_per_node = max_t(unsigned,
(numvecs - done) / nodes, 1);
else
vecs_per_node = 1;

vecs_to_assign = min(vecs_per_node, ncpus);

/* Account for rounding errors */
Expand All @@ -156,13 +168,11 @@ static int __irq_build_affinity_masks(unsigned int startvec,
}

done += v;
if (done >= numvecs)
break;
if (curvec >= last_affv)
curvec = firstvec;
--nodes;
}
return done;
return done < numvecs ? done : numvecs;
}

/*
Expand Down

0 comments on commit 53c1788

Please sign in to comment.