Skip to content

Commit 53c1788

Browse files
Ming LeiKAGA-KOKO
authored andcommitted
genirq/affinity: Improve __irq_build_affinity_masks()
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b6a32bb commit 53c1788

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

kernel/irq/affinity.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,26 @@ static int __irq_build_affinity_masks(unsigned int startvec,
129129
for_each_node_mask(n, nodemsk) {
130130
unsigned int ncpus, v, vecs_to_assign, vecs_per_node;
131131

132-
/* Spread the vectors per node */
133-
vecs_per_node = (numvecs - (curvec - firstvec)) / nodes;
134-
135132
/* Get the cpus on this node which are in the mask */
136133
cpumask_and(nmsk, cpu_mask, node_to_cpumask[n]);
137-
138-
/* Calculate the number of cpus per vector */
139134
ncpus = cpumask_weight(nmsk);
135+
if (!ncpus)
136+
continue;
137+
138+
/*
139+
* Calculate the number of cpus per vector
140+
*
141+
* Spread the vectors evenly per node. If the requested
142+
* vector number has been reached, simply allocate one
143+
* vector for each remaining node so that all nodes can
144+
* be covered
145+
*/
146+
if (numvecs > done)
147+
vecs_per_node = max_t(unsigned,
148+
(numvecs - done) / nodes, 1);
149+
else
150+
vecs_per_node = 1;
151+
140152
vecs_to_assign = min(vecs_per_node, ncpus);
141153

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

158170
done += v;
159-
if (done >= numvecs)
160-
break;
161171
if (curvec >= last_affv)
162172
curvec = firstvec;
163173
--nodes;
164174
}
165-
return done;
175+
return done < numvecs ? done : numvecs;
166176
}
167177

168178
/*

0 commit comments

Comments
 (0)