ia64/xen-unstable

changeset 16203:4393255607be

x86, dom0: Allow get idle time stats by mask.
Signed-off-by: Kevin Tian <kevin.tian@intel.com>
author Keir Fraser <keir@xensource.com>
date Wed Oct 24 10:49:03 2007 +0100 (2007-10-24)
parents c05ec22a9106
children eb786950169c
files xen/arch/x86/platform_hypercall.c xen/include/public/platform.h
line diff
     1.1 --- a/xen/arch/x86/platform_hypercall.c	Wed Oct 24 10:20:03 2007 +0100
     1.2 +++ b/xen/arch/x86/platform_hypercall.c	Wed Oct 24 10:49:03 2007 +0100
     1.3 @@ -293,34 +293,44 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
     1.4  
     1.5      case XENPF_getidletime:
     1.6      {
     1.7 -        uint32_t i, nr_cpus;
     1.8 -        uint64_t idletime;
     1.9 +        uint32_t cpu;
    1.10 +        uint64_t idletime, now = NOW();
    1.11          struct vcpu *v;
    1.12 +        struct xenctl_cpumap ctlmap;
    1.13 +        cpumask_t cpumap;
    1.14          XEN_GUEST_HANDLE(uint64_t) idletimes;
    1.15  
    1.16          ret = -ENOSYS;
    1.17          if ( cpufreq_controller != FREQCTL_dom0_kernel )
    1.18              break;
    1.19  
    1.20 +        memset(&ctlmap, 0, sizeof(ctlmap));
    1.21 +        ctlmap.nr_cpus  = op->u.getidletime.cpumap_nr_cpus;
    1.22 +        ctlmap.bitmap.p = op->u.getidletime.cpumap_bitmap.p;
    1.23 +        xenctl_cpumap_to_cpumask(&cpumap, &ctlmap);
    1.24          guest_from_compat_handle(idletimes, op->u.getidletime.idletime);
    1.25 -        nr_cpus = min_t(uint32_t, op->u.getidletime.max_cpus, NR_CPUS);
    1.26  
    1.27 -        for ( i = 0; i < nr_cpus; i++ )
    1.28 +        for_each_cpu_mask ( cpu, cpumap )
    1.29          {
    1.30 -            /* Assume no holes in idle-vcpu map. */
    1.31 -            if ( (v = idle_vcpu[i]) == NULL )
    1.32 -                break;
    1.33 -
    1.34 -            idletime = v->runstate.time[RUNSTATE_running];
    1.35 -            if ( v->is_running )
    1.36 -                idletime += NOW() - v->runstate.state_entry_time;
    1.37 +            if ( (v = idle_vcpu[cpu]) != NULL )
    1.38 +            {
    1.39 +                idletime = v->runstate.time[RUNSTATE_running];
    1.40 +                if ( v->is_running )
    1.41 +                    idletime += now - v->runstate.state_entry_time;
    1.42 +            }
    1.43 +            else
    1.44 +            {
    1.45 +                idletime = 0;
    1.46 +                cpu_clear(cpu, cpumap);
    1.47 +            }
    1.48  
    1.49              ret = -EFAULT;
    1.50 -            if ( copy_to_guest_offset(idletimes, i, &idletime, 1) )
    1.51 +            if ( copy_to_guest_offset(idletimes, cpu, &idletime, 1) )
    1.52                  goto out;
    1.53          }
    1.54  
    1.55 -        op->u.getidletime.nr_cpus = i;
    1.56 +        op->u.getidletime.now = now;
    1.57 +        cpumask_to_xenctl_cpumap(&ctlmap, &cpumap);
    1.58          ret = copy_to_guest(u_xenpf_op, op, 1) ? -EFAULT : 0;
    1.59      }
    1.60      break;
     2.1 --- a/xen/include/public/platform.h	Wed Oct 24 10:20:03 2007 +0100
     2.2 +++ b/xen/include/public/platform.h	Wed Oct 24 10:49:03 2007 +0100
     2.3 @@ -174,13 +174,27 @@ struct xenpf_change_freq {
     2.4  typedef struct xenpf_change_freq xenpf_change_freq_t;
     2.5  DEFINE_XEN_GUEST_HANDLE(xenpf_change_freq_t);
     2.6  
     2.7 +/*
     2.8 + * Get idle times (nanoseconds since boot) for physical CPUs specified in the
     2.9 + * @cpumap_bitmap with range [0..@cpumap_nr_cpus-1]. The @idletime array is
    2.10 + * indexed by CPU number; only entries with the corresponding @cpumap_bitmap
    2.11 + * bit set are written to. On return, @cpumap_bitmap is modified so that any
    2.12 + * non-existent CPUs are cleared. Such CPUs have their @idletime array entry
    2.13 + * cleared.
    2.14 + */
    2.15  #define XENPF_getidletime         53
    2.16  struct xenpf_getidletime {
    2.17 -    /* IN variables. */
    2.18 -    uint32_t max_cpus;
    2.19 +    /* IN/OUT variables */
    2.20 +    /* IN: CPUs to interrogate; OUT: subset of IN which are present */
    2.21 +    XEN_GUEST_HANDLE(uint8_t) cpumap_bitmap;
    2.22 +    /* IN variables */
    2.23 +    /* Size of cpumap bitmap. */
    2.24 +    uint32_t cpumap_nr_cpus;
    2.25 +    /* Must be indexable for every cpu in cpumap_bitmap. */
    2.26      XEN_GUEST_HANDLE(uint64_t) idletime;
    2.27 -    /* OUT variables. */
    2.28 -    uint32_t nr_cpus;
    2.29 +    /* OUT variables */
    2.30 +    /* System time when the idletime snapshots were taken. */
    2.31 +    uint64_t now;
    2.32  };
    2.33  typedef struct xenpf_getidletime xenpf_getidletime_t;
    2.34  DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);