WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list

* Keir Fraser <Keir.Fraser@xxxxxxxxxxxx> [2005-10-20 15:20]:
> 
> On 20 Oct 2005, at 17:23, Ryan Harper wrote:
> 
> >>>I would think mapping cpu % nr_cpus, throwing away duplicates would 
> >>>be
> >>>best.  With [0,1,2,3] and nr_cpus=2, cpumap would be [0,1].
> >>
> >>I think Xen should ignore non-existent cpus in a cpumap. I'm not 
> >>really
> >>fussed what you do with them in xend -- ignoring them there too would
> >>probably make most sense.
> >
> >I am a little concerned that if a user pins a vcpu to cpus 0-7 , on a
> >two-way, and the output of vcpu-list shows him [0,1], that it might 
> >look
> >like the pin operation didn't work.  If this isn't a big deal, then 
> >I'll
> >also look at throwing out invalid cpus from the cpumap representation.
> 
> If the user is trying to pin to CPUs 0-7 on a dual-cpu system, maybe 
> the user doesn't know what they're doing. :-)

Heh.  Fair enough.

> You can trust Xen itself to ignore non-existsent CPUs in a cpumap. 
> Whether you filter them out in xend or not I think doesn't matter a 
> great deal.

OK.  How does this look:

root@bebop:~ # xm list -v
xm list -v is deprecated.  Please use xm vcpu-list.
Name                              ID  VCPU  CPU  State  Time(s)  CPU Map
Domain-0                           0     0    0   r--      14.6  0-1

root@bebop:~ # xm create /etc/xen/debian_sarge_dom2_512M vcpus=4
Using config file "/etc/xen/debian_sarge_dom2_512M".
Started domain debian_sarge_2
root@bebop:~ # xm list -v
xm list -v is deprecated.  Please use xm vcpu-list.
Name                              ID  VCPU  CPU  State  Time(s)  CPU Map
Domain-0                           0     0    0   r--      15.1  0-1
debian_sarge_2                     2     0    1   -b-       0.3  0-1
debian_sarge_2                     2     1    0   -b-       0.0  0-1
debian_sarge_2                     2     2    1   -b-       0.0  0-1
debian_sarge_2                     2     3    0   -b-       0.0  0-1

root@bebop:~ # xm vcpu-pin 2 3 1
root@bebop:~ # xm list -v
xm list -v is deprecated.  Please use xm vcpu-list.
Name                              ID  VCPU  CPU  State  Time(s)  CPU Map
Domain-0                           0     0    0   r--      15.3  0-1
debian_sarge_2                     2     0    1   -b-       1.6  0-1
debian_sarge_2                     2     1    0   ---       2.2  0-1
debian_sarge_2                     2     2    1   -b-       1.1  0-1
debian_sarge_2                     2     3    1   -b-       0.1  1

root@bebop:~ # xm vcpu-pin 2 3 1
root@bebop:~ # xm list -v
xm list -v is deprecated.  Please use xm vcpu-list.
Name                              ID  VCPU  CPU  State  Time(s)  CPU Map
Domain-0                           0     0    0   r--      15.3  0-1
debian_sarge_2                     2     0    1   -b-       1.6  0-1
debian_sarge_2                     2     1    0   ---       2.2  0-1
debian_sarge_2                     2     2    1   -b-       1.1  0-1
debian_sarge_2                     2     3    1   -b-       0.1  1


I'm not sure what to do about the python binding in pincpu.  As you
mentioned, python2.2 doesn't support 'K' (unsigned long long), but it
can support 'L' (long long).

Looking into python2.2 source, python-2.2/Python/getargs.c, there is
this:

#ifdef HAVE_LONG_LONG
   case 'L': /* LONG_LONG int */
      {
         (void) va_arg(*p_va, LONG_LONG *);
         break;
      }
#endif

If we used 'L', we could set up to 63 bits on 32-bit platforms and all
64-bits on 64-bit platforms.

If we leave it as 'i', then the CPU Map listing looks a bit odd:

root@bebop:~ # xm vcpu-pin 2 3 1
root@bebop:~ # xm list -v
xm list -v is deprecated.  Please use xm vcpu-list.
Name                              ID  VCPU  CPU  State  Time(s)  CPU Map
Domain-0                           0     0    0   r--      15.3  0-1
debian_sarge_2                     2     0    1   -b-       1.6  0-1
debian_sarge_2                     2     1    0   ---       2.2  0-1
debian_sarge_2                     2     2    1   -b-       1.1  0-1
debian_sarge_2                     2     3    1   -b-       0.1  0-1
                                             ^^^                 ^^^

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
ryanh@xxxxxxxxxx


diffstat output:
 lowlevel/xc/xc.c |   17 ++++++++++-----
 xm/main.py       |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 8 deletions(-)

Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
---
diff -r 7c951e3eb5ab tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed Oct 19 10:53:00 2005
+++ b/tools/python/xen/lowlevel/xc/xc.c Thu Oct 20 16:17:24 2005
@@ -209,7 +209,7 @@
 
     static char *kwd_list[] = { "dom", "vcpu", "cpumap", NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list, 
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iL", kwd_list, 
                                       &dom, &vcpu, &cpumap) )
         return NULL;
 
@@ -347,11 +347,12 @@
                                    PyObject *kwds)
 {
     XcObject *xc = (XcObject *)self;
-    PyObject *info_dict;
+    PyObject *info_dict, *cpumap;
 
     uint32_t dom, vcpu = 0;
     xc_vcpuinfo_t info;
     int rc;
+    cpumap_t i;
 
     static char *kwd_list[] = { "dom", "vcpu", NULL };
     
@@ -363,14 +364,18 @@
     if ( rc < 0 )
         return PyErr_SetFromErrno(xc_error);
 
-    info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i,s:i}",
+    info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i}",
                               "online",   info.online,
                               "blocked",  info.blocked,
                               "running",  info.running,
                               "cpu_time", info.cpu_time,
-                              "cpu",      info.cpu,
-                              "cpumap",   info.cpumap);
-
+                              "cpu",      info.cpu);
+    cpumap = PyList_New(0);
+    for ( i = 0; i < sizeof(cpumap_t)*8; i++ )
+        if ( (1 << i) & info.cpumap )
+            PyList_Append(cpumap, PyInt_FromLong(i));
+
+    PyDict_SetItemString(info_dict, "cpumap", cpumap);
     return info_dict;
 }
 
diff -r 7c951e3eb5ab tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed Oct 19 10:53:00 2005
+++ b/tools/python/xen/xm/main.py       Thu Oct 20 16:17:24 2005
@@ -289,6 +289,62 @@
         def get_info(n):
             return sxp.child_value(dom, n)
 
+        #
+        # convert a list of integers into a list of pairs indicating
+        # continuous sequences in the list:
+        #
+        # [0,1,2,3]   -> [(0,3)]
+        # [1,2,4,5]   -> [(1,2),(4,5)]
+        # [0]         -> [(0,0)]
+        # [0,1,4,6,7] -> [(0,1),(4,4),(6,7)]
+        #
+        def list_to_rangepairs(cmap):
+            cmap.sort()
+            pairs = []
+            x = y = 0
+            for i in range(0,len(cmap)):
+                try:
+                    if ((cmap[y+1] - cmap[i]) > 1):
+                        pairs.append((cmap[x],cmap[y]))
+                        x = y = i+1
+                    else:
+                        y = y + 1
+                # if we go off the end, then just add x to y
+                except IndexError:
+                    pairs.append((cmap[x],cmap[y]))
+
+            return pairs
+
+        #
+        # Convert pairs to range string, e.g: [(1,2),(3,3),(5,7)] -> 1-2,3,5-7
+        #
+        def format_pairs(pairs):
+            out = ""
+            for f,s in pairs:
+                if (f==s):
+                    out += '%d'%f
+                else:
+                    out += '%d-%d'%(f,s)
+                out += ','
+            # trim trailing ','
+            return out[:-1]
+
+        def format_cpumap(cpumap):
+            def uniq(x):
+               return [ u for u in x if u not in locals()['_[1]'] ]
+
+            from xen.xend.XendClient import server
+            for x in server.xend_node()[1:]:
+                if len(x) > 1 and x[0] == 'nr_cpus':
+                    nr_cpus = int(x[1])
+                    break
+ 
+            return format_pairs(
+                          list_to_rangepairs(
+                              map(lambda x: x % nr_cpus, 
+                                  uniq(map(lambda x: int(x), cpumap)) )))
+                
+
         name  =     get_info('name')
         domid = int(get_info('domid'))
 
@@ -299,7 +355,7 @@
 
             number   = vinfo('number',   int)
             cpu      = vinfo('cpu',      int)
-            cpumap   = vinfo('cpumap',   int)
+            cpumap   = format_cpumap(vinfo('cpumap',   list))
             online   = vinfo('online',   int)
             cpu_time = vinfo('cpu_time', float)
             running  = vinfo('running',  int)
@@ -321,7 +377,7 @@
                 s = "--p"
 
             print (
-                "%(name)-32s %(domid)3d  %(number)4d  %(c)3s   %(s)-3s   
%(cpu_time)7.1f  0x%(cpumap)x" %
+                "%(name)-32s %(domid)3d  %(number)4d  %(c)3s   %(s)-3s   
%(cpu_time)7.1f  %(cpumap)s" %
                 locals())
 
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel