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

[Xen-changelog] [xen-unstable] Clean up numa-info sysctl.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1271161666 -3600
# Node ID da90dd1a09b93ae41ab451d223ff87dca04356f5
# Parent  6bcd9677f4137d4962945734337f555489db03a7
Clean up numa-info sysctl.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 tools/python/xen/lowlevel/xc/xc.c |   33 ++++++++++----
 tools/python/xen/xend/XendNode.py |   11 +++-
 xen/arch/x86/sysctl.c             |   85 +++++++++++++-------------------------
 xen/include/public/sysctl.h       |   45 ++++++++------------
 4 files changed, 79 insertions(+), 95 deletions(-)

diff -r 6bcd9677f413 -r da90dd1a09b9 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Tue Apr 13 12:48:17 2010 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Tue Apr 13 13:27:46 2010 +0100
@@ -1269,21 +1269,22 @@ static PyObject *pyxc_numainfo(XcObject 
 static PyObject *pyxc_numainfo(XcObject *self)
 {
 #define MAX_NODE_INDEX 31
-    xc_numainfo_t ninfo;
+    xc_numainfo_t ninfo = { 0 };
     int i, j, max_node_index;
     uint64_t free_heap;
-    PyObject *ret_obj;
+    PyObject *ret_obj, *node_to_node_dist_list_obj;
     PyObject *node_to_memsize_obj, *node_to_memfree_obj;
     PyObject *node_to_dma32_mem_obj, *node_to_node_dist_obj;
     xc_node_to_memsize_t node_memsize[MAX_NODE_INDEX + 1];
     xc_node_to_memfree_t node_memfree[MAX_NODE_INDEX + 1];
-    xc_node_to_node_dist_t nodes_dist[(MAX_NODE_INDEX * MAX_NODE_INDEX) + 1];
+    xc_node_to_node_dist_t nodes_dist[(MAX_NODE_INDEX+1) * (MAX_NODE_INDEX+1)];
 
     set_xen_guest_handle(ninfo.node_to_memsize, node_memsize);
     set_xen_guest_handle(ninfo.node_to_memfree, node_memfree);
     set_xen_guest_handle(ninfo.node_to_node_distance, nodes_dist);
     ninfo.max_node_index = MAX_NODE_INDEX;
-    if( xc_numainfo(self->xc_handle, &ninfo) != 0 )
+
+    if ( xc_numainfo(self->xc_handle, &ninfo) != 0 )
         return pyxc_error_to_exception();
 
     max_node_index = ninfo.max_node_index;
@@ -1294,7 +1295,7 @@ static PyObject *pyxc_numainfo(XcObject 
     node_to_memsize_obj = PyList_New(0);
     node_to_memfree_obj = PyList_New(0);
     node_to_dma32_mem_obj = PyList_New(0);
-    node_to_node_dist_obj = PyList_New(0);
+    node_to_node_dist_list_obj = PyList_New(0);
     for ( i = 0; i < max_node_index; i++ )
     {
         PyObject *pyint;
@@ -1316,12 +1317,23 @@ static PyObject *pyxc_numainfo(XcObject 
         Py_DECREF(pyint);
 
         /* Node to Node Distance */
+        node_to_node_dist_obj = PyList_New(0);
         for ( j = 0; j < ninfo.max_node_index; j++ )
         {
-            pyint = PyInt_FromLong(nodes_dist[(i * ninfo.max_node_index) + j]);
-            PyList_Append(node_to_node_dist_obj, pyint);
-            Py_DECREF(pyint);
+            uint32_t dist = nodes_dist[i*(max_node_index+1) + j];
+            if ( dist == INVALID_TOPOLOGY_ID )
+            {
+                PyList_Append(node_to_node_dist_obj, Py_None);
+            }
+            else
+            {
+                pyint = PyInt_FromLong(dist);
+                PyList_Append(node_to_node_dist_obj, pyint);
+                Py_DECREF(pyint);
+            }
         }
+        PyList_Append(node_to_node_dist_list_obj, node_to_node_dist_obj);
+        Py_DECREF(node_to_node_dist_obj);
     }
 
     ret_obj = Py_BuildValue("{s:i}", "max_node_index", max_node_index);
@@ -1335,8 +1347,9 @@ static PyObject *pyxc_numainfo(XcObject 
     PyDict_SetItemString(ret_obj, "node_to_dma32_mem", node_to_dma32_mem_obj);
     Py_DECREF(node_to_dma32_mem_obj);
 
-    PyDict_SetItemString(ret_obj, "node_to_node_dist", node_to_node_dist_obj);
-    Py_DECREF(node_to_node_dist_obj);
+    PyDict_SetItemString(ret_obj, "node_to_node_dist",
+                         node_to_node_dist_list_obj);
+    Py_DECREF(node_to_node_dist_list_obj);
  
     return ret_obj;
 #undef MAX_NODE_INDEX
diff -r 6bcd9677f413 -r da90dd1a09b9 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Tue Apr 13 12:48:17 2010 +0100
+++ b/tools/python/xen/xend/XendNode.py Tue Apr 13 13:27:46 2010 +0100
@@ -893,18 +893,21 @@ class XendNode:
 
     def format_numa_info(self, ninfo):
         try:
-            nr_nodes=ninfo['max_node_index']
+            max_node_index=ninfo['max_node_index']
             str='\nnode: TotalMemory FreeMemory dma32Memory NodeDist:'
-            for i in range(0, nr_nodes):
+            for i in range(0, max_node_index+1):
                 str+='%4d ' % i
             str+='\n'
-            for i in range(0, nr_nodes):
+            for i in range(0, max_node_index+1):
                 str+='%4d:  %8dMB %8dMB  %8dMB         :' % (i, 
                                       ninfo['node_memsize'][i],
                                       ninfo['node_memfree'][i],
                                       ninfo['node_to_dma32_mem'][i])
                 for j in range(0, nr_nodes):
-                    str+='%4d ' % ninfo['node_to_node_dist'][(i*nr_nodes)+j]
+                    try:
+                        str+='%4d ' % ninfo['node_to_node_dist'][i][j]
+                    except:
+                        str+='-    '
                 str+='\n'
         except:
             str='none\n'
diff -r 6bcd9677f413 -r da90dd1a09b9 xen/arch/x86/sysctl.c
--- a/xen/arch/x86/sysctl.c     Tue Apr 13 12:48:17 2010 +0100
+++ b/xen/arch/x86/sysctl.c     Tue Apr 13 13:27:46 2010 +0100
@@ -116,74 +116,49 @@ long arch_do_sysctl(
 
     case XEN_SYSCTL_numainfo:
     {
-        uint32_t i, max_node_index;
-        XEN_GUEST_HANDLE_64(uint64) node_to_memsize_arr;
-        XEN_GUEST_HANDLE_64(uint64) node_to_memfree_arr;
-        XEN_GUEST_HANDLE_64(uint32) node_to_node_distance_arr;
-
+        uint32_t i, j, max_node_index, last_online_node;
         xen_sysctl_numainfo_t *ni = &sysctl->u.numainfo;
 
-        max_node_index = ni->max_node_index;
-        node_to_memsize_arr = ni->node_to_memsize;
-        node_to_memfree_arr = ni->node_to_memfree;
-        node_to_node_distance_arr = ni->node_to_node_distance;
-
-        memset(ni, 0, sizeof(*ni));
-        ni->node_to_memsize = node_to_memsize_arr;
-        ni->node_to_memfree = node_to_memfree_arr;
-        ni->node_to_node_distance = node_to_node_distance_arr;
-
-        max_node_index = min_t(uint32_t, max_node_index, num_online_nodes());
-        ni->max_node_index = max_node_index;
-
-        ret = 0;
-
-        for ( i = 0; i < max_node_index; i++ )
-        {
-            if ( !guest_handle_is_null(node_to_memsize_arr) )
+        last_online_node = last_node(node_online_map);
+        max_node_index = min_t(uint32_t, ni->max_node_index, last_online_node);
+        ni->max_node_index = last_online_node;
+
+        for ( i = 0; i <= max_node_index; i++ )
+        {
+            if ( !guest_handle_is_null(ni->node_to_memsize) )
             {
                 uint64_t memsize = node_online(i) ? 
                                    node_spanned_pages(i) << PAGE_SHIFT : 0ul;
-                if ( copy_to_guest_offset(node_to_memsize_arr, i, &memsize, 1) 
)
-                {
-                    ret = -EFAULT;
-                    break;
-                }
-            }
-            if ( !guest_handle_is_null(node_to_memfree_arr) )
+                if ( copy_to_guest_offset(ni->node_to_memsize, i, &memsize, 1) 
)
+                    break;
+            }
+            if ( !guest_handle_is_null(ni->node_to_memfree) )
             {
                 uint64_t memfree = node_online(i) ? 
                                    avail_node_heap_pages(i) << PAGE_SHIFT : 
0ul;
-                if ( copy_to_guest_offset(node_to_memfree_arr, i, &memfree, 1) 
)
-                {
-                    ret = -EFAULT;
-                    break;
-                }
-            }
-
-            if ( !guest_handle_is_null(node_to_node_distance_arr) )
-           {
-                int j;
-                for ( j = 0; j < max_node_index; j++)
+                if ( copy_to_guest_offset(ni->node_to_memfree, i, &memfree, 1) 
)
+                    break;
+            }
+
+            if ( !guest_handle_is_null(ni->node_to_node_distance) )
+            {
+                for ( j = 0; j <= max_node_index; j++)
                 {
                     uint32_t distance = ~0u;
-                    if (node_online(i) && node_online (j)) 
+                    if ( node_online(i) && node_online(j) )
                         distance = __node_distance(i, j);
-                    
-                    if ( copy_to_guest_offset(node_to_node_distance_arr, 
-                         (i * max_node_index + j), &distance, 1) )
-                    {
-                        ret = -EFAULT;
+                    if ( copy_to_guest_offset(
+                        ni->node_to_node_distance, 
+                        i*(max_node_index+1) + j, &distance, 1) )
                         break;
-                    }
                 }
-            }
-        }
-        if (ret)
-            break;
-
-        if ( copy_to_guest(u_sysctl, sysctl, 1) )
-            ret = -EFAULT;
+                if ( j <= max_node_index )
+                    break;
+            }
+        }
+
+        ret = ((i <= max_node_index) || copy_to_guest(u_sysctl, sysctl, 1))
+            ? -EFAULT : 0;
     }
     break;
     
diff -r 6bcd9677f413 -r da90dd1a09b9 xen/include/public/sysctl.h
--- a/xen/include/public/sysctl.h       Tue Apr 13 12:48:17 2010 +0100
+++ b/xen/include/public/sysctl.h       Tue Apr 13 13:27:46 2010 +0100
@@ -460,10 +460,9 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_lockp
 #define INVALID_TOPOLOGY_ID  (~0U)
 struct xen_sysctl_topologyinfo {
     /*
-     * IN: maximum addressable entry in the caller-provided cpu_to_core, 
-     * cpu_to_socket & cpu_to_node arrays.
+     * IN: maximum addressable entry in the caller-provided arrays.
      * OUT: largest cpu identifier in the system.
-     * If OUT is greater than IN then the cpu_to_node array is truncated!
+     * If OUT is greater than IN then the arrays are truncated!
      */
     uint32_t max_cpu_index;
 
@@ -486,35 +485,29 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_topol
 #define XEN_SYSCTL_numainfo          17        
 struct xen_sysctl_numainfo {
     /*
-     * IN: maximum addressable entry in the caller-provided node_numbers, 
-     * node_to_memsize & node_to_memfree arrays.
-     * OUT: largest possible node index for the system.
-     * If OUT is greater than IN then these arrays are truncated!
+     * IN: maximum addressable entry in the caller-provided arrays.
+     * OUT: largest node identifier in the system.
+     * If OUT is greater than IN then the arrays are truncated!
      */
     uint32_t max_node_index;
 
-    /* For node_to_memsize & node_to_memfree arrays, the 
-     * entry with same index corrosponds to the same node.
-     * If a entry has no node information (e.g., node not present) then the 
-     * sentinel value ~0u is written for_node_number, and value 0u is written 
-     * for node_to_memsize & node_to_memfree.
-     * The size of this array is specified by the caller in @max_node_index. 
-     * If the actual @max_node_index is smaller than the array then the 
-     * trailing elements of the array will not be written by the sysctl.
-     */
+    /* NB. Entries are 0 if node is not present. */
     XEN_GUEST_HANDLE_64(uint64) node_to_memsize;
     XEN_GUEST_HANDLE_64(uint64) node_to_memfree;
 
-
-    /* node_to_node_distance is array of size (nr_nodes * nr_nodes) listing
-     * memory access distances between nodes. i'th  entry in the array 
-     * specifies distance between node (i / nr_nodes) & node (i % nr_nodes)
-     * If a entry has no node distance information (e.g., node not present) 
-     * then the sentinel value ~0u is written.
-     * The size of this array is specified by the caller in 
-     * @max_node_distance_index. If the max_node_index*max_node_index is 
-     * smaller than the array then the trailing elements of the array will 
-     * not be written by the sysctl.
+    /*
+     * Array, of size (max_node_index+1)^2, listing memory access distances
+     * between nodes. If an entry has no node distance information (e.g., node 
+     * not present) then the value ~0u is written.
+     * 
+     * Note that the array rows must be indexed by multiplying by the minimum 
+     * of the caller-provided max_node_index and the returned value of
+     * max_node_index. That is, if the largest node index in the system is
+     * smaller than the caller can handle, a smaller 2-d array is constructed
+     * within the space provided by the caller. When this occurs, trailing
+     * space provided by the caller is not modified. If the largest node index
+     * in the system is larger than the caller can handle, then a 2-d array of
+     * the maximum size handleable by the caller is constructed.
      */
     XEN_GUEST_HANDLE_64(uint32) node_to_node_distance;
 };

_______________________________________________
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®.