topology.h 6.2 KB

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