aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cpumask.c
diff options
context:
space:
mode:
authorAmir Vadai <amirv@mellanox.com>2014-06-09 03:24:38 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-11 17:58:16 -0400
commitda91309e0a7e8966d916a74cce42ed170fde06bf (patch)
tree71bb5b4da988abb97d1a696c2f64bf39ecf9ae0d /lib/cpumask.c
parentd4f3862017f9aaa1a6b6bade396a99a4b77e2cb2 (diff)
cpumask: Utility function to set n'th cpu - local cpu first
This function sets the n'th cpu - local cpu's first. For example: in a 16 cores server with even cpu's local, will get the following values: cpumask_set_cpu_local_first(0, numa, cpumask) => cpu 0 is set cpumask_set_cpu_local_first(1, numa, cpumask) => cpu 2 is set ... cpumask_set_cpu_local_first(7, numa, cpumask) => cpu 14 is set cpumask_set_cpu_local_first(8, numa, cpumask) => cpu 1 is set cpumask_set_cpu_local_first(9, numa, cpumask) => cpu 3 is set ... cpumask_set_cpu_local_first(15, numa, cpumask) => cpu 15 is set Curently this function will be used by multi queue networking devices to calculate the irq affinity mask, such that as many local cpu's as possible will be utilized to handle the mq device irq's. Signed-off-by: Amir Vadai <amirv@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/cpumask.c')
-rw-r--r--lib/cpumask.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/cpumask.c b/lib/cpumask.c
index b810b753c607..c101230658eb 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -164,3 +164,66 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask)
164 memblock_free_early(__pa(mask), cpumask_size()); 164 memblock_free_early(__pa(mask), cpumask_size());
165} 165}
166#endif 166#endif
167
168/**
169 * cpumask_set_cpu_local_first - set i'th cpu with local numa cpu's first
170 *
171 * @i: index number
172 * @numa_node: local numa_node
173 * @dstp: cpumask with the relevant cpu bit set according to the policy
174 *
175 * This function sets the cpumask according to a numa aware policy.
176 * cpumask could be used as an affinity hint for the IRQ related to a
177 * queue. When the policy is to spread queues across cores - local cores
178 * first.
179 *
180 * Returns 0 on success, -ENOMEM for no memory, and -EAGAIN when failed to set
181 * the cpu bit and need to re-call the function.
182 */
183int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp)
184{
185 cpumask_var_t mask;
186 int cpu;
187 int ret = 0;
188
189 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
190 return -ENOMEM;
191
192 i %= num_online_cpus();
193
194 if (!cpumask_of_node(numa_node)) {
195 /* Use all online cpu's for non numa aware system */
196 cpumask_copy(mask, cpu_online_mask);
197 } else {
198 int n;
199
200 cpumask_and(mask,
201 cpumask_of_node(numa_node), cpu_online_mask);
202
203 n = cpumask_weight(mask);
204 if (i >= n) {
205 i -= n;
206
207 /* If index > number of local cpu's, mask out local
208 * cpu's
209 */
210 cpumask_andnot(mask, cpu_online_mask, mask);
211 }
212 }
213
214 for_each_cpu(cpu, mask) {
215 if (--i < 0)
216 goto out;
217 }
218
219 ret = -EAGAIN;
220
221out:
222 free_cpumask_var(mask);
223
224 if (!ret)
225 cpumask_set_cpu(cpu, dstp);
226
227 return ret;
228}
229EXPORT_SYMBOL(cpumask_set_cpu_local_first);