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 16 #include "qemu/osdep.h" 17 #include "monitor/hmp.h" 18 #include "monitor/monitor.h" 19 #include "qapi/error.h" 20 #include "qapi/qapi-builtin-visit.h" 21 #include "qapi/qapi-commands-machine.h" 22 #include "qapi/qmp/qdict.h" 23 #include "qapi/string-output-visitor.h" 24 #include "qemu/error-report.h" 25 #include "sysemu/numa.h" 26 27 void hmp_info_cpus(Monitor *mon, const QDict *qdict) 28 { 29 CpuInfoFastList *cpu_list, *cpu; 30 31 cpu_list = qmp_query_cpus_fast(NULL); 32 33 for (cpu = cpu_list; cpu; cpu = cpu->next) { 34 int active = ' '; 35 36 if (cpu->value->cpu_index == monitor_get_cpu_index()) { 37 active = '*'; 38 } 39 40 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, 41 cpu->value->cpu_index); 42 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); 43 } 44 45 qapi_free_CpuInfoFastList(cpu_list); 46 } 47 48 void hmp_cpu_add(Monitor *mon, const QDict *qdict) 49 { 50 int cpuid; 51 Error *err = NULL; 52 53 error_report("cpu_add is deprecated, please use device_add instead"); 54 55 cpuid = qdict_get_int(qdict, "id"); 56 qmp_cpu_add(cpuid, &err); 57 hmp_handle_error(mon, &err); 58 } 59 60 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) 61 { 62 Error *err = NULL; 63 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err); 64 HotpluggableCPUList *saved = l; 65 CpuInstanceProperties *c; 66 67 if (err != NULL) { 68 hmp_handle_error(mon, &err); 69 return; 70 } 71 72 monitor_printf(mon, "Hotpluggable CPUs:\n"); 73 while (l) { 74 monitor_printf(mon, " type: \"%s\"\n", l->value->type); 75 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n", 76 l->value->vcpus_count); 77 if (l->value->has_qom_path) { 78 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path); 79 } 80 81 c = l->value->props; 82 monitor_printf(mon, " CPUInstance Properties:\n"); 83 if (c->has_node_id) { 84 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id); 85 } 86 if (c->has_socket_id) { 87 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id); 88 } 89 if (c->has_core_id) { 90 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id); 91 } 92 if (c->has_thread_id) { 93 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id); 94 } 95 96 l = l->next; 97 } 98 99 qapi_free_HotpluggableCPUList(saved); 100 } 101 102 void hmp_info_memdev(Monitor *mon, const QDict *qdict) 103 { 104 Error *err = NULL; 105 MemdevList *memdev_list = qmp_query_memdev(&err); 106 MemdevList *m = memdev_list; 107 Visitor *v; 108 char *str; 109 110 while (m) { 111 v = string_output_visitor_new(false, &str); 112 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); 113 monitor_printf(mon, "memory backend: %s\n", m->value->id); 114 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); 115 monitor_printf(mon, " merge: %s\n", 116 m->value->merge ? "true" : "false"); 117 monitor_printf(mon, " dump: %s\n", 118 m->value->dump ? "true" : "false"); 119 monitor_printf(mon, " prealloc: %s\n", 120 m->value->prealloc ? "true" : "false"); 121 monitor_printf(mon, " policy: %s\n", 122 HostMemPolicy_str(m->value->policy)); 123 visit_complete(v, &str); 124 monitor_printf(mon, " host nodes: %s\n", str); 125 126 g_free(str); 127 visit_free(v); 128 m = m->next; 129 } 130 131 monitor_printf(mon, "\n"); 132 133 qapi_free_MemdevList(memdev_list); 134 hmp_handle_error(mon, &err); 135 } 136 137 void hmp_info_numa(Monitor *mon, const QDict *qdict) 138 { 139 int i; 140 NumaNodeMem *node_mem; 141 CpuInfoList *cpu_list, *cpu; 142 143 cpu_list = qmp_query_cpus(&error_abort); 144 node_mem = g_new0(NumaNodeMem, nb_numa_nodes); 145 146 query_numa_node_mem(node_mem); 147 monitor_printf(mon, "%d nodes\n", nb_numa_nodes); 148 for (i = 0; i < nb_numa_nodes; i++) { 149 monitor_printf(mon, "node %d cpus:", i); 150 for (cpu = cpu_list; cpu; cpu = cpu->next) { 151 if (cpu->value->has_props && cpu->value->props->has_node_id && 152 cpu->value->props->node_id == i) { 153 monitor_printf(mon, " %" PRIi64, cpu->value->CPU); 154 } 155 } 156 monitor_printf(mon, "\n"); 157 monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i, 158 node_mem[i].node_mem >> 20); 159 monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i, 160 node_mem[i].node_plugged_mem >> 20); 161 } 162 qapi_free_CpuInfoList(cpu_list); 163 g_free(node_mem); 164 } 165