topology.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #ifndef _LINUX_SCHED_TOPOLOGY_H
  2. #define _LINUX_SCHED_TOPOLOGY_H
  3. #include <linux/sched.h>
  4. #include <linux/sched/idle.h>
  5. /*
  6. * sched-domains (multiprocessor balancing) declarations:
  7. */
  8. #ifdef CONFIG_SMP
  9. #define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */
  10. #define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */
  11. #define SD_BALANCE_EXEC 0x0004 /* Balance on exec */
  12. #define SD_BALANCE_FORK 0x0008 /* Balance on fork, clone */
  13. #define SD_BALANCE_WAKE 0x0010 /* Balance on wakeup */
  14. #define SD_WAKE_AFFINE 0x0020 /* Wake task to waking CPU */
  15. #define SD_ASYM_CPUCAPACITY 0x0040 /* Groups have different max cpu capacities */
  16. #define SD_SHARE_CPUCAPACITY 0x0080 /* Domain members share cpu capacity */
  17. #define SD_SHARE_POWERDOMAIN 0x0100 /* Domain members share power domain */
  18. #define SD_SHARE_PKG_RESOURCES 0x0200 /* Domain members share cpu pkg resources */
  19. #define SD_SERIALIZE 0x0400 /* Only a single load balancing instance */
  20. #define SD_ASYM_PACKING 0x0800 /* Place busy groups earlier in the domain */
  21. #define SD_PREFER_SIBLING 0x1000 /* Prefer to place tasks in a sibling domain */
  22. #define SD_OVERLAP 0x2000 /* sched_domains of this level overlap */
  23. #define SD_NUMA 0x4000 /* cross-node balancing */
  24. /*
  25. * Increase resolution of cpu_capacity calculations
  26. */
  27. #define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT
  28. #define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
  29. #ifdef CONFIG_SCHED_SMT
  30. static inline int cpu_smt_flags(void)
  31. {
  32. return SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
  33. }
  34. #endif
  35. #ifdef CONFIG_SCHED_MC
  36. static inline int cpu_core_flags(void)
  37. {
  38. return SD_SHARE_PKG_RESOURCES;
  39. }
  40. #endif
  41. #ifdef CONFIG_NUMA
  42. static inline int cpu_numa_flags(void)
  43. {
  44. return SD_NUMA;
  45. }
  46. #endif
  47. extern int arch_asym_cpu_priority(int cpu);
  48. struct sched_domain_attr {
  49. int relax_domain_level;
  50. };
  51. #define SD_ATTR_INIT (struct sched_domain_attr) { \
  52. .relax_domain_level = -1, \
  53. }
  54. extern int sched_domain_level_max;
  55. struct sched_group;
  56. struct sched_domain_shared {
  57. atomic_t ref;
  58. atomic_t nr_busy_cpus;
  59. int has_idle_cores;
  60. };
  61. struct sched_domain {
  62. /* These fields must be setup */
  63. struct sched_domain *parent; /* top domain must be null terminated */
  64. struct sched_domain *child; /* bottom domain must be null terminated */
  65. struct sched_group *groups; /* the balancing groups of the domain */
  66. unsigned long min_interval; /* Minimum balance interval ms */
  67. unsigned long max_interval; /* Maximum balance interval ms */
  68. unsigned int busy_factor; /* less balancing by factor if busy */
  69. unsigned int imbalance_pct; /* No balance until over watermark */
  70. unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */
  71. unsigned int busy_idx;
  72. unsigned int idle_idx;
  73. unsigned int newidle_idx;
  74. unsigned int wake_idx;
  75. unsigned int forkexec_idx;
  76. unsigned int smt_gain;
  77. int nohz_idle; /* NOHZ IDLE status */
  78. int flags; /* See SD_* */
  79. int level;
  80. /* Runtime fields. */
  81. unsigned long last_balance; /* init to jiffies. units in jiffies */
  82. unsigned int balance_interval; /* initialise to 1. units in ms. */
  83. unsigned int nr_balance_failed; /* initialise to 0 */
  84. /* idle_balance() stats */
  85. u64 max_newidle_lb_cost;
  86. unsigned long next_decay_max_lb_cost;
  87. u64 avg_scan_cost; /* select_idle_sibling */
  88. #ifdef CONFIG_SCHEDSTATS
  89. /* load_balance() stats */
  90. unsigned int lb_count[CPU_MAX_IDLE_TYPES];
  91. unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
  92. unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
  93. unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
  94. unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
  95. unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
  96. unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
  97. unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
  98. /* Active load balancing */
  99. unsigned int alb_count;
  100. unsigned int alb_failed;
  101. unsigned int alb_pushed;
  102. /* SD_BALANCE_EXEC stats */
  103. unsigned int sbe_count;
  104. unsigned int sbe_balanced;
  105. unsigned int sbe_pushed;
  106. /* SD_BALANCE_FORK stats */
  107. unsigned int sbf_count;
  108. unsigned int sbf_balanced;
  109. unsigned int sbf_pushed;
  110. /* try_to_wake_up() stats */
  111. unsigned int ttwu_wake_remote;
  112. unsigned int ttwu_move_affine;
  113. unsigned int ttwu_move_balance;
  114. #endif
  115. #ifdef CONFIG_SCHED_DEBUG
  116. char *name;
  117. #endif
  118. union {
  119. void *private; /* used during construction */
  120. struct rcu_head rcu; /* used during destruction */
  121. };
  122. struct sched_domain_shared *shared;
  123. unsigned int span_weight;
  124. /*
  125. * Span of all CPUs in this domain.
  126. *
  127. * NOTE: this field is variable length. (Allocated dynamically
  128. * by attaching extra space to the end of the structure,
  129. * depending on how many CPUs the kernel has booted up with)
  130. */
  131. unsigned long span[0];
  132. };
  133. static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
  134. {
  135. return to_cpumask(sd->span);
  136. }
  137. extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
  138. struct sched_domain_attr *dattr_new);
  139. /* Allocate an array of sched domains, for partition_sched_domains(). */
  140. cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
  141. void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
  142. bool cpus_share_cache(int this_cpu, int that_cpu);
  143. typedef const struct cpumask *(*sched_domain_mask_f)(int cpu);
  144. typedef int (*sched_domain_flags_f)(void);
  145. #define SDTL_OVERLAP 0x01
  146. struct sd_data {
  147. struct sched_domain **__percpu sd;
  148. struct sched_domain_shared **__percpu sds;
  149. struct sched_group **__percpu sg;
  150. struct sched_group_capacity **__percpu sgc;
  151. };
  152. struct sched_domain_topology_level {
  153. sched_domain_mask_f mask;
  154. sched_domain_flags_f sd_flags;
  155. int flags;
  156. int numa_level;
  157. struct sd_data data;
  158. #ifdef CONFIG_SCHED_DEBUG
  159. char *name;
  160. #endif
  161. };
  162. extern void set_sched_topology(struct sched_domain_topology_level *tl);
  163. #ifdef CONFIG_SCHED_DEBUG
  164. # define SD_INIT_NAME(type) .name = #type
  165. #else
  166. # define SD_INIT_NAME(type)
  167. #endif
  168. #else /* CONFIG_SMP */
  169. struct sched_domain_attr;
  170. static inline void
  171. partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
  172. struct sched_domain_attr *dattr_new)
  173. {
  174. }
  175. static inline bool cpus_share_cache(int this_cpu, int that_cpu)
  176. {
  177. return true;
  178. }
  179. #endif /* !CONFIG_SMP */
  180. #endif /* _LINUX_SCHED_TOPOLOGY_H */