topology.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. | 0*SD_POWERSAVINGS_BALANCE \
  94. | 1*SD_SHARE_PKG_RESOURCES \
  95. | 0*SD_SERIALIZE \
  96. | 0*SD_PREFER_SIBLING \
  97. | arch_sd_sibling_asym_packing() \
  98. , \
  99. .last_balance = jiffies, \
  100. .balance_interval = 1, \
  101. .smt_gain = 1178, /* 15% */ \
  102. }
  103. #endif
  104. #endif /* CONFIG_SCHED_SMT */
  105. #ifdef CONFIG_SCHED_MC
  106. /* Common values for MC siblings. for now mostly derived from SD_CPU_INIT */
  107. #ifndef SD_MC_INIT
  108. #define SD_MC_INIT (struct sched_domain) { \
  109. .min_interval = 1, \
  110. .max_interval = 4, \
  111. .busy_factor = 64, \
  112. .imbalance_pct = 125, \
  113. .cache_nice_tries = 1, \
  114. .busy_idx = 2, \
  115. .wake_idx = 0, \
  116. .forkexec_idx = 0, \
  117. \
  118. .flags = 1*SD_LOAD_BALANCE \
  119. | 1*SD_BALANCE_NEWIDLE \
  120. | 1*SD_BALANCE_EXEC \
  121. | 1*SD_BALANCE_FORK \
  122. | 0*SD_BALANCE_WAKE \
  123. | 1*SD_WAKE_AFFINE \
  124. | 0*SD_PREFER_LOCAL \
  125. | 0*SD_SHARE_CPUPOWER \
  126. | 1*SD_SHARE_PKG_RESOURCES \
  127. | 0*SD_SERIALIZE \
  128. | sd_balance_for_mc_power() \
  129. | sd_power_saving_flags() \
  130. , \
  131. .last_balance = jiffies, \
  132. .balance_interval = 1, \
  133. }
  134. #endif
  135. #endif /* CONFIG_SCHED_MC */
  136. /* Common values for CPUs */
  137. #ifndef SD_CPU_INIT
  138. #define SD_CPU_INIT (struct sched_domain) { \
  139. .min_interval = 1, \
  140. .max_interval = 4, \
  141. .busy_factor = 64, \
  142. .imbalance_pct = 125, \
  143. .cache_nice_tries = 1, \
  144. .busy_idx = 2, \
  145. .idle_idx = 1, \
  146. .newidle_idx = 0, \
  147. .wake_idx = 0, \
  148. .forkexec_idx = 0, \
  149. \
  150. .flags = 1*SD_LOAD_BALANCE \
  151. | 1*SD_BALANCE_NEWIDLE \
  152. | 1*SD_BALANCE_EXEC \
  153. | 1*SD_BALANCE_FORK \
  154. | 0*SD_BALANCE_WAKE \
  155. | 1*SD_WAKE_AFFINE \
  156. | 0*SD_PREFER_LOCAL \
  157. | 0*SD_SHARE_CPUPOWER \
  158. | 0*SD_SHARE_PKG_RESOURCES \
  159. | 0*SD_SERIALIZE \
  160. | sd_balance_for_package_power() \
  161. | sd_power_saving_flags() \
  162. , \
  163. .last_balance = jiffies, \
  164. .balance_interval = 1, \
  165. }
  166. #endif
  167. #ifdef CONFIG_SCHED_BOOK
  168. #ifndef SD_BOOK_INIT
  169. #error Please define an appropriate SD_BOOK_INIT in include/asm/topology.h!!!
  170. #endif
  171. #endif /* CONFIG_SCHED_BOOK */
  172. #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  173. DECLARE_PER_CPU(int, numa_node);
  174. #ifndef numa_node_id
  175. /* Returns the number of the current Node. */
  176. static inline int numa_node_id(void)
  177. {
  178. return __this_cpu_read(numa_node);
  179. }
  180. #endif
  181. #ifndef cpu_to_node
  182. static inline int cpu_to_node(int cpu)
  183. {
  184. return per_cpu(numa_node, cpu);
  185. }
  186. #endif
  187. #ifndef set_numa_node
  188. static inline void set_numa_node(int node)
  189. {
  190. percpu_write(numa_node, node);
  191. }
  192. #endif
  193. #ifndef set_cpu_numa_node
  194. static inline void set_cpu_numa_node(int cpu, int node)
  195. {
  196. per_cpu(numa_node, cpu) = node;
  197. }
  198. #endif
  199. #else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  200. /* Returns the number of the current Node. */
  201. #ifndef numa_node_id
  202. static inline int numa_node_id(void)
  203. {
  204. return cpu_to_node(raw_smp_processor_id());
  205. }
  206. #endif
  207. #endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  208. #ifdef CONFIG_HAVE_MEMORYLESS_NODES
  209. /*
  210. * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
  211. * It will not be defined when CONFIG_HAVE_MEMORYLESS_NODES is not defined.
  212. * Use the accessor functions set_numa_mem(), numa_mem_id() and cpu_to_mem().
  213. */
  214. DECLARE_PER_CPU(int, _numa_mem_);
  215. #ifndef set_numa_mem
  216. static inline void set_numa_mem(int node)
  217. {
  218. percpu_write(_numa_mem_, node);
  219. }
  220. #endif
  221. #ifndef numa_mem_id
  222. /* Returns the number of the nearest Node with memory */
  223. static inline int numa_mem_id(void)
  224. {
  225. return __this_cpu_read(_numa_mem_);
  226. }
  227. #endif
  228. #ifndef cpu_to_mem
  229. static inline int cpu_to_mem(int cpu)
  230. {
  231. return per_cpu(_numa_mem_, cpu);
  232. }
  233. #endif
  234. #ifndef set_cpu_numa_mem
  235. static inline void set_cpu_numa_mem(int cpu, int node)
  236. {
  237. per_cpu(_numa_mem_, cpu) = node;
  238. }
  239. #endif
  240. #else /* !CONFIG_HAVE_MEMORYLESS_NODES */
  241. #ifndef numa_mem_id
  242. /* Returns the number of the nearest Node with memory */
  243. static inline int numa_mem_id(void)
  244. {
  245. return numa_node_id();
  246. }
  247. #endif
  248. #ifndef cpu_to_mem
  249. static inline int cpu_to_mem(int cpu)
  250. {
  251. return cpu_to_node(cpu);
  252. }
  253. #endif
  254. #endif /* [!]CONFIG_HAVE_MEMORYLESS_NODES */
  255. #ifndef topology_physical_package_id
  256. #define topology_physical_package_id(cpu) ((void)(cpu), -1)
  257. #endif
  258. #ifndef topology_core_id
  259. #define topology_core_id(cpu) ((void)(cpu), 0)
  260. #endif
  261. #ifndef topology_thread_cpumask
  262. #define topology_thread_cpumask(cpu) cpumask_of(cpu)
  263. #endif
  264. #ifndef topology_core_cpumask
  265. #define topology_core_cpumask(cpu) cpumask_of(cpu)
  266. #endif
  267. #endif /* _LINUX_TOPOLOGY_H */