Andrew Morton | 0edaf86 | 2016-05-19 17:10:58 -0700 | [diff] [blame] | 1 | #include <linux/nodemask.h> |
| 2 | #include <linux/module.h> |
| 3 | #include <linux/random.h> |
| 4 | |
Kees Cook | 2811cda | 2022-05-18 13:52:23 -0700 | [diff] [blame] | 5 | unsigned int __next_node_in(int node, const nodemask_t *srcp) |
Andrew Morton | 0edaf86 | 2016-05-19 17:10:58 -0700 | [diff] [blame] | 6 | { |
Kees Cook | 2811cda | 2022-05-18 13:52:23 -0700 | [diff] [blame] | 7 | unsigned int ret = __next_node(node, srcp); |
Andrew Morton | 0edaf86 | 2016-05-19 17:10:58 -0700 | [diff] [blame] | 8 | |
| 9 | if (ret == MAX_NUMNODES) |
| 10 | ret = __first_node(srcp); |
| 11 | return ret; |
| 12 | } |
| 13 | EXPORT_SYMBOL(__next_node_in); |
| 14 | |
| 15 | #ifdef CONFIG_NUMA |
| 16 | /* |
| 17 | * Return the bit number of a random bit set in the nodemask. |
| 18 | * (returns NUMA_NO_NODE if nodemask is empty) |
| 19 | */ |
| 20 | int node_random(const nodemask_t *maskp) |
| 21 | { |
| 22 | int w, bit = NUMA_NO_NODE; |
| 23 | |
| 24 | w = nodes_weight(*maskp); |
| 25 | if (w) |
| 26 | bit = bitmap_ord_to_pos(maskp->bits, |
| 27 | get_random_int() % w, MAX_NUMNODES); |
| 28 | return bit; |
| 29 | } |
| 30 | #endif |