toptree.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * NUMA support for s390
  4. *
  5. * A tree structure used for machine topology mangling
  6. *
  7. * Copyright IBM Corp. 2015
  8. */
  9. #ifndef S390_TOPTREE_H
  10. #define S390_TOPTREE_H
  11. #include <linux/cpumask.h>
  12. #include <linux/list.h>
  13. struct toptree {
  14. int level;
  15. int id;
  16. cpumask_t mask;
  17. struct toptree *parent;
  18. struct list_head sibling;
  19. struct list_head children;
  20. };
  21. struct toptree *toptree_alloc(int level, int id);
  22. void toptree_free(struct toptree *cand);
  23. void toptree_update_mask(struct toptree *cand);
  24. void toptree_unify(struct toptree *cand);
  25. struct toptree *toptree_get_child(struct toptree *cand, int id);
  26. void toptree_move(struct toptree *cand, struct toptree *target);
  27. int toptree_count(struct toptree *context, int level);
  28. struct toptree *toptree_first(struct toptree *context, int level);
  29. struct toptree *toptree_next(struct toptree *cur, struct toptree *context,
  30. int level);
  31. #define toptree_for_each_child(child, ptree) \
  32. list_for_each_entry(child, &ptree->children, sibling)
  33. #define toptree_for_each_child_safe(child, ptmp, ptree) \
  34. list_for_each_entry_safe(child, ptmp, &ptree->children, sibling)
  35. #define toptree_is_last(ptree) \
  36. ((ptree->parent == NULL) || \
  37. (ptree->parent->children.prev == &ptree->sibling))
  38. #define toptree_for_each(ptree, cont, ttype) \
  39. for (ptree = toptree_first(cont, ttype); \
  40. ptree != NULL; \
  41. ptree = toptree_next(ptree, cont, ttype))
  42. #define toptree_for_each_safe(ptree, tmp, cont, ttype) \
  43. for (ptree = toptree_first(cont, ttype), \
  44. tmp = toptree_next(ptree, cont, ttype); \
  45. ptree != NULL; \
  46. ptree = tmp, \
  47. tmp = toptree_next(ptree, cont, ttype))
  48. #define toptree_for_each_sibling(ptree, start) \
  49. toptree_for_each(ptree, start->parent, start->level)
  50. #endif /* S390_TOPTREE_H */