2
0

machine-hmp-cmds.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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()) {
  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_cpu_add(Monitor *mon, const QDict *qdict)
  42. {
  43. int cpuid;
  44. Error *err = NULL;
  45. error_report("cpu_add is deprecated, please use device_add instead");
  46. cpuid = qdict_get_int(qdict, "id");
  47. qmp_cpu_add(cpuid, &err);
  48. hmp_handle_error(mon, &err);
  49. }
  50. void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
  51. {
  52. Error *err = NULL;
  53. HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
  54. HotpluggableCPUList *saved = l;
  55. CpuInstanceProperties *c;
  56. if (err != NULL) {
  57. hmp_handle_error(mon, &err);
  58. return;
  59. }
  60. monitor_printf(mon, "Hotpluggable CPUs:\n");
  61. while (l) {
  62. monitor_printf(mon, " type: \"%s\"\n", l->value->type);
  63. monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
  64. l->value->vcpus_count);
  65. if (l->value->has_qom_path) {
  66. monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
  67. }
  68. c = l->value->props;
  69. monitor_printf(mon, " CPUInstance Properties:\n");
  70. if (c->has_node_id) {
  71. monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
  72. }
  73. if (c->has_socket_id) {
  74. monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
  75. }
  76. if (c->has_die_id) {
  77. monitor_printf(mon, " die-id: \"%" PRIu64 "\"\n", c->die_id);
  78. }
  79. if (c->has_core_id) {
  80. monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
  81. }
  82. if (c->has_thread_id) {
  83. monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
  84. }
  85. l = l->next;
  86. }
  87. qapi_free_HotpluggableCPUList(saved);
  88. }
  89. void hmp_info_memdev(Monitor *mon, const QDict *qdict)
  90. {
  91. Error *err = NULL;
  92. MemdevList *memdev_list = qmp_query_memdev(&err);
  93. MemdevList *m = memdev_list;
  94. Visitor *v;
  95. char *str;
  96. while (m) {
  97. v = string_output_visitor_new(false, &str);
  98. visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
  99. monitor_printf(mon, "memory backend: %s\n", m->value->id);
  100. monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
  101. monitor_printf(mon, " merge: %s\n",
  102. m->value->merge ? "true" : "false");
  103. monitor_printf(mon, " dump: %s\n",
  104. m->value->dump ? "true" : "false");
  105. monitor_printf(mon, " prealloc: %s\n",
  106. m->value->prealloc ? "true" : "false");
  107. monitor_printf(mon, " policy: %s\n",
  108. HostMemPolicy_str(m->value->policy));
  109. visit_complete(v, &str);
  110. monitor_printf(mon, " host nodes: %s\n", str);
  111. g_free(str);
  112. visit_free(v);
  113. m = m->next;
  114. }
  115. monitor_printf(mon, "\n");
  116. qapi_free_MemdevList(memdev_list);
  117. hmp_handle_error(mon, &err);
  118. }
  119. void hmp_info_numa(Monitor *mon, const QDict *qdict)
  120. {
  121. int i, nb_numa_nodes;
  122. NumaNodeMem *node_mem;
  123. CpuInfoList *cpu_list, *cpu;
  124. MachineState *ms = MACHINE(qdev_get_machine());
  125. nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
  126. monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
  127. if (!nb_numa_nodes) {
  128. return;
  129. }
  130. cpu_list = qmp_query_cpus(&error_abort);
  131. node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
  132. query_numa_node_mem(node_mem, ms);
  133. for (i = 0; i < nb_numa_nodes; i++) {
  134. monitor_printf(mon, "node %d cpus:", i);
  135. for (cpu = cpu_list; cpu; cpu = cpu->next) {
  136. if (cpu->value->has_props && cpu->value->props->has_node_id &&
  137. cpu->value->props->node_id == i) {
  138. monitor_printf(mon, " %" PRIi64, cpu->value->CPU);
  139. }
  140. }
  141. monitor_printf(mon, "\n");
  142. monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
  143. node_mem[i].node_mem >> 20);
  144. monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i,
  145. node_mem[i].node_plugged_mem >> 20);
  146. }
  147. qapi_free_CpuInfoList(cpu_list);
  148. g_free(node_mem);
  149. }