From patchwork Sun Jun 9 19:13:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 250105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 144732C02A8 for ; Mon, 10 Jun 2013 05:28:13 +1000 (EST) Received: from localhost ([::1]:39920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UllHf-0005UM-4Y for incoming@patchwork.ozlabs.org; Sun, 09 Jun 2013 15:28:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4g-00017m-D0 for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ull4e-0000qo-1U for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:46 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44465 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4d-0000qZ-Mx for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:43 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3EB2AA398F for ; Sun, 9 Jun 2013 21:14:43 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sun, 9 Jun 2013 21:13:17 +0200 Message-Id: <1370805206-26574-51-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370805206-26574-1-git-send-email-afaerber@suse.de> References: <1370805206-26574-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH qom-cpu 50/59] cpus: Abstract qmp_query_cpus() with qemu_for_each_cpu() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Andreas Färber --- 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,