topology.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 nr_cpus_node
  36. #define nr_cpus_node(node) cpumask_weight(cpumask_of_node(node))
  37. #endif
  38. #define for_each_node_with_cpus(node) \
  39. for_each_online_node(node) \
  40. if (nr_cpus_node(node))
  41. int arch_update_cpu_topology(void);
  42. /* Conform to ACPI 2.0 SLIT distance definitions */
  43. #define LOCAL_DISTANCE 10
  44. #define REMOTE_DISTANCE 20
  45. #ifndef node_distance
  46. #define node_distance(from,to) ((from) == (to) ? LOCAL_DISTANCE : REMOTE_DISTANCE)
  47. #endif
  48. #ifndef RECLAIM_DISTANCE
  49. /*
  50. * If the distance between nodes in a system is larger than RECLAIM_DISTANCE
  51. * (in whatever arch specific measurement units returned by node_distance())
  52. * and node_reclaim_mode is enabled then the VM will only call node_reclaim()
  53. * on nodes within this distance.
  54. */
  55. #define RECLAIM_DISTANCE 30
  56. #endif
  57. #ifndef PENALTY_FOR_NODE_WITH_CPUS
  58. #define PENALTY_FOR_NODE_WITH_CPUS (1)
  59. #endif
  60. #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  61. DECLARE_PER_CPU(int, numa_node);
  62. #ifndef numa_node_id
  63. /* Returns the number of the current Node. */
  64. static inline int numa_node_id(void)
  65. {
  66. return raw_cpu_read(numa_node);
  67. }
  68. #endif
  69. #ifndef cpu_to_node
  70. static inline int cpu_to_node(int cpu)
  71. {
  72. return per_cpu(numa_node, cpu);
  73. }
  74. #endif
  75. #ifndef set_numa_node
  76. static inline void set_numa_node(int node)
  77. {
  78. this_cpu_write(numa_node, node);
  79. }
  80. #endif
  81. #ifndef set_cpu_numa_node
  82. static inline void set_cpu_numa_node(int cpu, int node)
  83. {
  84. per_cpu(numa_node, cpu) = node;
  85. }
  86. #endif
  87. #else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  88. /* Returns the number of the current Node. */
  89. #ifndef numa_node_id
  90. static inline int numa_node_id(void)
  91. {
  92. return cpu_to_node(raw_smp_processor_id());
  93. }
  94. #endif
  95. #endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  96. #ifdef CONFIG_HAVE_MEMORYLESS_NODES
  97. /*
  98. * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
  99. * It will not be defined when CONFIG_HAVE_MEMORYLESS_NODES is not defined.
  100. * Use the accessor functions set_numa_mem(), numa_mem_id() and cpu_to_mem().
  101. */
  102. DECLARE_PER_CPU(int, _numa_mem_);
  103. extern int _node_numa_mem_[MAX_NUMNODES];
  104. #ifndef set_numa_mem
  105. static inline void set_numa_mem(int node)
  106. {
  107. this_cpu_write(_numa_mem_, node);
  108. _node_numa_mem_[numa_node_id()] = node;
  109. }
  110. #endif
  111. #ifndef node_to_mem_node
  112. static inline int node_to_mem_node(int node)
  113. {
  114. return _node_numa_mem_[node];
  115. }
  116. #endif
  117. #ifndef numa_mem_id
  118. /* Returns the number of the nearest Node with memory */
  119. static inline int numa_mem_id(void)
  120. {
  121. return raw_cpu_read(_numa_mem_);
  122. }
  123. #endif
  124. #ifndef cpu_to_mem
  125. static inline int cpu_to_mem(int cpu)
  126. {
  127. return per_cpu(_numa_mem_, cpu);
  128. }
  129. #endif
  130. #ifndef set_cpu_numa_mem
  131. static inline void set_cpu_numa_mem(int cpu, int node)
  132. {
  133. per_cpu(_numa_mem_, cpu) = node;
  134. _node_numa_mem_[cpu_to_node(cpu)] = node;
  135. }
  136. #endif
  137. #else /* !CONFIG_HAVE_MEMORYLESS_NODES */
  138. #ifndef numa_mem_id
  139. /* Returns the number of the nearest Node with memory */
  140. static inline int numa_mem_id(void)
  141. {
  142. return numa_node_id();
  143. }
  144. #endif
  145. #ifndef node_to_mem_node
  146. static inline int node_to_mem_node(int node)
  147. {
  148. return node;
  149. }
  150. #endif
  151. #ifndef cpu_to_mem
  152. static inline int cpu_to_mem(int cpu)
  153. {
  154. return cpu_to_node(cpu);
  155. }
  156. #endif
  157. #endif /* [!]CONFIG_HAVE_MEMORYLESS_NODES */
  158. #ifndef topology_physical_package_id
  159. #define topology_physical_package_id(cpu) ((void)(cpu), -1)
  160. #endif
  161. #ifndef topology_core_id
  162. #define topology_core_id(cpu) ((void)(cpu), 0)
  163. #endif
  164. #ifndef topology_sibling_cpumask
  165. #define topology_sibling_cpumask(cpu) cpumask_of(cpu)
  166. #endif
  167. #ifndef topology_core_cpumask
  168. #define topology_core_cpumask(cpu) cpumask_of(cpu)
  169. #endif
  170. #ifdef CONFIG_SCHED_SMT
  171. static inline const struct cpumask *cpu_smt_mask(int cpu)
  172. {
  173. return topology_sibling_cpumask(cpu);
  174. }
  175. #endif
  176. static inline const struct cpumask *cpu_cpu_mask(int cpu)
  177. {
  178. return cpumask_of_node(cpu_to_node(cpu));
  179. }
  180. #endif /* _LINUX_TOPOLOGY_H */