Hi Ewan, I''m almost ready to integrate some PPC-specific stuff into xend, and I was wondering if you had a plan for how that should work. First example: the device tree data structure we talked about a few weeks ago. We will need to pass the config data to PPC code, probably in XendDomainInfo.initDomain(), and then pass the resulting data structure into libxc''s xc_linux_load() somehow. As another example, initDomain() already has some architecture hackage in it for memory allocation. We think we''ll need to modify that some more in the future for PPC, possibly even changing the "order" argument to xc.domain_memory_increase_reservation(). Rather than having these inline tests everywhere ("if os.uname()[4] in (''ia64'', ''ppc64''):"), would it make more sense to have some sort of "architecture" object, and do things like: class Architecture: def init_reservation(self, mem_kb): return mem_kb def init_reservation_order(self): return 0 class ia64_Architecture(Architecture): def init_reservation(self, mem_kb): if ''hvm'' in xc.xeninfo()[''xen_caps'']: mem_kb += 4*1024; return mem_kb Sample use in XendDomainInfo.py: from xen.xend import arch ... init_reservation = arch.init_reservation(mem_kb) I''m not sure how/where to instantiate the arch object though. Does that make sense to you? The Architecture object would expand to include every piece of arch-specific functionality we run across in the future. -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
John Levon
2006-Aug-08 15:59 UTC
[XenPPC] Re: [Xen-devel] architecture-specific stuff in xend
On Tue, Aug 08, 2006 at 10:34:25AM -0500, Hollis Blanchard wrote:> Rather than having these inline tests everywhere ("if os.uname()[4] in > (''ia64'', ''ppc64''):"), would it make more sense to have some sort of > "architecture" object, and do things like:It''d be good if it were slightly more general and covered other system stuff too (namely OS). On Solaris some of the Xen binaries/scripts live in different locations in order to meet our file system requirements.> I''m not sure how/where to instantiate the arch object though.Presumably you could do the instance() singleton trick? regards john _______________________________________________ Xen-ppc-devel mailing list Xen-ppc-devel@lists.xensource.com http://lists.xensource.com/xen-ppc-devel
Hollis Blanchard
2006-Aug-08 16:15 UTC
Re: [Xen-devel] architecture-specific stuff in xend
On Tue, 2006-08-08 at 16:59 +0100, John Levon wrote:> On Tue, Aug 08, 2006 at 10:34:25AM -0500, Hollis Blanchard wrote: > > > Rather than having these inline tests everywhere ("if os.uname()[4] in > > (''ia64'', ''ppc64''):"), would it make more sense to have some sort of > > "architecture" object, and do things like: > > It''d be good if it were slightly more general and covered other system > stuff too (namely OS).Sure, we could make it "class Platform" and have it represent an architecture/OS pair.> On Solaris some of the Xen binaries/scripts live > in different locations in order to meet our file system requirements.Does that impact code under tools/python/xen much?> > I''m not sure how/where to instantiate the arch object though. > > Presumably you could do the instance() singleton trick?Not sure what you mean. Actually, you bring up a good point: since we have no state (at least not in the examples I''m thinking of), we really don''t want/need a class; a module would do just fine. So we could have separate files/modules with just plain functions: platform/ia64.py: def init_reservation(mem_kb): return something platform/platform.py: import xen.xend.platform.ia64 as platform ... or something. Like I said, I really don''t know modules, but as long as we don''t have any arch-specific state we need to save, I''m pretty sure modules are the right solution to this problem. -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Tue, Aug 08, 2006 at 11:15:18AM -0500, Hollis Blanchard wrote:> > On Solaris some of the Xen binaries/scripts live > > in different locations in order to meet our file system requirements. > > Does that impact code under tools/python/xen much?Very little, but it does affect the location of the network scripts, for example.> > Presumably you could do the instance() singleton trick? > > Not sure what you mean.See XendRoot.py''s instance().> Actually, you bring up a good point: since we have no state (at least > not in the examples I''m thinking of), we really don''t want/need a class; > a module would do just fine. So we could have separate files/modules > with just plain functions: > > platform/ia64.py: > def init_reservation(mem_kb): > return something > > platform/platform.py: > import xen.xend.platform.ia64 as platformWe''d still need something to import the right bits... regards john _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Tue, Aug 08, 2006 at 04:59:53PM +0100, John Levon wrote:> On Tue, Aug 08, 2006 at 10:34:25AM -0500, Hollis Blanchard wrote: > > > Rather than having these inline tests everywhere ("if os.uname()[4] in > > (''ia64'', ''ppc64''):"), would it make more sense to have some sort of > > "architecture" object, and do things like: > > It''d be good if it were slightly more general and covered other system > stuff too (namely OS). On Solaris some of the Xen binaries/scripts live > in different locations in order to meet our file system requirements. > > > I''m not sure how/where to instantiate the arch object though. > > Presumably you could do the instance() singleton trick?This being Python, you don''t actually need singletons -- the containing module is a singleton in its own right. You can just write Platform.py: import os if os.uname()[4] in (''ia64'', ''ppc64''): def init_reservation(mem_kb): return something_else(mem_kb) else: def init_reservation(mem_kb): return mem_kb and then import Platform Platform.init_reservation(100) will do the right thing. Ewan. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Aug-09 15:07 UTC
Re: [Xen-devel] architecture-specific stuff in xend
On Wed, 2006-08-09 at 10:28 +0100, Ewan Mellor wrote:> On Tue, Aug 08, 2006 at 04:59:53PM +0100, John Levon wrote: > > > On Tue, Aug 08, 2006 at 10:34:25AM -0500, Hollis Blanchard wrote: > > > > > I''m not sure how/where to instantiate the arch object though. > > > > Presumably you could do the instance() singleton trick? > > This being Python, you don''t actually need singletons -- the containing module > is a singleton in its own right. You can just write > > Platform.py: > > import os > > if os.uname()[4] in (''ia64'', ''ppc64''): > def init_reservation(mem_kb): > return something_else(mem_kb) > > else: > def init_reservation(mem_kb): > return mem_kb > > and then > > import Platform > Platform.init_reservation(100) > > will do the right thing.Ewan, does this mean you think the proposal is going in the right direction and you''re waiting for a patch? -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Wed, Aug 09, 2006 at 10:07:12AM -0500, Hollis Blanchard wrote:> On Wed, 2006-08-09 at 10:28 +0100, Ewan Mellor wrote: > > On Tue, Aug 08, 2006 at 04:59:53PM +0100, John Levon wrote: > > > > > On Tue, Aug 08, 2006 at 10:34:25AM -0500, Hollis Blanchard wrote: > > > > > > > I''m not sure how/where to instantiate the arch object though. > > > > > > Presumably you could do the instance() singleton trick? > > > > This being Python, you don''t actually need singletons -- the containing module > > is a singleton in its own right. You can just write > > > > Platform.py: > > > > import os > > > > if os.uname()[4] in (''ia64'', ''ppc64''): > > def init_reservation(mem_kb): > > return something_else(mem_kb) > > > > else: > > def init_reservation(mem_kb): > > return mem_kb > > > > and then > > > > import Platform > > Platform.init_reservation(100) > > > > will do the right thing. > > Ewan, does this mean you think the proposal is going in the right > direction and you''re waiting for a patch?Yes, your proposal sounds fine to me. Ewan. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Aug-10 21:12 UTC
[Xen-devel] [PATCH] architecture-specific stuff in xend
On Wed, 2006-08-09 at 17:18 +0100, Ewan Mellor wrote:> > Yes, your proposal sounds fine to me.OK, here is the first proof-of-concept. IA64 and HVM people will definitely need to check this over, because it looks like there was some *serious* bitrot in this area. (For example, I can''t see how an HVM domain would have made it into class ImageHandler in the first place.) John, would you extend this scheme to cover host OS differences? I think it''s worth separating the attributes of the host and the guest, and this patch below is all about guest stuff. W.R.T. tools/python/xen/util/Brctl.py, wouldn''t it make more sense to replace that file entirely depending on the host OS? [XEND] Abstract architecture-specific guest code into a module. Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 15:45:00 2006 -0500 @@ -1279,23 +1279,14 @@ class XendDomainInfo: cpu = [ int( cpus[v % len(cpus)] ) ] xc.vcpu_setaffinity(self.domid, v, cpu) - # set domain maxmem in KiB - xc.domain_setmaxmem(self.domid, self.info[''maxmem''] * 1024) - - m = self.image.getDomainMemory(self.info[''memory''] * 1024) - balloon.free(m) - - init_reservation = self.info[''memory''] * 1024 - if os.uname()[4] in (''ia64'', ''ppc64''): - # Workaround for architectures that don''t yet support - # ballooning. - init_reservation = m - # Following line from xiantao.zhang@intel.com - # Needed for IA64 until supports ballooning -- okay for PPC64? - xc.domain_setmaxmem(self.domid, m) - - xc.domain_memory_increase_reservation(self.domid, init_reservation, - 0, 0) + # set memory limit + maxmem = self.image.getRequiredMemory(self.info[''maxmem''] * 1024) + xc.domain_setmaxmem(self.domid, maxmem) + + # initial memory allocation + mem_kb = self.image.getRequiredMemory(self.info[''memory''] * 1024) + balloon.free(mem_kb) + xc.domain_memory_increase_reservation(self.domid, mem_kb, 0, 0) self.createChannels() diff -r 8cca42e2610a tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/image.py Thu Aug 10 15:45:21 2006 -0500 @@ -27,6 +27,7 @@ from xen.xend.XendLogging import log from xen.xend.XendLogging import log from xen.xend.server.netif import randomMAC from xen.xend.xenstore.xswatch import xswatch +from xen.xend import arch xc = xen.lowlevel.xc.xc() @@ -141,17 +142,8 @@ class ImageHandler: raise VmError(''Building domain failed: ostype=%s dom=%d err=%s'' % (self.ostype, self.vm.getDomid(), str(result))) - - def getDomainMemory(self, mem_kb): - """@return The memory required, in KiB, by the domain to store the - given amount, also in KiB.""" - if os.uname()[4] != ''ia64'': - # A little extra because auto-ballooning is broken w.r.t. HVM - # guests. Also, slack is necessary for live migration since that - # uses shadow page tables. - if ''hvm'' in xc.xeninfo()[''xen_caps'']: - mem_kb += 4*1024; - return mem_kb + def getRequiredMemory(self, domain_kb): + return domain_kb def buildDomain(self): """Build the domain. Define in subclass.""" @@ -349,20 +341,8 @@ class HVMImageHandler(ImageHandler): os.waitpid(self.pid, 0) self.pid = 0 - def getDomainMemory(self, mem_kb): - """@see ImageHandler.getDomainMemory""" - if os.uname()[4] == ''ia64'': - page_kb = 16 - # ROM size for guest firmware, ioreq page and xenstore page - extra_pages = 1024 + 2 - else: - page_kb = 4 - # This was derived emperically: - # 2.4 MB overhead per 1024 MB RAM + 8 MB constant - # + 4 to avoid low-memory condition - extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; - extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) - return mem_kb + extra_pages * page_kb + def getRequiredMemory(self, domain_kb): + return arch.HVMRequiredMemory(domain_kb) def register_shutdown_watch(self): """ add xen store watch on control/shutdown """ diff -r 8cca42e2610a tools/python/xen/xend/arch/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/__init__.py Thu Aug 10 15:18:58 2006 -0500 @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +import os + +_uname = os.uname()[4] +if _uname in ("i386", "i486", "i586", "i686"): + from x86 import * +elif _uname in ("ia64"): + from ia64 import * +elif _uname in ("ppc", "ppc64"): + from powerpc import * diff -r 8cca42e2610a tools/python/xen/xend/arch/ia64.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/ia64.py Thu Aug 10 15:45:08 2006 -0500 @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +def HVMRequiredMemory(mem_kb): + page_kb = 16 + # ROM size for guest firmware, ioreq page and xenstore page + extra_pages = 1024 + 2 + return mem_kb + extra_pages * page_kb diff -r 8cca42e2610a tools/python/xen/xend/arch/x86.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/x86.py Thu Aug 10 15:45:13 2006 -0500 @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +def HVMRequiredMemory(mem_kb): + page_kb = 4 + # This was derived emperically: + # 2.4 MB overhead per 1024 MB RAM + 8 MB constant + # + 4 to avoid low-memory condition + extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; + extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) + return mem_kb + extra_pages * page_kb -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
John Levon
2006-Aug-10 21:27 UTC
Re: [Xen-devel] [PATCH] architecture-specific stuff in xend
On Thu, Aug 10, 2006 at 04:12:37PM -0500, Hollis Blanchard wrote:> John, would you extend this scheme to cover host OS differences? I thinkI think it makes sense to use a parallel scheme of xen/xend/host/ for those parameters. That is, the way you''ve done this looks good to me.> tools/python/xen/util/Brctl.py, wouldn''t it make more sense to replace > that file entirely depending on the host OS?Yes. As it is, it''s only used for the vnet stuff, which only exists on Linux, so it''s not a super-big problem right now. thanks john _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Daniel Miles
2006-Aug-11 22:59 UTC
Re: [Xen-devel] [PATCH] architecture-specific stuff in xend
I tried the patch on an ia64 box and it seemed to work just fine, I think it''s a great idea. On Thu, 2006-08-10 at 16:12 -0500, Hollis Blanchard wrote:> On Wed, 2006-08-09 at 17:18 +0100, Ewan Mellor wrote: > > > > Yes, your proposal sounds fine to me. > > OK, here is the first proof-of-concept. > > IA64 and HVM people will definitely need to check this over, because it > looks like there was some *serious* bitrot in this area. (For example, I > can''t see how an HVM domain would have made it into class ImageHandler > in the first place.) > > John, would you extend this scheme to cover host OS differences? I think > it''s worth separating the attributes of the host and the guest, and this > patch below is all about guest stuff. W.R.T. > tools/python/xen/util/Brctl.py, wouldn''t it make more sense to replace > that file entirely depending on the host OS? > > > > [XEND] Abstract architecture-specific guest code into a module. > Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> > > diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py > --- a/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 14:29:04 2006 +0100 > +++ b/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 15:45:00 2006 -0500 > @@ -1279,23 +1279,14 @@ class XendDomainInfo: > cpu = [ int( cpus[v % len(cpus)] ) ] > xc.vcpu_setaffinity(self.domid, v, cpu) > > - # set domain maxmem in KiB > - xc.domain_setmaxmem(self.domid, self.info[''maxmem''] * 1024) > - > - m = self.image.getDomainMemory(self.info[''memory''] * 1024) > - balloon.free(m) > - > - init_reservation = self.info[''memory''] * 1024 > - if os.uname()[4] in (''ia64'', ''ppc64''): > - # Workaround for architectures that don''t yet support > - # ballooning. > - init_reservation = m > - # Following line from xiantao.zhang@intel.com > - # Needed for IA64 until supports ballooning -- okay for PPC64? > - xc.domain_setmaxmem(self.domid, m) > - > - xc.domain_memory_increase_reservation(self.domid, init_reservation, > - 0, 0) > + # set memory limit > + maxmem = self.image.getRequiredMemory(self.info[''maxmem''] * 1024) > + xc.domain_setmaxmem(self.domid, maxmem) > + > + # initial memory allocation > + mem_kb = self.image.getRequiredMemory(self.info[''memory''] * 1024) > + balloon.free(mem_kb) > + xc.domain_memory_increase_reservation(self.domid, mem_kb, 0, 0) > > self.createChannels() > > diff -r 8cca42e2610a tools/python/xen/xend/image.py > --- a/tools/python/xen/xend/image.py Thu Aug 10 14:29:04 2006 +0100 > +++ b/tools/python/xen/xend/image.py Thu Aug 10 15:45:21 2006 -0500 > @@ -27,6 +27,7 @@ from xen.xend.XendLogging import log > from xen.xend.XendLogging import log > from xen.xend.server.netif import randomMAC > from xen.xend.xenstore.xswatch import xswatch > +from xen.xend import arch > > > xc = xen.lowlevel.xc.xc() > @@ -141,17 +142,8 @@ class ImageHandler: > raise VmError(''Building domain failed: ostype=%s dom=%d err=%s'' > % (self.ostype, self.vm.getDomid(), str(result))) > > - > - def getDomainMemory(self, mem_kb): > - """@return The memory required, in KiB, by the domain to store the > - given amount, also in KiB.""" > - if os.uname()[4] != ''ia64'': > - # A little extra because auto-ballooning is broken w.r.t. HVM > - # guests. Also, slack is necessary for live migration since that > - # uses shadow page tables. > - if ''hvm'' in xc.xeninfo()[''xen_caps'']: > - mem_kb += 4*1024; > - return mem_kb > + def getRequiredMemory(self, domain_kb): > + return domain_kb > > def buildDomain(self): > """Build the domain. Define in subclass.""" > @@ -349,20 +341,8 @@ class HVMImageHandler(ImageHandler): > os.waitpid(self.pid, 0) > self.pid = 0 > > - def getDomainMemory(self, mem_kb): > - """@see ImageHandler.getDomainMemory""" > - if os.uname()[4] == ''ia64'': > - page_kb = 16 > - # ROM size for guest firmware, ioreq page and xenstore page > - extra_pages = 1024 + 2 > - else: > - page_kb = 4 > - # This was derived emperically: > - # 2.4 MB overhead per 1024 MB RAM + 8 MB constant > - # + 4 to avoid low-memory condition > - extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; > - extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) > - return mem_kb + extra_pages * page_kb > + def getRequiredMemory(self, domain_kb): > + return arch.HVMRequiredMemory(domain_kb) > > def register_shutdown_watch(self): > """ add xen store watch on control/shutdown """ > diff -r 8cca42e2610a tools/python/xen/xend/arch/__init__.py > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/python/xen/xend/arch/__init__.py Thu Aug 10 15:18:58 2006 -0500 > @@ -0,0 +1,28 @@ > +#!/usr/bin/env python > +# > +# This library is free software; you can redistribute it and/or > +# modify it under the terms of version 2.1 of the GNU Lesser General Public > +# License as published by the Free Software Foundation. > +# > +# This library is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > +# Lesser General Public License for more details. > +# > +# You should have received a copy of the GNU Lesser General Public > +# License along with this library; if not, write to the Free Software > +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > +# > +# Copyright (C) IBM Corp. 2006 > +# > +# Authors: Hollis Blanchard <hollisb@us.ibm.com> > + > +import os > + > +_uname = os.uname()[4] > +if _uname in ("i386", "i486", "i586", "i686"): > + from x86 import * > +elif _uname in ("ia64"): > + from ia64 import * > +elif _uname in ("ppc", "ppc64"): > + from powerpc import * > diff -r 8cca42e2610a tools/python/xen/xend/arch/ia64.py > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/python/xen/xend/arch/ia64.py Thu Aug 10 15:45:08 2006 -0500 > @@ -0,0 +1,24 @@ > +#!/usr/bin/env python > +# > +# This library is free software; you can redistribute it and/or > +# modify it under the terms of version 2.1 of the GNU Lesser General Public > +# License as published by the Free Software Foundation. > +# > +# This library is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > +# Lesser General Public License for more details. > +# > +# You should have received a copy of the GNU Lesser General Public > +# License along with this library; if not, write to the Free Software > +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > +# > +# Copyright (C) IBM Corp. 2006 > +# > +# Authors: Hollis Blanchard <hollisb@us.ibm.com> > + > +def HVMRequiredMemory(mem_kb): > + page_kb = 16 > + # ROM size for guest firmware, ioreq page and xenstore page > + extra_pages = 1024 + 2 > + return mem_kb + extra_pages * page_kb > diff -r 8cca42e2610a tools/python/xen/xend/arch/x86.py > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/python/xen/xend/arch/x86.py Thu Aug 10 15:45:13 2006 -0500 > @@ -0,0 +1,27 @@ > +#!/usr/bin/env python > +# > +# This library is free software; you can redistribute it and/or > +# modify it under the terms of version 2.1 of the GNU Lesser General Public > +# License as published by the Free Software Foundation. > +# > +# This library is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > +# Lesser General Public License for more details. > +# > +# You should have received a copy of the GNU Lesser General Public > +# License along with this library; if not, write to the Free Software > +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > +# > +# Copyright (C) IBM Corp. 2006 > +# > +# Authors: Hollis Blanchard <hollisb@us.ibm.com> > + > +def HVMRequiredMemory(mem_kb): > + page_kb = 4 > + # This was derived emperically: > + # 2.4 MB overhead per 1024 MB RAM + 8 MB constant > + # + 4 to avoid low-memory condition > + extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; > + extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) > + return mem_kb + extra_pages * page_kb > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Aug-14 17:40 UTC
[XenPPC] [PATCH] architecture-specific stuff in xend
Here is the update. Special thanks to Dan Stekloff and Daniel Miles, who tested on HVM and IA64, respectively. Ewan, please apply. [XEND] Abstract architecture-specific guest code into a module. Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r 8cca42e2610a tools/python/setup.py --- a/tools/python/setup.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/setup.py Mon Aug 14 11:56:40 2006 -0500 @@ -51,6 +51,7 @@ setup(name = ''xen'', ''xen.web'', ''xen.sv'', + ''xen.xend.arch'', ''xen.xend.tests'', ''xen.xend.server.tests'', ''xen.xend.xenstore.tests'', diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 15:45:00 2006 -0500 @@ -1279,23 +1279,14 @@ class XendDomainInfo: cpu = [ int( cpus[v % len(cpus)] ) ] xc.vcpu_setaffinity(self.domid, v, cpu) - # set domain maxmem in KiB - xc.domain_setmaxmem(self.domid, self.info[''maxmem''] * 1024) - - m = self.image.getDomainMemory(self.info[''memory''] * 1024) - balloon.free(m) - - init_reservation = self.info[''memory''] * 1024 - if os.uname()[4] in (''ia64'', ''ppc64''): - # Workaround for architectures that don''t yet support - # ballooning. - init_reservation = m - # Following line from xiantao.zhang@intel.com - # Needed for IA64 until supports ballooning -- okay for PPC64? - xc.domain_setmaxmem(self.domid, m) - - xc.domain_memory_increase_reservation(self.domid, init_reservation, - 0, 0) + # set memory limit + maxmem = self.image.getRequiredMemory(self.info[''maxmem''] * 1024) + xc.domain_setmaxmem(self.domid, maxmem) + + # initial memory allocation + mem_kb = self.image.getRequiredMemory(self.info[''memory''] * 1024) + balloon.free(mem_kb) + xc.domain_memory_increase_reservation(self.domid, mem_kb, 0, 0) self.createChannels() diff -r 8cca42e2610a tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/image.py Mon Aug 14 11:46:46 2006 -0500 @@ -19,7 +19,6 @@ import os, string import re -import math import xen.lowlevel.xc from xen.xend import sxp @@ -27,6 +26,7 @@ from xen.xend.XendLogging import log from xen.xend.XendLogging import log from xen.xend.server.netif import randomMAC from xen.xend.xenstore.xswatch import xswatch +from xen.xend import arch xc = xen.lowlevel.xc.xc() @@ -141,17 +141,8 @@ class ImageHandler: raise VmError(''Building domain failed: ostype=%s dom=%d err=%s'' % (self.ostype, self.vm.getDomid(), str(result))) - - def getDomainMemory(self, mem_kb): - """@return The memory required, in KiB, by the domain to store the - given amount, also in KiB.""" - if os.uname()[4] != ''ia64'': - # A little extra because auto-ballooning is broken w.r.t. HVM - # guests. Also, slack is necessary for live migration since that - # uses shadow page tables. - if ''hvm'' in xc.xeninfo()[''xen_caps'']: - mem_kb += 4*1024; - return mem_kb + def getRequiredMemory(self, domain_kb): + return domain_kb def buildDomain(self): """Build the domain. Define in subclass.""" @@ -349,20 +340,8 @@ class HVMImageHandler(ImageHandler): os.waitpid(self.pid, 0) self.pid = 0 - def getDomainMemory(self, mem_kb): - """@see ImageHandler.getDomainMemory""" - if os.uname()[4] == ''ia64'': - page_kb = 16 - # ROM size for guest firmware, ioreq page and xenstore page - extra_pages = 1024 + 2 - else: - page_kb = 4 - # This was derived emperically: - # 2.4 MB overhead per 1024 MB RAM + 8 MB constant - # + 4 to avoid low-memory condition - extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; - extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) - return mem_kb + extra_pages * page_kb + def getRequiredMemory(self, domain_kb): + return arch.HVMRequiredMemory(domain_kb) def register_shutdown_watch(self): """ add xen store watch on control/shutdown """ diff -r 8cca42e2610a tools/python/xen/xend/arch/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/__init__.py Thu Aug 10 15:18:58 2006 -0500 @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +import os + +_uname = os.uname()[4] +if _uname in ("i386", "i486", "i586", "i686"): + from x86 import * +elif _uname in ("ia64"): + from ia64 import * +elif _uname in ("ppc", "ppc64"): + from powerpc import * diff -r 8cca42e2610a tools/python/xen/xend/arch/ia64.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/ia64.py Thu Aug 10 15:45:08 2006 -0500 @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +def HVMRequiredMemory(mem_kb): + page_kb = 16 + # ROM size for guest firmware, ioreq page and xenstore page + extra_pages = 1024 + 2 + return mem_kb + extra_pages * page_kb diff -r 8cca42e2610a tools/python/xen/xend/arch/x86.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch/x86.py Mon Aug 14 11:46:35 2006 -0500 @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +import math + +def HVMRequiredMemory(mem_kb): + page_kb = 4 + # This was derived emperically: + # 2.4 MB overhead per 1024 MB RAM + 8 MB constant + # + 4 to avoid low-memory condition + extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; + extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) + return mem_kb + extra_pages * page_kb -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-ppc-devel mailing list Xen-ppc-devel@lists.xensource.com http://lists.xensource.com/xen-ppc-devel
Hollis Blanchard
2006-Aug-15 02:14 UTC
Re: [Xen-devel] [PATCH] architecture-specific stuff in xend
On Mon, 2006-08-14 at 12:40 -0500, Hollis Blanchard wrote:> Here is the update. Special thanks to Dan Stekloff and Daniel Miles, who > tested on HVM and IA64, respectively....> @@ -349,20 +340,8 @@ class HVMImageHandler(ImageHandler): > os.waitpid(self.pid, 0) > self.pid = 0 > > - def getDomainMemory(self, mem_kb): > - """@see ImageHandler.getDomainMemory""" > - if os.uname()[4] == ''ia64'': > - page_kb = 16 > - # ROM size for guest firmware, ioreq page and xenstore page > - extra_pages = 1024 + 2 > - else: > - page_kb = 4 > - # This was derived emperically: > - # 2.4 MB overhead per 1024 MB RAM + 8 MB constant > - # + 4 to avoid low-memory condition > - extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; > - extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) > - return mem_kb + extra_pages * page_kb > + def getRequiredMemory(self, domain_kb): > + return arch.HVMRequiredMemory(domain_kb) > > def register_shutdown_watch(self): > """ add xen store watch on control/shutdown """I''m actually not sure about this approach now. getRequiredMemory() could more naturally be implemented in an ia64- or x86-specific HVM subclass. Here is a totally untested patch illustrating the idea: diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Aug 14 19:57:38 2006 -0500 @@ -1279,23 +1279,14 @@ class XendDomainInfo: cpu = [ int( cpus[v % len(cpus)] ) ] xc.vcpu_setaffinity(self.domid, v, cpu) - # set domain maxmem in KiB - xc.domain_setmaxmem(self.domid, self.info[''maxmem''] * 1024) - - m = self.image.getDomainMemory(self.info[''memory''] * 1024) - balloon.free(m) - - init_reservation = self.info[''memory''] * 1024 - if os.uname()[4] in (''ia64'', ''ppc64''): - # Workaround for architectures that don''t yet support - # ballooning. - init_reservation = m - # Following line from xiantao.zhang@intel.com - # Needed for IA64 until supports ballooning -- okay for PPC64? - xc.domain_setmaxmem(self.domid, m) - - xc.domain_memory_increase_reservation(self.domid, init_reservation, - 0, 0) + # set memory limit + maxmem = self.image.getRequiredMemory(self.info[''maxmem''] * 1024) + xc.domain_setmaxmem(self.domid, maxmem) + + # initial memory allocation + mem_kb = self.image.getRequiredMemory(self.info[''memory''] * 1024) + balloon.free(mem_kb) + xc.domain_memory_increase_reservation(self.domid, mem_kb, 0, 0) self.createChannels() diff -r 8cca42e2610a tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Thu Aug 10 14:29:04 2006 +0100 +++ b/tools/python/xen/xend/image.py Mon Aug 14 20:52:55 2006 -0500 @@ -27,6 +27,7 @@ from xen.xend.XendLogging import log from xen.xend.XendLogging import log from xen.xend.server.netif import randomMAC from xen.xend.xenstore.xswatch import xswatch +from xen.xend import arch xc = xen.lowlevel.xc.xc() @@ -141,17 +142,8 @@ class ImageHandler: raise VmError(''Building domain failed: ostype=%s dom=%d err=%s'' % (self.ostype, self.vm.getDomid(), str(result))) - - def getDomainMemory(self, mem_kb): - """@return The memory required, in KiB, by the domain to store the - given amount, also in KiB.""" - if os.uname()[4] != ''ia64'': - # A little extra because auto-ballooning is broken w.r.t. HVM - # guests. Also, slack is necessary for live migration since that - # uses shadow page tables. - if ''hvm'' in xc.xeninfo()[''xen_caps'']: - mem_kb += 4*1024; - return mem_kb + def getRequiredMemory(self, domain_kb): + return domain_kb def buildDomain(self): """Build the domain. Define in subclass.""" @@ -192,8 +184,6 @@ class LinuxImageHandler(ImageHandler): features = self.vm.getFeatures()) class HVMImageHandler(ImageHandler): - - ostype = "hvm" def configure(self, imageConfig, deviceConfig): ImageHandler.configure(self, imageConfig, deviceConfig) @@ -349,21 +339,6 @@ class HVMImageHandler(ImageHandler): os.waitpid(self.pid, 0) self.pid = 0 - def getDomainMemory(self, mem_kb): - """@see ImageHandler.getDomainMemory""" - if os.uname()[4] == ''ia64'': - page_kb = 16 - # ROM size for guest firmware, ioreq page and xenstore page - extra_pages = 1024 + 2 - else: - page_kb = 4 - # This was derived emperically: - # 2.4 MB overhead per 1024 MB RAM + 8 MB constant - # + 4 to avoid low-memory condition - extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; - extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) - return mem_kb + extra_pages * page_kb - def register_shutdown_watch(self): """ add xen store watch on control/shutdown """ self.shutdownWatch = xswatch(self.vm.dompath + "/control/shutdown", \ @@ -400,15 +375,42 @@ class HVMImageHandler(ImageHandler): return 1 # Keep watching -"""Table of image handler classes for virtual machine images. Indexed by -image type. -""" -imageHandlerClasses = {} - - -for h in LinuxImageHandler, HVMImageHandler: - imageHandlerClasses[h.ostype] = h - +class IA64_HVM_ImageHandler(HVMImageHandler): + + ostype = "hvm" + + def getRequiredMemory(self): + page_kb = 16 + # ROM size for guest firmware, ioreq page and xenstore page + extra_pages = 1024 + 2 + return mem_kb + extra_pages * page_kb + +class X86_HVM_ImageHandler(HVMImageHandler): + + ostype = "hvm" + + def getRequiredMemory(self): + page_kb = 4 + # This was derived emperically: + # 2.4 MB overhead per 1024 MB RAM + 8 MB constant + # + 4 to avoid low-memory condition + extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; + extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) + return mem_kb + extra_pages * page_kb + +_handlers = { + "powerpc": { + "linux": LinuxImageHandler, + }, + "ia64": { + "linux": LinuxImageHandler, + "hvm": IA64_HVM_ImageHandler, + } + "x86": { + "linux": LinuxImageHandler, + "hvm": X86_HVM_ImageHandler, + }, +} def findImageHandlerClass(image): """Find the image handler class for an image config. @@ -416,10 +418,10 @@ def findImageHandlerClass(image): @param image config @return ImageHandler subclass or None """ - ty = sxp.name(image) - if ty is None: + type = sxp.name(image) + if type is None: raise VmError(''missing image type'') - imageClass = imageHandlerClasses.get(ty) - if imageClass is None: - raise VmError(''unknown image type: '' + ty) - return imageClass + try: + return _handlers[arch.type][type] + except KeyError: + raise VmError(''unknown image type: '' + type) diff -r 8cca42e2610a tools/python/xen/xend/arch.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/arch.py Mon Aug 14 20:45:42 2006 -0500 @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (C) IBM Corp. 2006 +# +# Authors: Hollis Blanchard <hollisb@us.ibm.com> + +import os + +_types = { + "i386": "x86", + "i486": "x86", + "i586": "x86", + "i686": "x86", + "ia64": "ia64", + "ppc": "powerpc", + "ppc64": "powerpc", +} +type = _types.get(os.uname()[4], "unknown") Notice that findImageHandlerClass() had to change because we now have two "hvm" handlers. The PowerPC builder will layer on top of that patch: diff -r acb9e95d892b tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py Mon Aug 14 20:53:11 2006 -0500 +++ b/tools/python/xen/xend/image.py Mon Aug 14 21:11:55 2006 -0500 @@ -28,6 +28,7 @@ from xen.xend.server.netif import random from xen.xend.server.netif import randomMAC from xen.xend.xenstore.xswatch import xswatch from xen.xend import arch +from xen.xend import FlatDeviceTree xc = xen.lowlevel.xc.xc() @@ -182,6 +183,38 @@ class LinuxImageHandler(ImageHandler): cmdline = self.cmdline, ramdisk = self.ramdisk, features = self.vm.getFeatures()) + +class PPC_LinuxImageHandler(LinuxImageHandler): + + ostype = "linux" + + def configure(self, imageConfig, deviceConfig): + LinuxImageHandler.__init__(self, imageConfig, deviceConfig) + self.imageConfig = imageConfig + + def buildDomain(self): + store_evtchn = self.vm.getStorePort() + console_evtchn = self.vm.getConsolePort() + + log.debug("dom = %d", self.vm.getDomid()) + log.debug("image = %s", self.kernel) + log.debug("store_evtchn = %d", store_evtchn) + log.debug("console_evtchn = %d", console_evtchn) + log.debug("cmdline = %s", self.cmdline) + log.debug("ramdisk = %s", self.ramdisk) + log.debug("vcpus = %d", self.vm.getVCpuCount()) + log.debug("features = %s", self.vm.getFeatures()) + + devtree = FlatDeviceTree.build(self.imageConfig) + + return xc.linux_build(dom = self.vm.getDomid(), + image = self.kernel, + store_evtchn = store_evtchn, + console_evtchn = console_evtchn, + cmdline = self.cmdline, + ramdisk = self.ramdisk, + features = self.vm.getFeatures() + arch_args = devtree.to_bin()) class HVMImageHandler(ImageHandler): @@ -400,7 +433,7 @@ class X86_HVM_ImageHandler(HVMImageHandl _handlers = { "powerpc": { - "linux": LinuxImageHandler, + "linux": PPC_LinuxImageHandler, }, "ia64": { "linux": LinuxImageHandler, PowerPC needs to convert ''imageConfig'' into a special data structure, as you can see here. (I haven''t attached FlatDeviceTree.py because it''s large and irrelevant for now.) Also, the xc.linux_build() stuff is going to be changed drastically per Keir''s preference, but you get the idea: PowerPC needs extra communication with libxc.. This approach would locate xend architecture-specific code wherever it''s used, rather than in an architecture-specific module. That could probably be changed if desired, but I think it will require mastering __import__(). Thoughts? -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Seemingly Similar Threads
- [RFC PATCH 0/2] use larger max_request_size for virtio_blk
- [RFC PATCH 0/2] use larger max_request_size for virtio_blk
- [PATH] ioemu: use SIGHUP instead of SIGKILL
- xm create - Xend has probably crashed! Invalid or missing HTTP status code.
- xc_dom_create.py cpu flag