blob: 3aa454c54c0de676be2d10cd62603d30d88f3253 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Andrew Morton0edaf862016-05-19 17:10:58 -07002#include <linux/nodemask.h>
3#include <linux/module.h>
4#include <linux/random.h>
5
6int __next_node_in(int node, const nodemask_t *srcp)
7{
8 int ret = __next_node(node, srcp);
9
10 if (ret == MAX_NUMNODES)
11 ret = __first_node(srcp);
12 return ret;
13}
14EXPORT_SYMBOL(__next_node_in);
15
16#ifdef CONFIG_NUMA
17/*
18 * Return the bit number of a random bit set in the nodemask.
19 * (returns NUMA_NO_NODE if nodemask is empty)
20 */
21int node_random(const nodemask_t *maskp)
22{
23 int w, bit = NUMA_NO_NODE;
24
25 w = nodes_weight(*maskp);
26 if (w)
27 bit = bitmap_ord_to_pos(maskp->bits,
28 get_random_int() % w, MAX_NUMNODES);
29 return bit;
30}
31#endif