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