2
0

machine-hmp-cmds.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * HMP commands related to machines and CPUs
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. * Contributions after 2012-01-13 are licensed under the terms of the
  13. * GNU GPL, version 2 or (at your option) any later version.
  14. */
  15. #include "qemu/osdep.h"
  16. #include "monitor/hmp.h"
  17. #include "monitor/monitor.h"
  18. #include "qapi/error.h"
  19. #include "qapi/qapi-builtin-visit.h"
  20. #include "qapi/qapi-commands-machine.h"
  21. #include "qapi/qmp/qdict.h"
  22. #include "qapi/string-output-visitor.h"
  23. #include "qemu/error-report.h"
  24. #include "sysemu/numa.h"
  25. #include "hw/boards.h"
  26. void hmp_info_cpus(Monitor *mon, const QDict *qdict)
  27. {
  28. CpuInfoFastList *cpu_list, *cpu;
  29. cpu_list = qmp_query_cpus_fast(NULL);
  30. for (cpu = cpu_list; cpu; cpu = cpu->next) {
  31. int active = ' ';
  32. if (cpu->value->cpu_index == monitor_get_cpu_index(mon)) {
  33. active = '*';
  34. }
  35. monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
  36. cpu->value->cpu_index);
  37. monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
  38. }
  39. qapi_free_CpuInfoFastList(cpu_list);
  40. }
  41. void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
  42. {
  43. Error *err = NULL;
  44. HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
  45. HotpluggableCPUList *saved = l;
  46. CpuInstanceProperties *c;
  47. if (err != NULL) {
  48. hmp_handle_error(mon, err);
  49. return;
  50. }
  51. monitor_printf(mon, "Hotpluggable CPUs:\n");
  52. while (l) {
  53. monitor_printf(mon, " type: \"%s\"\n", l->value->type);
  54. monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
  55. l->value->vcpus_count);
  56. if (l->value->has_qom_path) {
  57. monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
  58. }
  59. c = l->value->props;
  60. monitor_printf(mon, " CPUInstance Properties:\n");
  61. if (c->has_node_id) {
  62. monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
  63. }
  64. if (c->has_socket_id) {
  65. monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
  66. }
  67. if (c->has_die_id) {
  68. monitor_printf(mon, " die-id: \"%" PRIu64 "\"\n", c->die_id);
  69. }
  70. if (c->has_core_id) {
  71. monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
  72. }
  73. if (c->has_thread_id) {
  74. monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
  75. }
  76. l = l->next;
  77. }
  78. qapi_free_HotpluggableCPUList(saved);
  79. }
  80. void hmp_info_memdev(Monitor *mon, const QDict *qdict)
  81. {
  82. Error *err = NULL;
  83. MemdevList *memdev_list = qmp_query_memdev(&err);
  84. MemdevList *m = memdev_list;
  85. Visitor *v;
  86. char *str;
  87. while (m) {
  88. v = string_output_visitor_new(false, &str);
  89. visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort);
  90. monitor_printf(mon, "memory backend: %s\n", m->value->id);
  91. monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
  92. monitor_printf(mon, " merge: %s\n",
  93. m->value->merge ? "true" : "false");
  94. monitor_printf(mon, " dump: %s\n",
  95. m->value->dump ? "true" : "false");
  96. monitor_printf(mon, " prealloc: %s\n",
  97. m->value->prealloc ? "true" : "false");
  98. monitor_printf(mon, " policy: %s\n",
  99. HostMemPolicy_str(m->value->policy));
  100. visit_complete(v, &str);
  101. monitor_printf(mon, " host nodes: %s\n", str);
  102. g_free(str);
  103. visit_free(v);
  104. m = m->next;
  105. }
  106. monitor_printf(mon, "\n");
  107. qapi_free_MemdevList(memdev_list);
  108. hmp_handle_error(mon, err);
  109. }
  110. void hmp_info_numa(Monitor *mon, const QDict *qdict)
  111. {
  112. int i, nb_numa_nodes;
  113. NumaNodeMem *node_mem;
  114. CpuInfoList *cpu_list, *cpu;
  115. MachineState *ms = MACHINE(qdev_get_machine());
  116. nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
  117. monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
  118. if (!nb_numa_nodes) {
  119. return;
  120. }
  121. cpu_list = qmp_query_cpus(&error_abort);
  122. node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
  123. query_numa_node_mem(node_mem, ms);
  124. for (i = 0; i < nb_numa_nodes; i++) {
  125. monitor_printf(mon, "node %d cpus:", i);
  126. for (cpu = cpu_list; cpu; cpu = cpu->next) {
  127. if (cpu->value->has_props && cpu->value->props->has_node_id &&
  128. cpu->value->props->node_id == i) {
  129. monitor_printf(mon, " %" PRIi64, cpu->value->CPU);
  130. }
  131. }
  132. monitor_printf(mon, "\n");
  133. monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
  134. node_mem[i].node_mem >> 20);
  135. monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i,
  136. node_mem[i].node_plugged_mem >> 20);
  137. }
  138. qapi_free_CpuInfoList(cpu_list);
  139. g_free(node_mem);
  140. }