topology.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * include/linux/topology.h
  3. *
  4. * Written by: Matthew Dobson, IBM Corporation
  5. *
  6. * Copyright (C) 2002, IBM Corp.
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <colpatch@us.ibm.com>
  26. */
  27. #ifndef _LINUX_TOPOLOGY_H
  28. #define _LINUX_TOPOLOGY_H
  29. #include <linux/cpumask.h>
  30. #include <linux/bitops.h>
  31. #include <linux/mmzone.h>
  32. #include <linux/smp.h>
  33. #include <linux/percpu.h>
  34. #include <asm/topology.h>
  35. #ifndef node_has_online_mem
  36. #define node_has_online_mem(nid) (1)
  37. #endif
  38. #ifndef nr_cpus_node
  39. #define nr_cpus_node(node) cpumask_weight(cpumask_of_node(node))
  40. #endif
  41. #define for_each_node_with_cpus(node) \
  42. for_each_online_node(node) \
  43. if (nr_cpus_node(node))
  44. int arch_update_cpu_topology(void);
  45. /* Conform to ACPI 2.0 SLIT distance definitions */
  46. #define LOCAL_DISTANCE 10
  47. #define REMOTE_DISTANCE 20
  48. #ifndef node_distance
  49. #define node_distance(from,to) ((from) == (to) ? LOCAL_DISTANCE : REMOTE_DISTANCE)
  50. #endif
  51. #ifndef RECLAIM_DISTANCE
  52. /*
  53. * If the distance between nodes in a system is larger than RECLAIM_DISTANCE
  54. * (in whatever arch specific measurement units returned by node_distance())
  55. * then switch on zone reclaim on boot.
  56. */
  57. #define RECLAIM_DISTANCE 30
  58. #endif
  59. #ifndef PENALTY_FOR_NODE_WITH_CPUS
  60. #define PENALTY_FOR_NODE_WITH_CPUS (1)
  61. #endif
  62. /*
  63. * Below are the 3 major initializers used in building sched_domains:
  64. * SD_SIBLING_INIT, for SMT domains
  65. * SD_CPU_INIT, for SMP domains
  66. * SD_NODE_INIT, for NUMA domains
  67. *
  68. * Any architecture that cares to do any tuning to these values should do so
  69. * by defining their own arch-specific initializer in include/asm/topology.h.
  70. * A definition there will automagically override these default initializers
  71. * and allow arch-specific performance tuning of sched_domains.
  72. * (Only non-zero and non-null fields need be specified.)
  73. */
  74. #ifdef CONFIG_SCHED_SMT
  75. /* MCD - Do we really need this? It is always on if CONFIG_SCHED_SMT is,
  76. * so can't we drop this in favor of CONFIG_SCHED_SMT?
  77. */
  78. #define ARCH_HAS_SCHED_WAKE_IDLE
  79. /* Common values for SMT siblings */
  80. #ifndef SD_SIBLING_INIT
  81. #define SD_SIBLING_INIT (struct sched_domain) { \
  82. .min_interval = 1, \
  83. .max_interval = 2, \
  84. .busy_factor = 64, \
  85. .imbalance_pct = 110, \
  86. \
  87. .flags = 1*SD_LOAD_BALANCE \
  88. | 1*SD_BALANCE_NEWIDLE \
  89. | 1*SD_BALANCE_EXEC \
  90. | 1*SD_BALANCE_FORK \
  91. | 0*SD_BALANCE_WAKE \
  92. | 1*SD_WAKE_AFFINE \
  93. | 1*SD_SHARE_CPUPOWER \
  94. | 0*SD_POWERSAVINGS_BALANCE \
  95. | 1*SD_SHARE_PKG_RESOURCES \
  96. | 0*SD_SERIALIZE \
  97. | 0*SD_PREFER_SIBLING \
  98. | arch_sd_sibling_asym_packing() \
  99. , \
  100. .last_balance = jiffies, \
  101. .balance_interval = 1, \
  102. .smt_gain = 1178, /* 15% */ \
  103. }
  104. #endif
  105. #endif /* CONFIG_SCHED_SMT */
  106. #ifdef CONFIG_SCHED_MC
  107. /* Common values for MC siblings. for now mostly derived from SD_CPU_INIT */
  108. #ifndef SD_MC_INIT
  109. #define SD_MC_INIT (struct sched_domain) { \
  110. .min_interval = 1, \
  111. .max_interval = 4, \
  112. .busy_factor = 1, \
  113. .imbalance_pct = 125, \
  114. .cache_nice_tries = 1, \
  115. .busy_idx = 2, \
  116. .wake_idx = 0, \
  117. .forkexec_idx = 0, \
  118. \
  119. .flags = 1*SD_LOAD_BALANCE \
  120. | 1*SD_BALANCE_NEWIDLE \
  121. | 1*SD_BALANCE_EXEC \
  122. | 1*SD_BALANCE_FORK \
  123. | 0*SD_BALANCE_WAKE \
  124. | 1*SD_WAKE_AFFINE \
  125. | 0*SD_PREFER_LOCAL \
  126. | 0*SD_SHARE_CPUPOWER \
  127. | 1*SD_SHARE_PKG_RESOURCES \
  128. | 0*SD_SERIALIZE \
  129. | sd_balance_for_mc_power() \
  130. | sd_power_saving_flags() \
  131. , \
  132. .last_balance = jiffies, \
  133. .balance_interval = 1, \
  134. }
  135. #endif
  136. #endif /* CONFIG_SCHED_MC */
  137. /* Common values for CPUs */
  138. #ifndef SD_CPU_INIT
  139. #define SD_CPU_INIT (struct sched_domain) { \
  140. .min_interval = 1, \
  141. .max_interval = 4, \
  142. .busy_factor = 64, \
  143. .imbalance_pct = 125, \
  144. .cache_nice_tries = 1, \
  145. .busy_idx = 2, \
  146. .idle_idx = 1, \
  147. .newidle_idx = 0, \
  148. .wake_idx = 0, \
  149. .forkexec_idx = 0, \
  150. \
  151. .flags = 1*SD_LOAD_BALANCE \
  152. | 1*SD_BALANCE_NEWIDLE \
  153. | 1*SD_BALANCE_EXEC \
  154. | 1*SD_BALANCE_FORK \
  155. | 0*SD_BALANCE_WAKE \
  156. | 1*SD_WAKE_AFFINE \
  157. | 0*SD_PREFER_LOCAL \
  158. | 0*SD_SHARE_CPUPOWER \
  159. | 1*SD_SHARE_PKG_RESOURCES \
  160. | 0*SD_SERIALIZE \
  161. | sd_balance_for_package_power() \
  162. | sd_power_saving_flags() \
  163. , \
  164. .last_balance = jiffies, \
  165. .balance_interval = 1, \
  166. }
  167. #endif
  168. /* sched_domains SD_ALLNODES_INIT for NUMA machines */
  169. #define SD_ALLNODES_INIT (struct sched_domain) { \
  170. .min_interval = 64, \
  171. .max_interval = 64*num_online_cpus(), \
  172. .busy_factor = 128, \
  173. .imbalance_pct = 133, \
  174. .cache_nice_tries = 1, \
  175. .busy_idx = 3, \
  176. .idle_idx = 3, \
  177. .flags = 1*SD_LOAD_BALANCE \
  178. | 1*SD_BALANCE_NEWIDLE \
  179. | 0*SD_BALANCE_EXEC \
  180. | 0*SD_BALANCE_FORK \
  181. | 0*SD_BALANCE_WAKE \
  182. | 0*SD_WAKE_AFFINE \
  183. | 0*SD_SHARE_CPUPOWER \
  184. | 0*SD_POWERSAVINGS_BALANCE \
  185. | 0*SD_SHARE_PKG_RESOURCES \
  186. | 1*SD_SERIALIZE \
  187. | 0*SD_PREFER_SIBLING \
  188. , \
  189. .last_balance = jiffies, \
  190. .balance_interval = 64, \
  191. }
  192. #ifndef SD_NODES_PER_DOMAIN
  193. #define SD_NODES_PER_DOMAIN 16
  194. #endif
  195. #ifdef CONFIG_SCHED_BOOK
  196. #ifndef SD_BOOK_INIT
  197. #error Please define an appropriate SD_BOOK_INIT in include/asm/topology.h!!!
  198. #endif
  199. #endif /* CONFIG_SCHED_BOOK */
  200. #ifdef CONFIG_NUMA
  201. #ifndef SD_NODE_INIT
  202. #error Please define an appropriate SD_NODE_INIT in include/asm/topology.h!!!
  203. #endif
  204. #endif /* CONFIG_NUMA */
  205. #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  206. DECLARE_PER_CPU(int, numa_node);
  207. #ifndef numa_node_id
  208. /* Returns the number of the current Node. */
  209. static inline int numa_node_id(void)
  210. {
  211. return raw_cpu_read(numa_node);
  212. }
  213. #endif
  214. #ifndef cpu_to_node
  215. static inline int cpu_to_node(int cpu)
  216. {
  217. return per_cpu(numa_node, cpu);
  218. }
  219. #endif
  220. #ifndef set_numa_node
  221. static inline void set_numa_node(int node)
  222. {
  223. percpu_write(numa_node, node);
  224. }
  225. #endif
  226. #ifndef set_cpu_numa_node
  227. static inline void set_cpu_numa_node(int cpu, int node)
  228. {
  229. per_cpu(numa_node, cpu) = node;
  230. }
  231. #endif
  232. #else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  233. /* Returns the number of the current Node. */
  234. #ifndef numa_node_id
  235. static inline int numa_node_id(void)
  236. {
  237. return cpu_to_node(raw_smp_processor_id());
  238. }
  239. #endif
  240. #endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  241. #ifdef CONFIG_HAVE_MEMORYLESS_NODES
  242. /*
  243. * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
  244. * It will not be defined when CONFIG_HAVE_MEMORYLESS_NODES is not defined.
  245. * Use the accessor functions set_numa_mem(), numa_mem_id() and cpu_to_mem().
  246. */
  247. DECLARE_PER_CPU(int, _numa_mem_);
  248. #ifndef set_numa_mem
  249. static inline void set_numa_mem(int node)
  250. {
  251. percpu_write(_numa_mem_, node);
  252. }
  253. #endif
  254. #ifndef numa_mem_id
  255. /* Returns the number of the nearest Node with memory */
  256. static inline int numa_mem_id(void)
  257. {
  258. return raw_cpu_read(_numa_mem_);
  259. }
  260. #endif
  261. #ifndef cpu_to_mem
  262. static inline int cpu_to_mem(int cpu)
  263. {
  264. return per_cpu(_numa_mem_, cpu);
  265. }
  266. #endif
  267. #ifndef set_cpu_numa_mem
  268. static inline void set_cpu_numa_mem(int cpu, int node)
  269. {
  270. per_cpu(_numa_mem_, cpu) = node;
  271. }
  272. #endif
  273. #else /* !CONFIG_HAVE_MEMORYLESS_NODES */
  274. #ifndef numa_mem_id
  275. /* Returns the number of the nearest Node with memory */
  276. static inline int numa_mem_id(void)
  277. {
  278. return numa_node_id();
  279. }
  280. #endif
  281. #ifndef cpu_to_mem
  282. static inline int cpu_to_mem(int cpu)
  283. {
  284. return cpu_to_node(cpu);
  285. }
  286. #endif
  287. #endif /* [!]CONFIG_HAVE_MEMORYLESS_NODES */
  288. #ifndef topology_physical_package_id
  289. #define topology_physical_package_id(cpu) ((void)(cpu), -1)
  290. #endif
  291. #ifndef topology_core_id
  292. #define topology_core_id(cpu) ((void)(cpu), 0)
  293. #endif
  294. #ifndef topology_thread_cpumask
  295. #define topology_thread_cpumask(cpu) cpumask_of(cpu)
  296. #endif
  297. #ifndef topology_core_cpumask
  298. #define topology_core_cpumask(cpu) cpumask_of(cpu)
  299. #endif
  300. #endif /* _LINUX_TOPOLOGY_H */