ia64/xen-unstable
changeset 7483:94cee9a918de
cpumap cleanups -- Python now deals with lists of cpus
rather than cpu bitmaps.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
rather than cpu bitmaps.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Sat Oct 22 08:35:03 2005 +0100 (2005-10-22) |
parents | 6b8a91dcdc2e |
children | a2cf10b8da5a |
files | tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xm/main.py |
line diff
1.1 --- a/tools/python/xen/lowlevel/xc/xc.c Sat Oct 22 07:43:56 2005 +0100 1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c Sat Oct 22 08:35:03 2005 +0100 1.3 @@ -204,15 +204,23 @@ static PyObject *pyxc_domain_pincpu(PyOb 1.4 XcObject *xc = (XcObject *)self; 1.5 1.6 uint32_t dom; 1.7 - int vcpu = 0; 1.8 + int vcpu = 0, i; 1.9 cpumap_t cpumap = ~0ULL; 1.10 + PyObject *cpulist = NULL; 1.11 1.12 static char *kwd_list[] = { "dom", "vcpu", "cpumap", NULL }; 1.13 1.14 - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list, 1.15 - &dom, &vcpu, &cpumap) ) 1.16 + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list, 1.17 + &dom, &vcpu, &cpulist) ) 1.18 return NULL; 1.19 1.20 + if ( (cpulist != NULL) && PyList_Check(cpulist) ) 1.21 + { 1.22 + cpumap = 0ULL; 1.23 + for ( i = 0; i < PyList_Size(cpulist); i++ ) 1.24 + cpumap |= (cpumap_t)1 << PyInt_AsLong(PyList_GetItem(cpulist, i)); 1.25 + } 1.26 + 1.27 if ( xc_domain_pincpu(xc->xc_handle, dom, vcpu, cpumap) != 0 ) 1.28 return PyErr_SetFromErrno(xc_error); 1.29 1.30 @@ -347,11 +355,12 @@ static PyObject *pyxc_vcpu_getinfo(PyObj 1.31 PyObject *kwds) 1.32 { 1.33 XcObject *xc = (XcObject *)self; 1.34 - PyObject *info_dict; 1.35 + PyObject *info_dict, *cpulist; 1.36 1.37 uint32_t dom, vcpu = 0; 1.38 xc_vcpuinfo_t info; 1.39 - int rc; 1.40 + int rc, i; 1.41 + cpumap_t cpumap; 1.42 1.43 static char *kwd_list[] = { "dom", "vcpu", NULL }; 1.44 1.45 @@ -363,13 +372,22 @@ static PyObject *pyxc_vcpu_getinfo(PyObj 1.46 if ( rc < 0 ) 1.47 return PyErr_SetFromErrno(xc_error); 1.48 1.49 - info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i,s:i}", 1.50 + info_dict = Py_BuildValue("{s:i,s:i,s:i,s:L,s:i}", 1.51 "online", info.online, 1.52 "blocked", info.blocked, 1.53 "running", info.running, 1.54 "cpu_time", info.cpu_time, 1.55 - "cpu", info.cpu, 1.56 - "cpumap", info.cpumap); 1.57 + "cpu", info.cpu); 1.58 + 1.59 + cpumap = info.cpumap; 1.60 + cpulist = PyList_New(0); 1.61 + for ( i = 0; cpumap != 0; i++ ) 1.62 + { 1.63 + if ( cpumap & 1 ) 1.64 + PyList_Append(cpulist, PyInt_FromLong(i)); 1.65 + cpumap >>= 1; 1.66 + } 1.67 + PyDict_SetItemString(info_dict, "cpumap", cpulist); 1.68 1.69 return info_dict; 1.70 } 1.71 @@ -896,7 +914,7 @@ static PyMethodDef pyxc_methods[] = { 1.72 "Pin a VCPU to a specified set CPUs.\n" 1.73 " dom [int]: Identifier of domain to which VCPU belongs.\n" 1.74 " vcpu [int, 0]: VCPU being pinned.\n" 1.75 - " cpumap [int, -1]: Bitmap of usable CPUs.\n\n" 1.76 + " cpumap [list, []]: list of usable CPUs.\n\n" 1.77 "Returns: [int] 0 on success; -1 on error.\n" }, 1.78 1.79 { "domain_setcpuweight",
2.1 --- a/tools/python/xen/xend/XendClient.py Sat Oct 22 07:43:56 2005 +0100 2.2 +++ b/tools/python/xen/xend/XendClient.py Sat Oct 22 08:35:03 2005 +0100 2.3 @@ -258,7 +258,7 @@ class Xend: 2.4 return self.xendPost(self.domainurl(id), 2.5 {'op' : 'pincpu', 2.6 'vcpu' : vcpu, 2.7 - 'cpumap' : cpumap }) 2.8 + 'cpumap' : str(cpumap) }) 2.9 2.10 def xend_domain_cpu_bvt_set(self, id, mcuadv, warpback, warpvalue, warpl, warpu): 2.11 return self.xendPost(self.domainurl(id),
3.1 --- a/tools/python/xen/xend/XendDomain.py Sat Oct 22 07:43:56 2005 +0100 3.2 +++ b/tools/python/xen/xend/XendDomain.py Sat Oct 22 08:35:03 2005 +0100 3.3 @@ -412,9 +412,12 @@ class XendDomain: 3.4 def domain_pincpu(self, domid, vcpu, cpumap): 3.5 """Set which cpus vcpu can use 3.6 3.7 - @param cpumap: bitmap of usable cpus 3.8 + @param cpumap: string repr of list of usable cpus 3.9 """ 3.10 dominfo = self.domain_lookup(domid) 3.11 + # convert cpumap string into a list of ints 3.12 + cpumap = map(lambda x: int(x), 3.13 + cpumap.replace("[", "").replace("]", "").split(",")) 3.14 try: 3.15 return xc.domain_pincpu(dominfo.getDomid(), vcpu, cpumap) 3.16 except Exception, ex:
4.1 --- a/tools/python/xen/xend/XendDomainInfo.py Sat Oct 22 07:43:56 2005 +0100 4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Sat Oct 22 08:35:03 2005 +0100 4.3 @@ -980,6 +980,9 @@ class XendDomainInfo: 4.4 4.5 def getVCPUInfo(self): 4.6 try: 4.7 + def filter_cpumap(map, max): 4.8 + return filter(lambda x: x >= 0, map[0:max]) 4.9 + 4.10 # We include the domain name and ID, to help xm. 4.11 sxpr = ['domain', 4.12 ['domid', self.domid], 4.13 @@ -996,7 +999,8 @@ class XendDomainInfo: 4.14 ['running', info['running']], 4.15 ['cpu_time', info['cpu_time'] / 1e9], 4.16 ['cpu', info['cpu']], 4.17 - ['cpumap', info['cpumap']]]) 4.18 + ['cpumap', filter_cpumap(info['cpumap'], 4.19 + self.info['vcpus'])]]) 4.20 4.21 return sxpr 4.22
5.1 --- a/tools/python/xen/xend/server/SrvDomain.py Sat Oct 22 07:43:56 2005 +0100 5.2 +++ b/tools/python/xen/xend/server/SrvDomain.py Sat Oct 22 08:35:03 2005 +0100 5.3 @@ -89,7 +89,7 @@ class SrvDomain(SrvDir): 5.4 fn = FormFn(self.xd.domain_pincpu, 5.5 [['dom', 'int'], 5.6 ['vcpu', 'int'], 5.7 - ['cpumap', 'int']]) 5.8 + ['cpumap', 'str']]) 5.9 val = fn(req.args, {'dom': self.dom.domid}) 5.10 return val 5.11
6.1 --- a/tools/python/xen/xm/main.py Sat Oct 22 07:43:56 2005 +0100 6.2 +++ b/tools/python/xen/xm/main.py Sat Oct 22 08:35:03 2005 +0100 6.3 @@ -289,6 +289,62 @@ def xm_vcpu_list(args): 6.4 def get_info(n): 6.5 return sxp.child_value(dom, n) 6.6 6.7 + # 6.8 + # convert a list of integers into a list of pairs indicating 6.9 + # continuous sequences in the list: 6.10 + # 6.11 + # [0,1,2,3] -> [(0,3)] 6.12 + # [1,2,4,5] -> [(1,2),(4,5)] 6.13 + # [0] -> [(0,0)] 6.14 + # [0,1,4,6,7] -> [(0,1),(4,4),(6,7)] 6.15 + # 6.16 + def list_to_rangepairs(cmap): 6.17 + cmap.sort() 6.18 + pairs = [] 6.19 + x = y = 0 6.20 + for i in range(0,len(cmap)): 6.21 + try: 6.22 + if ((cmap[y+1] - cmap[i]) > 1): 6.23 + pairs.append((cmap[x],cmap[y])) 6.24 + x = y = i+1 6.25 + else: 6.26 + y = y + 1 6.27 + # if we go off the end, then just add x to y 6.28 + except IndexError: 6.29 + pairs.append((cmap[x],cmap[y])) 6.30 + 6.31 + return pairs 6.32 + 6.33 + # 6.34 + # Convert pairs to range string, e.g: [(1,2),(3,3),(5,7)] -> 1-2,3,5-7 6.35 + # 6.36 + def format_pairs(pairs): 6.37 + out = "" 6.38 + for f,s in pairs: 6.39 + if (f==s): 6.40 + out += '%d'%f 6.41 + else: 6.42 + out += '%d-%d'%(f,s) 6.43 + out += ',' 6.44 + # trim trailing ',' 6.45 + return out[:-1] 6.46 + 6.47 + def format_cpumap(cpumap): 6.48 + def uniq(x): 6.49 + return [ u for u in x if u not in locals()['_[1]'] ] 6.50 + 6.51 + from xen.xend.XendClient import server 6.52 + for x in server.xend_node()[1:]: 6.53 + if len(x) > 1 and x[0] == 'nr_cpus': 6.54 + nr_cpus = int(x[1]) 6.55 + break 6.56 + 6.57 + return format_pairs( 6.58 + list_to_rangepairs( 6.59 + map(lambda x: x % nr_cpus, 6.60 + uniq(map(lambda x: int(x), cpumap)) ))) 6.61 + 6.62 + 6.63 name = get_info('name') 6.64 domid = int(get_info('domid')) 6.65 6.66 @@ -299,7 +355,7 @@ def xm_vcpu_list(args): 6.67 6.68 number = vinfo('number', int) 6.69 cpu = vinfo('cpu', int) 6.70 - cpumap = vinfo('cpumap', int) 6.71 + cpumap = format_cpumap(vinfo('cpumap', list)) 6.72 online = vinfo('online', int) 6.73 cpu_time = vinfo('cpu_time', float) 6.74 running = vinfo('running', int) 6.75 @@ -321,7 +377,7 @@ def xm_vcpu_list(args): 6.76 s = "--p" 6.77 6.78 print ( 6.79 - "%(name)-32s %(domid)3d %(number)4d %(c)3s %(s)-3s %(cpu_time)7.1f 0x%(cpumap)x" % 6.80 + "%(name)-32s %(domid)3d %(number)4d %(c)3s %(s)-3s %(cpu_time)7.1f %(cpumap)s" % 6.81 locals()) 6.82 6.83 6.84 @@ -355,7 +411,6 @@ def xm_subcommand(command, args): 6.85 6.86 def cpu_make_map(cpulist): 6.87 cpus = [] 6.88 - cpumap = 0 6.89 for c in cpulist.split(','): 6.90 if c.find('-') != -1: 6.91 (x,y) = c.split('-') 6.92 @@ -364,10 +419,7 @@ def cpu_make_map(cpulist): 6.93 else: 6.94 cpus.append(int(c)) 6.95 cpus.sort() 6.96 - for c in cpus: 6.97 - cpumap = cpumap | 1<<c 6.98 - 6.99 - return cpumap 6.100 + return cpus 6.101 6.102 def xm_vcpu_pin(args): 6.103 arg_check(args, 3, "vcpu-pin")