topology.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. * and zone_reclaim_mode is enabled then the VM will only call zone_reclaim()
  56. * on nodes within this distance.
  57. */
  58. #define RECLAIM_DISTANCE 30
  59. #endif
  60. #ifndef PENALTY_FOR_NODE_WITH_CPUS
  61. #define PENALTY_FOR_NODE_WITH_CPUS (1)
  62. #endif
  63. #ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  64. DECLARE_PER_CPU(int, numa_node);
  65. #ifndef numa_node_id
  66. /* Returns the number of the current Node. */
  67. static inline int numa_node_id(void)
  68. {
  69. return raw_cpu_read(numa_node);
  70. }
  71. #endif
  72. #ifndef cpu_to_node
  73. static inline int cpu_to_node(int cpu)
  74. {
  75. return per_cpu(numa_node, cpu);
  76. }
  77. #endif
  78. #ifndef set_numa_node
  79. static inline void set_numa_node(int node)
  80. {
  81. this_cpu_write(numa_node, node);
  82. }
  83. #endif
  84. #ifndef set_cpu_numa_node
  85. static inline void set_cpu_numa_node(int cpu, int node)
  86. {
  87. per_cpu(numa_node, cpu) = node;
  88. }
  89. #endif
  90. #else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  91. /* Returns the number of the current Node. */
  92. #ifndef numa_node_id
  93. static inline int numa_node_id(void)
  94. {
  95. return cpu_to_node(raw_smp_processor_id());
  96. }
  97. #endif
  98. #endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  99. #ifdef CONFIG_HAVE_MEMORYLESS_NODES
  100. /*
  101. * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
  102. * It will not be defined when CONFIG_HAVE_MEMORYLESS_NODES is not defined.
  103. * Use the accessor functions set_numa_mem(), numa_mem_id() and cpu_to_mem().
  104. */
  105. DECLARE_PER_CPU(int, _numa_mem_);
  106. extern int _node_numa_mem_[MAX_NUMNODES];
  107. #ifndef set_numa_mem
  108. static inline void set_numa_mem(int node)
  109. {
  110. this_cpu_write(_numa_mem_, node);
  111. _node_numa_mem_[numa_node_id()] = node;
  112. }
  113. #endif
  114. #ifndef node_to_mem_node
  115. static inline int node_to_mem_node(int node)
  116. {
  117. return _node_numa_mem_[node];
  118. }
  119. #endif
  120. #ifndef numa_mem_id
  121. /* Returns the number of the nearest Node with memory */
  122. static inline int numa_mem_id(void)
  123. {
  124. return raw_cpu_read(_numa_mem_);
  125. }
  126. #endif
  127. #ifndef cpu_to_mem
  128. static inline int cpu_to_mem(int cpu)
  129. {
  130. return per_cpu(_numa_mem_, cpu);
  131. }
  132. #endif
  133. #ifndef set_cpu_numa_mem
  134. static inline void set_cpu_numa_mem(int cpu, int node)
  135. {
  136. per_cpu(_numa_mem_, cpu) = node;
  137. _node_numa_mem_[cpu_to_node(cpu)] = node;
  138. }
  139. #endif
  140. #else /* !CONFIG_HAVE_MEMORYLESS_NODES */
  141. #ifndef numa_mem_id
  142. /* Returns the number of the nearest Node with memory */
  143. static inline int numa_mem_id(void)
  144. {
  145. return numa_node_id();
  146. }
  147. #endif
  148. #ifndef node_to_mem_node
  149. static inline int node_to_mem_node(int node)
  150. {
  151. return node;
  152. }
  153. #endif
  154. #ifndef cpu_to_mem
  155. static inline int cpu_to_mem(int cpu)
  156. {
  157. return cpu_to_node(cpu);
  158. }
  159. #endif
  160. #endif /* [!]CONFIG_HAVE_MEMORYLESS_NODES */
  161. #ifndef topology_physical_package_id
  162. #define topology_physical_package_id(cpu) ((void)(cpu), -1)
  163. #endif
  164. #ifndef topology_core_id
  165. #define topology_core_id(cpu) ((void)(cpu), 0)
  166. #endif
  167. #ifndef topology_thread_cpumask
  168. #define topology_thread_cpumask(cpu) cpumask_of(cpu)
  169. #endif
  170. #ifndef topology_core_cpumask
  171. #define topology_core_cpumask(cpu) cpumask_of(cpu)
  172. #endif
  173. #ifdef CONFIG_SCHED_SMT
  174. static inline const struct cpumask *cpu_smt_mask(int cpu)
  175. {
  176. return topology_thread_cpumask(cpu);
  177. }
  178. #endif
  179. static inline const struct cpumask *cpu_cpu_mask(int cpu)
  180. {
  181. return cpumask_of_node(cpu_to_node(cpu));
  182. }
  183. #endif /* _LINUX_TOPOLOGY_H */