topology.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/android_kabi.h>
  6. #include <linux/android_vendor.h>
  7. #include <linux/sched/idle.h>
  8. /*
  9. * sched-domains (multiprocessor balancing) declarations:
  10. */
  11. #ifdef CONFIG_SMP
  12. /* Generate SD flag indexes */
  13. #define SD_FLAG(name, mflags) __##name,
  14. enum {
  15. #include <linux/sched/sd_flags.h>
  16. __SD_FLAG_CNT,
  17. };
  18. #undef SD_FLAG
  19. /* Generate SD flag bits */
  20. #define SD_FLAG(name, mflags) name = 1 << __##name,
  21. enum {
  22. #include <linux/sched/sd_flags.h>
  23. };
  24. #undef SD_FLAG
  25. #ifdef CONFIG_SCHED_DEBUG
  26. struct sd_flag_debug {
  27. unsigned int meta_flags;
  28. char *name;
  29. };
  30. extern const struct sd_flag_debug sd_flag_debug[];
  31. #endif
  32. #ifdef CONFIG_SCHED_SMT
  33. static inline int cpu_smt_flags(void)
  34. {
  35. return SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
  36. }
  37. #endif
  38. #ifdef CONFIG_SCHED_CLUSTER
  39. static inline int cpu_cluster_flags(void)
  40. {
  41. return SD_SHARE_PKG_RESOURCES;
  42. }
  43. #endif
  44. #ifdef CONFIG_SCHED_MC
  45. static inline int cpu_core_flags(void)
  46. {
  47. return SD_SHARE_PKG_RESOURCES;
  48. }
  49. #endif
  50. #ifdef CONFIG_NUMA
  51. static inline int cpu_numa_flags(void)
  52. {
  53. return SD_NUMA;
  54. }
  55. #endif
  56. extern int arch_asym_cpu_priority(int cpu);
  57. struct sched_domain_attr {
  58. int relax_domain_level;
  59. };
  60. #define SD_ATTR_INIT (struct sched_domain_attr) { \
  61. .relax_domain_level = -1, \
  62. }
  63. extern int sched_domain_level_max;
  64. struct sched_group;
  65. struct sched_domain_shared {
  66. atomic_t ref;
  67. atomic_t nr_busy_cpus;
  68. int has_idle_cores;
  69. int nr_idle_scan;
  70. ANDROID_VENDOR_DATA(1);
  71. };
  72. struct sched_domain {
  73. /* These fields must be setup */
  74. struct sched_domain __rcu *parent; /* top domain must be null terminated */
  75. struct sched_domain __rcu *child; /* bottom domain must be null terminated */
  76. struct sched_group *groups; /* the balancing groups of the domain */
  77. unsigned long min_interval; /* Minimum balance interval ms */
  78. unsigned long max_interval; /* Maximum balance interval ms */
  79. unsigned int busy_factor; /* less balancing by factor if busy */
  80. unsigned int imbalance_pct; /* No balance until over watermark */
  81. unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */
  82. unsigned int imb_numa_nr; /* Nr running tasks that allows a NUMA imbalance */
  83. int nohz_idle; /* NOHZ IDLE status */
  84. int flags; /* See SD_* */
  85. int level;
  86. /* Runtime fields. */
  87. unsigned long last_balance; /* init to jiffies. units in jiffies */
  88. unsigned int balance_interval; /* initialise to 1. units in ms. */
  89. unsigned int nr_balance_failed; /* initialise to 0 */
  90. /* idle_balance() stats */
  91. u64 max_newidle_lb_cost;
  92. unsigned long last_decay_max_lb_cost;
  93. u64 avg_scan_cost; /* select_idle_sibling */
  94. #ifdef CONFIG_SCHEDSTATS
  95. /* load_balance() stats */
  96. unsigned int lb_count[CPU_MAX_IDLE_TYPES];
  97. unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
  98. unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
  99. unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
  100. unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
  101. unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
  102. unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
  103. unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
  104. /* Active load balancing */
  105. unsigned int alb_count;
  106. unsigned int alb_failed;
  107. unsigned int alb_pushed;
  108. /* SD_BALANCE_EXEC stats */
  109. unsigned int sbe_count;
  110. unsigned int sbe_balanced;
  111. unsigned int sbe_pushed;
  112. /* SD_BALANCE_FORK stats */
  113. unsigned int sbf_count;
  114. unsigned int sbf_balanced;
  115. unsigned int sbf_pushed;
  116. /* try_to_wake_up() stats */
  117. unsigned int ttwu_wake_remote;
  118. unsigned int ttwu_move_affine;
  119. unsigned int ttwu_move_balance;
  120. #endif
  121. #ifdef CONFIG_SCHED_DEBUG
  122. char *name;
  123. #endif
  124. union {
  125. void *private; /* used during construction */
  126. struct rcu_head rcu; /* used during destruction */
  127. };
  128. struct sched_domain_shared *shared;
  129. unsigned int span_weight;
  130. ANDROID_KABI_RESERVE(1);
  131. ANDROID_KABI_RESERVE(2);
  132. /*
  133. * Span of all CPUs in this domain.
  134. *
  135. * NOTE: this field is variable length. (Allocated dynamically
  136. * by attaching extra space to the end of the structure,
  137. * depending on how many CPUs the kernel has booted up with)
  138. */
  139. unsigned long span[];
  140. };
  141. static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
  142. {
  143. return to_cpumask(sd->span);
  144. }
  145. extern void partition_sched_domains_locked(int ndoms_new,
  146. cpumask_var_t doms_new[],
  147. struct sched_domain_attr *dattr_new);
  148. extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
  149. struct sched_domain_attr *dattr_new);
  150. /* Allocate an array of sched domains, for partition_sched_domains(). */
  151. cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
  152. void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
  153. bool cpus_share_cache(int this_cpu, int that_cpu);
  154. typedef const struct cpumask *(*sched_domain_mask_f)(int cpu);
  155. typedef int (*sched_domain_flags_f)(void);
  156. #define SDTL_OVERLAP 0x01
  157. struct sd_data {
  158. struct sched_domain *__percpu *sd;
  159. struct sched_domain_shared *__percpu *sds;
  160. struct sched_group *__percpu *sg;
  161. struct sched_group_capacity *__percpu *sgc;
  162. };
  163. struct sched_domain_topology_level {
  164. sched_domain_mask_f mask;
  165. sched_domain_flags_f sd_flags;
  166. int flags;
  167. int numa_level;
  168. struct sd_data data;
  169. #ifdef CONFIG_SCHED_DEBUG
  170. char *name;
  171. #endif
  172. };
  173. extern void set_sched_topology(struct sched_domain_topology_level *tl);
  174. #ifdef CONFIG_SCHED_DEBUG
  175. # define SD_INIT_NAME(type) .name = #type
  176. #else
  177. # define SD_INIT_NAME(type)
  178. #endif
  179. #else /* CONFIG_SMP */
  180. struct sched_domain_attr;
  181. static inline void
  182. partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],
  183. struct sched_domain_attr *dattr_new)
  184. {
  185. }
  186. static inline void
  187. partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
  188. struct sched_domain_attr *dattr_new)
  189. {
  190. }
  191. static inline bool cpus_share_cache(int this_cpu, int that_cpu)
  192. {
  193. return true;
  194. }
  195. #endif /* !CONFIG_SMP */
  196. #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
  197. extern void rebuild_sched_domains_energy(void);
  198. #else
  199. static inline void rebuild_sched_domains_energy(void)
  200. {
  201. }
  202. #endif
  203. #ifndef arch_scale_cpu_capacity
  204. /**
  205. * arch_scale_cpu_capacity - get the capacity scale factor of a given CPU.
  206. * @cpu: the CPU in question.
  207. *
  208. * Return: the CPU scale factor normalized against SCHED_CAPACITY_SCALE, i.e.
  209. *
  210. * max_perf(cpu)
  211. * ----------------------------- * SCHED_CAPACITY_SCALE
  212. * max(max_perf(c) : c \in CPUs)
  213. */
  214. static __always_inline
  215. unsigned long arch_scale_cpu_capacity(int cpu)
  216. {
  217. return SCHED_CAPACITY_SCALE;
  218. }
  219. #endif
  220. #ifndef arch_scale_thermal_pressure
  221. static __always_inline
  222. unsigned long arch_scale_thermal_pressure(int cpu)
  223. {
  224. return 0;
  225. }
  226. #endif
  227. #ifndef arch_update_thermal_pressure
  228. static __always_inline
  229. void arch_update_thermal_pressure(const struct cpumask *cpus,
  230. unsigned long capped_frequency)
  231. { }
  232. #endif
  233. static inline int task_node(const struct task_struct *p)
  234. {
  235. return cpu_to_node(task_cpu(p));
  236. }
  237. #endif /* _LINUX_SCHED_TOPOLOGY_H */