node.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /**
  21. * struct node_hmem_attrs - heterogeneous memory performance attributes
  22. *
  23. * @read_bandwidth: Read bandwidth in MB/s
  24. * @write_bandwidth: Write bandwidth in MB/s
  25. * @read_latency: Read latency in nanoseconds
  26. * @write_latency: Write latency in nanoseconds
  27. */
  28. struct node_hmem_attrs {
  29. unsigned int read_bandwidth;
  30. unsigned int write_bandwidth;
  31. unsigned int read_latency;
  32. unsigned int write_latency;
  33. };
  34. enum cache_indexing {
  35. NODE_CACHE_DIRECT_MAP,
  36. NODE_CACHE_INDEXED,
  37. NODE_CACHE_OTHER,
  38. };
  39. enum cache_write_policy {
  40. NODE_CACHE_WRITE_BACK,
  41. NODE_CACHE_WRITE_THROUGH,
  42. NODE_CACHE_WRITE_OTHER,
  43. };
  44. /**
  45. * struct node_cache_attrs - system memory caching attributes
  46. *
  47. * @indexing: The ways memory blocks may be placed in cache
  48. * @write_policy: Write back or write through policy
  49. * @size: Total size of cache in bytes
  50. * @line_size: Number of bytes fetched on a cache miss
  51. * @level: The cache hierarchy level
  52. */
  53. struct node_cache_attrs {
  54. enum cache_indexing indexing;
  55. enum cache_write_policy write_policy;
  56. u64 size;
  57. u16 line_size;
  58. u8 level;
  59. };
  60. #ifdef CONFIG_HMEM_REPORTING
  61. void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
  62. void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
  63. unsigned access);
  64. #else
  65. static inline void node_add_cache(unsigned int nid,
  66. struct node_cache_attrs *cache_attrs)
  67. {
  68. }
  69. static inline void node_set_perf_attrs(unsigned int nid,
  70. struct node_hmem_attrs *hmem_attrs,
  71. unsigned access)
  72. {
  73. }
  74. #endif
  75. struct node {
  76. struct device dev;
  77. struct list_head access_list;
  78. #ifdef CONFIG_HMEM_REPORTING
  79. struct list_head cache_attrs;
  80. struct device *cache_dev;
  81. #endif
  82. };
  83. struct memory_block;
  84. extern struct node *node_devices[];
  85. #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA)
  86. void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
  87. unsigned long end_pfn,
  88. enum meminit_context context);
  89. #else
  90. static inline void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
  91. unsigned long end_pfn,
  92. enum meminit_context context)
  93. {
  94. }
  95. #endif
  96. extern void unregister_node(struct node *node);
  97. #ifdef CONFIG_NUMA
  98. extern void node_dev_init(void);
  99. /* Core of the node registration - only memory hotplug should use this */
  100. extern int __register_one_node(int nid);
  101. /* Registers an online node */
  102. static inline int register_one_node(int nid)
  103. {
  104. int error = 0;
  105. if (node_online(nid)) {
  106. struct pglist_data *pgdat = NODE_DATA(nid);
  107. unsigned long start_pfn = pgdat->node_start_pfn;
  108. unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
  109. error = __register_one_node(nid);
  110. if (error)
  111. return error;
  112. register_memory_blocks_under_node(nid, start_pfn, end_pfn,
  113. MEMINIT_EARLY);
  114. }
  115. return error;
  116. }
  117. extern void unregister_one_node(int nid);
  118. extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
  119. extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
  120. extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
  121. extern int register_memory_node_under_compute_node(unsigned int mem_nid,
  122. unsigned int cpu_nid,
  123. unsigned access);
  124. #else
  125. static inline void node_dev_init(void)
  126. {
  127. }
  128. static inline int __register_one_node(int nid)
  129. {
  130. return 0;
  131. }
  132. static inline int register_one_node(int nid)
  133. {
  134. return 0;
  135. }
  136. static inline int unregister_one_node(int nid)
  137. {
  138. return 0;
  139. }
  140. static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
  141. {
  142. return 0;
  143. }
  144. static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
  145. {
  146. return 0;
  147. }
  148. static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
  149. {
  150. }
  151. #endif
  152. #define to_node(device) container_of(device, struct node, dev)
  153. #endif /* _LINUX_NODE_H_ */