All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org, avi@redhat.com
Subject: [Qemu-devel] Re: [PATCH 15/15] monitor: Convert do_info_cpus() to QObject
Date: Wed, 7 Oct 2009 10:04:01 -0300	[thread overview]
Message-ID: <20091007100401.7cc47cf2@doriath> (raw)
In-Reply-To: <4ACBF30D.2020100@us.ibm.com>

On Tue, 06 Oct 2009 20:46:53 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> Luiz Capitulino wrote:
> > 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 <lcapitulino@redhat.com>
> > ---
> >  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));
> >   
> 
> I'd almost think that a json parser that supported varadics would make 
> this much easier..

 In this specific case most values are conditionally inserted into the dict,
so I think it's easier to insert them separately.

 But I've a function called qobject_from_fmt() which allows one to
do something like:

QObject *obj = qobject_from_fmt("{ s: [ i, s ], s: i }", ... );

 I'm not sure I've implemented it correctly, but will submit as
part of the series that will use it.

      reply	other threads:[~2009-10-07 13:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07  0:26 [Qemu-devel] [PATCH v2 00/15]: Initial QObject conversion Luiz Capitulino
2009-10-07  0:26 ` [Qemu-devel] [PATCH 01/15] QObject: Accept NULL Luiz Capitulino
2009-10-07  0:26 ` [Qemu-devel] [PATCH 02/15] Introduce QList Luiz Capitulino
2009-10-07  1:37   ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:48     ` Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 03/15] Introduce QList unit-tests Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 04/15] monitor: Add user_print() to mon_cmd_t Luiz Capitulino
2009-10-07  1:40   ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:52     ` Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 05/15] monitor: Handle new and old style handlers Luiz Capitulino
2009-10-07  1:42   ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:54     ` Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 06/15] monitor: do_info(): handle new and old info handlers Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 07/15] monitor: Convert do_quit() do QObject Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 08/15] monitor: Convert do_stop() to QObject Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 09/15] monitor: Convert do_system_reset() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 10/15] monitor: Convert do_system_powerdown() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 11/15] monitor: Convert do_cont() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 12/15] monitor: Convert do_balloon() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 13/15] monitor: Convert do_info_version() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 14/15] monitor: Convert do_info_balloon() " Luiz Capitulino
2009-10-07  0:27 ` [Qemu-devel] [PATCH 15/15] monitor: Convert do_info_cpus() " Luiz Capitulino
2009-10-07  1:46   ` [Qemu-devel] " Anthony Liguori
2009-10-07 13:04     ` Luiz Capitulino [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091007100401.7cc47cf2@doriath \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.