ia64/xen-unstable

changeset 17128:6ef22eefc360

xend: Add free memory size of every node in physinfo to help user to
get usage of memory of their NUMA machine.

Signed-off-by: Duan Ronghui <ronghui.duan@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 26 15:00:08 2008 +0000 (2008-02-26)
parents c8b58f82d893
children 450be98ef36b
files tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendNode.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Tue Feb 26 14:50:45 2008 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Tue Feb 26 15:00:08 2008 +0000
     1.3 @@ -764,7 +764,8 @@ static PyObject *pyxc_physinfo(XcObject 
     1.4      xc_physinfo_t info;
     1.5      char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;
     1.6      int i, j, max_cpu_id;
     1.7 -    PyObject *ret_obj, *node_to_cpu_obj;
     1.8 +    uint64_t free_heap;
     1.9 +    PyObject *ret_obj, *node_to_cpu_obj, *node_to_memory_obj;
    1.10      xc_cpu_to_node_t map[MAX_CPU_ID + 1];
    1.11  
    1.12      set_xen_guest_handle(info.cpu_to_node, map);
    1.13 @@ -812,7 +813,17 @@ static PyObject *pyxc_physinfo(XcObject 
    1.14          PyList_Append(node_to_cpu_obj, cpus); 
    1.15      }
    1.16  
    1.17 +    node_to_memory_obj = PyList_New(0);
    1.18 +
    1.19 +    for ( i = 0; i < info.nr_nodes; i++ )
    1.20 +    {
    1.21 +	xc_availheap(self->xc_handle, 0, 0, i, &free_heap);
    1.22 +	PyList_Append(node_to_memory_obj,
    1.23 +	    PyInt_FromLong(free_heap / 1024));
    1.24 +    }
    1.25 +	
    1.26      PyDict_SetItemString(ret_obj, "node_to_cpu", node_to_cpu_obj);
    1.27 +    PyDict_SetItemString(ret_obj, "node_to_memory", node_to_memory_obj);
    1.28   
    1.29      return ret_obj;
    1.30  #undef MAX_CPU_ID
     2.1 --- a/tools/python/xen/xend/XendNode.py	Tue Feb 26 14:50:45 2008 +0000
     2.2 +++ b/tools/python/xen/xend/XendNode.py	Tue Feb 26 15:00:08 2008 +0000
     2.3 @@ -573,6 +573,20 @@ class XendNode:
     2.4          except:
     2.5              str='none\n'
     2.6          return str[:-1];
     2.7 +    def format_node_to_memory(self, pinfo):
     2.8 +        str=''
     2.9 +        whitespace=''
    2.10 +        try:
    2.11 +            node_to_memory=pinfo['node_to_memory']
    2.12 +            for i in range(0, pinfo['nr_nodes']):
    2.13 +                str+='%snode%d:%d\n' % (whitespace,
    2.14 +                                        i,
    2.15 +                                        node_to_memory[i] / 1024)
    2.16 +                whitespace='%25s' % ''
    2.17 +        except:
    2.18 +            str='none\n'
    2.19 +        return str[:-1];
    2.20 +
    2.21  
    2.22      def physinfo(self):
    2.23          info = self.xc.physinfo()
    2.24 @@ -583,6 +597,7 @@ class XendNode:
    2.25          info['total_memory'] = info['total_memory'] / 1024
    2.26          info['free_memory']  = info['free_memory'] / 1024
    2.27          info['node_to_cpu']  = self.format_node_to_cpu(info)
    2.28 +        info['node_to_memory'] = self.format_node_to_memory(info)
    2.29  
    2.30          ITEM_ORDER = ['nr_cpus',
    2.31                        'nr_nodes',
    2.32 @@ -592,7 +607,8 @@ class XendNode:
    2.33                        'hw_caps',
    2.34                        'total_memory',
    2.35                        'free_memory',
    2.36 -                      'node_to_cpu'
    2.37 +                      'node_to_cpu',
    2.38 +                      'node_to_memory'
    2.39                        ]
    2.40  
    2.41          return [[k, info[k]] for k in ITEM_ORDER]