direct-io.hg

changeset 15427:4ab9e4bbd61b

Add new sysctl to return runtime information about physical CPU utilization.

Signed-off-by: Steven Hadn <steven@xensource.com>
author Steven Hand <steven@xensource.com>
date Wed Jun 27 21:01:08 2007 +0100 (2007-06-27)
parents 9590c9b48e07
children f152e44325a7
files tools/libxc/xc_misc.c tools/libxc/xenctrl.h xen/common/schedule.c xen/common/sysctl.c xen/include/public/sysctl.h
line diff
     1.1 --- a/tools/libxc/xc_misc.c	Wed Jun 27 20:56:25 2007 +0100
     1.2 +++ b/tools/libxc/xc_misc.c	Wed Jun 27 21:01:08 2007 +0100
     1.3 @@ -109,6 +109,25 @@ int xc_perfc_control(int xc_handle,
     1.4      return rc;
     1.5  }
     1.6  
     1.7 +int xc_cpuinfo(int xc_handle, int max_cpus, uint64_t *info, int *nr_cpus)
     1.8 +{
     1.9 +    int ret;
    1.10 +    DECLARE_SYSCTL;
    1.11 +
    1.12 +    sysctl.cmd = XEN_SYSCTL_cpuinfo;
    1.13 +    sysctl.u.cpuinfo.max_cpus = max_cpus; 
    1.14 +    set_xen_guest_handle(sysctl.u.cpuinfo.buffer, info); 
    1.15 +
    1.16 +    if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
    1.17 +        return ret;
    1.18 +
    1.19 +    if(nr_cpus) 
    1.20 +        *nr_cpus = sysctl.u.cpuinfo.nr_cpus; 
    1.21 +
    1.22 +    return 0;
    1.23 +}
    1.24 +
    1.25 +
    1.26  int xc_hvm_set_pci_intx_level(
    1.27      int xc_handle, domid_t dom,
    1.28      uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
     2.1 --- a/tools/libxc/xenctrl.h	Wed Jun 27 20:56:25 2007 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Wed Jun 27 21:01:08 2007 +0100
     2.3 @@ -479,6 +479,8 @@ int xc_physinfo(int xc_handle,
     2.4  int xc_sched_id(int xc_handle,
     2.5                  int *sched_id);
     2.6  
     2.7 +int xc_cpuinfo(int xc_handle, int max_cpus, uint64_t *info, int *nr_cpus); 
     2.8 +
     2.9  int xc_domain_setmaxmem(int xc_handle,
    2.10                          uint32_t domid,
    2.11                          unsigned int max_memkb);
     3.1 --- a/xen/common/schedule.c	Wed Jun 27 20:56:25 2007 +0100
     3.2 +++ b/xen/common/schedule.c	Wed Jun 27 21:01:08 2007 +0100
     3.3 @@ -72,8 +72,12 @@ static inline void vcpu_runstate_change(
     3.4      ASSERT(v->runstate.state != new_state);
     3.5      ASSERT(spin_is_locked(&per_cpu(schedule_data,v->processor).schedule_lock));
     3.6  
     3.7 -    v->runstate.time[v->runstate.state] +=
     3.8 -        new_entry_time - v->runstate.state_entry_time;
     3.9 +    if(unlikely((v->runstate.state_entry_time - new_entry_time) > TIME_SLOP))
    3.10 +        /* Local time on this CPU has been warped */
    3.11 +        v->runstate.time[v->runstate.state] = new_entry_time; 
    3.12 +    else 
    3.13 +        v->runstate.time[v->runstate.state] +=
    3.14 +            new_entry_time - v->runstate.state_entry_time;
    3.15      v->runstate.state_entry_time = new_entry_time;
    3.16      v->runstate.state = new_state;
    3.17  }
     4.1 --- a/xen/common/sysctl.c	Wed Jun 27 20:56:25 2007 +0100
     4.2 +++ b/xen/common/sysctl.c	Wed Jun 27 21:01:08 2007 +0100
     4.3 @@ -136,6 +136,38 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
     4.4      }
     4.5      break;
     4.6  
     4.7 +    case XEN_SYSCTL_cpuinfo:
     4.8 +    {
     4.9 +        uint32_t i, nr_cpus;
    4.10 +        uint64_t idletime;
    4.11 +
    4.12 +        nr_cpus = (op->u.cpuinfo.max_cpus > NR_CPUS) ? NR_CPUS :
    4.13 +            op->u.cpuinfo.max_cpus;
    4.14 +
    4.15 +        for ( i = 0; i < nr_cpus; i++ )
    4.16 +        {
    4.17 +            if(!idle_vcpu[i])
    4.18 +                /* XXX: assumes no further CPUs after first missing one */
    4.19 +                break;
    4.20 +
    4.21 +            /* somewhat imprecise but should suffice */
    4.22 +            idletime = idle_vcpu[i]->runstate.time[RUNSTATE_running] +
    4.23 +                (NOW() - idle_vcpu[i]->runstate.state_entry_time);
    4.24 +            if ( copy_to_guest_offset(op->u.cpuinfo.buffer, i, &idletime, 1) )
    4.25 +            {
    4.26 +                ret = -EFAULT;
    4.27 +                break;
    4.28 +            }
    4.29 +        }
    4.30 +
    4.31 +        op->u.cpuinfo.nr_cpus = i;
    4.32 +        ret = 0;
    4.33 +
    4.34 +        if( copy_to_guest (u_sysctl, op, 1) )
    4.35 +            ret = -EFAULT;
    4.36 +    }
    4.37 +    break;
    4.38 +
    4.39      default:
    4.40          ret = arch_do_sysctl(op, u_sysctl);
    4.41          break;
     5.1 --- a/xen/include/public/sysctl.h	Wed Jun 27 20:56:25 2007 +0100
     5.2 +++ b/xen/include/public/sysctl.h	Wed Jun 27 21:01:08 2007 +0100
     5.3 @@ -152,6 +152,18 @@ struct xen_sysctl_debug_keys {
     5.4  typedef struct xen_sysctl_debug_keys xen_sysctl_debug_keys_t;
     5.5  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_debug_keys_t);
     5.6  
     5.7 +/* Get physical CPU information */
     5.8 +#define XEN_SYSCTL_cpuinfo           8
     5.9 +struct xen_sysctl_cpuinfo {
    5.10 +    /* IN variables. */
    5.11 +    uint32_t                      max_cpus;
    5.12 +    XEN_GUEST_HANDLE_64(uint64_t) buffer;
    5.13 +    /* IN/OUT variables. */
    5.14 +    uint32_t                      nr_cpus;
    5.15 +}; 
    5.16 +typedef struct xen_sysctl_cpuinfo xen_sysctl_cpuinfo_t;
    5.17 +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpuinfo_t); 
    5.18 +
    5.19  struct xen_sysctl {
    5.20      uint32_t cmd;
    5.21      uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
    5.22 @@ -163,6 +175,7 @@ struct xen_sysctl {
    5.23          struct xen_sysctl_perfc_op          perfc_op;
    5.24          struct xen_sysctl_getdomaininfolist getdomaininfolist;
    5.25          struct xen_sysctl_debug_keys        debug_keys;
    5.26 +        struct xen_sysctl_cpuinfo           cpuinfo;
    5.27          uint8_t                             pad[128];
    5.28      } u;
    5.29  };