nodemask.c 653 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/nodemask.h>
  3. #include <linux/module.h>
  4. #include <linux/random.h>
  5. int __next_node_in(int node, const nodemask_t *srcp)
  6. {
  7. int ret = __next_node(node, srcp);
  8. if (ret == MAX_NUMNODES)
  9. ret = __first_node(srcp);
  10. return ret;
  11. }
  12. EXPORT_SYMBOL(__next_node_in);
  13. #ifdef CONFIG_NUMA
  14. /*
  15. * Return the bit number of a random bit set in the nodemask.
  16. * (returns NUMA_NO_NODE if nodemask is empty)
  17. */
  18. int node_random(const nodemask_t *maskp)
  19. {
  20. int w, bit = NUMA_NO_NODE;
  21. w = nodes_weight(*maskp);
  22. if (w)
  23. bit = bitmap_ord_to_pos(maskp->bits,
  24. get_random_int() % w, MAX_NUMNODES);
  25. return bit;
  26. }
  27. #endif