node.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/node.h - generic node definition
  4. *
  5. * This is mainly for topological representation. We define the
  6. * basic 'struct node' here, which can be embedded in per-arch
  7. * definitions of processors.
  8. *
  9. * Basic handling of the devices is done in drivers/base/node.c
  10. * and system devices are handled in drivers/base/sys.c.
  11. *
  12. * Nodes are exported via driverfs in the class/node/devices/
  13. * directory.
  14. */
  15. #ifndef _LINUX_NODE_H_
  16. #define _LINUX_NODE_H_
  17. #include <linux/device.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/list.h>
  20. #include <linux/workqueue.h>
  21. /**
  22. * struct node_hmem_attrs - heterogeneous memory performance attributes
  23. *
  24. * @read_bandwidth: Read bandwidth in MB/s
  25. * @write_bandwidth: Write bandwidth in MB/s
  26. * @read_latency: Read latency in nanoseconds
  27. * @write_latency: Write latency in nanoseconds
  28. */
  29. struct node_hmem_attrs {
  30. unsigned int read_bandwidth;
  31. unsigned int write_bandwidth;
  32. unsigned int read_latency;
  33. unsigned int write_latency;
  34. };
  35. enum cache_indexing {
  36. NODE_CACHE_DIRECT_MAP,
  37. NODE_CACHE_INDEXED,
  38. NODE_CACHE_OTHER,
  39. };
  40. enum cache_write_policy {
  41. NODE_CACHE_WRITE_BACK,
  42. NODE_CACHE_WRITE_THROUGH,
  43. NODE_CACHE_WRITE_OTHER,
  44. };
  45. /**
  46. * struct node_cache_attrs - system memory caching attributes
  47. *
  48. * @indexing: The ways memory blocks may be placed in cache
  49. * @write_policy: Write back or write through policy
  50. * @size: Total size of cache in bytes
  51. * @line_size: Number of bytes fetched on a cache miss
  52. * @level: The cache hierarchy level
  53. */
  54. struct node_cache_attrs {
  55. enum cache_indexing indexing;
  56. enum cache_write_policy write_policy;
  57. u64 size;
  58. u16 line_size;
  59. u8 level;
  60. };
  61. #ifdef CONFIG_HMEM_REPORTING
  62. void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
  63. void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
  64. unsigned access);
  65. #else
  66. static inline void node_add_cache(unsigned int nid,
  67. struct node_cache_attrs *cache_attrs)
  68. {
  69. }
  70. static inline void node_set_perf_attrs(unsigned int nid,
  71. struct node_hmem_attrs *hmem_attrs,
  72. unsigned access)
  73. {
  74. }
  75. #endif
  76. struct node {
  77. struct device dev;
  78. struct list_head access_list;
  79. #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
  80. struct work_struct node_work;
  81. #endif
  82. #ifdef CONFIG_HMEM_REPORTING
  83. struct list_head cache_attrs;
  84. struct device *cache_dev;
  85. #endif
  86. };
  87. struct memory_block;
  88. extern struct node *node_devices[];
  89. typedef void (*node_registration_func_t)(struct node *);
  90. #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
  91. void link_mem_sections(int nid, unsigned long start_pfn,
  92. unsigned long end_pfn,
  93. enum meminit_context context);
  94. #else
  95. static inline void link_mem_sections(int nid, unsigned long start_pfn,
  96. unsigned long end_pfn,
  97. enum meminit_context context)
  98. {
  99. }
  100. #endif
  101. extern void unregister_node(struct node *node);
  102. #ifdef CONFIG_NUMA
  103. /* Core of the node registration - only memory hotplug should use this */
  104. extern int __register_one_node(int nid);
  105. /* Registers an online node */
  106. static inline int register_one_node(int nid)
  107. {
  108. int error = 0;
  109. if (node_online(nid)) {
  110. struct pglist_data *pgdat = NODE_DATA(nid);
  111. unsigned long start_pfn = pgdat->node_start_pfn;
  112. unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
  113. error = __register_one_node(nid);
  114. if (error)
  115. return error;
  116. /* link memory sections under this node */
  117. link_mem_sections(nid, start_pfn, end_pfn, MEMINIT_EARLY);
  118. }
  119. return error;
  120. }
  121. extern void unregister_one_node(int nid);
  122. extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
  123. extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
  124. extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
  125. extern int register_memory_node_under_compute_node(unsigned int mem_nid,
  126. unsigned int cpu_nid,
  127. unsigned access);
  128. #ifdef CONFIG_HUGETLBFS
  129. extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
  130. node_registration_func_t unregister);
  131. #endif
  132. #else
  133. static inline int __register_one_node(int nid)
  134. {
  135. return 0;
  136. }
  137. static inline int register_one_node(int nid)
  138. {
  139. return 0;
  140. }
  141. static inline int unregister_one_node(int nid)
  142. {
  143. return 0;
  144. }
  145. static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
  146. {
  147. return 0;
  148. }
  149. static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
  150. {
  151. return 0;
  152. }
  153. static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
  154. {
  155. }
  156. static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
  157. node_registration_func_t unreg)
  158. {
  159. }
  160. #endif
  161. #define to_node(device) container_of(device, struct node, dev)
  162. #endif /* _LINUX_NODE_H_ */