direct-io.hg

changeset 7397:fa0faada967b

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@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Oct 17 11:36:36 2005 +0100 (2005-10-17)
parents 9b51e7637676
children 446aa56ca4fe
files tools/libxc/xc_core.c tools/libxc/xc_domain.c tools/libxc/xenctrl.h tools/python/xen/lowlevel/xc/xc.c tools/xenstat/libxenstat/src/xenstat.c xen/common/dom0_ops.c xen/include/public/dom0_ops.h
line diff
     1.1 --- a/tools/libxc/xc_core.c	Sun Oct 16 17:25:15 2005 +0100
     1.2 +++ b/tools/libxc/xc_core.c	Mon Oct 17 11:36:36 2005 +0100
     1.3 @@ -33,10 +33,10 @@ xc_domain_dumpcore(int xc_handle,
     1.4      unsigned long nr_pages;
     1.5      unsigned long *page_array;
     1.6      xc_dominfo_t info;
     1.7 -    int i, j, dump_fd;
     1.8 +    int i, nr_vcpus = 0, dump_fd;
     1.9      char *dump_mem, *dump_mem_start = NULL;
    1.10      struct xc_core_header header;
    1.11 -    vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    1.12 +    vcpu_guest_context_t  ctxt[MAX_VIRT_CPUS];
    1.13  
    1.14   
    1.15      if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
    1.16 @@ -54,24 +54,25 @@ xc_domain_dumpcore(int xc_handle,
    1.17          goto error_out;
    1.18      }
    1.19   
    1.20 -    for (i = 0, j = 0; i < 32; i++)
    1.21 -        if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j]) == 0)
    1.22 -            j++;
    1.23 +    for (i = 0; i < info.max_vcpu_id; i++)
    1.24 +        if (xc_domain_get_vcpu_context(xc_handle, domid,
    1.25 +                                       i, &ctxt[nr_vcpus]) == 0)
    1.26 +            nr_vcpus++;
    1.27   
    1.28      nr_pages = info.nr_pages;
    1.29  
    1.30      header.xch_magic = 0xF00FEBED; 
    1.31 -    header.xch_nr_vcpus = info.vcpus;
    1.32 +    header.xch_nr_vcpus = nr_vcpus;
    1.33      header.xch_nr_pages = nr_pages;
    1.34      header.xch_ctxt_offset = sizeof(struct xc_core_header);
    1.35      header.xch_index_offset = sizeof(struct xc_core_header) +
    1.36 -        sizeof(vcpu_guest_context_t)*info.vcpus;
    1.37 +        sizeof(vcpu_guest_context_t)*nr_vcpus;
    1.38      header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
    1.39 -                                         (sizeof(vcpu_guest_context_t) * info.vcpus) + 
    1.40 +                                         (sizeof(vcpu_guest_context_t) * nr_vcpus) +
    1.41                                           (nr_pages * sizeof(unsigned long)));
    1.42  
    1.43      write(dump_fd, &header, sizeof(struct xc_core_header));
    1.44 -    write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
    1.45 +    write(dump_fd, &ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.46  
    1.47      if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
    1.48          printf("Could not allocate memory\n");
     2.1 --- a/tools/libxc/xc_domain.c	Sun Oct 16 17:25:15 2005 +0100
     2.2 +++ b/tools/libxc/xc_domain.c	Mon Oct 17 11:36:36 2005 +0100
     2.3 @@ -113,7 +113,8 @@ int xc_domain_getinfo(int xc_handle,
     2.4          info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
     2.5          info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
     2.6          info->cpu_time = op.u.getdomaininfo.cpu_time;
     2.7 -        info->vcpus = op.u.getdomaininfo.n_vcpu;
     2.8 +        info->nr_online_vcpus = op.u.getdomaininfo.nr_online_vcpus;
     2.9 +        info->max_vcpu_id = op.u.getdomaininfo.max_vcpu_id;
    2.10  
    2.11          memcpy(info->handle, op.u.getdomaininfo.handle,
    2.12                 sizeof(xen_domain_handle_t));
    2.13 @@ -344,6 +345,25 @@ int xc_domain_sethandle(int xc_handle, u
    2.14      return do_dom0_op(xc_handle, &op);
    2.15  }
    2.16  
    2.17 +int xc_domain_get_vcpu_info(int xc_handle,
    2.18 +                            uint32_t domid,
    2.19 +                            uint32_t vcpu,
    2.20 +                            xc_vcpuinfo_t *info)
    2.21 +{
    2.22 +    int rc;
    2.23 +    dom0_op_t op;
    2.24 +
    2.25 +    op.cmd = DOM0_GETVCPUINFO;
    2.26 +    op.u.getvcpuinfo.domain = (domid_t)domid;
    2.27 +    op.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
    2.28 +
    2.29 +    rc = do_dom0_op(xc_handle, &op);
    2.30 +
    2.31 +    memcpy(info, &op.u.getvcpuinfo, sizeof(*info));
    2.32 +
    2.33 +    return rc;
    2.34 +}
    2.35 +
    2.36  /*
    2.37   * Local variables:
    2.38   * mode: C
     3.1 --- a/tools/libxc/xenctrl.h	Sun Oct 16 17:25:15 2005 +0100
     3.2 +++ b/tools/libxc/xenctrl.h	Mon Oct 17 11:36:36 2005 +0100
     3.3 @@ -132,7 +132,8 @@ typedef struct {
     3.4      unsigned long shared_info_frame;
     3.5      uint64_t      cpu_time;
     3.6      unsigned long max_memkb;
     3.7 -    unsigned int  vcpus;
     3.8 +    unsigned int  nr_online_vcpus;
     3.9 +    unsigned int  max_vcpu_id;
    3.10      xen_domain_handle_t handle;
    3.11  } xc_dominfo_t;
    3.12  
    3.13 @@ -250,6 +251,13 @@ int xc_domain_get_vcpu_context(int xc_ha
    3.14                                 uint32_t vcpu,
    3.15                                 vcpu_guest_context_t *ctxt);
    3.16  
    3.17 +typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
    3.18 +int xc_domain_get_vcpu_info(int xc_handle,
    3.19 +                            uint32_t domid,
    3.20 +                            uint32_t vcpu,
    3.21 +                            xc_vcpuinfo_t *info);
    3.22 +
    3.23 +
    3.24  int xc_domain_setcpuweight(int xc_handle,
    3.25                             uint32_t domid,
    3.26                             float weight);
     4.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Sun Oct 16 17:25:15 2005 +0100
     4.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Mon Oct 17 11:36:36 2005 +0100
     4.3 @@ -317,10 +317,13 @@ static PyObject *pyxc_domain_getinfo(PyO
     4.4          PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
     4.5          for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
     4.6              PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
     4.7 -        info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
     4.8 +        info_dict = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
     4.9                                    ",s:l,s:L,s:l,s:i,s:i}",
    4.10                                    "dom",       info[i].domid,
    4.11 -                                  "vcpus",     info[i].vcpus,
    4.12 +                                  /* XXX 'vcpus' field is obsolete! */
    4.13 +                                  "vcpus",     info[i].nr_online_vcpus,
    4.14 +                                  "online_vcpus", info[i].nr_online_vcpus,
    4.15 +                                  "max_vcpu_id", info[i].max_vcpu_id,
    4.16                                    "dying",     info[i].dying,
    4.17                                    "crashed",   info[i].crashed,
    4.18                                    "shutdown",  info[i].shutdown,
    4.19 @@ -341,6 +344,38 @@ static PyObject *pyxc_domain_getinfo(PyO
    4.20      return list;
    4.21  }
    4.22  
    4.23 +static PyObject *pyxc_vcpu_getinfo(PyObject *self,
    4.24 +                                   PyObject *args,
    4.25 +                                   PyObject *kwds)
    4.26 +{
    4.27 +    XcObject *xc = (XcObject *)self;
    4.28 +    PyObject *info_dict;
    4.29 +
    4.30 +    uint32_t dom, vcpu = 0;
    4.31 +    xc_vcpuinfo_t info;
    4.32 +    int rc;
    4.33 +
    4.34 +    static char *kwd_list[] = { "dom", "vcpu", NULL };
    4.35 +    
    4.36 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
    4.37 +                                      &dom, &vcpu) )
    4.38 +        return NULL;
    4.39 +
    4.40 +    rc = xc_domain_get_vcpu_info(xc->xc_handle, dom, vcpu, &info);
    4.41 +    if ( rc < 0 )
    4.42 +        return PyErr_SetFromErrno(xc_error);
    4.43 +
    4.44 +    info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i,s:i,s:i}",
    4.45 +                              "online",   info.online,
    4.46 +                              "blocked",  info.blocked,
    4.47 +                              "running",  info.running,
    4.48 +                              "cpu_time", info.cpu_time,
    4.49 +                              "cpu",      info.cpu,
    4.50 +                              "cpumap",   info.cpumap);
    4.51 +
    4.52 +    return info_dict;
    4.53 +}
    4.54 +
    4.55  static PyObject *pyxc_linux_build(PyObject *self,
    4.56                                    PyObject *args,
    4.57                                    PyObject *kwds)
    4.58 @@ -948,6 +983,20 @@ static PyMethodDef pyxc_methods[] = {
    4.59        "reason why it shut itself down.\n" 
    4.60        " vcpu_to_cpu [[int]]: List that maps VCPUS to CPUS\n" },
    4.61  
    4.62 +    { "vcpu_getinfo", 
    4.63 +      (PyCFunction)pyxc_vcpu_getinfo, 
    4.64 +      METH_VARARGS | METH_KEYWORDS, "\n"
    4.65 +      "Get information regarding a VCPU.\n"
    4.66 +      " dom  [int]:    Domain to retrieve info about.\n"
    4.67 +      " vcpu [int, 0]: VCPU to retrieve info about.\n\n"
    4.68 +      "Returns: [dict]\n"
    4.69 +      " online   [int]:  Bool - Is this VCPU currently online?\n"
    4.70 +      " blocked  [int]:  Bool - Is this VCPU blocked waiting for an event?\n"
    4.71 +      " running  [int]:  Bool - Is this VCPU currently running on a CPU?\n"
    4.72 +      " cpu_time [long]: CPU time consumed, in nanoseconds\n"
    4.73 +      " cpumap   [int]:  Bitmap of CPUs this VCPU can run on\n"
    4.74 +      " cpu      [int]:  CPU that this VCPU is currently bound to\n" },
    4.75 +
    4.76      { "linux_build", 
    4.77        (PyCFunction)pyxc_linux_build, 
    4.78        METH_VARARGS | METH_KEYWORDS, "\n"
     5.1 --- a/tools/xenstat/libxenstat/src/xenstat.c	Sun Oct 16 17:25:15 2005 +0100
     5.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Mon Oct 17 11:36:36 2005 +0100
     5.3 @@ -229,7 +229,7 @@ xenstat_node *xenstat_get_node(xenstat_h
     5.4  			domain->id = domaininfo[i].domain;
     5.5  			domain->state = domaininfo[i].flags;
     5.6  			domain->cpu_ns = domaininfo[i].cpu_time;
     5.7 -			domain->num_vcpus = domaininfo[i].n_vcpu;
     5.8 +			domain->num_vcpus = domaininfo[i].nr_online_vcpus;
     5.9  			domain->vcpus = NULL;
    5.10  			domain->cur_mem =
    5.11  			    ((unsigned long long)domaininfo[i].tot_pages)
     6.1 --- a/xen/common/dom0_ops.c	Sun Oct 16 17:25:15 2005 +0100
     6.2 +++ b/xen/common/dom0_ops.c	Mon Oct 17 11:36:36 2005 +0100
     6.3 @@ -43,10 +43,10 @@ static void getdomaininfo(struct domain 
     6.4  {
     6.5      struct vcpu   *v;
     6.6      u64 cpu_time = 0;
     6.7 -    int vcpu_count = 0;
     6.8      int flags = DOMFLAGS_BLOCKED;
     6.9      
    6.10      info->domain = d->domain_id;
    6.11 +    info->nr_online_vcpus = 0;
    6.12      
    6.13      /* 
    6.14       * - domain is marked as blocked only if all its vcpus are blocked
    6.15 @@ -54,18 +54,18 @@ static void getdomaininfo(struct domain 
    6.16       */
    6.17      for_each_vcpu ( d, v ) {
    6.18          cpu_time += v->cpu_time;
    6.19 +        info->max_vcpu_id = v->vcpu_id;
    6.20          if ( !test_bit(_VCPUF_down, &v->vcpu_flags) )
    6.21          {
    6.22              if ( !(v->vcpu_flags & VCPUF_blocked) )
    6.23                  flags &= ~DOMFLAGS_BLOCKED;
    6.24              if ( v->vcpu_flags & VCPUF_running )
    6.25                  flags |= DOMFLAGS_RUNNING;
    6.26 -            vcpu_count++;
    6.27 +            info->nr_online_vcpus++;
    6.28          }
    6.29      }
    6.30      
    6.31      info->cpu_time = cpu_time;
    6.32 -    info->n_vcpu = vcpu_count;
    6.33      
    6.34      info->flags = flags |
    6.35          ((d->domain_flags & DOMF_dying)      ? DOMFLAGS_DYING    : 0) |
     7.1 --- a/xen/include/public/dom0_ops.h	Sun Oct 16 17:25:15 2005 +0100
     7.2 +++ b/xen/include/public/dom0_ops.h	Mon Oct 17 11:36:36 2005 +0100
     7.3 @@ -88,7 +88,8 @@ typedef struct {
     7.4      unsigned long max_pages;
     7.5      unsigned long shared_info_frame;       /* MFN of shared_info struct */
     7.6      uint64_t cpu_time;
     7.7 -    uint32_t n_vcpu;
     7.8 +    uint32_t nr_online_vcpus;     /* Number of VCPUs currently online. */
     7.9 +    uint32_t max_vcpu_id;         /* Maximum VCPUID in use by this domain. */
    7.10      uint32_t ssidref;
    7.11      xen_domain_handle_t handle;
    7.12  } dom0_getdomaininfo_t;