machine-hmp-cmds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 "qobject/qdict.h"
  22. #include "qapi/string-output-visitor.h"
  23. #include "qemu/error-report.h"
  24. #include "system/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 (hmp_handle_error(mon, err)) {
  48. return;
  49. }
  50. monitor_printf(mon, "Hotpluggable CPUs:\n");
  51. while (l) {
  52. monitor_printf(mon, " type: \"%s\"\n", l->value->type);
  53. monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
  54. l->value->vcpus_count);
  55. if (l->value->qom_path) {
  56. monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
  57. }
  58. c = l->value->props;
  59. monitor_printf(mon, " CPUInstance Properties:\n");
  60. if (c->has_node_id) {
  61. monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
  62. }
  63. if (c->has_drawer_id) {
  64. monitor_printf(mon, " drawer-id: \"%" PRIu64 "\"\n", c->drawer_id);
  65. }
  66. if (c->has_book_id) {
  67. monitor_printf(mon, " book-id: \"%" PRIu64 "\"\n", c->book_id);
  68. }
  69. if (c->has_socket_id) {
  70. monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
  71. }
  72. if (c->has_die_id) {
  73. monitor_printf(mon, " die-id: \"%" PRIu64 "\"\n", c->die_id);
  74. }
  75. if (c->has_cluster_id) {
  76. monitor_printf(mon, " cluster-id: \"%" PRIu64 "\"\n",
  77. c->cluster_id);
  78. }
  79. if (c->has_module_id) {
  80. monitor_printf(mon, " module-id: \"%" PRIu64 "\"\n",
  81. c->module_id);
  82. }
  83. if (c->has_core_id) {
  84. monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
  85. }
  86. if (c->has_thread_id) {
  87. monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
  88. }
  89. l = l->next;
  90. }
  91. qapi_free_HotpluggableCPUList(saved);
  92. }
  93. void hmp_info_memdev(Monitor *mon, const QDict *qdict)
  94. {
  95. Error *err = NULL;
  96. MemdevList *memdev_list = qmp_query_memdev(&err);
  97. MemdevList *m = memdev_list;
  98. Visitor *v;
  99. char *str;
  100. while (m) {
  101. v = string_output_visitor_new(false, &str);
  102. visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort);
  103. monitor_printf(mon, "memory backend: %s\n", m->value->id);
  104. monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
  105. monitor_printf(mon, " merge: %s\n",
  106. m->value->merge ? "true" : "false");
  107. monitor_printf(mon, " dump: %s\n",
  108. m->value->dump ? "true" : "false");
  109. monitor_printf(mon, " prealloc: %s\n",
  110. m->value->prealloc ? "true" : "false");
  111. monitor_printf(mon, " share: %s\n",
  112. m->value->share ? "true" : "false");
  113. if (m->value->has_reserve) {
  114. monitor_printf(mon, " reserve: %s\n",
  115. m->value->reserve ? "true" : "false");
  116. }
  117. monitor_printf(mon, " policy: %s\n",
  118. HostMemPolicy_str(m->value->policy));
  119. visit_complete(v, &str);
  120. monitor_printf(mon, " host nodes: %s\n", str);
  121. g_free(str);
  122. visit_free(v);
  123. m = m->next;
  124. }
  125. monitor_printf(mon, "\n");
  126. qapi_free_MemdevList(memdev_list);
  127. hmp_handle_error(mon, err);
  128. }
  129. void hmp_info_kvm(Monitor *mon, const QDict *qdict)
  130. {
  131. KvmInfo *info;
  132. info = qmp_query_kvm(NULL);
  133. monitor_printf(mon, "kvm support: ");
  134. if (info->present) {
  135. monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
  136. } else {
  137. monitor_printf(mon, "not compiled\n");
  138. }
  139. qapi_free_KvmInfo(info);
  140. }
  141. void hmp_info_uuid(Monitor *mon, const QDict *qdict)
  142. {
  143. UuidInfo *info;
  144. info = qmp_query_uuid(NULL);
  145. monitor_printf(mon, "%s\n", info->UUID);
  146. qapi_free_UuidInfo(info);
  147. }
  148. void hmp_info_balloon(Monitor *mon, const QDict *qdict)
  149. {
  150. BalloonInfo *info;
  151. Error *err = NULL;
  152. info = qmp_query_balloon(&err);
  153. if (hmp_handle_error(mon, err)) {
  154. return;
  155. }
  156. monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
  157. qapi_free_BalloonInfo(info);
  158. }
  159. void hmp_system_reset(Monitor *mon, const QDict *qdict)
  160. {
  161. qmp_system_reset(NULL);
  162. }
  163. void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
  164. {
  165. qmp_system_powerdown(NULL);
  166. }
  167. void hmp_memsave(Monitor *mon, const QDict *qdict)
  168. {
  169. uint32_t size = qdict_get_int(qdict, "size");
  170. const char *filename = qdict_get_str(qdict, "filename");
  171. uint64_t addr = qdict_get_int(qdict, "val");
  172. Error *err = NULL;
  173. int cpu_index = monitor_get_cpu_index(mon);
  174. if (cpu_index < 0) {
  175. monitor_printf(mon, "No CPU available\n");
  176. return;
  177. }
  178. qmp_memsave(addr, size, filename, true, cpu_index, &err);
  179. hmp_handle_error(mon, err);
  180. }
  181. void hmp_pmemsave(Monitor *mon, const QDict *qdict)
  182. {
  183. uint32_t size = qdict_get_int(qdict, "size");
  184. const char *filename = qdict_get_str(qdict, "filename");
  185. uint64_t addr = qdict_get_int(qdict, "val");
  186. Error *err = NULL;
  187. qmp_pmemsave(addr, size, filename, &err);
  188. hmp_handle_error(mon, err);
  189. }
  190. void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
  191. {
  192. Error *err = NULL;
  193. qmp_system_wakeup(&err);
  194. hmp_handle_error(mon, err);
  195. }
  196. void hmp_nmi(Monitor *mon, const QDict *qdict)
  197. {
  198. Error *err = NULL;
  199. qmp_inject_nmi(&err);
  200. hmp_handle_error(mon, err);
  201. }
  202. void hmp_balloon(Monitor *mon, const QDict *qdict)
  203. {
  204. int64_t value = qdict_get_int(qdict, "value");
  205. Error *err = NULL;
  206. qmp_balloon(value, &err);
  207. hmp_handle_error(mon, err);
  208. }
  209. void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
  210. {
  211. Error *err = NULL;
  212. MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
  213. MemoryDeviceInfoList *info;
  214. VirtioPMEMDeviceInfo *vpi;
  215. VirtioMEMDeviceInfo *vmi;
  216. MemoryDeviceInfo *value;
  217. PCDIMMDeviceInfo *di;
  218. SgxEPCDeviceInfo *se;
  219. HvBalloonDeviceInfo *hi;
  220. for (info = info_list; info; info = info->next) {
  221. value = info->value;
  222. if (value) {
  223. switch (value->type) {
  224. case MEMORY_DEVICE_INFO_KIND_DIMM:
  225. case MEMORY_DEVICE_INFO_KIND_NVDIMM:
  226. di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
  227. value->u.dimm.data : value->u.nvdimm.data;
  228. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  229. MemoryDeviceInfoKind_str(value->type),
  230. di->id ? di->id : "");
  231. monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
  232. monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
  233. monitor_printf(mon, " node: %" PRId64 "\n", di->node);
  234. monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
  235. monitor_printf(mon, " memdev: %s\n", di->memdev);
  236. monitor_printf(mon, " hotplugged: %s\n",
  237. di->hotplugged ? "true" : "false");
  238. monitor_printf(mon, " hotpluggable: %s\n",
  239. di->hotpluggable ? "true" : "false");
  240. break;
  241. case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
  242. vpi = value->u.virtio_pmem.data;
  243. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  244. MemoryDeviceInfoKind_str(value->type),
  245. vpi->id ? vpi->id : "");
  246. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
  247. monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
  248. monitor_printf(mon, " memdev: %s\n", vpi->memdev);
  249. break;
  250. case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
  251. vmi = value->u.virtio_mem.data;
  252. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  253. MemoryDeviceInfoKind_str(value->type),
  254. vmi->id ? vmi->id : "");
  255. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
  256. monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
  257. monitor_printf(mon, " requested-size: %" PRIu64 "\n",
  258. vmi->requested_size);
  259. monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
  260. monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
  261. monitor_printf(mon, " block-size: %" PRIu64 "\n",
  262. vmi->block_size);
  263. monitor_printf(mon, " memdev: %s\n", vmi->memdev);
  264. break;
  265. case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
  266. se = value->u.sgx_epc.data;
  267. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  268. MemoryDeviceInfoKind_str(value->type),
  269. se->id ? se->id : "");
  270. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
  271. monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
  272. monitor_printf(mon, " node: %" PRId64 "\n", se->node);
  273. monitor_printf(mon, " memdev: %s\n", se->memdev);
  274. break;
  275. case MEMORY_DEVICE_INFO_KIND_HV_BALLOON:
  276. hi = value->u.hv_balloon.data;
  277. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  278. MemoryDeviceInfoKind_str(value->type),
  279. hi->id ? hi->id : "");
  280. if (hi->has_memaddr) {
  281. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n",
  282. hi->memaddr);
  283. }
  284. monitor_printf(mon, " max-size: %" PRIu64 "\n", hi->max_size);
  285. if (hi->memdev) {
  286. monitor_printf(mon, " memdev: %s\n", hi->memdev);
  287. }
  288. break;
  289. default:
  290. g_assert_not_reached();
  291. }
  292. }
  293. }
  294. qapi_free_MemoryDeviceInfoList(info_list);
  295. hmp_handle_error(mon, err);
  296. }
  297. void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
  298. {
  299. Error *err = NULL;
  300. GuidInfo *info = qmp_query_vm_generation_id(&err);
  301. if (info) {
  302. monitor_printf(mon, "%s\n", info->guid);
  303. }
  304. hmp_handle_error(mon, err);
  305. qapi_free_GuidInfo(info);
  306. }
  307. void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
  308. {
  309. Error *err = NULL;
  310. MemoryInfo *info = qmp_query_memory_size_summary(&err);
  311. if (info) {
  312. monitor_printf(mon, "base memory: %" PRIu64 "\n",
  313. info->base_memory);
  314. if (info->has_plugged_memory) {
  315. monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
  316. info->plugged_memory);
  317. }
  318. qapi_free_MemoryInfo(info);
  319. }
  320. hmp_handle_error(mon, err);
  321. }