qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH qom-cpu 31/59] monitor: Simplify do_info_numa()


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH qom-cpu 31/59] monitor: Simplify do_info_numa()
Date: Mon, 10 Jun 2013 09:20:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

Andreas Färber <address@hidden> writes:

> Use new qemu_for_each_cpu().
>
> Signed-off-by: Andreas Färber <address@hidden>
> ---
>  monitor.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index 9be515c..f37bf3d 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1803,21 +1803,32 @@ static void do_info_mtree(Monitor *mon, const QDict 
> *qdict)
>      mtree_info((fprintf_function)monitor_printf, mon);
>  }
>  
> +typedef struct DoInfoNUMAData {
> +    Monitor *mon;
> +    int numa_node;
> +} DoInfoNUMAData;
> +
> +static void do_info_numa_one(CPUState *cpu, void *data)
> +{
> +    DoInfoNUMAData *s = data;
> +
> +    if (cpu->numa_node == s->numa_node) {
> +        monitor_printf(s->mon, " %d", cpu->cpu_index);
> +    }
> +}
> +
>  static void do_info_numa(Monitor *mon, const QDict *qdict)
>  {
>      int i;
> -    CPUArchState *env;
> -    CPUState *cpu;
> +    DoInfoNUMAData s = {
> +        .mon = mon,
> +    };
>  
>      monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
>      for (i = 0; i < nb_numa_nodes; i++) {
>          monitor_printf(mon, "node %d cpus:", i);
> -        for (env = first_cpu; env != NULL; env = env->next_cpu) {
> -            cpu = ENV_GET_CPU(env);
> -            if (cpu->numa_node == i) {
> -                monitor_printf(mon, " %d", cpu->cpu_index);
> -            }
> -        }
> +        s.numa_node = i;
> +        qemu_for_each_cpu(do_info_numa_one, &s);
>          monitor_printf(mon, "\n");
>          monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
>              node_mem[i] >> 20);

This again demonstrates the relative clunkiness of higher order
functions in C.  Control flow jumps back and forth in the source
(lambda, how I miss you), you need an extra type, and you need to go
around the type system.

In my experience, loops are a much more natural fit for C.

Would it be possible to have a function cpu_next(CPUState *)?  So you
can simply do:

        for (cpu = cpu_next(NULL); cpu; cpu = cpu_next(cpu) {
            if (cpu->numa_node == i) {
                monitor_printf(mon, " %d", cpu->cpu_index);
            }
        }

Simple and type safe.

Precedence: bdrv_next().



reply via email to

[Prev in Thread] Current Thread [Next in Thread]