compat/nes: Adding pci_zalloc_consistent backport
[compat-rdma/compat.git] / compat / compat-4.1.c
1 #include <linux/slab.h>
2 #include <linux/kernel.h>
3 #include <linux/bitops.h>
4 #include <linux/cpumask.h>
5 #include <linux/export.h>
6 #include <linux/bootmem.h>
7
8 /**
9  * cpumask_local_spread - select the i'th cpu with local numa cpu's first
10  * @i: index number
11  * @node: local numa_node
12  *
13  * This function selects an online CPU according to a numa aware policy;
14  * local cpus are returned first, followed by non-local ones, then it
15  * wraps around.
16  *
17  * It's not very efficient, but useful for setup.
18  */
19 #define cpumask_local_spread LINUX_BACKPORT(cpumask_local_spread)
20 unsigned int cpumask_local_spread(unsigned int i, int node)
21 {
22         int cpu;
23
24         /* Wrap: we always want a cpu. */
25         i %= num_online_cpus();
26
27         if (node == -1) {
28                 for_each_cpu(cpu, cpu_online_mask)
29                         if (i-- == 0)
30                                 return cpu;
31         } else {
32                 /* NUMA first. */
33                 for_each_cpu_and(cpu, cpumask_of_node(node), cpu_online_mask)
34                         if (i-- == 0)
35                                 return cpu;
36
37                 for_each_cpu(cpu, cpu_online_mask) {
38                         /* Skip NUMA nodes, done above. */
39                         if (cpumask_test_cpu(cpu, cpumask_of_node(node)))
40                                 continue;
41
42                         if (i-- == 0)
43                                 return cpu;
44                 }
45         }
46         BUG();
47 }
48 EXPORT_SYMBOL(cpumask_local_spread);