qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Hu Tao <hutao@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: imammedo@redhat.com, lersek@redhat.com,
	Wanlong Gao <gaowanlong@cn.fujitsu.com>
Subject: Re: [Qemu-devel] [PATCH v18 14/14] amp: add query-memdev
Date: Wed, 19 Feb 2014 10:07:44 +0100	[thread overview]
Message-ID: <53047460.1020003@redhat.com> (raw)
In-Reply-To: <8bbf3cab7e2ed5828697cad55989fe062b2009bd.1392794450.git.hutao@cn.fujitsu.com>

Il 19/02/2014 08:54, Hu Tao ha scritto:
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  backends/hostmem-ram.c | 71 ++++++++++++++++++++++++++++++++++++++++++++------
>  qapi-schema.json       | 31 ++++++++++++++++++++++
>  qmp-commands.hx        | 30 +++++++++++++++++++++
>  3 files changed, 124 insertions(+), 8 deletions(-)

This is in principle not necessary, because we can query everything via 
qom-get/qom-set; but I can see that it is useful.  If you want this:

(1) please put it in numa.c and code it in a way that does not use 
internal information of HostMemoryBackend; for example, you can walk 
numa_info[...].node_memdev and use object_property_get/set on the object 
to fill in the result.

This will also eliminate all duplicate code between func and the 
property visitors.

(2) please add an HMP variant "info memdev".

Paolo

> diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
> index 2da9341..9f19ab8 100644
> --- a/backends/hostmem-ram.c
> +++ b/backends/hostmem-ram.c
> @@ -15,6 +15,7 @@
>  #include "qapi-visit.h"
>  #include "qemu/config-file.h"
>  #include "qapi/opts-visitor.h"
> +#include "qmp-commands.h"
>
>  #define TYPE_MEMORY_BACKEND_RAM "memory-ram"
>  #define MEMORY_BACKEND_RAM(obj) \
> @@ -37,8 +38,66 @@ struct HostMemoryBackendRam {
>      DECLARE_BITMAP(host_nodes, MAX_NODES);
>      HostMemPolicy policy;
>      bool relative;
> +
> +    QTAILQ_ENTRY(HostMemoryBackendRam) next;
> +};
> +
> +static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
> +    [HOST_MEM_POLICY_DEFAULT] = "default",
> +    [HOST_MEM_POLICY_PREFERRED] = "preferred",
> +    [HOST_MEM_POLICY_MEMBIND] = "membind",
> +    [HOST_MEM_POLICY_INTERLEAVE] = "interleave",
> +    [HOST_MEM_POLICY_MAX] = NULL,
>  };
>
> +static GSList *memdevs;
> +
> +static void func(gpointer data, gpointer user_data)
> +{
> +    HostMemoryBackendRam *backend = data;
> +    MemdevList **list = user_data;
> +    MemdevList *m;
> +    uint16List **node;
> +    unsigned long value;
> +
> +    m = g_malloc0(sizeof(*m));
> +    m->value = g_malloc0(sizeof(*m->value));
> +    m->value->policy = g_strdup(policies[backend->policy]);
> +    m->value->relative = backend->relative;
> +
> +    node = &m->value->host_nodes;
> +
> +    value = find_first_bit(backend->host_nodes, MAX_NODES);
> +    if (value < MAX_NODES) {
> +        *node = g_malloc0(sizeof(**node));
> +        (*node)->value = value;
> +        node = &(*node)->next;
> +
> +        do {
> +            value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
> +            if (value == MAX_NODES) {
> +                break;
> +            }
> +
> +            *node = g_malloc0(sizeof(**node));
> +            (*node)->value = value;
> +            node = &(*node)->next;
> +        } while (true);
> +    }
> +
> +    m->next = *list;
> +    *list = m;
> +}
> +
> +MemdevList *qmp_query_memdev(Error **errp)
> +{
> +    MemdevList *list = NULL;
> +
> +    g_slist_foreach(memdevs, func, &list);
> +
> +    return list;
> +}
> +
>  static void
>  get_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
>                 Error **errp)
> @@ -86,14 +145,6 @@ set_host_nodes(Object *obj, Visitor *v, void *opaque, const char *name,
>      }
>  }
>
> -static const char *policies[HOST_MEM_POLICY_MAX + 1] = {
> -    [HOST_MEM_POLICY_DEFAULT] = "default",
> -    [HOST_MEM_POLICY_PREFERRED] = "preferred",
> -    [HOST_MEM_POLICY_MEMBIND] = "membind",
> -    [HOST_MEM_POLICY_INTERLEAVE] = "interleave",
> -    [HOST_MEM_POLICY_MAX] = NULL,
> -};
> -
>  static void
>  get_policy(Object *obj, Visitor *v, void *opaque, const char *name,
>             Error **errp)
> @@ -172,6 +223,8 @@ ram_backend_memory_init(HostMemoryBackend *backend, Error **errp)
>  static void
>  ram_backend_initfn(Object *obj)
>  {
> +    HostMemoryBackendRam *ram_backend = MEMORY_BACKEND_RAM(obj);
> +
>      object_property_add(obj, "host-nodes", "int",
>                          get_host_nodes,
>                          set_host_nodes, NULL, NULL, NULL);
> @@ -180,6 +233,8 @@ ram_backend_initfn(Object *obj)
>                          set_policy, NULL, NULL, NULL);
>      object_property_add_bool(obj, "relative",
>                               get_relative, set_relative, NULL);
> +
> +    memdevs = g_slist_append(memdevs, ram_backend);
>  }
>
>  static void
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 9d6370f..7b5027d 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4474,3 +4474,34 @@
>  ##
>  { 'enum': 'HostMemPolicy',
>    'data': [ 'default', 'preferred', 'membind', 'interleave' ] }
> +
> +##
> +# @Memdev:
> +#
> +# Information of memory device
> +#
> +# @id: memory device id
> +#
> +# @host-nodes: host nodes for its memory policy
> +#
> +# @policy: memory policy of memory device
> +#
> +# Since: 2.0
> +##
> +
> +{ 'type': 'Memdev',
> +  'data': {
> +    'host-nodes': ['uint16'],
> +    'policy': 'str',
> +    'relative': 'bool' }}
> +
> +##
> +# @query-memdev:
> +#
> +# Returns information for all memory devices.
> +#
> +# Returns: a list of @Memdev.
> +#
> +# Since: 2.0
> +##
> +{ 'command': 'query-memdev', 'returns': ['Memdev'] }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index cce6b81..20368f7 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3457,3 +3457,33 @@ Example:
>                     } } ] }
>
>  EQMP
> +
> +    {
> +        .name       = "query-memdev",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_memdev,
> +    },
> +
> +SQMP
> +query-memdev
> +------------
> +
> +Show memory devices information.
> +
> +
> +Example (1):
> +
> +-> { "execute": "query-memdev" }
> +<- { "return": [
> +       {
> +         "host-nodes": [0, 1],
> +         "policy": "bind"
> +       },
> +       {
> +         "host-nodes": [2, 3],
> +         "policy": "preferred"
> +       }
> +     ]
> +   }
> +
> +EQMP
>

      parent reply	other threads:[~2014-02-19  9:07 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-19  7:53 [Qemu-devel] [PATCH v18 00/14] Add support for binding guest numa nodes to host numa nodes Hu Tao
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 01/14] NUMA: move numa related code to new file numa.c Hu Tao
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 02/14] NUMA: check if the total numa memory size is equal to ram_size Hu Tao
2014-02-25 13:38   ` Eric Blake
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 03/14] NUMA: Add numa_info structure to contain numa nodes info Hu Tao
2014-02-19  9:26   ` Igor Mammedov
2014-02-21  2:54     ` hu tao
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 04/14] NUMA: convert -numa option to use OptsVisitor Hu Tao
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 05/14] NUMA: expand MAX_NODES from 64 to 128 Hu Tao
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 06/14] qapi: add SIZE type parser to string_input_visitor Hu Tao
2014-02-19  9:54   ` Igor Mammedov
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 07/14] add memdev backend infrastructure Hu Tao
2014-02-19  9:15   ` Igor Mammedov
2014-02-19  7:53 ` [Qemu-devel] [PATCH v18 08/14] pc: pass QEMUMachineInitArgs to pc_memory_init Hu Tao
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 09/14] numa: introduce memory_region_allocate_system_memory Hu Tao
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 10/14] numa: add -numa node, memdev= option Hu Tao
2014-02-19  9:50   ` Igor Mammedov
2014-02-19 11:53     ` Paolo Bonzini
2014-03-04  0:10   ` Eric Blake
2014-03-04  2:20     ` Hu Tao
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 11/14] qapi: make string input visitor parse int list Hu Tao
2014-02-19  8:17   ` Hu Tao
2014-02-19  8:42     ` Paolo Bonzini
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 12/14] qapi: add HostMemPolicy enum type Hu Tao
2014-02-19  9:08   ` Paolo Bonzini
2014-02-19 11:23   ` Igor Mammedov
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 13/14] memory backend: fill memory backend ram fields Hu Tao
2014-02-19  9:03   ` Paolo Bonzini
2014-02-19  9:36     ` Igor Mammedov
2014-02-25 10:20       ` Hu Tao
2014-02-25 14:15         ` Paolo Bonzini
2014-02-26  5:00           ` Hu Tao
2014-02-26  8:47             ` Igor Mammedov
2014-02-26  8:59               ` Hu Tao
2014-02-26 12:19                 ` Igor Mammedov
2014-02-26 11:22               ` Paolo Bonzini
2014-02-26  5:57       ` Hu Tao
2014-02-26  9:05         ` Paolo Bonzini
2014-02-26  9:10         ` Igor Mammedov
2014-02-26 10:33           ` Paolo Bonzini
2014-02-26 12:31             ` Igor Mammedov
2014-02-26 12:45               ` Paolo Bonzini
2014-02-26 12:58                 ` Marcelo Tosatti
2014-02-26 13:14                   ` Paolo Bonzini
2014-02-26 13:43                 ` Igor Mammedov
2014-02-26 13:47                   ` Paolo Bonzini
2014-02-26 14:25                     ` Igor Mammedov
2014-02-26 14:39                       ` Paolo Bonzini
2014-02-25 10:09     ` Hu Tao
2014-03-03  3:24       ` Hu Tao
2014-02-19  7:54 ` [Qemu-devel] [PATCH v18 14/14] amp: add query-memdev Hu Tao
2014-02-19  8:14   ` Hu Tao
2014-02-19  9:07   ` Paolo Bonzini [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=53047460.1020003@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gaowanlong@cn.fujitsu.com \
    --cc=hutao@cn.fujitsu.com \
    --cc=imammedo@redhat.com \
    --cc=lersek@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).