Ryan Harper
2005-Oct-19 22:45 UTC
[Xen-devel] [PATCH] tools: convert cpumap bitmap to list
This patch modifies the lowlevel xc vcpuinfo call to convert a vcpu''s cpumap to a list of int. XendDomainInfo.py filters the cpumap into a smaller list that is bound by the number of vcpus allocated to a domain. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com diffstat output: lowlevel/xc/xc.c | 21 +++++++++++++++------ xend/XendDomainInfo.py | 6 +++++- xm/main.py | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) Signed-off-by: Ryan Harper <ryanh@us.ibm.com> --- 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 Wed Oct 19 17:35:34 2005 @@ -347,11 +347,11 @@ PyObject *kwds) { XcObject *xc = (XcObject *)self; - PyObject *info_dict; + PyObject *info_dict, *cpumap; uint32_t dom, vcpu = 0; xc_vcpuinfo_t info; - int rc; + int rc, i; static char *kwd_list[] = { "dom", "vcpu", NULL }; @@ -363,14 +363,23 @@ 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); + /* XXX: we should truncate this list by max_vcpu_id+1 instead + * of calculating # of bits in cpumap_t. */ + cpumap = PyList_New(sizeof(cpumap_t)*8); + for ( i = 0; i < sizeof(cpumap_t)*8; i++ ) { + if ( (1 << i) & info.cpumap ) + PyList_SetItem(cpumap, i, PyInt_FromLong(i)); + else + PyList_SetItem(cpumap, i, PyInt_FromLong(-1)); + } + + PyDict_SetItemString(info_dict, "cpumap", cpumap); return info_dict; } diff -r 7c951e3eb5ab tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Wed Oct 19 10:53:00 2005 +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Oct 19 17:35:34 2005 @@ -982,6 +982,9 @@ def getVCPUInfo(self): try: + def filter_cpumap(map, max): + return filter(lambda x: x >= 0, map[0:max]) + # We include the domain name and ID, to help xm. sxpr = [''domain'', [''domid'', self.domid], @@ -998,7 +1001,8 @@ [''running'', info[''running'']], [''cpu_time'', info[''cpu_time''] / 1e9], [''cpu'', info[''cpu'']], - [''cpumap'', info[''cpumap'']]]) + [''cpumap'', filter_cpumap(info[''cpumap''], + self.info[''vcpus''])]]) return sxpr 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 Wed Oct 19 17:35:34 2005 @@ -299,7 +299,7 @@ number = vinfo(''number'', int) cpu = vinfo(''cpu'', int) - cpumap = vinfo(''cpumap'', int) + cpumap = vinfo(''cpumap'', list) online = vinfo(''online'', int) cpu_time = vinfo(''cpu_time'', float) running = vinfo(''running'', int) @@ -321,7 +321,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@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2005-Oct-20 10:44 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
On 19 Oct 2005, at 23:45, Ryan Harper wrote:> This patch modifies the lowlevel xc vcpuinfo call to convert a vcpu''s > cpumap to a list of int. XendDomainInfo.py filters the cpumap into a > smaller list that is bound by the number of vcpus allocated to a > domain.Two things: First, there is no correspondence between size of cpumap and max_vcpu_id, because there is no direct relationship between sizes of virtual and physical CPU spaces. We could have a system with more vcpus than physical cpus, or vice versa. And cpumap represents sets of physical cpus, not sets of virtual cpus. Second, I meant that the cpumap list should contain just the list of physical cpus that that vcpu can run on. So, for example, a cpumap bitmask of 0x5 would correspond to the cpumap list [0, 2], not the list [0, -1, 2, -1, -1, ...]. The latter is a weird and redundant representation. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ryan Harper
2005-Oct-20 15:24 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [2005-10-20 05:39]:> > On 19 Oct 2005, at 23:45, Ryan Harper wrote: > > >This patch modifies the lowlevel xc vcpuinfo call to convert a vcpu''s > >cpumap to a list of int. XendDomainInfo.py filters the cpumap into a > >smaller list that is bound by the number of vcpus allocated to a > >domain. > > Two things: > > First, there is no correspondence between size of cpumap and > max_vcpu_id, because there is no direct relationship between sizes of > virtual and physical CPU spaces. We could have a system with more vcpus > than physical cpus, or vice versa. And cpumap represents sets of > physical cpus, not sets of virtual cpus.Right. I was carrying through the previous incorrect behavior: cpumap = sxp.child_value(info, ''cpumap'', []) mask = ((int(sxp.child_value(info, ''vcpus'', ''0'')))**2) - 1> > Second, I meant that the cpumap list should contain just the list of > physical cpus that that vcpu can run on. So, for example, a cpumap > bitmask of 0x5 would correspond to the cpumap list [0, 2], not the list > [0, -1, 2, -1, -1, ...]. The latter is a weird and redundant > representation.OK. That was my poor hack around python/c blowing up if you didn''t fill out every spot in the list you created. I''m going to switch to using PyList_Append() rather than creating the list size up front. Are you interested in any modification of the cpumap to list conversion? Or is it ok if vcpu-list shows a long list of integers? 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]. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2005-Oct-20 16:03 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
On 20 Oct 2005, at 16:24, Ryan Harper wrote:> Are you interested in any modification of the cpumap to list > conversion? > Or is it ok if vcpu-list shows a long list of integers?I think an ordered list of cpus is most user-friendly, perhaps using range notation to keep it short (so, for example, mask 0x77 would print as ''0-2, 4-6'' rather than ''0, 1, 2, 4, 5, 6''). A mask is a more succinct representation but maybe not so good for users. :-)> 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. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ryan Harper
2005-Oct-20 16:23 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [2005-10-20 11:00]:> > On 20 Oct 2005, at 16:24, Ryan Harper wrote: > > >Are you interested in any modification of the cpumap to list > >conversion? > >Or is it ok if vcpu-list shows a long list of integers? > > I think an ordered list of cpus is most user-friendly, perhaps using > range notation to keep it short (so, for example, mask 0x77 would print > as ''0-2, 4-6'' rather than ''0, 1, 2, 4, 5, 6''). A mask is a more > succinct representation but maybe not so good for users. :-)Agreed. I''ll work up something that tries to shrink the list into something smaller but still readable.> > >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. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2005-Oct-20 20:10 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
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. :-) 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. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ryan Harper
2005-Oct-21 14:03 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [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@us.ibm.com diffstat output: lowlevel/xc/xc.c | 17 ++++++++++----- xm/main.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 8 deletions(-) Signed-off-by: Ryan Harper <ryanh@us.ibm.com> --- 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@lists.xensource.com http://lists.xensource.com/xen-devel
Ryan Harper
2005-Oct-21 15:02 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [2005-10-21 10:00]:> > On 21 Oct 2005, at 15:03, Ryan Harper wrote: > > >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). > > The usage examples you posted look fine to me. > > As for pincpu: I think it should accept a list of integers and turn > that into a cpumap_t (i.e., do the reverse operation of what we do in > vcpu_getinfo). > > Then python code does not see cpumap bitmaps at all. Just lists of > integers.Makes sense. I''ll send in a patch. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2005-Oct-21 15:04 UTC
Re: [Xen-devel] [PATCH] tools: convert cpumap bitmap to list
On 21 Oct 2005, at 15:03, Ryan Harper wrote:> 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).The usage examples you posted look fine to me. As for pincpu: I think it should accept a list of integers and turn that into a cpumap_t (i.e., do the reverse operation of what we do in vcpu_getinfo). Then python code does not see cpumap bitmaps at all. Just lists of integers. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [2005-10-21 10:00]:> > On 21 Oct 2005, at 15:03, Ryan Harper wrote: > > >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). > > The usage examples you posted look fine to me. > > As for pincpu: I think it should accept a list of integers and turn > that into a cpumap_t (i.e., do the reverse operation of what we do in > vcpu_getinfo). > > Then python code does not see cpumap bitmaps at all. Just lists of > integers.This patch removes the assembly of the cpumap_t from python. xm/xend only pass around a list of ints, or a string representation of the list as xc_domain_pincpu now constructs the cpumap from the list if it is passed. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com diffstat output: lowlevel/xc/xc.c | 19 ++++++++++++++----- xend/XendClient.py | 2 +- xend/XendDomain.py | 9 ++++++--- xend/server/SrvDomain.py | 2 +- xm/main.py | 6 +----- 5 files changed, 23 insertions(+), 15 deletions(-) Signed-off-by: Ryan Harper <ryanh@us.ibm.com> --- diff -r 3fea5df6d4cd tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/lowlevel/xc/xc.c Fri Oct 21 11:55:55 2005 @@ -204,14 +204,23 @@ XcObject *xc = (XcObject *)self; uint32_t dom; - int vcpu = 0; + int vcpu = 0, i; cpumap_t cpumap = ~0ULL; + PyObject *list; static char *kwd_list[] = { "dom", "vcpu", "cpumap", NULL }; - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|il", kwd_list, - &dom, &vcpu, &cpumap) ) - return NULL; + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list, + &dom, &vcpu, &list) ) + return NULL; + + /* see if a list was passed */ + if(PyList_Check(list)) { + /* clear the map for building the value from list */ + cpumap = 0ULL; + for ( i = 0; i < PyList_Size(list); i++ ) + cpumap |= (cpumap_t)(1 << PyInt_AsLong(PyList_GetItem(list, i))); + } if ( xc_domain_pincpu(xc->xc_handle, dom, vcpu, cpumap) != 0 ) return PyErr_SetFromErrno(xc_error); @@ -900,7 +909,7 @@ "Pin a VCPU to a specified set CPUs.\n" " dom [int]: Identifier of domain to which VCPU belongs.\n" " vcpu [int, 0]: VCPU being pinned.\n" - " cpumap [int, -1]: Bitmap of usable CPUs.\n\n" + " cpumap [list, []]: list of usable CPUs.\n\n" "Returns: [int] 0 on success; -1 on error.\n" }, { "domain_setcpuweight", diff -r 3fea5df6d4cd tools/python/xen/xend/XendClient.py --- a/tools/python/xen/xend/XendClient.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/XendClient.py Fri Oct 21 11:55:55 2005 @@ -258,7 +258,7 @@ return self.xendPost(self.domainurl(id), {''op'' : ''pincpu'', ''vcpu'' : vcpu, - ''cpumap'' : cpumap }) + ''cpumap'' : str(cpumap) }) def xend_domain_cpu_bvt_set(self, id, mcuadv, warpback, warpvalue, warpl, warpu): return self.xendPost(self.domainurl(id), diff -r 3fea5df6d4cd tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/XendDomain.py Fri Oct 21 11:55:55 2005 @@ -412,9 +412,12 @@ def domain_pincpu(self, domid, vcpu, cpumap): """Set which cpus vcpu can use - @param cpumap: bitmap of usable cpus - """ - dominfo = self.domain_lookup(domid) + @param cpumap: string repr of list of usable cpus + """ + dominfo = self.domain_lookup(domid) + # convert cpumap string into a list of ints + cpumap = map(lambda x: int(x), + cpumap.replace("[", "").replace("]", "").split(",")) try: return xc.domain_pincpu(dominfo.getDomid(), vcpu, cpumap) except Exception, ex: diff -r 3fea5df6d4cd tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/server/SrvDomain.py Fri Oct 21 11:55:55 2005 @@ -89,7 +89,7 @@ fn = FormFn(self.xd.domain_pincpu, [[''dom'', ''int''], [''vcpu'', ''int''], - [''cpumap'', ''int'']]) + [''cpumap'', ''str'']]) val = fn(req.args, {''dom'': self.dom.domid}) return val diff -r 3fea5df6d4cd tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xm/main.py Fri Oct 21 11:55:55 2005 @@ -411,7 +411,6 @@ def cpu_make_map(cpulist): cpus = [] - cpumap = 0 for c in cpulist.split('',''): if c.find(''-'') != -1: (x,y) = c.split(''-'') @@ -420,10 +419,7 @@ else: cpus.append(int(c)) cpus.sort() - for c in cpus: - cpumap = cpumap | 1<<c - - return cpumap + return cpus def xm_vcpu_pin(args): arg_check(args, 3, "vcpu-pin") _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
* Keir Fraser <Keir.Fraser@cl.cam.ac.uk> [2005-10-21 10:00]:> > On 21 Oct 2005, at 15:03, Ryan Harper wrote: > > >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). > > The usage examples you posted look fine to me. > > As for pincpu: I think it should accept a list of integers and turn > that into a cpumap_t (i.e., do the reverse operation of what we do in > vcpu_getinfo). > > Then python code does not see cpumap bitmaps at all. Just lists of > integers.This patch removes the assembly of the cpumap_t from python. xm/xend only pass around a list of ints, or a string representation of the list as xc_domain_pincpu now constructs the cpumap from the list if it is passed. -- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx (512) 838-9253 T/L: 678-9253 ryanh@us.ibm.com diffstat output: lowlevel/xc/xc.c | 19 ++++++++++++++----- xend/XendClient.py | 2 +- xend/XendDomain.py | 9 ++++++--- xend/server/SrvDomain.py | 2 +- xm/main.py | 6 +----- 5 files changed, 23 insertions(+), 15 deletions(-) Signed-off-by: Ryan Harper <ryanh@us.ibm.com> --- diff -r 3fea5df6d4cd tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/lowlevel/xc/xc.c Fri Oct 21 11:55:55 2005 @@ -204,14 +204,23 @@ XcObject *xc = (XcObject *)self; uint32_t dom; - int vcpu = 0; + int vcpu = 0, i; cpumap_t cpumap = ~0ULL; + PyObject *list; static char *kwd_list[] = { "dom", "vcpu", "cpumap", NULL }; - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|il", kwd_list, - &dom, &vcpu, &cpumap) ) - return NULL; + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|iO", kwd_list, + &dom, &vcpu, &list) ) + return NULL; + + /* see if a list was passed */ + if(PyList_Check(list)) { + /* clear the map for building the value from list */ + cpumap = 0ULL; + for ( i = 0; i < PyList_Size(list); i++ ) + cpumap |= (cpumap_t)(1 << PyInt_AsLong(PyList_GetItem(list, i))); + } if ( xc_domain_pincpu(xc->xc_handle, dom, vcpu, cpumap) != 0 ) return PyErr_SetFromErrno(xc_error); @@ -900,7 +909,7 @@ "Pin a VCPU to a specified set CPUs.\n" " dom [int]: Identifier of domain to which VCPU belongs.\n" " vcpu [int, 0]: VCPU being pinned.\n" - " cpumap [int, -1]: Bitmap of usable CPUs.\n\n" + " cpumap [list, []]: list of usable CPUs.\n\n" "Returns: [int] 0 on success; -1 on error.\n" }, { "domain_setcpuweight", diff -r 3fea5df6d4cd tools/python/xen/xend/XendClient.py --- a/tools/python/xen/xend/XendClient.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/XendClient.py Fri Oct 21 11:55:55 2005 @@ -258,7 +258,7 @@ return self.xendPost(self.domainurl(id), {''op'' : ''pincpu'', ''vcpu'' : vcpu, - ''cpumap'' : cpumap }) + ''cpumap'' : str(cpumap) }) def xend_domain_cpu_bvt_set(self, id, mcuadv, warpback, warpvalue, warpl, warpu): return self.xendPost(self.domainurl(id), diff -r 3fea5df6d4cd tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/XendDomain.py Fri Oct 21 11:55:55 2005 @@ -412,9 +412,12 @@ def domain_pincpu(self, domid, vcpu, cpumap): """Set which cpus vcpu can use - @param cpumap: bitmap of usable cpus - """ - dominfo = self.domain_lookup(domid) + @param cpumap: string repr of list of usable cpus + """ + dominfo = self.domain_lookup(domid) + # convert cpumap string into a list of ints + cpumap = map(lambda x: int(x), + cpumap.replace("[", "").replace("]", "").split(",")) try: return xc.domain_pincpu(dominfo.getDomid(), vcpu, cpumap) except Exception, ex: diff -r 3fea5df6d4cd tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xend/server/SrvDomain.py Fri Oct 21 11:55:55 2005 @@ -89,7 +89,7 @@ fn = FormFn(self.xd.domain_pincpu, [[''dom'', ''int''], [''vcpu'', ''int''], - [''cpumap'', ''int'']]) + [''cpumap'', ''str'']]) val = fn(req.args, {''dom'': self.dom.domid}) return val diff -r 3fea5df6d4cd tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Fri Oct 21 15:03:28 2005 +++ b/tools/python/xen/xm/main.py Fri Oct 21 11:55:55 2005 @@ -411,7 +411,6 @@ def cpu_make_map(cpulist): cpus = [] - cpumap = 0 for c in cpulist.split('',''): if c.find(''-'') != -1: (x,y) = c.split(''-'') @@ -420,10 +419,7 @@ else: cpus.append(int(c)) cpus.sort() - for c in cpus: - cpumap = cpumap | 1<<c - - return cpumap + return cpus def xm_vcpu_pin(args): arg_check(args, 3, "vcpu-pin") _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel