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

[Xen-changelog] Plumb GETVCPUINFO dom0_op through to Python. Remove



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID fa0faada967bfc34cfc3626bc44a6a183e9206f3
# Parent  9b51e7637676902aa9cd4a259e04655246e9dfea
Plumb GETVCPUINFO dom0_op through to Python. Remove
n_vcpu field from GETDOMAININFO: replaced with
nr_online_vcpus and max_vcpu_id (both plumbed through to
Python).

TODO: Remove 'vcpus' entry in getdomaininfo Python
      dictionary.

TODO: Don't represent 'cpumap' as a bitmap in Python.
      It would be more sensible to represent as a list
      of integer CPU numbers.

Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r 9b51e7637676 -r fa0faada967b tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Sun Oct 16 16:25:15 2005
+++ b/tools/libxc/xc_core.c     Mon Oct 17 10:36:36 2005
@@ -33,10 +33,10 @@
     unsigned long nr_pages;
     unsigned long *page_array;
     xc_dominfo_t info;
-    int i, j, dump_fd;
+    int i, nr_vcpus = 0, dump_fd;
     char *dump_mem, *dump_mem_start = NULL;
     struct xc_core_header header;
-    vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
+    vcpu_guest_context_t  ctxt[MAX_VIRT_CPUS];
 
  
     if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
@@ -54,24 +54,25 @@
         goto error_out;
     }
  
-    for (i = 0, j = 0; i < 32; i++)
-        if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j]) == 0)
-            j++;
+    for (i = 0; i < info.max_vcpu_id; i++)
+        if (xc_domain_get_vcpu_context(xc_handle, domid,
+                                       i, &ctxt[nr_vcpus]) == 0)
+            nr_vcpus++;
  
     nr_pages = info.nr_pages;
 
     header.xch_magic = 0xF00FEBED; 
-    header.xch_nr_vcpus = info.vcpus;
+    header.xch_nr_vcpus = nr_vcpus;
     header.xch_nr_pages = nr_pages;
     header.xch_ctxt_offset = sizeof(struct xc_core_header);
     header.xch_index_offset = sizeof(struct xc_core_header) +
-        sizeof(vcpu_guest_context_t)*info.vcpus;
+        sizeof(vcpu_guest_context_t)*nr_vcpus;
     header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
-                                         (sizeof(vcpu_guest_context_t) * 
info.vcpus) + 
+                                         (sizeof(vcpu_guest_context_t) * 
nr_vcpus) +
                                          (nr_pages * sizeof(unsigned long)));
 
     write(dump_fd, &header, sizeof(struct xc_core_header));
-    write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
+    write(dump_fd, &ctxt, sizeof(ctxt[0]) * nr_vcpus);
 
     if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
         printf("Could not allocate memory\n");
diff -r 9b51e7637676 -r fa0faada967b tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Sun Oct 16 16:25:15 2005
+++ b/tools/libxc/xc_domain.c   Mon Oct 17 10:36:36 2005
@@ -113,7 +113,8 @@
         info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
         info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
         info->cpu_time = op.u.getdomaininfo.cpu_time;
-        info->vcpus = op.u.getdomaininfo.n_vcpu;
+        info->nr_online_vcpus = op.u.getdomaininfo.nr_online_vcpus;
+        info->max_vcpu_id = op.u.getdomaininfo.max_vcpu_id;
 
         memcpy(info->handle, op.u.getdomaininfo.handle,
                sizeof(xen_domain_handle_t));
@@ -344,6 +345,25 @@
     return do_dom0_op(xc_handle, &op);
 }
 
+int xc_domain_get_vcpu_info(int xc_handle,
+                            uint32_t domid,
+                            uint32_t vcpu,
+                            xc_vcpuinfo_t *info)
+{
+    int rc;
+    dom0_op_t op;
+
+    op.cmd = DOM0_GETVCPUINFO;
+    op.u.getvcpuinfo.domain = (domid_t)domid;
+    op.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
+
+    rc = do_dom0_op(xc_handle, &op);
+
+    memcpy(info, &op.u.getvcpuinfo, sizeof(*info));
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 9b51e7637676 -r fa0faada967b tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Sun Oct 16 16:25:15 2005
+++ b/tools/libxc/xenctrl.h     Mon Oct 17 10:36:36 2005
@@ -132,7 +132,8 @@
     unsigned long shared_info_frame;
     uint64_t      cpu_time;
     unsigned long max_memkb;
-    unsigned int  vcpus;
+    unsigned int  nr_online_vcpus;
+    unsigned int  max_vcpu_id;
     xen_domain_handle_t handle;
 } xc_dominfo_t;
 
@@ -249,6 +250,13 @@
                                uint32_t domid,
                                uint32_t vcpu,
                                vcpu_guest_context_t *ctxt);
+
+typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
+int xc_domain_get_vcpu_info(int xc_handle,
+                            uint32_t domid,
+                            uint32_t vcpu,
+                            xc_vcpuinfo_t *info);
+
 
 int xc_domain_setcpuweight(int xc_handle,
                            uint32_t domid,
diff -r 9b51e7637676 -r fa0faada967b tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Sun Oct 16 16:25:15 2005
+++ b/tools/python/xen/lowlevel/xc/xc.c Mon Oct 17 10:36:36 2005
@@ -317,10 +317,13 @@
         PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
         for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
             PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
-        info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
+        info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
                                   ",s:l,s:L,s:l,s:i,s:i}",
                                   "dom",       info[i].domid,
-                                  "vcpus",     info[i].vcpus,
+                                  /* XXX 'vcpus' field is obsolete! */
+                                  "vcpus",     info[i].nr_online_vcpus,
+                                  "online_vcpus", info[i].nr_online_vcpus,
+                                  "max_vcpu_id", info[i].max_vcpu_id,
                                   "dying",     info[i].dying,
                                   "crashed",   info[i].crashed,
                                   "shutdown",  info[i].shutdown,
@@ -339,6 +342,38 @@
     free(info);
 
     return list;
+}
+
+static PyObject *pyxc_vcpu_getinfo(PyObject *self,
+                                   PyObject *args,
+                                   PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+    PyObject *info_dict;
+
+    uint32_t dom, vcpu = 0;
+    xc_vcpuinfo_t info;
+    int rc;
+
+    static char *kwd_list[] = { "dom", "vcpu", NULL };
+    
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
+                                      &dom, &vcpu) )
+        return NULL;
+
+    rc = xc_domain_get_vcpu_info(xc->xc_handle, dom, vcpu, &info);
+    if ( rc < 0 )
+        return PyErr_SetFromErrno(xc_error);
+
+    info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i,s:i,s:i}",
+                              "online",   info.online,
+                              "blocked",  info.blocked,
+                              "running",  info.running,
+                              "cpu_time", info.cpu_time,
+                              "cpu",      info.cpu,
+                              "cpumap",   info.cpumap);
+
+    return info_dict;
 }
 
 static PyObject *pyxc_linux_build(PyObject *self,
@@ -948,6 +983,20 @@
       "reason why it shut itself down.\n" 
       " vcpu_to_cpu [[int]]: List that maps VCPUS to CPUS\n" },
 
+    { "vcpu_getinfo", 
+      (PyCFunction)pyxc_vcpu_getinfo, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Get information regarding a VCPU.\n"
+      " dom  [int]:    Domain to retrieve info about.\n"
+      " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
+      "Returns: [dict]\n"
+      " online   [int]:  Bool - Is this VCPU currently online?\n"
+      " blocked  [int]:  Bool - Is this VCPU blocked waiting for an event?\n"
+      " running  [int]:  Bool - Is this VCPU currently running on a CPU?\n"
+      " cpu_time [long]: CPU time consumed, in nanoseconds\n"
+      " cpumap   [int]:  Bitmap of CPUs this VCPU can run on\n"
+      " cpu      [int]:  CPU that this VCPU is currently bound to\n" },
+
     { "linux_build", 
       (PyCFunction)pyxc_linux_build, 
       METH_VARARGS | METH_KEYWORDS, "\n"
diff -r 9b51e7637676 -r fa0faada967b tools/xenstat/libxenstat/src/xenstat.c
--- a/tools/xenstat/libxenstat/src/xenstat.c    Sun Oct 16 16:25:15 2005
+++ b/tools/xenstat/libxenstat/src/xenstat.c    Mon Oct 17 10:36:36 2005
@@ -229,7 +229,7 @@
                        domain->id = domaininfo[i].domain;
                        domain->state = domaininfo[i].flags;
                        domain->cpu_ns = domaininfo[i].cpu_time;
-                       domain->num_vcpus = domaininfo[i].n_vcpu;
+                       domain->num_vcpus = domaininfo[i].nr_online_vcpus;
                        domain->vcpus = NULL;
                        domain->cur_mem =
                            ((unsigned long long)domaininfo[i].tot_pages)
diff -r 9b51e7637676 -r fa0faada967b xen/common/dom0_ops.c
--- a/xen/common/dom0_ops.c     Sun Oct 16 16:25:15 2005
+++ b/xen/common/dom0_ops.c     Mon Oct 17 10:36:36 2005
@@ -43,10 +43,10 @@
 {
     struct vcpu   *v;
     u64 cpu_time = 0;
-    int vcpu_count = 0;
     int flags = DOMFLAGS_BLOCKED;
     
     info->domain = d->domain_id;
+    info->nr_online_vcpus = 0;
     
     /* 
      * - domain is marked as blocked only if all its vcpus are blocked
@@ -54,18 +54,18 @@
      */
     for_each_vcpu ( d, v ) {
         cpu_time += v->cpu_time;
+        info->max_vcpu_id = v->vcpu_id;
         if ( !test_bit(_VCPUF_down, &v->vcpu_flags) )
         {
             if ( !(v->vcpu_flags & VCPUF_blocked) )
                 flags &= ~DOMFLAGS_BLOCKED;
             if ( v->vcpu_flags & VCPUF_running )
                 flags |= DOMFLAGS_RUNNING;
-            vcpu_count++;
+            info->nr_online_vcpus++;
         }
     }
     
     info->cpu_time = cpu_time;
-    info->n_vcpu = vcpu_count;
     
     info->flags = flags |
         ((d->domain_flags & DOMF_dying)      ? DOMFLAGS_DYING    : 0) |
diff -r 9b51e7637676 -r fa0faada967b xen/include/public/dom0_ops.h
--- a/xen/include/public/dom0_ops.h     Sun Oct 16 16:25:15 2005
+++ b/xen/include/public/dom0_ops.h     Mon Oct 17 10:36:36 2005
@@ -88,7 +88,8 @@
     unsigned long max_pages;
     unsigned long shared_info_frame;       /* MFN of shared_info struct */
     uint64_t cpu_time;
-    uint32_t n_vcpu;
+    uint32_t nr_online_vcpus;     /* Number of VCPUs currently online. */
+    uint32_t max_vcpu_id;         /* Maximum VCPUID in use by this domain. */
     uint32_t ssidref;
     xen_domain_handle_t handle;
 } dom0_getdomaininfo_t;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.