All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxl: add a new Array type to the IDL
@ 2012-06-27 10:10 Ian Campbell
  2012-06-27 10:15 ` Ian Campbell
  2012-06-28 13:50 ` Ian Jackson
  0 siblings, 2 replies; 5+ messages in thread
From: Ian Campbell @ 2012-06-27 10:10 UTC (permalink / raw)
  To: xen-devel; +Cc: Dario Faggioli, Ian Jackson

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1340791557 -3600
# Node ID 03b641aa89f979a1670b9fe2a0827687a17d5459
# Parent  91b2e1c01cc28427bf2b30fee5040f412dee9257
libxl: add a new Array type to the IDL

And make all the required infrastructure updates to enable this.

Since there are currently no uses of this type there is no change to
the generated code.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Tested-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---

Dario extracted this from my "RFC: libxl: move definition of
libxl_domain_config into the IDL" patch for use in his "Automatically
place guest on host's NUMA nodes with xl" series. I have addressed Ian
Jackson's review comments and am reposting as a separate patch.

Changes made to the idl.txt comments, in particular mention the
requirement to name the fields num_FOO.

Added support for converting C arrays into ocaml arrays (not lists as
previous patches).

diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/libxl/gentest.py
--- a/tools/libxl/gentest.py	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/libxl/gentest.py	Wed Jun 27 11:05:57 2012 +0100
@@ -27,6 +27,18 @@ def gen_rand_init(ty, v, indent = "    "
     s = ""
     if isinstance(ty, idl.Enumeration):
         s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), randomize_enum(ty))
+    elif isinstance(ty, idl.Array):
+        if parent is None:
+            raise Exception("Array type must have a parent")
+        s += "%s = rand()%%8;\n" % (parent + ty.lenvar.name)
+        s += "%s = calloc(%s, sizeof(*%s));\n" % \
+            (v, parent + ty.lenvar.name, v)
+        s += "{\n"
+        s += "    int i;\n"
+        s += "    for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
+        s += gen_rand_init(ty.elem_type, v+"[i]",
+                           indent + "        ", parent)
+        s += "}\n"
     elif isinstance(ty, idl.KeyedUnion):
         if parent is None:
             raise Exception("KeyedUnion type must have a parent")
diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/libxl/gentypes.py	Wed Jun 27 11:05:57 2012 +0100
@@ -11,8 +11,12 @@ def libxl_C_instance_of(ty, instancename
             return libxl_C_type_define(ty)
         else:
             return libxl_C_type_define(ty) + " " + instancename
-    else:
-        return ty.typename + " " + instancename
+
+    s = ""
+    if isinstance(ty, idl.Array):
+        s += libxl_C_instance_of(ty.lenvar.type, ty.lenvar.name) + ";\n"
+
+    return s + ty.typename + " " + instancename
 
 def libxl_C_type_define(ty, indent = ""):
     s = ""
@@ -66,6 +70,21 @@ def libxl_C_type_dispose(ty, v, indent =
             s += libxl_C_type_dispose(f.type, fexpr, indent + "    ", nparent)
             s += "    break;\n"
         s += "}\n"
+    elif isinstance(ty, idl.Array):
+        if parent is None:
+            raise Exception("Array type must have a parent")
+        if ty.elem_type.dispose_fn is not None:
+            s += "{\n"
+            s += "    int i;\n"
+            s += "    for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
+            s += libxl_C_type_dispose(ty.elem_type, v+"[i]",
+                                      indent + "        ", parent)
+        if ty.dispose_fn is not None:
+            if ty.elem_type.dispose_fn is not None:
+                s += "    "
+            s += "%s(%s);\n" % (ty.dispose_fn, ty.pass_arg(v, parent is None))
+        if ty.elem_type.dispose_fn is not None:
+            s += "}\n"
     elif isinstance(ty, idl.Struct) and (parent is None or ty.dispose_fn is None):
         for f in [f for f in ty.fields if not f.const]:
             (nparent,fexpr) = ty.member(v, f, parent is None)
@@ -164,7 +183,24 @@ def libxl_C_type_gen_json(ty, v, indent 
     s = ""
     if parent is None:
         s += "yajl_gen_status s;\n"
-    if isinstance(ty, idl.Enumeration):
+
+    if isinstance(ty, idl.Array):
+        if parent is None:
+            raise Exception("Array type must have a parent")
+        s += "{\n"
+        s += "    int i;\n"
+        s += "    s = yajl_gen_array_open(hand);\n"
+        s += "    if (s != yajl_gen_status_ok)\n"
+        s += "        goto out;\n"
+        s += "    for (i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
+        s += libxl_C_type_gen_json(ty.elem_type, v+"[i]",
+                                   indent + "        ", parent)
+        s += "    }\n"
+        s += "    s = yajl_gen_array_close(hand);\n"
+        s += "    if (s != yajl_gen_status_ok)\n"
+        s += "        goto out;\n"
+        s += "}\n"
+    elif isinstance(ty, idl.Enumeration):
         s += "s = libxl__yajl_gen_enum(hand, %s_to_string(%s));\n" % (ty.typename, ty.pass_arg(v, parent is None))
         s += "if (s != yajl_gen_status_ok)\n"
         s += "    goto out;\n"
diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/libxl/idl.py
--- a/tools/libxl/idl.py	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/libxl/idl.py	Wed Jun 27 11:05:57 2012 +0100
@@ -266,6 +266,17 @@ string = Builtin("char *", namespace = N
                  json_fn = "libxl__string_gen_json",
                  autogenerate_json = False)
 
+class Array(Type):
+    """An array of the same type"""
+    def __init__(self, elem_type, lenvar_name, **kwargs):
+        kwargs.setdefault('dispose_fn', 'free')
+        Type.__init__(self, namespace=elem_type.namespace, typename=elem_type.rawname + " *", **kwargs)
+
+        lv_kwargs = dict([(x.lstrip('lenvar_'),y) for (x,y) in kwargs.items() if x.startswith('lenvar_')])
+
+        self.lenvar = Field(integer, lenvar_name, **lv_kwargs)
+        self.elem_type = elem_type
+
 class OrderedDict(dict):
     """A dictionary which remembers insertion order.
 
diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/libxl/idl.txt
--- a/tools/libxl/idl.txt	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/libxl/idl.txt	Wed Jun 27 11:05:57 2012 +0100
@@ -145,11 +145,24 @@ idl.KeyedUnion
 
  A subclass of idl.Aggregate which represents the C union type
  where the currently valid member of the union can be determined based
- upon another member in the containing type.
+ upon another member in the containing type. An idl.KeyedUnion must
+ always be a member of a containing idl.Aggregate type.
 
- The KeyedUnion.keyvar contains an idl.type the member of the
- containing type which determines the valid member of the union. The
- must be an instance of the Enumeration type.
+ The KeyedUnion.keyvar contains an idl.Field, this is the member of
+ the containing type which determines the valid member of the
+ union. The idl.Field.type of the keyvar must be an Enumeration type.
+
+idl.Array
+
+  A class representing an array of similar elements. An idl.Array must
+  always be an idl.Field of a containing idl.Aggregate.
+
+  idl.Array.elem_type contains an idl.Type which is the type of each
+  element of the array.
+
+  idl.Array.len_var contains an idl.Field which is added to the parent
+  idl.Aggregate and will contain the length of the array. The field
+  MUST be named num_ARRAYNAME.
 
 Standard Types
 --------------
diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/ocaml/libs/xl/genwrap.py
--- a/tools/ocaml/libs/xl/genwrap.py	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/ocaml/libs/xl/genwrap.py	Wed Jun 27 11:05:57 2012 +0100
@@ -55,7 +55,8 @@ def ocaml_type_of(ty):
             return "int%d" % ty.width
         else:
             return "int"
-
+    elif isinstance(ty,idl.Array):
+        return "%s array" % ocaml_type_of(ty.elem_type)
     elif isinstance(ty,idl.Builtin):
         if not builtins.has_key(ty.typename):
             raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
@@ -138,6 +139,8 @@ def c_val(ty, c, o, indent="", parent = 
         if not fn:
             raise NotImplementedError("No c_val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
         s += "%s;" % (fn % { "o": o, "c": c })
+    elif isinstance (ty,idl.Array):
+        raise("Cannot handle Array type\n")
     elif isinstance(ty,idl.Enumeration) and (parent is None):
         n = 0
         s += "switch(Int_val(%s)) {\n" % o
@@ -195,6 +198,16 @@ def ocaml_Val(ty, o, c, indent="", paren
         if not fn:
             raise NotImplementedError("No ocaml Val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
         s += "%s = %s;" % (o, fn % { "c": c })
+    elif isinstance(ty, idl.Array):
+        s += "{\n"
+        s += "\t    int i;\n"
+        s += "\t    value array_elem;\n"
+        s += "\t    %s = caml_alloc(%s,0);\n" % (o, parent + ty.lenvar.name)
+        s += "\t    for(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
+        s += "\t        %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "")
+        s += "\t        Store_field(%s, i, array_elem);\n" % o
+        s += "\t    }\n"
+        s += "\t}"
     elif isinstance(ty,idl.Enumeration) and (parent is None):
         n = 0
         s += "switch(%s) {\n" % c
diff -r 91b2e1c01cc2 -r 03b641aa89f9 tools/python/genwrap.py
--- a/tools/python/genwrap.py	Wed Jun 27 10:04:50 2012 +0100
+++ b/tools/python/genwrap.py	Wed Jun 27 11:05:57 2012 +0100
@@ -4,7 +4,7 @@ import sys,os
 
 import idl
 
-(TYPE_DEFBOOL, TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = range(6)
+(TYPE_DEFBOOL, TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_ARRAY, TYPE_AGGREGATE) = range(7)
 
 def py_type(ty):
     if ty == idl.bool:
@@ -18,6 +18,8 @@ def py_type(ty):
             return TYPE_INT
         else:
             return TYPE_UINT
+    if isinstance(ty, idl.Array):
+        return TYPE_ARRAY
     if isinstance(ty, idl.Aggregate):
         return TYPE_AGGREGATE
     if ty == idl.string:
@@ -74,7 +76,7 @@ def py_attrib_get(ty, f):
         l.append('    return genwrap__ull_get(self->obj.%s);'%f.name)
     elif t == TYPE_STRING:
         l.append('    return genwrap__string_get(&self->obj.%s);'%f.name)
-    elif t == TYPE_AGGREGATE:
+    elif t == TYPE_AGGREGATE or t == TYPE_ARRAY:
         l.append('    PyErr_SetString(PyExc_NotImplementedError, "Getting %s");'%ty.typename)
         l.append('    return NULL;')
     else:
@@ -105,7 +107,7 @@ def py_attrib_set(ty, f):
         l.append('    return ret;')
     elif t == TYPE_STRING:
         l.append('    return genwrap__string_set(v, &self->obj.%s);'%f.name)
-    elif t == TYPE_AGGREGATE:
+    elif t == TYPE_AGGREGATE or t == TYPE_ARRAY:
         l.append('    PyErr_SetString(PyExc_NotImplementedError, "Setting %s");'%ty.typename)
         l.append('    return -1;')
     else:

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: add a new Array type to the IDL
  2012-06-27 10:10 [PATCH] libxl: add a new Array type to the IDL Ian Campbell
@ 2012-06-27 10:15 ` Ian Campbell
  2012-06-28 14:14   ` Ian Jackson
  2012-06-28 13:50 ` Ian Jackson
  1 sibling, 1 reply; 5+ messages in thread
From: Ian Campbell @ 2012-06-27 10:15 UTC (permalink / raw)
  To: xen-devel; +Cc: Dario Faggioli, Ian Jackson


> Since there are currently no uses of this type there is no change to
> the generated code.

But for reference if I add Dario's numa info type:

diff -r 03b641aa89f9 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl	Wed Jun 27 11:05:57 2012 +0100
+++ b/tools/libxl/libxl_types.idl	Wed Jun 27 11:13:44 2012 +0100
@@ -423,6 +423,12 @@ libxl_physinfo = Struct("physinfo", [
     ("cap_hvm_directio", bool),
     ], dir=DIR_OUT)
 
+libxl_numainfo = Struct("numainfo", [
+    ("size", uint64),
+    ("free", uint64),
+    ("dists", Array(uint32, "num_dists")),
+    ], dir=DIR_OUT)
+
 libxl_cputopology = Struct("cputopology", [
     ("core", uint32),
     ("socket", uint32),

then I get the following diff to the generated files:

--- tools/libxl/_libxl_types.c.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/libxl/_libxl_types.c	2012-06-27 11:12:06.000000000 +0100
@@ -176,6 +176,12 @@ void libxl_physinfo_dispose(libxl_physin
     memset(p, LIBXL_DTOR_POISON, sizeof(*p));
 }
 
+void libxl_numainfo_dispose(libxl_numainfo *p)
+{
+    free(p->dists);
+    memset(p, LIBXL_DTOR_POISON, sizeof(*p));
+}
+
 void libxl_cputopology_dispose(libxl_cputopology *p)
 {
     memset(p, LIBXL_DTOR_POISON, sizeof(*p));
@@ -337,6 +343,11 @@ void libxl_physinfo_init(libxl_physinfo
     memset(p, '\0', sizeof(*p));
 }
 
+void libxl_numainfo_init(libxl_numainfo *p)
+{
+    memset(p, '\0', sizeof(*p));
+}
+
 void libxl_cputopology_init(libxl_cputopology *p)
 {
     memset(p, '\0', sizeof(*p));
@@ -2554,6 +2565,53 @@ char *libxl_physinfo_to_json(libxl_ctx *
     return libxl__object_to_json(ctx, "libxl_physinfo", (libxl__gen_json_callback)&libxl_physinfo_gen_json, (void *)p);
 }
 
+yajl_gen_status libxl_numainfo_gen_json(yajl_gen hand, libxl_numainfo *p)
+{
+    yajl_gen_status s;
+    s = yajl_gen_map_open(hand);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    s = yajl_gen_string(hand, (const unsigned char *)"size", sizeof("size")-1);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    s = yajl_gen_integer(hand, p->size);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    s = yajl_gen_string(hand, (const unsigned char *)"free", sizeof("free")-1);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    s = yajl_gen_integer(hand, p->free);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    s = yajl_gen_string(hand, (const unsigned char *)"dists", sizeof("dists")-1);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    {
+        int i;
+        s = yajl_gen_array_open(hand);
+        if (s != yajl_gen_status_ok)
+            goto out;
+        for (i=0; i<p->num_dists; i++) {
+            s = yajl_gen_integer(hand, p->dists[i]);
+            if (s != yajl_gen_status_ok)
+                goto out;
+        }
+        s = yajl_gen_array_close(hand);
+        if (s != yajl_gen_status_ok)
+            goto out;
+    }
+    s = yajl_gen_map_close(hand);
+    if (s != yajl_gen_status_ok)
+        goto out;
+    out:
+    return s;
+}
+
+char *libxl_numainfo_to_json(libxl_ctx *ctx, libxl_numainfo *p)
+{
+    return libxl__object_to_json(ctx, "libxl_numainfo", (libxl__gen_json_callback)&libxl_numainfo_gen_json, (void *)p);
+}
+
 yajl_gen_status libxl_cputopology_gen_json(yajl_gen hand, libxl_cputopology *p)
 {
     yajl_gen_status s;
--- tools/libxl/_libxl_types.h.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/libxl/_libxl_types.h	2012-06-27 11:12:06.000000000 +0100
@@ -475,6 +475,16 @@ void libxl_physinfo_dispose(libxl_physin
 void libxl_physinfo_init(libxl_physinfo *p);
 char *libxl_physinfo_to_json(libxl_ctx *ctx, libxl_physinfo *p);
 
+typedef struct libxl_numainfo {
+    uint64_t size;
+    uint64_t free;
+    int num_dists;
+    uint32_t * dists;
+} libxl_numainfo;
+void libxl_numainfo_dispose(libxl_numainfo *p);
+void libxl_numainfo_init(libxl_numainfo *p);
+char *libxl_numainfo_to_json(libxl_ctx *ctx, libxl_numainfo *p);
+
 typedef struct libxl_cputopology {
     uint32_t core;
     uint32_t socket;
--- tools/libxl/_libxl_types_json.h.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/libxl/_libxl_types_json.h	2012-06-27 11:12:06.000000000 +0100
@@ -40,6 +40,7 @@ yajl_gen_status libxl_diskinfo_gen_json(
 yajl_gen_status libxl_nicinfo_gen_json(yajl_gen hand, libxl_nicinfo *p);
 yajl_gen_status libxl_vcpuinfo_gen_json(yajl_gen hand, libxl_vcpuinfo *p);
 yajl_gen_status libxl_physinfo_gen_json(yajl_gen hand, libxl_physinfo *p);
+yajl_gen_status libxl_numainfo_gen_json(yajl_gen hand, libxl_numainfo *p);
 yajl_gen_status libxl_cputopology_gen_json(yajl_gen hand, libxl_cputopology *p);
 yajl_gen_status libxl_sched_credit_params_gen_json(yajl_gen hand, libxl_sched_credit_params *p);
 yajl_gen_status libxl_domain_remus_info_gen_json(yajl_gen hand, libxl_domain_remus_info *p);
--- tools/python/xen/lowlevel/xl/_pyxl_types.h.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/python/xen/lowlevel/xl/_pyxl_types.h	2012-06-27 11:12:09.000000000 +0100
@@ -268,6 +268,17 @@ _hidden int Pyphysinfo_Check(PyObject *s
 
 _hidden PyObject *attrib__libxl_hwcap_get(libxl_hwcap *hw_cap);
 
+/* Internal API for libxl_numainfo wrapper */
+typedef struct {
+    PyObject_HEAD;
+    libxl_numainfo obj;
+}Py_numainfo;
+
+_hidden Py_numainfo *Pynumainfo_New(void);
+
+_hidden int Pynumainfo_Check(PyObject *self);
+
+
 /* Internal API for libxl_cputopology wrapper */
 typedef struct {
     PyObject_HEAD;
--- tools/python/xen/lowlevel/xl/_pyxl_types.c.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/python/xen/lowlevel/xl/_pyxl_types.c	2012-06-27 11:12:09.000000000 +0100
@@ -3495,6 +3495,111 @@ int Pyphysinfo_Check(PyObject *self)
 {
     return (self->ob_type == &Pyphysinfo_Type);
 }
+/* Attribute get/set functions for libxl_numainfo */
+static PyObject *py_numainfo_size_get(Py_numainfo *self, void *priv)
+{
+    return genwrap__ull_get(self->obj.size);
+}
+
+static PyObject *py_numainfo_free_get(Py_numainfo *self, void *priv)
+{
+    return genwrap__ull_get(self->obj.free);
+}
+
+static PyObject *py_numainfo_dists_get(Py_numainfo *self, void *priv)
+{
+    PyErr_SetString(PyExc_NotImplementedError, "Getting libxl_numainfo");
+    return NULL;
+}
+
+static void Pynumainfo_dealloc(Py_numainfo *self)
+{
+    libxl_numainfo_dispose(&self->obj);
+    self->ob_type->tp_free((PyObject *)self);
+}
+
+static int Pynumainfo_init(Py_numainfo *self, PyObject *args, PyObject *kwds)
+{
+    memset(&self->obj, 0, sizeof(self->obj));
+    return genwrap__obj_init((PyObject *)self, args, kwds);
+}
+
+static PyObject *Pynumainfo_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    Py_numainfo *self = (Py_numainfo *)type->tp_alloc(type, 0);
+    if (self == NULL)
+        return NULL;
+    memset(&self->obj, 0, sizeof(self->obj));
+    return (PyObject *)self;
+}
+
+static PyGetSetDef Pynumainfo_getset[] = {
+    { .name = "size", 
+      .get = (getter)py_numainfo_size_get, 
+      .set = (setter)NULL,
+    },
+    { .name = "free", 
+      .get = (getter)py_numainfo_free_get, 
+      .set = (setter)NULL,
+    },
+    { .name = "dists", 
+      .get = (getter)py_numainfo_dists_get, 
+      .set = (setter)NULL,
+    },
+    { .name = NULL }
+};
+
+static PyTypeObject Pynumainfo_Type= {
+    PyObject_HEAD_INIT(NULL)
+    0,
+    PKG ".numainfo",
+    sizeof(Py_numainfo),
+    0,
+    (destructor)Pynumainfo_dealloc,     /* tp_dealloc        */
+    NULL,                         /* tp_print          */
+    NULL,                         /* tp_getattr        */
+    NULL,                         /* tp_setattr        */
+    NULL,                         /* tp_compare        */
+    NULL,                         /* tp_repr           */
+    NULL,                         /* tp_as_number      */
+    NULL,                         /* tp_as_sequence    */
+    NULL,                         /* tp_as_mapping     */
+    NULL,                         /* tp_hash           */
+    NULL,                         /* tp_call           */
+    NULL,                         /* tp_str            */
+    NULL,                         /* tp_getattro       */
+    NULL,                         /* tp_setattro       */
+    NULL,                         /* tp_as_buffer      */
+    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags          */
+    "numainfo",                         /* tp_doc            */
+    NULL,                         /* tp_traverse       */
+    NULL,                         /* tp_clear          */
+    NULL,                         /* tp_richcompare    */
+    0,                            /* tp_weaklistoffset */
+    NULL,                         /* tp_iter           */
+    NULL,                         /* tp_iternext       */
+    NULL,                         /* tp_methods        */
+    NULL,                         /* tp_members        */
+    Pynumainfo_getset,                  /* tp_getset         */
+    NULL,                         /* tp_base           */
+    NULL,                         /* tp_dict           */
+    NULL,                         /* tp_descr_get      */
+    NULL,                         /* tp_descr_set      */
+    0,                            /* tp_dictoffset     */
+    (initproc)Pynumainfo_init,          /* tp_init           */
+    NULL,                         /* tp_alloc          */
+    Pynumainfo_new,                     /* tp_new            */
+};
+
+Py_numainfo *Pynumainfo_New(void)
+{
+    return (Py_numainfo *)Pynumainfo_new(&Pynumainfo_Type, NULL, NULL);
+}
+
+int Pynumainfo_Check(PyObject *self)
+{
+    return (self->ob_type == &Pynumainfo_Type);
+}
 /* Attribute get/set functions for libxl_cputopology */
 static PyObject *py_cputopology_core_get(Py_cputopology *self, void *priv)
 {
@@ -4100,6 +4205,10 @@ void genwrap__init(PyObject *m)
         Py_INCREF(&Pyphysinfo_Type);
         PyModule_AddObject(m, "physinfo", (PyObject *)&Pyphysinfo_Type);
     }
+    if (PyType_Ready(&Pynumainfo_Type) >= 0) {
+        Py_INCREF(&Pynumainfo_Type);
+        PyModule_AddObject(m, "numainfo", (PyObject *)&Pynumainfo_Type);
+    }
     if (PyType_Ready(&Pycputopology_Type) >= 0) {
         Py_INCREF(&Pycputopology_Type);
         PyModule_AddObject(m, "cputopology", (PyObject *)&Pycputopology_Type);
--- tools/ocaml/libs/xl/_libxl_types.inc.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/ocaml/libs/xl/_libxl_types.inc	2012-06-27 11:12:11.000000000 +0100
@@ -1129,6 +1129,36 @@ static value Val_physinfo (caml_gc *gc,
 /* Stubs for physinfo */
 value stub_xl_physinfo_get(value v1);
 
+/* Convert numainfo to a caml value */
+static value Val_numainfo (caml_gc *gc, struct caml_logger *lg, libxl_numainfo *numainfo_c)
+{
+	CAMLparam0();
+	CAMLlocal1(numainfo_ocaml);
+	{
+		value numainfo_field;
+	
+		numainfo_ocaml = caml_alloc_tuple(3);
+	
+		numainfo_field = caml_copy_int64(numainfo_c->size);
+		Store_field(numainfo_ocaml, 0, numainfo_field);
+	
+		numainfo_field = caml_copy_int64(numainfo_c->free);
+		Store_field(numainfo_ocaml, 1, numainfo_field);
+	
+		{
+		    int i;
+		    value array_elem;
+		    numainfo_field = caml_alloc(numainfo_c->num_dists,0);
+		    for(i=0; i<numainfo_c->num_dists; i++) {
+		        array_elem = caml_copy_int32(numainfo_c->dists[i]);
+		        Store_field(numainfo_field, i, array_elem);
+		    }
+		}
+		Store_field(numainfo_ocaml, 2, numainfo_field);
+	}
+	CAMLreturn(numainfo_ocaml);
+}
+
 /* Convert cputopology to a caml value */
 static value Val_cputopology (caml_gc *gc, struct caml_logger *lg, libxl_cputopology *cputopology_c)
 {
--- tools/ocaml/libs/xl/_libxl_types.mli.in.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/ocaml/libs/xl/_libxl_types.mli.in	2012-06-27 11:12:11.000000000 +0100
@@ -312,6 +312,15 @@ module Physinfo : sig
 	external get : unit -> t = "stub_xl_physinfo_get"
 end
 
+module Numainfo : sig
+	type t =
+	{
+		size : int64;
+		free : int64;
+		dists : int32 array;
+	}
+end
+
 module Cputopology : sig
 	type t =
 	{
--- tools/ocaml/libs/xl/_libxl_types.ml.in.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/ocaml/libs/xl/_libxl_types.ml.in	2012-06-27 11:12:11.000000000 +0100
@@ -312,6 +312,15 @@ module Physinfo = struct
 	external get : unit -> t = "stub_xl_physinfo_get"
 end
 
+module Numainfo = struct
+	type t =
+	{
+		size : int64;
+		free : int64;
+		dists : int32 array;
+	}
+end
+
 module Cputopology = struct
 	type t =
 	{
--- tools/libxl/testidl.c.baseline	2012-06-27 10:08:58.000000000 +0100
+++ tools/libxl/testidl.c	2012-06-27 11:12:06.000000000 +0100
@@ -521,6 +521,20 @@ static void libxl_physinfo_rand_init(lib
     p->cap_hvm_directio = rand() % 2;
 }
 
+static void libxl_numainfo_rand_init(libxl_numainfo *p);
+static void libxl_numainfo_rand_init(libxl_numainfo *p)
+{
+    p->size = rand() % (sizeof(p->size)*8);
+    p->free = rand() % (sizeof(p->free)*8);
+    p->num_dists = rand()%8;
+    p->dists = calloc(p->num_dists, sizeof(*p->dists));
+    {
+        int i;
+        for (i=0; i<p->num_dists; i++)
+            p->dists[i] = rand() % (sizeof(p->dists[i])*8);
+    }
+}
+
 static void libxl_cputopology_rand_init(libxl_cputopology *p);
 static void libxl_cputopology_rand_init(libxl_cputopology *p)
 {
@@ -610,6 +624,7 @@ int main(int argc, char **argv)
     libxl_nicinfo libxl_nicinfo_val;
     libxl_vcpuinfo libxl_vcpuinfo_val;
     libxl_physinfo libxl_physinfo_val;
+    libxl_numainfo libxl_numainfo_val;
     libxl_cputopology libxl_cputopology_val;
     libxl_sched_credit_params libxl_sched_credit_params_val;
     libxl_domain_remus_info libxl_domain_remus_info_val;
@@ -842,6 +857,13 @@ int main(int argc, char **argv)
     free(s);
     libxl_physinfo_dispose(&libxl_physinfo_val);
 
+    libxl_numainfo_rand_init(&libxl_numainfo_val);
+    s = libxl_numainfo_to_json(ctx, &libxl_numainfo_val);
+    printf("%s: %s\n", "libxl_numainfo", s);
+    if (s == NULL) abort();
+    free(s);
+    libxl_numainfo_dispose(&libxl_numainfo_val);
+
     libxl_cputopology_rand_init(&libxl_cputopology_val);
     s = libxl_cputopology_to_json(ctx, &libxl_cputopology_val);
     printf("%s: %s\n", "libxl_cputopology", s);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: add a new Array type to the IDL
  2012-06-27 10:10 [PATCH] libxl: add a new Array type to the IDL Ian Campbell
  2012-06-27 10:15 ` Ian Campbell
@ 2012-06-28 13:50 ` Ian Jackson
  2012-06-28 14:20   ` Dario Faggioli
  1 sibling, 1 reply; 5+ messages in thread
From: Ian Jackson @ 2012-06-28 13:50 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Dario Faggioli, xen-devel

Ian Campbell writes ("[PATCH] libxl: add a new Array type to the IDL"):
> libxl: add a new Array type to the IDL
> 
> And make all the required infrastructure updates to enable this.
> 
> Since there are currently no uses of this type there is no change to
> the generated code.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Tested-by: Dario Faggioli <dario.faggioli@citrix.com>
> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Great, thanks.

Dario, I take it you'll pick this up into your series so I don't need
to apply it separately.

Ian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: add a new Array type to the IDL
  2012-06-27 10:15 ` Ian Campbell
@ 2012-06-28 14:14   ` Ian Jackson
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2012-06-28 14:14 UTC (permalink / raw)
  To: Ian Campbell; +Cc: Dario Faggioli, xen-devel

Ian Campbell writes ("Re: [Xen-devel] [PATCH] libxl: add a new Array type to the IDL"):
> > Since there are currently no uses of this type there is no change to
> > the generated code.
> 
> But for reference if I add Dario's numa info type:

Thanks for providing that.  That's what I was looking at before and it
looked reasonable then.  I'm happy with it now too.

Ian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: add a new Array type to the IDL
  2012-06-28 13:50 ` Ian Jackson
@ 2012-06-28 14:20   ` Dario Faggioli
  0 siblings, 0 replies; 5+ messages in thread
From: Dario Faggioli @ 2012-06-28 14:20 UTC (permalink / raw)
  To: Ian Jackson; +Cc: Ian Campbell, xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 673 bytes --]

On Thu, 2012-06-28 at 14:50 +0100, Ian Jackson wrote:
> > Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> > Tested-by: Dario Faggioli <dario.faggioli@citrix.com>
> > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
> 
> Great, thanks.
> 
> Dario, I take it you'll pick this up into your series so I don't need
> to apply it separately.
> 
That's fine.

Thanks and Regards,
Dario

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-28 14:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-27 10:10 [PATCH] libxl: add a new Array type to the IDL Ian Campbell
2012-06-27 10:15 ` Ian Campbell
2012-06-28 14:14   ` Ian Jackson
2012-06-28 13:50 ` Ian Jackson
2012-06-28 14:20   ` Dario Faggioli

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.