[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH qom-cpu 50/59] cpus: Abstract qmp_query_cpus() with
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PATCH qom-cpu 50/59] cpus: Abstract qmp_query_cpus() with qemu_for_each_cpu() |
Date: |
Sun, 9 Jun 2013 21:13:17 +0200 |
Signed-off-by: Andreas Färber <address@hidden>
---
cpus.c | 75 ++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 43 insertions(+), 32 deletions(-)
diff --git a/cpus.c b/cpus.c
index 3856bf1..a0b8e6b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1205,49 +1205,60 @@ void list_cpus(FILE *f, fprintf_function cpu_fprintf,
const char *optarg)
#endif
}
-CpuInfoList *qmp_query_cpus(Error **errp)
-{
- CpuInfoList *head = NULL, *cur_item = NULL;
- CPUArchState *env;
+typedef struct QMPQueryCPUs {
+ CpuInfoList *head;
+ CpuInfoList *cur_item;
+} QMPQueryCPUs;
- for (env = first_cpu; env != NULL; env = env->next_cpu) {
- CPUState *cpu = ENV_GET_CPU(env);
- CpuInfoList *info;
+static void qmp_query_one_cpu(CPUState *cpu, void *data)
+{
+ QMPQueryCPUs *s = data;
+ CPUArchState *env = cpu->env_ptr;
+ CpuInfoList *info;
- cpu_synchronize_state(cpu);
+ cpu_synchronize_state(cpu);
- info = g_malloc0(sizeof(*info));
- info->value = g_malloc0(sizeof(*info->value));
- info->value->CPU = cpu->cpu_index;
- info->value->current = (env == first_cpu);
- info->value->halted = cpu->halted;
- info->value->thread_id = cpu->thread_id;
+ info = g_malloc0(sizeof(*info));
+ info->value = g_malloc0(sizeof(*info->value));
+ info->value->CPU = cpu->cpu_index;
+ info->value->current = (env == first_cpu);
+ info->value->halted = cpu->halted;
+ info->value->thread_id = cpu->thread_id;
#if defined(TARGET_I386)
- info->value->has_pc = true;
- info->value->pc = env->eip + env->segs[R_CS].base;
+ info->value->has_pc = true;
+ info->value->pc = env->eip + env->segs[R_CS].base;
#elif defined(TARGET_PPC)
- info->value->has_nip = true;
- info->value->nip = env->nip;
+ info->value->has_nip = true;
+ info->value->nip = env->nip;
#elif defined(TARGET_SPARC)
- info->value->has_pc = true;
- info->value->pc = env->pc;
- info->value->has_npc = true;
- info->value->npc = env->npc;
+ info->value->has_pc = true;
+ info->value->pc = env->pc;
+ info->value->has_npc = true;
+ info->value->npc = env->npc;
#elif defined(TARGET_MIPS)
- info->value->has_PC = true;
- info->value->PC = env->active_tc.PC;
+ info->value->has_PC = true;
+ info->value->PC = env->active_tc.PC;
#endif
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ /* XXX: waiting for the qapi to support GSList */
+ if (s->cur_item == NULL) {
+ s->head = s->cur_item = info;
+ } else {
+ s->cur_item->next = info;
+ s->cur_item = info;
}
+}
+
+CpuInfoList *qmp_query_cpus(Error **errp)
+{
+ QMPQueryCPUs s = {
+ .head = NULL,
+ .cur_item = NULL,
+ };
+
+ qemu_for_each_cpu(qmp_query_one_cpu, &s);
- return head;
+ return s.head;
}
void qmp_memsave(int64_t addr, int64_t size, const char *filename,
--
1.8.1.4
- [Qemu-devel] [PATCH qom-cpu 43/59] kvmclock: Abstract kvmclock_vm_state_change() with qemu_for_each_cpu(), (continued)
- [Qemu-devel] [PATCH qom-cpu 43/59] kvmclock: Abstract kvmclock_vm_state_change() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 45/59] pc: Abstract pic_irq_request() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 44/59] kvmvapic: Abstract vapic_enable_tpr_reporting() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 46/59] ppc: Abstract ppce500_set_mpic_proxy() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 48/59] cpus: Abstract all_cpu_threads_idle() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 47/59] spapr: Abstract spapr_fix_cpu_dt() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 49/59] cpus: Abstract all_vcpus_paused() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 50/59] cpus: Abstract qmp_query_cpus() with qemu_for_each_cpu(),
Andreas Färber <=
- [Qemu-devel] [PATCH qom-cpu 51/59] exec: Abstract qemu_get_cpu() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 52/59] gdbstub: Abstract gdb_breakpoint_{insert, remove}() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 53/59] gdbstub: Abstract gdb_breakpoint_remove_all() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 55/59] spapr_rtas: Abstract rtas_query_cpu_stopped_state() with qemu_get_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 56/59] spapr_rtas: Abstract rtas_start_cpu() with qemu_get_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 54/59] spapr: Abstract spapr_create_fdt_skel() with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 58/59] linux-user: Change thread_env to CPUState, Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu 57/59] cpu: Make first_cpu and next_cpu CPUState (WIP), Andreas Färber, 2013/06/09