nodemask.c 617 B

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