toptree.h 1.8 KB

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