numa.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef SYSTEM_NUMA_H
  2. #define SYSTEM_NUMA_H
  3. #include "qemu/bitmap.h"
  4. #include "qapi/qapi-types-machine.h"
  5. struct CPUArchId;
  6. #define MAX_NODES 128
  7. #define NUMA_NODE_UNASSIGNED MAX_NODES
  8. #define NUMA_DISTANCE_MIN 10
  9. #define NUMA_DISTANCE_DEFAULT 20
  10. #define NUMA_DISTANCE_MAX 254
  11. #define NUMA_DISTANCE_UNREACHABLE 255
  12. /* the value of AcpiHmatLBInfo flags */
  13. enum {
  14. HMAT_LB_MEM_MEMORY = 0,
  15. HMAT_LB_MEM_CACHE_1ST_LEVEL = 1,
  16. HMAT_LB_MEM_CACHE_2ND_LEVEL = 2,
  17. HMAT_LB_MEM_CACHE_3RD_LEVEL = 3,
  18. HMAT_LB_LEVELS /* must be the last entry */
  19. };
  20. /* the value of AcpiHmatLBInfo data type */
  21. enum {
  22. HMAT_LB_DATA_ACCESS_LATENCY = 0,
  23. HMAT_LB_DATA_READ_LATENCY = 1,
  24. HMAT_LB_DATA_WRITE_LATENCY = 2,
  25. HMAT_LB_DATA_ACCESS_BANDWIDTH = 3,
  26. HMAT_LB_DATA_READ_BANDWIDTH = 4,
  27. HMAT_LB_DATA_WRITE_BANDWIDTH = 5,
  28. HMAT_LB_TYPES /* must be the last entry */
  29. };
  30. #define UINT16_BITS 16
  31. typedef struct NodeInfo {
  32. uint64_t node_mem;
  33. struct HostMemoryBackend *node_memdev;
  34. bool present;
  35. bool has_cpu;
  36. bool has_gi;
  37. uint8_t lb_info_provided;
  38. uint16_t initiator;
  39. uint8_t distance[MAX_NODES];
  40. } NodeInfo;
  41. typedef struct NumaNodeMem {
  42. uint64_t node_mem;
  43. uint64_t node_plugged_mem;
  44. } NumaNodeMem;
  45. struct HMAT_LB_Data {
  46. uint8_t initiator;
  47. uint8_t target;
  48. uint64_t data;
  49. };
  50. typedef struct HMAT_LB_Data HMAT_LB_Data;
  51. struct HMAT_LB_Info {
  52. /* Indicates it's memory or the specified level memory side cache. */
  53. uint8_t hierarchy;
  54. /* Present the type of data, access/read/write latency or bandwidth. */
  55. uint8_t data_type;
  56. /* The range bitmap of bandwidth for calculating common base */
  57. uint64_t range_bitmap;
  58. /* The common base unit for latencies or bandwidths */
  59. uint64_t base;
  60. /* Array to store the latencies or bandwidths */
  61. GArray *list;
  62. };
  63. typedef struct HMAT_LB_Info HMAT_LB_Info;
  64. struct NumaState {
  65. /* Number of NUMA nodes */
  66. int num_nodes;
  67. /* Allow setting NUMA distance for different NUMA nodes */
  68. bool have_numa_distance;
  69. /* Detect if HMAT support is enabled. */
  70. bool hmat_enabled;
  71. /* NUMA nodes information */
  72. NodeInfo nodes[MAX_NODES];
  73. /* NUMA nodes HMAT Locality Latency and Bandwidth Information */
  74. HMAT_LB_Info *hmat_lb[HMAT_LB_LEVELS][HMAT_LB_TYPES];
  75. /* Memory Side Cache Information Structure */
  76. NumaHmatCacheOptions *hmat_cache[MAX_NODES][HMAT_LB_LEVELS];
  77. };
  78. typedef struct NumaState NumaState;
  79. void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp);
  80. void parse_numa_opts(MachineState *ms);
  81. void parse_numa_hmat_lb(NumaState *numa_state, NumaHmatLBOptions *node,
  82. Error **errp);
  83. void parse_numa_hmat_cache(MachineState *ms, NumaHmatCacheOptions *node,
  84. Error **errp);
  85. void numa_complete_configuration(MachineState *ms);
  86. void query_numa_node_mem(NumaNodeMem node_mem[], MachineState *ms);
  87. extern QemuOptsList qemu_numa_opts;
  88. void numa_cpu_pre_plug(const struct CPUArchId *slot, DeviceState *dev,
  89. Error **errp);
  90. bool numa_uses_legacy_mem(void);
  91. #endif