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

Re: [libvirt] [libvirt-glib 2/2] API to deal with topology information of CPU capabilities



On Tue, May 22, 2012 at 06:51:46PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> ---
>  libvirt-gconfig/Makefile.am                        |    2 +
>  .../libvirt-gconfig-capabilities-cpu-topology.c    |   83 ++++++++++++++++++++
>  .../libvirt-gconfig-capabilities-cpu-topology.h    |   71 +++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c |   22 +++++
>  libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h |    4 +
>  libvirt-gconfig/libvirt-gconfig.h                  |    1 +
>  libvirt-gconfig/libvirt-gconfig.sym                |    6 ++
>  libvirt-gconfig/tests/test-capabilities-parse.c    |    7 ++
>  8 files changed, 196 insertions(+), 0 deletions(-)
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.h
> 
> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> index 4bc3ee1..19aa6ba 100644
> --- a/libvirt-gconfig/Makefile.am
> +++ b/libvirt-gconfig/Makefile.am
> @@ -15,6 +15,7 @@ GCONFIG_HEADER_FILES = \
>  			libvirt-gconfig-capabilities-host.h \
>  			libvirt-gconfig-capabilities-cpu.h \
>  			libvirt-gconfig-capabilities-cpu-feature.h \
> +			libvirt-gconfig-capabilities-cpu-topology.h \
>  			libvirt-gconfig-capabilities-guest.h \
>  			libvirt-gconfig-capabilities-guest-arch.h \
>  			libvirt-gconfig-capabilities-guest-domain.h \
> @@ -82,6 +83,7 @@ GCONFIG_SOURCE_FILES = \
>  			libvirt-gconfig-capabilities-host.c \
>  			libvirt-gconfig-capabilities-cpu.c \
>  			libvirt-gconfig-capabilities-cpu-feature.c \
> +			libvirt-gconfig-capabilities-cpu-topology.c \
>  			libvirt-gconfig-capabilities-guest.c \
>  			libvirt-gconfig-capabilities-guest-arch.c \
>  			libvirt-gconfig-capabilities-guest-domain.c \
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.c
> new file mode 100644
> index 0000000..65ebcb1
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.c
> @@ -0,0 +1,83 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-topology.c: libvirt CPU topology capabilities
> + *
> + * Copyright (C) 2008 Daniel P. Berrange
> + * Copyright (C) 2010-2012 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Authors: Zeeshan Ali <zeenix redhat com>
> + *          Daniel P. Berrange <berrange redhat com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY, GVirConfigCapabilitiesCpuTopologyPrivate))
> +
> +struct _GVirConfigCapabilitiesCpuTopologyPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuTopology, gvir_config_capabilities_cpu_topology, GVIR_CONFIG_TYPE_OBJECT);
> +
> +static void gvir_config_capabilities_cpu_topology_class_init(GVirConfigCapabilitiesCpuTopologyClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuTopologyPrivate));
> +}
> +
> +static void gvir_config_capabilities_cpu_topology_init(GVirConfigCapabilitiesCpuTopology *topology)
> +{
> +    g_debug("Init GVirConfigCapabilitiesCpuTopology=%p", topology);
> +
> +    topology->priv = GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY_GET_PRIVATE(topology);
> +}
> +
> +guint64
> +gvir_config_capabilities_cpu_topology_get_sockets(GVirConfigCapabilitiesCpuTopology *topology)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_TOPOLOGY(topology), 0);
> +
> +    return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(topology),
> +                                                   NULL,
> +                                                   "sockets",
> +                                                   0);
> +}
> +
> +guint64
> +gvir_config_capabilities_cpu_topology_get_cores(GVirConfigCapabilitiesCpuTopology *topology)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_TOPOLOGY(topology), 0);
> +
> +    return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(topology),
> +                                                   NULL,
> +                                                   "cores",
> +                                                   0);
> +}
> +
> +guint64
> +gvir_config_capabilities_cpu_topology_get_threads(GVirConfigCapabilitiesCpuTopology *topology)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_TOPOLOGY(topology), 0);
> +
> +    return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(topology),
> +                                                   NULL,
> +                                                   "threads",
> +                                                   0);
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.h
> new file mode 100644
> index 0000000..673a340
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.h
> @@ -0,0 +1,71 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-topology.h: libvirt CPU topology capabilities
> + *
> + * Copyright (C) 2010-2012 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Authors: Zeeshan Ali <zeenix redhat com>
> + *          Daniel P. Berrange <berrange redhat com>
> + */
> +
> +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
> +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
> +#endif
> +
> +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_TOPOLOGY_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_TOPOLOGY_H__
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY            (gvir_config_capabilities_cpu_topology_get_type ())
> +#define GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY, GVirConfigCapabilitiesCpuTopology))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY, GVirConfigCapabilitiesCpuTopologyClass))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_TOPOLOGY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_TOPOLOGY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY, GVirConfigCapabilitiesCpuTopologyClass))
> +
> +typedef struct _GVirConfigCapabilitiesCpuTopology GVirConfigCapabilitiesCpuTopology;
> +typedef struct _GVirConfigCapabilitiesCpuTopologyPrivate GVirConfigCapabilitiesCpuTopologyPrivate;
> +typedef struct _GVirConfigCapabilitiesCpuTopologyClass GVirConfigCapabilitiesCpuTopologyClass;
> +
> +struct _GVirConfigCapabilitiesCpuTopology
> +{
> +    GVirConfigObject parent;
> +
> +    GVirConfigCapabilitiesCpuTopologyPrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigCapabilitiesCpuTopologyClass
> +{
> +    GVirConfigObjectClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +GType gvir_config_capabilities_cpu_topology_get_type(void);
> +
> +guint64
> +gvir_config_capabilities_cpu_topology_get_sockets(GVirConfigCapabilitiesCpuTopology *topology);
> +guint64
> +gvir_config_capabilities_cpu_topology_get_cores(GVirConfigCapabilitiesCpuTopology *topology);
> +guint64
> +gvir_config_capabilities_cpu_topology_get_threads(GVirConfigCapabilitiesCpuTopology *topology);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_TOPOLOGY_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> index be23f13..c6dcdc4 100644
> --- a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> @@ -111,3 +111,25 @@ gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
>  
>      return data.features;
>  }
> +
> +/**
> + * gvir_config_capabilities_cpu_get_topology:
> + *
> + * Gets the toplogoy of the cpu.

topology

> + *
> + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpuTopology.
> + */
> +GVirConfigCapabilitiesCpuTopology *
> +gvir_config_capabilities_cpu_get_topology(GVirConfigCapabilitiesCpu *cpu)
> +{
> +    GVirConfigObject *object;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(cpu), NULL);
> +
> +    object = gvir_config_object_get_child_with_type
> +                                (GVIR_CONFIG_OBJECT(cpu),
> +                                 "topology",
> +                                 GVIR_CONFIG_TYPE_CAPABILITIES_CPU_TOPOLOGY);
> +
> +    return GVIR_CONFIG_CAPABILITIES_CPU_TOPOLOGY(object);
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
> index 8b221ae..4d896ef 100644
> --- a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
> @@ -28,6 +28,8 @@
>  #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__
>  #define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__
>  
> +#include "libvirt-gconfig-capabilities-cpu-topology.h"
> +
>  G_BEGIN_DECLS
>  
>  #define GVIR_CONFIG_TYPE_CAPABILITIES_CPU            (gvir_config_capabilities_cpu_get_type ())
> @@ -63,6 +65,8 @@ const gchar *
>  gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu);
>  GList *
>  gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu);
> +GVirConfigCapabilitiesCpuTopology *
> +gvir_config_capabilities_cpu_get_topology(GVirConfigCapabilitiesCpu *cpu);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> index 1201eb8..1e69962 100644
> --- a/libvirt-gconfig/libvirt-gconfig.h
> +++ b/libvirt-gconfig/libvirt-gconfig.h
> @@ -31,6 +31,7 @@
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index 11c01f1..0db0320 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -388,10 +388,16 @@ LIBVIRT_GCONFIG_0.0.9 {
>  	gvir_config_capabilities_cpu_get_type;
>  	gvir_config_capabilities_cpu_get_arch;
>  	gvir_config_capabilities_cpu_get_features;
> +	gvir_config_capabilities_cpu_get_topology;
>  
>  	gvir_config_capabilities_cpu_feature_get_type;
>  	gvir_config_capabilities_cpu_feature_get_name;
>  
> +	gvir_config_capabilities_cpu_topology_get_type;
> +	gvir_config_capabilities_cpu_topology_get_sockets;
> +	gvir_config_capabilities_cpu_topology_get_cores;
> +	gvir_config_capabilities_cpu_topology_get_threads;

Move _sockets after _cores to preserve alphabetical ordering?

> +
>  	gvir_config_capabilities_guest_get_type;
>  	gvir_config_capabilities_guest_get_arch;
>  	gvir_config_capabilities_guest_get_features;
> diff --git a/libvirt-gconfig/tests/test-capabilities-parse.c b/libvirt-gconfig/tests/test-capabilities-parse.c
> index 4b0da8f..72aead4 100644
> --- a/libvirt-gconfig/tests/test-capabilities-parse.c
> +++ b/libvirt-gconfig/tests/test-capabilities-parse.c
> @@ -34,6 +34,7 @@
>  static void verify_host_caps(GVirConfigCapabilitiesHost *host_caps)
>  {
>      GVirConfigCapabilitiesCpu *cpu_caps;
> +    GVirConfigCapabilitiesCpuTopology *topology;
>      GList *features, *iter;
>      const char *str;
>  
> @@ -51,6 +52,12 @@ static void verify_host_caps(GVirConfigCapabilitiesHost *host_caps)
>          g_object_unref(G_OBJECT(iter->data));
>      }
>      g_list_free(features);
> +
> +    topology = gvir_config_capabilities_cpu_get_topology(cpu_caps);
> +    g_assert(topology != NULL);
> +    g_assert(gvir_config_capabilities_cpu_topology_get_sockets(topology) == 1);
> +    g_assert(gvir_config_capabilities_cpu_topology_get_cores(topology) == 2);
> +    g_assert(gvir_config_capabilities_cpu_topology_get_threads(topology) == 2);

g_object_unref(G_OBJECT(topology));

ACK with these few issues fixed.

Christophe

Attachment: pgplFMxSr1Ku0.pgp
Description: PGP signature


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