machine-hmp-cmds.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. void hmp_info_cpus(Monitor *mon, const QDict *qdict)
  26. {
  27. CpuInfoFastList *cpu_list, *cpu;
  28. cpu_list = qmp_query_cpus_fast(NULL);
  29. for (cpu = cpu_list; cpu; cpu = cpu->next) {
  30. int active = ' ';
  31. if (cpu->value->cpu_index == monitor_get_cpu_index()) {
  32. active = '*';
  33. }
  34. monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
  35. cpu->value->cpu_index);
  36. monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
  37. }
  38. qapi_free_CpuInfoFastList(cpu_list);
  39. }
  40. void hmp_cpu_add(Monitor *mon, const QDict *qdict)
  41. {
  42. int cpuid;
  43. Error *err = NULL;
  44. error_report("cpu_add is deprecated, please use device_add instead");
  45. cpuid = qdict_get_int(qdict, "id");
  46. qmp_cpu_add(cpuid, &err);
  47. hmp_handle_error(mon, &err);
  48. }
  49. void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
  50. {
  51. Error *err = NULL;
  52. HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
  53. HotpluggableCPUList *saved = l;
  54. CpuInstanceProperties *c;
  55. if (err != NULL) {
  56. hmp_handle_error(mon, &err);
  57. return;
  58. }
  59. monitor_printf(mon, "Hotpluggable CPUs:\n");
  60. while (l) {
  61. monitor_printf(mon, " type: \"%s\"\n", l->value->type);
  62. monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
  63. l->value->vcpus_count);
  64. if (l->value->has_qom_path) {
  65. monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
  66. }
  67. c = l->value->props;
  68. monitor_printf(mon, " CPUInstance Properties:\n");
  69. if (c->has_node_id) {
  70. monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
  71. }
  72. if (c->has_socket_id) {
  73. monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
  74. }
  75. if (c->has_core_id) {
  76. monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
  77. }
  78. if (c->has_thread_id) {
  79. monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
  80. }
  81. l = l->next;
  82. }
  83. qapi_free_HotpluggableCPUList(saved);
  84. }
  85. void hmp_info_memdev(Monitor *mon, const QDict *qdict)
  86. {
  87. Error *err = NULL;
  88. MemdevList *memdev_list = qmp_query_memdev(&err);
  89. MemdevList *m = memdev_list;
  90. Visitor *v;
  91. char *str;
  92. while (m) {
  93. v = string_output_visitor_new(false, &str);
  94. visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
  95. monitor_printf(mon, "memory backend: %s\n", m->value->id);
  96. monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
  97. monitor_printf(mon, " merge: %s\n",
  98. m->value->merge ? "true" : "false");
  99. monitor_printf(mon, " dump: %s\n",
  100. m->value->dump ? "true" : "false");
  101. monitor_printf(mon, " prealloc: %s\n",
  102. m->value->prealloc ? "true" : "false");
  103. monitor_printf(mon, " policy: %s\n",
  104. HostMemPolicy_str(m->value->policy));
  105. visit_complete(v, &str);
  106. monitor_printf(mon, " host nodes: %s\n", str);
  107. g_free(str);
  108. visit_free(v);
  109. m = m->next;
  110. }
  111. monitor_printf(mon, "\n");
  112. qapi_free_MemdevList(memdev_list);
  113. hmp_handle_error(mon, &err);
  114. }
  115. void hmp_info_numa(Monitor *mon, const QDict *qdict)
  116. {
  117. int i;
  118. NumaNodeMem *node_mem;
  119. CpuInfoList *cpu_list, *cpu;
  120. cpu_list = qmp_query_cpus(&error_abort);
  121. node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
  122. query_numa_node_mem(node_mem);
  123. monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
  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. }