2
0

machine-hmp-cmds.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 (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_socket_id) {
  64. monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
  65. }
  66. if (c->has_die_id) {
  67. monitor_printf(mon, " die-id: \"%" PRIu64 "\"\n", c->die_id);
  68. }
  69. if (c->has_cluster_id) {
  70. monitor_printf(mon, " cluster-id: \"%" PRIu64 "\"\n",
  71. c->cluster_id);
  72. }
  73. if (c->has_core_id) {
  74. monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
  75. }
  76. if (c->has_thread_id) {
  77. monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
  78. }
  79. l = l->next;
  80. }
  81. qapi_free_HotpluggableCPUList(saved);
  82. }
  83. void hmp_info_memdev(Monitor *mon, const QDict *qdict)
  84. {
  85. Error *err = NULL;
  86. MemdevList *memdev_list = qmp_query_memdev(&err);
  87. MemdevList *m = memdev_list;
  88. Visitor *v;
  89. char *str;
  90. while (m) {
  91. v = string_output_visitor_new(false, &str);
  92. visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort);
  93. monitor_printf(mon, "memory backend: %s\n", m->value->id);
  94. monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
  95. monitor_printf(mon, " merge: %s\n",
  96. m->value->merge ? "true" : "false");
  97. monitor_printf(mon, " dump: %s\n",
  98. m->value->dump ? "true" : "false");
  99. monitor_printf(mon, " prealloc: %s\n",
  100. m->value->prealloc ? "true" : "false");
  101. monitor_printf(mon, " share: %s\n",
  102. m->value->share ? "true" : "false");
  103. if (m->value->has_reserve) {
  104. monitor_printf(mon, " reserve: %s\n",
  105. m->value->reserve ? "true" : "false");
  106. }
  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_kvm(Monitor *mon, const QDict *qdict)
  120. {
  121. KvmInfo *info;
  122. info = qmp_query_kvm(NULL);
  123. monitor_printf(mon, "kvm support: ");
  124. if (info->present) {
  125. monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
  126. } else {
  127. monitor_printf(mon, "not compiled\n");
  128. }
  129. qapi_free_KvmInfo(info);
  130. }
  131. void hmp_info_uuid(Monitor *mon, const QDict *qdict)
  132. {
  133. UuidInfo *info;
  134. info = qmp_query_uuid(NULL);
  135. monitor_printf(mon, "%s\n", info->UUID);
  136. qapi_free_UuidInfo(info);
  137. }
  138. void hmp_info_balloon(Monitor *mon, const QDict *qdict)
  139. {
  140. BalloonInfo *info;
  141. Error *err = NULL;
  142. info = qmp_query_balloon(&err);
  143. if (hmp_handle_error(mon, err)) {
  144. return;
  145. }
  146. monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
  147. qapi_free_BalloonInfo(info);
  148. }
  149. void hmp_system_reset(Monitor *mon, const QDict *qdict)
  150. {
  151. qmp_system_reset(NULL);
  152. }
  153. void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
  154. {
  155. qmp_system_powerdown(NULL);
  156. }
  157. void hmp_memsave(Monitor *mon, const QDict *qdict)
  158. {
  159. uint32_t size = qdict_get_int(qdict, "size");
  160. const char *filename = qdict_get_str(qdict, "filename");
  161. uint64_t addr = qdict_get_int(qdict, "val");
  162. Error *err = NULL;
  163. int cpu_index = monitor_get_cpu_index(mon);
  164. if (cpu_index < 0) {
  165. monitor_printf(mon, "No CPU available\n");
  166. return;
  167. }
  168. qmp_memsave(addr, size, filename, true, cpu_index, &err);
  169. hmp_handle_error(mon, err);
  170. }
  171. void hmp_pmemsave(Monitor *mon, const QDict *qdict)
  172. {
  173. uint32_t size = qdict_get_int(qdict, "size");
  174. const char *filename = qdict_get_str(qdict, "filename");
  175. uint64_t addr = qdict_get_int(qdict, "val");
  176. Error *err = NULL;
  177. qmp_pmemsave(addr, size, filename, &err);
  178. hmp_handle_error(mon, err);
  179. }
  180. void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
  181. {
  182. Error *err = NULL;
  183. qmp_system_wakeup(&err);
  184. hmp_handle_error(mon, err);
  185. }
  186. void hmp_nmi(Monitor *mon, const QDict *qdict)
  187. {
  188. Error *err = NULL;
  189. qmp_inject_nmi(&err);
  190. hmp_handle_error(mon, err);
  191. }
  192. void hmp_balloon(Monitor *mon, const QDict *qdict)
  193. {
  194. int64_t value = qdict_get_int(qdict, "value");
  195. Error *err = NULL;
  196. qmp_balloon(value, &err);
  197. hmp_handle_error(mon, err);
  198. }
  199. void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
  200. {
  201. Error *err = NULL;
  202. MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
  203. MemoryDeviceInfoList *info;
  204. VirtioPMEMDeviceInfo *vpi;
  205. VirtioMEMDeviceInfo *vmi;
  206. MemoryDeviceInfo *value;
  207. PCDIMMDeviceInfo *di;
  208. SgxEPCDeviceInfo *se;
  209. for (info = info_list; info; info = info->next) {
  210. value = info->value;
  211. if (value) {
  212. switch (value->type) {
  213. case MEMORY_DEVICE_INFO_KIND_DIMM:
  214. case MEMORY_DEVICE_INFO_KIND_NVDIMM:
  215. di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
  216. value->u.dimm.data : value->u.nvdimm.data;
  217. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  218. MemoryDeviceInfoKind_str(value->type),
  219. di->id ? di->id : "");
  220. monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
  221. monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
  222. monitor_printf(mon, " node: %" PRId64 "\n", di->node);
  223. monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
  224. monitor_printf(mon, " memdev: %s\n", di->memdev);
  225. monitor_printf(mon, " hotplugged: %s\n",
  226. di->hotplugged ? "true" : "false");
  227. monitor_printf(mon, " hotpluggable: %s\n",
  228. di->hotpluggable ? "true" : "false");
  229. break;
  230. case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
  231. vpi = value->u.virtio_pmem.data;
  232. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  233. MemoryDeviceInfoKind_str(value->type),
  234. vpi->id ? vpi->id : "");
  235. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
  236. monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
  237. monitor_printf(mon, " memdev: %s\n", vpi->memdev);
  238. break;
  239. case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM:
  240. vmi = value->u.virtio_mem.data;
  241. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  242. MemoryDeviceInfoKind_str(value->type),
  243. vmi->id ? vmi->id : "");
  244. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr);
  245. monitor_printf(mon, " node: %" PRId64 "\n", vmi->node);
  246. monitor_printf(mon, " requested-size: %" PRIu64 "\n",
  247. vmi->requested_size);
  248. monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size);
  249. monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size);
  250. monitor_printf(mon, " block-size: %" PRIu64 "\n",
  251. vmi->block_size);
  252. monitor_printf(mon, " memdev: %s\n", vmi->memdev);
  253. break;
  254. case MEMORY_DEVICE_INFO_KIND_SGX_EPC:
  255. se = value->u.sgx_epc.data;
  256. monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
  257. MemoryDeviceInfoKind_str(value->type),
  258. se->id ? se->id : "");
  259. monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr);
  260. monitor_printf(mon, " size: %" PRIu64 "\n", se->size);
  261. monitor_printf(mon, " node: %" PRId64 "\n", se->node);
  262. monitor_printf(mon, " memdev: %s\n", se->memdev);
  263. break;
  264. default:
  265. g_assert_not_reached();
  266. }
  267. }
  268. }
  269. qapi_free_MemoryDeviceInfoList(info_list);
  270. hmp_handle_error(mon, err);
  271. }
  272. void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
  273. {
  274. Error *err = NULL;
  275. GuidInfo *info = qmp_query_vm_generation_id(&err);
  276. if (info) {
  277. monitor_printf(mon, "%s\n", info->guid);
  278. }
  279. hmp_handle_error(mon, err);
  280. qapi_free_GuidInfo(info);
  281. }
  282. void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
  283. {
  284. Error *err = NULL;
  285. MemoryInfo *info = qmp_query_memory_size_summary(&err);
  286. if (info) {
  287. monitor_printf(mon, "base memory: %" PRIu64 "\n",
  288. info->base_memory);
  289. if (info->has_plugged_memory) {
  290. monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
  291. info->plugged_memory);
  292. }
  293. qapi_free_MemoryInfo(info);
  294. }
  295. hmp_handle_error(mon, err);
  296. }