topology.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. *
  67. * Any architecture that cares to do any tuning to these values should do so
  68. * by defining their own arch-specific initializer in include/asm/topology.h.
  69. * A definition there will automagically override these default initializers
  70. * and allow arch-specific performance tuning of sched_domains.
  71. * (Only non-zero and non-null fields need be specified.)
  72. */
  73. #ifdef CONFIG_SCHED_SMT
  74. /* MCD - Do we really need this? It is always on if CONFIG_SCHED_SMT is,
  75. * so can't we drop this in favor of CONFIG_SCHED_SMT?
  76. */
  77. #define ARCH_HAS_SCHED_WAKE_IDLE
  78. /* Common values for SMT siblings */
  79. #ifndef SD_SIBLING_INIT
  80. #define SD_SIBLING_INIT (struct sched_domain) { \
  81. .min_interval = 1, \
  82. .max_interval = 2, \
  83. .busy_factor = 64, \
  84. .imbalance_pct = 110, \
  85. \
  86. .flags = 1*SD_LOAD_BALANCE \
  87. | 1*SD_BALANCE_NEWIDLE \
  88. | 1*SD_BALANCE_EXEC \
  89. | 1*SD_BALANCE_FORK \
  90. | 0*SD_BALANCE_WAKE \
  91. | 1*SD_WAKE_AFFINE \
  92. | 1*SD_SHARE_CPUPOWER \
  93. | 1*SD_SHARE_PKG_RESOURCES \
  94. | 0*SD_SERIALIZE \
  95. | 0*SD_PREFER_SIBLING \
  96. | arch_sd_sibling_asym_packing() \
  97. , \
  98. .last_balance = jiffies, \
  99. .balance_interval = 1, \
  100. .smt_gain = 1178, /* 15% */ \
  101. }
  102. #endif
  103. #endif /* CONFIG_SCHED_SMT */
  104. #ifdef CONFIG_SCHED_MC
  105. /* Common values for MC siblings. for now mostly derived from SD_CPU_INIT */
  106. #ifndef SD_MC_INIT
  107. #define SD_MC_INIT (struct sched_domain) { \
  108. .min_interval = 1, \
  109. .max_interval = 4, \
  110. .busy_factor = 64, \
  111. .imbalance_pct = 125, \
  112. .cache_nice_tries = 1, \
  113. .busy_idx = 2, \
  114. .wake_idx = 0, \
  115. .forkexec_idx = 0, \
  116. \
  117. .flags = 1*SD_LOAD_BALANCE \
  118. | 1*SD_BALANCE_NEWIDLE \
  119. | 1*SD_BALANCE_EXEC \
  120. | 1*SD_BALANCE_FORK \
  121. | 0*SD_BALANCE_WAKE \
  122. | 1*SD_WAKE_AFFINE \
  123. | 0*SD_PREFER_LOCAL \
  124. | 0*SD_SHARE_CPUPOWER \
  125. | 1*SD_SHARE_PKG_RESOURCES \
  126. | 0*SD_SERIALIZE \
  127. , \
  128. .last_balance = jiffies, \
  129. .balance_interval = 1, \
  130. }
  131. #endif
  132. #endif /* CONFIG_SCHED_MC */
  133. /* Common values for CPUs */
  134. #ifndef SD_CPU_INIT
  135. #define SD_CPU_INIT (struct sched_domain) { \
  136. .min_interval = 1, \
  137. .max_interval = 4, \
  138. .busy_factor = 64, \
  139. .imbalance_pct = 125, \
  140. .cache_nice_tries = 1, \
  141. .busy_idx = 2, \
  142. .idle_idx = 1, \
  143. .newidle_idx = 0, \
  144. .wake_idx = 0, \
  145. .forkexec_idx = 0, \
  146. \
  147. .flags = 1*SD_LOAD_BALANCE \
  148. | 1*SD_BALANCE_NEWIDLE \
  149. | 1*SD_BALANCE_EXEC \
  150. | 1*SD_BALANCE_FORK \
  151. | 0*SD_BALANCE_WAKE \
  152. | 1*SD_WAKE_AFFINE \
  153. | 0*SD_PREFER_LOCAL \
  154. | 0*SD_SHARE_CPUPOWER \
  155. | 0*SD_SHARE_PKG_RESOURCES \
  156. | 0*SD_SERIALIZE \
  157. , \
  158. .last_balance = jiffies, \
  159. .balance_interval = 1, \
  160. }
  161. #endif
  162. #ifdef CONFIG_SCHED_BOOK
  163. #ifndef SD_BOOK_INIT
  164. #error Please define an appropriate SD_BOOK_INIT in include/asm/topology.h!!!
  165. #endif
  166. #endif /* CONFIG_SCHED_BOOK */
  167. #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  168. DECLARE_PER_CPU(int, numa_node);
  169. #ifndef numa_node_id
  170. /* Returns the number of the current Node. */
  171. static inline int numa_node_id(void)
  172. {
  173. return __this_cpu_read(numa_node);
  174. }
  175. #endif
  176. #ifndef cpu_to_node
  177. static inline int cpu_to_node(int cpu)
  178. {
  179. return per_cpu(numa_node, cpu);
  180. }
  181. #endif
  182. #ifndef set_numa_node
  183. static inline void set_numa_node(int node)
  184. {
  185. this_cpu_write(numa_node, node);
  186. }
  187. #endif
  188. #ifndef set_cpu_numa_node
  189. static inline void set_cpu_numa_node(int cpu, int node)
  190. {
  191. per_cpu(numa_node, cpu) = node;
  192. }
  193. #endif
  194. #else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  195. /* Returns the number of the current Node. */
  196. #ifndef numa_node_id
  197. static inline int numa_node_id(void)
  198. {
  199. return cpu_to_node(raw_smp_processor_id());
  200. }
  201. #endif
  202. #endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  203. #ifdef CONFIG_HAVE_MEMORYLESS_NODES
  204. /*
  205. * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
  206. * It will not be defined when CONFIG_HAVE_MEMORYLESS_NODES is not defined.
  207. * Use the accessor functions set_numa_mem(), numa_mem_id() and cpu_to_mem().
  208. */
  209. DECLARE_PER_CPU(int, _numa_mem_);
  210. #ifndef set_numa_mem
  211. static inline void set_numa_mem(int node)
  212. {
  213. this_cpu_write(_numa_mem_, node);
  214. }
  215. #endif
  216. #ifndef numa_mem_id
  217. /* Returns the number of the nearest Node with memory */
  218. static inline int numa_mem_id(void)
  219. {
  220. return __this_cpu_read(_numa_mem_);
  221. }
  222. #endif
  223. #ifndef cpu_to_mem
  224. static inline int cpu_to_mem(int cpu)
  225. {
  226. return per_cpu(_numa_mem_, cpu);
  227. }
  228. #endif
  229. #ifndef set_cpu_numa_mem
  230. static inline void set_cpu_numa_mem(int cpu, int node)
  231. {
  232. per_cpu(_numa_mem_, cpu) = node;
  233. }
  234. #endif
  235. #else /* !CONFIG_HAVE_MEMORYLESS_NODES */
  236. #ifndef numa_mem_id
  237. /* Returns the number of the nearest Node with memory */
  238. static inline int numa_mem_id(void)
  239. {
  240. return numa_node_id();
  241. }
  242. #endif
  243. #ifndef cpu_to_mem
  244. static inline int cpu_to_mem(int cpu)
  245. {
  246. return cpu_to_node(cpu);
  247. }
  248. #endif
  249. #endif /* [!]CONFIG_HAVE_MEMORYLESS_NODES */
  250. #ifndef topology_physical_package_id
  251. #define topology_physical_package_id(cpu) ((void)(cpu), -1)
  252. #endif
  253. #ifndef topology_core_id
  254. #define topology_core_id(cpu) ((void)(cpu), 0)
  255. #endif
  256. #ifndef topology_thread_cpumask
  257. #define topology_thread_cpumask(cpu) cpumask_of(cpu)
  258. #endif
  259. #ifndef topology_core_cpumask
  260. #define topology_core_cpumask(cpu) cpumask_of(cpu)
  261. #endif
  262. #endif /* _LINUX_TOPOLOGY_H */