debuggers.hg

changeset 21200:2a4970daad74

Topology-info sysctl cleanups.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 13 09:38:54 2010 +0100 (2010-04-13)
parents d2d8805868f1
children de7a50eb4854
files tools/libxc/xc_pm.c tools/libxc/xenctrl.h tools/misc/xenpm.c tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendNode.py xen/arch/x86/sysctl.c xen/drivers/acpi/pmstat.c xen/include/public/sysctl.h
line diff
     1.1 --- a/tools/libxc/xc_pm.c	Tue Apr 13 08:37:16 2010 +0100
     1.2 +++ b/tools/libxc/xc_pm.c	Tue Apr 13 09:38:54 2010 +0100
     1.3 @@ -326,26 +326,6 @@ int xc_get_cpufreq_avgfreq(int xc_handle
     1.4      return ret;
     1.5  }
     1.6  
     1.7 -int xc_get_cputopo(int xc_handle, struct xc_get_cputopo *info)
     1.8 -{
     1.9 -    int rc;
    1.10 -    DECLARE_SYSCTL;
    1.11 -
    1.12 -    sysctl.cmd = XEN_SYSCTL_pm_op;
    1.13 -    sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_get_cputopo;
    1.14 -    sysctl.u.pm_op.cpuid = 0;
    1.15 -    set_xen_guest_handle( sysctl.u.pm_op.u.get_topo.cpu_to_core,
    1.16 -                         info->cpu_to_core );
    1.17 -    set_xen_guest_handle( sysctl.u.pm_op.u.get_topo.cpu_to_socket,
    1.18 -                         info->cpu_to_socket );
    1.19 -    sysctl.u.pm_op.u.get_topo.max_cpus = info->max_cpus;
    1.20 -
    1.21 -    rc = do_sysctl(xc_handle, &sysctl);
    1.22 -    info->nr_cpus = sysctl.u.pm_op.u.get_topo.nr_cpus;
    1.23 -
    1.24 -    return rc;
    1.25 -}
    1.26 -
    1.27  /* value:   0 - disable sched_smt_power_savings 
    1.28              1 - enable sched_smt_power_savings
    1.29   */
     2.1 --- a/tools/libxc/xenctrl.h	Tue Apr 13 08:37:16 2010 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Tue Apr 13 09:38:54 2010 +0100
     2.3 @@ -1303,22 +1303,6 @@ int xc_set_cpufreq_para(int xc_handle, i
     2.4                          int ctrl_type, int ctrl_value);
     2.5  int xc_get_cpufreq_avgfreq(int xc_handle, int cpuid, int *avg_freq);
     2.6  
     2.7 -struct xc_get_cputopo {
     2.8 -     /* IN: maximum addressable entry in
     2.9 -      * the caller-provided cpu_to_core/socket.
    2.10 -      */
    2.11 -    uint32_t max_cpus;
    2.12 -    uint32_t *cpu_to_core;
    2.13 -    uint32_t *cpu_to_socket;
    2.14 -
    2.15 -    /* OUT: number of cpus returned
    2.16 -     * If OUT is greater than IN then the cpu_to_core/socket is truncated!
    2.17 -     */
    2.18 -    uint32_t nr_cpus;
    2.19 -};
    2.20 -
    2.21 -int xc_get_cputopo(int xc_handle, struct xc_get_cputopo *info);
    2.22 -
    2.23  int xc_set_sched_opt_smt(int xc_handle, uint32_t value);
    2.24  int xc_set_vcpu_migration_delay(int xc_handle, uint32_t value);
    2.25  int xc_get_vcpu_migration_delay(int xc_handle, uint32_t *value);
     3.1 --- a/tools/misc/xenpm.c	Tue Apr 13 08:37:16 2010 +0100
     3.2 +++ b/tools/misc/xenpm.c	Tue Apr 13 09:38:54 2010 +0100
     3.3 @@ -842,32 +842,32 @@ void cpu_topology_func(int argc, char *a
     3.4  {
     3.5      uint32_t cpu_to_core[MAX_NR_CPU];
     3.6      uint32_t cpu_to_socket[MAX_NR_CPU];
     3.7 -    struct xc_get_cputopo info;
     3.8 -    int i, ret;
     3.9 +    uint32_t cpu_to_node[MAX_NR_CPU];
    3.10 +    xc_topologyinfo_t info = { 0 };
    3.11 +    int i;
    3.12  
    3.13 -    info.cpu_to_core = cpu_to_core;
    3.14 -    info.cpu_to_socket = cpu_to_socket;
    3.15 -    info.max_cpus = MAX_NR_CPU;
    3.16 -    ret = xc_get_cputopo(xc_fd, &info);
    3.17 -    if (!ret)
    3.18 +    set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
    3.19 +    set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
    3.20 +    set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
    3.21 +    info.max_cpu_index = MAX_NR_CPU-1;
    3.22 +
    3.23 +    if ( xc_topologyinfo(xc_fd, &info) )
    3.24      {
    3.25 -        printf("CPU\tcore\tsocket\n");
    3.26 -        for (i=0; i<info.nr_cpus; i++)
    3.27 -        {
    3.28 -            if ( info.cpu_to_core[i] != INVALID_TOPOLOGY_ID &&
    3.29 -                    info.cpu_to_socket[i] != INVALID_TOPOLOGY_ID )
    3.30 -            {
    3.31 -            printf("CPU%d\t %d\t %d\n", i, info.cpu_to_core[i],
    3.32 -                    info.cpu_to_socket[i]);
    3.33 -            }
    3.34 -        }
    3.35 -    }
    3.36 -    else
    3.37 -    {
    3.38 -        printf("Can not get Xen CPU topology!\n");
    3.39 +        printf("Can not get Xen CPU topology: %d\n", errno);
    3.40 +        return;
    3.41      }
    3.42  
    3.43 -    return ;
    3.44 +    if ( info.max_cpu_index > (MAX_NR_CPU-1) )
    3.45 +        info.max_cpu_index = MAX_NR_CPU-1;
    3.46 +
    3.47 +    printf("CPU\tcore\tsocket\tnode\n");
    3.48 +    for ( i = 0; i < info.max_cpu_index; i++ )
    3.49 +    {
    3.50 +        if ( cpu_to_core[i] == INVALID_TOPOLOGY_ID )
    3.51 +            continue;
    3.52 +        printf("CPU%d\t %d\t %d\t %d\n",
    3.53 +               i, cpu_to_core[i], cpu_to_socket[i], cpu_to_node[i]);
    3.54 +    }
    3.55  }
    3.56  
    3.57  void set_sched_smt_func(int argc, char *argv[])
     4.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Tue Apr 13 08:37:16 2010 +0100
     4.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Tue Apr 13 09:38:54 2010 +0100
     4.3 @@ -1191,7 +1191,7 @@ static PyObject *pyxc_physinfo(XcObject 
     4.4  static PyObject *pyxc_topologyinfo(XcObject *self)
     4.5  {
     4.6  #define MAX_CPU_INDEX 255
     4.7 -    xc_topologyinfo_t tinfo;
     4.8 +    xc_topologyinfo_t tinfo = { 0 };
     4.9      int i, max_cpu_index;
    4.10      PyObject *ret_obj;
    4.11      PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
    4.12 @@ -1199,7 +1199,6 @@ static PyObject *pyxc_topologyinfo(XcObj
    4.13      xc_cpu_to_socket_t socketmap[MAX_CPU_INDEX + 1];
    4.14      xc_cpu_to_node_t nodemap[MAX_CPU_INDEX + 1];
    4.15  
    4.16 -
    4.17      set_xen_guest_handle(tinfo.cpu_to_core, coremap);
    4.18      set_xen_guest_handle(tinfo.cpu_to_socket, socketmap);
    4.19      set_xen_guest_handle(tinfo.cpu_to_node, nodemap);
    4.20 @@ -1218,19 +1217,38 @@ static PyObject *pyxc_topologyinfo(XcObj
    4.21      cpu_to_node_obj = PyList_New(0);
    4.22      for ( i = 0; i < max_cpu_index; i++ )
    4.23      {
    4.24 -        PyObject *pyint;
    4.25 -
    4.26 -        pyint = PyInt_FromLong(coremap[i]);
    4.27 -        PyList_Append(cpu_to_core_obj, pyint);
    4.28 -        Py_DECREF(pyint);
    4.29 -
    4.30 -        pyint = PyInt_FromLong(socketmap[i]);
    4.31 -        PyList_Append(cpu_to_socket_obj, pyint);
    4.32 -        Py_DECREF(pyint);
    4.33 -
    4.34 -        pyint = PyInt_FromLong(nodemap[i]);
    4.35 -        PyList_Append(cpu_to_node_obj, pyint);
    4.36 -        Py_DECREF(pyint);
    4.37 +        if ( coremap[i] == INVALID_TOPOLOGY_ID )
    4.38 +        {
    4.39 +            PyList_Append(cpu_to_core_obj, Py_None);
    4.40 +        }
    4.41 +        else
    4.42 +        {
    4.43 +            PyObject *pyint = PyInt_FromLong(coremap[i]);
    4.44 +            PyList_Append(cpu_to_core_obj, pyint);
    4.45 +            Py_DECREF(pyint);
    4.46 +        }
    4.47 +
    4.48 +        if ( socketmap[i] == INVALID_TOPOLOGY_ID )
    4.49 +        {
    4.50 +            PyList_Append(cpu_to_socket_obj, Py_None);
    4.51 +        }
    4.52 +        else
    4.53 +        {
    4.54 +            PyObject *pyint = PyInt_FromLong(socketmap[i]);
    4.55 +            PyList_Append(cpu_to_socket_obj, pyint);
    4.56 +            Py_DECREF(pyint);
    4.57 +        }
    4.58 +
    4.59 +        if ( nodemap[i] == INVALID_TOPOLOGY_ID )
    4.60 +        {
    4.61 +            PyList_Append(cpu_to_node_obj, Py_None);
    4.62 +        }
    4.63 +        else
    4.64 +        {
    4.65 +            PyObject *pyint = PyInt_FromLong(nodemap[i]);
    4.66 +            PyList_Append(cpu_to_node_obj, pyint);
    4.67 +            Py_DECREF(pyint);
    4.68 +        }
    4.69      }
    4.70  
    4.71      ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpu_index);
     5.1 --- a/tools/python/xen/xend/XendNode.py	Tue Apr 13 08:37:16 2010 +0100
     5.2 +++ b/tools/python/xen/xend/XendNode.py	Tue Apr 13 09:38:54 2010 +0100
     5.3 @@ -879,16 +879,16 @@ class XendNode:
     5.4          return self.format_pairs(self.list_to_rangepairs(list))
     5.5  
     5.6      def format_cpu_to_core_socket_node(self, tinfo):
     5.7 -        try:
     5.8 -            nr_cpus=tinfo['max_cpu_index']
     5.9 -            str='\ncpu:    core    socket     node\n'
    5.10 -            for i in range(0, nr_cpus):
    5.11 +        max_cpu_index=tinfo['max_cpu_index']
    5.12 +        str='\ncpu:    core    socket     node\n'
    5.13 +        for i in range(0, max_cpu_index+1):
    5.14 +            try:
    5.15                  str+='%3d:%8d %8d %8d\n' % (i, 
    5.16 -                                          tinfo['cpu_to_core'][i],
    5.17 -                                          tinfo['cpu_to_socket'][i],
    5.18 -                                          tinfo['cpu_to_node'][i])
    5.19 -        except:
    5.20 -            str='none\n'
    5.21 +                                            tinfo['cpu_to_core'][i],
    5.22 +                                            tinfo['cpu_to_socket'][i],
    5.23 +                                            tinfo['cpu_to_node'][i])
    5.24 +            except:
    5.25 +                pass
    5.26          return str[:-1];
    5.27  
    5.28      def format_numa_info(self, ninfo):
     6.1 --- a/xen/arch/x86/sysctl.c	Tue Apr 13 08:37:16 2010 +0100
     6.2 +++ b/xen/arch/x86/sysctl.c	Tue Apr 13 09:38:54 2010 +0100
     6.3 @@ -80,64 +80,37 @@ long arch_do_sysctl(
     6.4          
     6.5      case XEN_SYSCTL_topologyinfo:
     6.6      {
     6.7 -        uint32_t i, max_cpu_index;
     6.8 -        XEN_GUEST_HANDLE_64(uint32) cpu_to_core_arr;
     6.9 -        XEN_GUEST_HANDLE_64(uint32) cpu_to_socket_arr;
    6.10 -        XEN_GUEST_HANDLE_64(uint32) cpu_to_node_arr;
    6.11 -
    6.12 +        uint32_t i, max_cpu_index, last_online_cpu;
    6.13          xen_sysctl_topologyinfo_t *ti = &sysctl->u.topologyinfo;
    6.14  
    6.15 -        max_cpu_index = ti->max_cpu_index;
    6.16 -        cpu_to_core_arr = ti->cpu_to_core;
    6.17 -        cpu_to_socket_arr = ti->cpu_to_socket;
    6.18 -        cpu_to_node_arr = ti->cpu_to_node;
    6.19 +        last_online_cpu = last_cpu(cpu_online_map);
    6.20 +        max_cpu_index = min_t(uint32_t, ti->max_cpu_index, last_online_cpu);
    6.21 +        ti->max_cpu_index = last_online_cpu;
    6.22  
    6.23 -        memset(ti, 0, sizeof(*ti));
    6.24 -        ti->cpu_to_core = cpu_to_core_arr;
    6.25 -        ti->cpu_to_socket = cpu_to_socket_arr;
    6.26 -        ti->cpu_to_node = cpu_to_node_arr;
    6.27 -
    6.28 -        max_cpu_index = min_t(uint32_t, max_cpu_index, num_online_cpus());
    6.29 -        ti->max_cpu_index = max_cpu_index;
    6.30 -
    6.31 -        ret = 0;
    6.32 -
    6.33 -        for ( i = 0; i < max_cpu_index; i++ )
    6.34 +        for ( i = 0; i <= max_cpu_index; i++ )
    6.35          {
    6.36 -            if ( !guest_handle_is_null(cpu_to_core_arr) )
    6.37 +            if ( !guest_handle_is_null(ti->cpu_to_core) )
    6.38              {
    6.39                  uint32_t core = cpu_online(i) ? cpu_to_core(i) : ~0u;
    6.40 -                if ( copy_to_guest_offset(cpu_to_core_arr, i, &core, 1) )
    6.41 -                {
    6.42 -                    ret = -EFAULT;
    6.43 +                if ( copy_to_guest_offset(ti->cpu_to_core, i, &core, 1) )
    6.44                      break;
    6.45 -                }
    6.46              }
    6.47 -            if ( !guest_handle_is_null(cpu_to_socket_arr) )
    6.48 +            if ( !guest_handle_is_null(ti->cpu_to_socket) )
    6.49              {
    6.50                  uint32_t socket = cpu_online(i) ? cpu_to_socket(i) : ~0u;
    6.51 -                if ( copy_to_guest_offset(cpu_to_socket_arr, i, &socket, 1) )
    6.52 -                {
    6.53 -                    ret = -EFAULT;
    6.54 +                if ( copy_to_guest_offset(ti->cpu_to_socket, i, &socket, 1) )
    6.55                      break;
    6.56 -                }
    6.57              }
    6.58 -            if ( !guest_handle_is_null(cpu_to_node_arr) )
    6.59 +            if ( !guest_handle_is_null(ti->cpu_to_node) )
    6.60              {
    6.61                  uint32_t node = cpu_online(i) ? cpu_to_node(i) : ~0u;
    6.62 -                if ( copy_to_guest_offset(cpu_to_node_arr, i, &node, 1) )
    6.63 -                {
    6.64 -                    ret = -EFAULT;
    6.65 +                if ( copy_to_guest_offset(ti->cpu_to_node, i, &node, 1) )
    6.66                      break;
    6.67 -                }
    6.68              }
    6.69          }
    6.70  
    6.71 -        if (ret)
    6.72 -            break;
    6.73 - 
    6.74 -        if ( copy_to_guest(u_sysctl, sysctl, 1) )
    6.75 -            ret = -EFAULT;
    6.76 +        ret = ((i <= max_cpu_index) || copy_to_guest(u_sysctl, sysctl, 1))
    6.77 +            ? -EFAULT : 0;
    6.78      }
    6.79      break;
    6.80  
     7.1 --- a/xen/drivers/acpi/pmstat.c	Tue Apr 13 08:37:16 2010 +0100
     7.2 +++ b/xen/drivers/acpi/pmstat.c	Tue Apr 13 09:38:54 2010 +0100
     7.3 @@ -419,52 +419,6 @@ static int get_cpufreq_avgfreq(struct xe
     7.4      return 0;
     7.5  }
     7.6  
     7.7 -static int get_cputopo (struct xen_sysctl_pm_op *op)
     7.8 -{
     7.9 -    uint32_t i, nr_cpus;
    7.10 -    XEN_GUEST_HANDLE_64(uint32) cpu_to_core_arr;
    7.11 -    XEN_GUEST_HANDLE_64(uint32) cpu_to_socket_arr;
    7.12 -    int arr_size, ret=0;
    7.13 -
    7.14 -    cpu_to_core_arr = op->u.get_topo.cpu_to_core;
    7.15 -    cpu_to_socket_arr = op->u.get_topo.cpu_to_socket;
    7.16 -    arr_size= min_t(uint32_t, op->u.get_topo.max_cpus, NR_CPUS);
    7.17 -
    7.18 -    if ( guest_handle_is_null( cpu_to_core_arr ) ||
    7.19 -            guest_handle_is_null(  cpu_to_socket_arr) )
    7.20 -    {
    7.21 -        ret = -EINVAL;
    7.22 -        goto out;
    7.23 -    }
    7.24 -
    7.25 -    nr_cpus = 0;
    7.26 -    for ( i = 0; i < arr_size; i++ )
    7.27 -    {
    7.28 -        uint32_t core, socket;
    7.29 -        if ( cpu_online(i) )
    7.30 -        {
    7.31 -            core = cpu_to_core(i);
    7.32 -            socket = cpu_to_socket(i);
    7.33 -            nr_cpus = i;
    7.34 -        }
    7.35 -        else
    7.36 -        {
    7.37 -            core = socket = INVALID_TOPOLOGY_ID;
    7.38 -        }
    7.39 -
    7.40 -        if ( copy_to_guest_offset(cpu_to_core_arr, i, &core, 1) ||
    7.41 -                copy_to_guest_offset(cpu_to_socket_arr, i, &socket, 1))
    7.42 -        {
    7.43 -            ret = -EFAULT;
    7.44 -            goto out;
    7.45 -        }
    7.46 -    }
    7.47 -
    7.48 -    op->u.get_topo.nr_cpus = nr_cpus + 1;
    7.49 -out:
    7.50 -    return ret;
    7.51 -}
    7.52 -
    7.53  int do_pm_op(struct xen_sysctl_pm_op *op)
    7.54  {
    7.55      int ret = 0;
    7.56 @@ -510,12 +464,6 @@ int do_pm_op(struct xen_sysctl_pm_op *op
    7.57          break;
    7.58      }
    7.59  
    7.60 -    case XEN_SYSCTL_pm_op_get_cputopo:
    7.61 -    {
    7.62 -        ret = get_cputopo(op);
    7.63 -        break;
    7.64 -    }
    7.65 -
    7.66      case XEN_SYSCTL_pm_op_set_sched_opt_smt:
    7.67      {
    7.68          uint32_t saved_value;
     8.1 --- a/xen/include/public/sysctl.h	Tue Apr 13 08:37:16 2010 +0100
     8.2 +++ b/xen/include/public/sysctl.h	Tue Apr 13 09:38:54 2010 +0100
     8.3 @@ -336,22 +336,6 @@ struct xen_set_cpufreq_para {
     8.4      uint32_t ctrl_value;
     8.5  };
     8.6  
     8.7 -/* Get physical CPU topology information. */
     8.8 -#define INVALID_TOPOLOGY_ID  (~0U)
     8.9 -struct xen_get_cputopo {
    8.10 -     /* IN: maximum addressable entry in
    8.11 -      * the caller-provided cpu_to_core/socket.
    8.12 -      */
    8.13 -    uint32_t max_cpus;
    8.14 -    XEN_GUEST_HANDLE_64(uint32) cpu_to_core;
    8.15 -    XEN_GUEST_HANDLE_64(uint32) cpu_to_socket;
    8.16 -
    8.17 -    /* OUT: number of cpus returned
    8.18 -     * If OUT is greater than IN then the cpu_to_core/socket is truncated!
    8.19 -     */
    8.20 -    uint32_t nr_cpus;
    8.21 -};
    8.22 -
    8.23  struct xen_sysctl_pm_op {
    8.24      #define PM_PARA_CATEGORY_MASK      0xf0
    8.25      #define CPUFREQ_PARA               0x10
    8.26 @@ -362,9 +346,6 @@ struct xen_sysctl_pm_op {
    8.27      #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
    8.28      #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
    8.29  
    8.30 -    /* get CPU topology */
    8.31 -    #define XEN_SYSCTL_pm_op_get_cputopo  0x20
    8.32 -
    8.33      /* set/reset scheduler power saving option */
    8.34      #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21
    8.35  
    8.36 @@ -387,7 +368,6 @@ struct xen_sysctl_pm_op {
    8.37          struct xen_set_cpufreq_gov  set_gov;
    8.38          struct xen_set_cpufreq_para set_para;
    8.39          uint64_aligned_t get_avgfreq;
    8.40 -        struct xen_get_cputopo      get_topo;
    8.41          uint32_t                    set_sched_opt_smt;
    8.42          uint32_t                    get_max_cstate;
    8.43          uint32_t                    set_max_cstate;
    8.44 @@ -477,8 +457,8 @@ typedef struct xen_sysctl_lockprof_op xe
    8.45  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_lockprof_op_t);
    8.46  
    8.47  #define XEN_SYSCTL_topologyinfo         16 
    8.48 +#define INVALID_TOPOLOGY_ID  (~0U)
    8.49  struct xen_sysctl_topologyinfo {
    8.50 -
    8.51      /*
    8.52       * IN: maximum addressable entry in the caller-provided cpu_to_core, 
    8.53       * cpu_to_socket & cpu_to_node arrays.
    8.54 @@ -498,8 +478,7 @@ struct xen_sysctl_topologyinfo {
    8.55       */
    8.56      XEN_GUEST_HANDLE_64(uint32) cpu_to_core;
    8.57      XEN_GUEST_HANDLE_64(uint32) cpu_to_socket;
    8.58 -    XEN_GUEST_HANDLE_64(uint32) cpu_to_node;  /* node_number */
    8.59 -
    8.60 +    XEN_GUEST_HANDLE_64(uint32) cpu_to_node;
    8.61  };
    8.62  typedef struct xen_sysctl_topologyinfo xen_sysctl_topologyinfo_t;
    8.63  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_topologyinfo_t);