From patchwork Wed Oct 7 00:27:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 85C69B7B9E for ; Wed, 7 Oct 2009 11:54:05 +1100 (EST) Received: from localhost ([127.0.0.1]:44140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvKn4-0003dR-HH for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2009 20:54:02 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvKNx-0001oB-NG for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:28:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvKNt-0001lm-TT for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:28:05 -0400 Received: from [199.232.76.173] (port=45755 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvKNt-0001lh-R4 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:28:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15247) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvKNt-00076q-EP for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:28:01 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n970S028006825; Tue, 6 Oct 2009 20:28:00 -0400 Received: from localhost (vpn-12-79.rdu.redhat.com [10.11.12.79]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n970Rx42027971; Tue, 6 Oct 2009 20:28:00 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 6 Oct 2009 21:27:12 -0300 Message-Id: <1254875232-25012-16-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com> References: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 15/15] monitor: Convert do_info_cpus() to QObject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Each CPU information is stored in a QDict and the returned QObject is a QList of all CPUs. The QDict contains the following information: - "CPU": cpu index - "current": "yes" or "no" - "pc": current PC - "halted": "yes" or "no" The user output in the Monitor should not change and the future monitor protocol is expected to emit something like: [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" }, { "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ] which corresponds to the following user output: * CPU #0: pc=0x00000000fffffff0 CPU #1: pc=0x00000000fffffff0 (halted) Signed-off-by: Luiz Capitulino --- monitor.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 80 insertions(+), 14 deletions(-) diff --git a/monitor.c b/monitor.c index 0dcf478..1487b72 100644 --- a/monitor.c +++ b/monitor.c @@ -46,6 +46,7 @@ #include "kvm.h" #include "acl.h" #include "qint.h" +#include "qlist.h" #include "qdict.h" #include "qstring.h" @@ -410,33 +411,98 @@ static void do_info_registers(Monitor *mon) #endif } -static void do_info_cpus(Monitor *mon) +static void print_cpu_iter(QObject *obj, void *opaque) +{ + QDict *cpu; + int active = ' '; + Monitor *mon = opaque; + + assert(qobject_type(obj) == QTYPE_QDICT); + cpu = qobject_to_qdict(obj); + + if (strcmp(qdict_get_str(cpu, "current"), "yes") == 0) + active = '*'; + + monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU")); + +#if defined(TARGET_I386) + monitor_printf(mon, "pc=0x" TARGET_FMT_lx, + (target_ulong) qdict_get_int(cpu, "pc")); +#elif defined(TARGET_PPC) + monitor_printf(mon, "nip=0x" TARGET_FMT_lx, + (target_long) qdict_get_int(cpu, "nip")); +#elif defined(TARGET_SPARC) + monitor_printf(mon, "pc=0x " TARGET_FMT_lx, + (target_long) qdict_get_int(cpu, "pc")); + monitor_printf(mon, "npc=0x" TARGET_FMT_lx, + (target_long) qdict_get_int(cpu, "npc")); +#elif defined(TARGET_MIPS) + monitor_printf(mon, "PC=0x" TARGET_FMT_lx, + (target_long) qdict_get_int(cpu, "PC")); +#endif + + if (strcmp(qdict_get_str(cpu, "halted"), "yes") == 0) + monitor_printf(mon, " (halted)"); + + monitor_printf(mon, "\n"); +} + +static void monitor_print_cpus(Monitor *mon, const QObject *data) +{ + QList *cpu_list; + + assert(qobject_type(data) == QTYPE_QLIST); + cpu_list = qobject_to_qlist(data); + qlist_iter(cpu_list, print_cpu_iter, mon); +} + +/** + * do_info_cpus(): Show CPU information + * + * Return a QList with a QDict for each CPU. + * + * For example: + * + * [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" }, + * { "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ] + */ +static void do_info_cpus(Monitor *mon, QObject **ret_data) { CPUState *env; + QList *cpu_list; + + cpu_list = qlist_new(); /* just to set the default cpu if not already done */ mon_get_cpu(); for(env = first_cpu; env != NULL; env = env->next_cpu) { + const char *answer; + QDict *cpu = qdict_new(); + cpu_synchronize_state(env); - monitor_printf(mon, "%c CPU #%d:", - (env == mon->mon_cpu) ? '*' : ' ', - env->cpu_index); + + qdict_put(cpu, "CPU", qint_from_int(env->cpu_index)); + answer = (env == mon->mon_cpu) ? "yes" : "no"; + qdict_put(cpu, "current", qstring_from_str(answer)); + #if defined(TARGET_I386) - monitor_printf(mon, " pc=0x" TARGET_FMT_lx, - env->eip + env->segs[R_CS].base); + qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base)); #elif defined(TARGET_PPC) - monitor_printf(mon, " nip=0x" TARGET_FMT_lx, env->nip); + qdict_put(cpu, "nip", qint_from_int(env->nip)); #elif defined(TARGET_SPARC) - monitor_printf(mon, " pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, - env->pc, env->npc); + qdict_put(cpu, "pc", qint_from_int(env->pc)); + qdict_put(cpu, "npc", qint_from_int(env->npc)); #elif defined(TARGET_MIPS) - monitor_printf(mon, " PC=0x" TARGET_FMT_lx, env->active_tc.PC); + qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); #endif - if (env->halted) - monitor_printf(mon, " (halted)"); - monitor_printf(mon, "\n"); + answer = env->halted ? "yes" : "no"; + qdict_put(cpu, "halted", qstring_from_str(answer)); + + qlist_append(cpu_list, cpu); } + + *ret_data = QOBJECT(cpu_list); } static void do_cpu_set(Monitor *mon, const QDict *qdict) @@ -1938,7 +2004,7 @@ static const mon_cmd_t info_cmds[] = { .name = "cpus", .args_type = "", .handler = do_info_cpus, - .user_print = NULL, + .user_print = monitor_print_cpus, .params = "", .help = "show infos for each CPU" },