Skip to contentSkip to conversation

architecture-specific stuff in xend

PATCH In review Hollis Blanchard 4 participants 12 messages Aug 8, 2006 – Aug 15, 2006

lore
Share & tools
lore
#0 lore raw

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.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#1 lore raw
Quoted 3 lines · Hollis Blanchard

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.

Quoted 1 line

I'm not sure how/where to instantiate the arch object though.

Presumably you could do the instance() singleton trick?

regards
john

#2 lore raw
Quoted 8 lines · John Levon
Quoted 3 lines · Hollis Blanchard

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.

Quoted 2 lines

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?

Quoted 3 lines
Quoted 1 line

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.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#3 lore raw
Quoted 4 lines · Hollis Blanchard
Quoted 2 lines

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.

Quoted 3 lines
Quoted 1 line

Presumably you could do the instance() singleton trick?

Not sure what you mean.

See XendRoot.py's instance().

Quoted 11 lines

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

We'd still need something to import the right bits...

regards
john

#4 lore raw
In reply to John Levon
Quoted 6 lines · John Levon
Quoted 3 lines · Hollis Blanchard

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:

Quoted 7 lines

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.

Quoted 1 line

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.

#5 lore raw
Quoted 23 lines · Ewan Mellor
Quoted 5 lines · John Levon
Quoted 1 line · Hollis Blanchard

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

Quoted 6 lines

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?

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#6 lore raw
Quoted 26 lines · Hollis Blanchard
Quoted 25 lines · Ewan Mellor
Quoted 5 lines · John Levon
Quoted 1 line · Hollis Blanchard

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

Quoted 7 lines
Quoted 4 lines

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.

#7 lore raw

PATCH 1/1 architecture-specific stuff in xend

Quoted 2 lines · Ewan Mellor

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.

tools/python/xen/xend/XendDomainInfo.py +8 -17
diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py
@@ -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 [email protected]
-                # 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()
 
tools/python/xen/xend/image.py +5 -25
diff -r 8cca42e2610a tools/python/xen/xend/image.py
@@ -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 """
tools/python/xen/xend/arch/__init__.py new file +28 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/__init__.py
@@ -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 <[email protected]>
+
+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 *
tools/python/xen/xend/arch/ia64.py new file +24 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/ia64.py
@@ -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 <[email protected]>
+
+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
tools/python/xen/xend/arch/x86.py new file +27 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/x86.py
@@ -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 <[email protected]>
+
+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
Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#8 lore raw
Quoted 1 line · Hollis Blanchard

John, would you extend this scheme to cover host OS differences? I think

I 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.

Quoted 2 lines

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

#9 lore raw
In reply to Hollis Blanchard

I tried the patch on an ia64 box and it seemed to work just fine, I think it's a great idea.

Quoted 195 lines · Hollis Blanchard
Quoted 2 lines · Ewan Mellor

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.

diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py

tools/python/xen/xend/XendDomainInfo.py +8 -17
@@ -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 [email protected]
-                # 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

tools/python/xen/xend/image.py +5 -25
@@ -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

tools/python/xen/xend/arch/__init__.py new file +28 -0
@@ -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 <[email protected]>
+
+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

tools/python/xen/xend/arch/ia64.py new file +24 -0
@@ -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 <[email protected]>
+
+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

tools/python/xen/xend/arch/x86.py new file +17 -0
@@ -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
+#

tools/python/xen/xend/arch/x86.py line 27

Quoted 10 lines
tools/python/xen/xend/arch/x86.py new file +10 -0
+# Authors: Hollis Blanchard <[email protected]>
+
+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
[email protected]
http://lists.xensource.com/xen-devel

#10 lore raw

PATCH 1/1 architecture-specific stuff in xend

In reply to Ewan Mellor

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.

tools/python/setup.py +1 -0
diff -r 8cca42e2610a tools/python/setup.py
@@ -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',
tools/python/xen/xend/XendDomainInfo.py +8 -17
diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py
@@ -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 [email protected]
-                # 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()
 
tools/python/xen/xend/image.py +5 -26
diff -r 8cca42e2610a tools/python/xen/xend/image.py
@@ -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 """
tools/python/xen/xend/arch/__init__.py new file +28 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/__init__.py
@@ -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 <[email protected]>
+
+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 *
tools/python/xen/xend/arch/ia64.py new file +24 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/ia64.py
@@ -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 <[email protected]>
+
+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
tools/python/xen/xend/arch/x86.py new file +29 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch/x86.py
@@ -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 <[email protected]>
+
+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
Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#11 lore raw
Quoted 2 lines · Hollis Blanchard

Here is the update. Special thanks to Dan Stekloff and Daniel Miles, who tested on HVM and IA64, respectively.

...

Quoted 13 lines
(quoted diff) +0 -9
@@ -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:

Review class HVMImageHandler(ImageHandler): · line 347

Quoted 10 lines
(quoted diff) +2 -5
-            #   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:

tools/python/xen/xend/XendDomainInfo.py +8 -17
diff -r 8cca42e2610a tools/python/xen/xend/XendDomainInfo.py
@@ -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 [email protected]
-                # 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()
 
tools/python/xen/xend/image.py +45 -43

122 lines not on this page · raw message

tools/python/xen/xend/arch.py new file +31 -0
diff -r 8cca42e2610a tools/python/xen/xend/arch.py
@@ -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 <[email protected]>
+
+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:

tools/python/xen/xend/image.py +34 -1
diff -r acb9e95d892b tools/python/xen/xend/image.py
@@ -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?

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center