aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Vadai <amirv@mellanox.com>2014-05-25 10:47:26 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-01 22:16:29 -0400
commitc8865b64b05b2f4eeefd369373e9c8aeb069e7a1 (patch)
treefef93ad82529c709aeb8d15fb4330631918698d9
parent90d0e08e574d1aa8553ee6179fcf3bf2b333ca6d (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>
-rw-r--r--include/linux/cpumask.h2
-rw-r--r--lib/cpumask.c64
2 files changed, 66 insertions, 0 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index d08e4d2a9b92..3551d667ef9f 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -257,6 +257,8 @@ static inline void cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
257 set_bit(cpumask_check(cpu), cpumask_bits(dstp)); 257 set_bit(cpumask_check(cpu), cpumask_bits(dstp));
258} 258}
259 259
260int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
261
260/** 262/**
261 * cpumask_clear_cpu - clear a cpu in a cpumask 263 * cpumask_clear_cpu - clear a cpu in a cpumask
262 * @cpu: cpu number (< nr_cpu_ids) 264 * @cpu: cpu number (< nr_cpu_ids)
diff --git a/lib/cpumask.c b/lib/cpumask.c
index b810b753c607..14049a96f04a 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -163,4 +163,68 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask)
163{ 163{
164 memblock_free_early(__pa(mask), cpumask_size()); 164 memblock_free_early(__pa(mask), cpumask_size());
165} 165}
166
167/**
168 * cpumask_set_cpu_local_first - set i'th cpu with local numa cpu's first
169 *
170 * @i: index number
171 * @numa_node: local numa_node
172 * @dstp: cpumask with the relevant cpu bit set according to the policy
173 *
174 * This function sets the cpumask according to a numa aware policy.
175 * cpumask could be used as an affinity hint for the IRQ related to a
176 * queue. When the policy is to spread queues across cores - local cores
177 * first.
178 *
179 * Returns 0 on success, -ENOMEM for no memory, and -EAGAIN when failed to set
180 * the cpu bit and need to re-call the function.
181 */
182int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp)
183{
184 cpumask_var_t mask;
185 int cpu;
186 int ret = 0;
187
188 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
189 return -ENOMEM;
190
191 i %= num_online_cpus();
192
193 if (!cpumask_of_node(numa_node)) {
194 /* Use all online cpu's for non numa aware system */
195 cpumask_copy(mask, cpu_online_mask);
196 } else {
197 int n;
198
199 cpumask_and(mask,
200 cpumask_of_node(numa_node), cpu_online_mask);
201
202 n = cpumask_weight(mask);
203 if (i >= n) {
204 i -= n;
205
206 /* If index > number of local cpu's, mask out local
207 * cpu's
208 */
209 cpumask_andnot(mask, cpu_online_mask, mask);
210 }
211 }
212
213 for_each_cpu(cpu, mask) {
214 if (--i < 0)
215 goto out;
216 }
217
218 ret = -EAGAIN;
219
220out:
221 free_cpumask_var(mask);
222
223 if (!ret)
224 cpumask_set_cpu(cpu, dstp);
225
226 return ret;
227}
228EXPORT_SYMBOL(cpumask_set_cpu_local_first);
229
166#endif 230#endif