[PATCH] BZ#251643: Allow to set the cpu pinning for to create installing domain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I want to set the cpu pinning for create installing domain by virt-install
on RHEL5.1.

So, I just add the option to virt-install.
We will be allowed to set "cpus" parameter in configuration file
and to set "cpuset" parameter in create installing domain with "cpuset" option
by this patch.

command-line example:
  # virt-install --name=domain1 --ram=512 --file=/dev/sdb --cpuset=0,2-4 ...

some notes are follows:
  - cpuset can only contain numeric, ',', or '-' characters.
  - cpuset's pCPU numbers must be less than pCPUs.
  - This is an effective feature for to create installing domain and
    configuration file with libvirt revision >= 1.789.
  - This is an effective feature for to create installing domain and
    configuration file with xen hypervisor.
    Other hypervisor(like kvm, qemu...) ignores this option.
  - This feature covers cpupin on virt-install of BZ#251643.
    It will work about other things(weight, cap, ...) in the future.

Signed-off-by: Tatsuro Enokura <fj7716hz@xxxxxxxxxxxxxxxxx>

Thanks,
Tatsuro Enokura

diff -r c98f26991bad virt-install
--- a/virt-install	Wed Dec 05 15:34:29 2007 -0800
+++ b/virt-install	Thu Dec 06 16:02:31 2007 +0900
@@ -205,6 +205,9 @@ def parse_args():
                       help=_("Number of vcpus to configure for your guest"))
     parser.add_option("", "--check-cpu", action="store_true", dest="check_cpu",
                       help=_("Check that vcpus do not exceed physical CPUs and warn if they do."))
+    parser.add_option("", "--cpuset", type="string", dest="cpuset",
+                      action="callback", callback=cli.check_before_store,
+                      help=_("Set which physical CPUs Domain can use."))
 
     # disk options
     parser.add_option("-f", "--file", type="string",
@@ -409,6 +412,10 @@ def main():
     cli.get_uuid(options.uuid, guest)
     cli.get_vcpus(options.vcpus, options.check_cpu, guest, conn)
 
+    # set up cpuset
+    if type == "xen":
+        cli.get_cpuset(options.cpuset, guest)
+
     # set up disks
     get_disks(options.diskfile, options.disksize, options.sparse, options.nodisks,
               guest, hvm, conn)
diff -r c98f26991bad virtinst/Guest.py
--- a/virtinst/Guest.py	Wed Dec 05 15:34:29 2007 -0800
+++ b/virtinst/Guest.py	Thu Dec 06 16:02:31 2007 +0900
@@ -497,6 +497,7 @@ class Guest(object):
         self._memory = None
         self._maxmemory = None
         self._vcpus = None
+        self._cpuset = None
         self._graphics = { "enabled": False }
         self._keymap = None
         
@@ -598,6 +599,28 @@ class Guest(object):
         self._vcpus = val
     vcpus = property(get_vcpus, set_vcpus)
 
+    # set phy-cpus for the guest
+    def get_cpuset(self):
+        return self._cpuset
+    def set_cpuset(self, val):
+        if type(val) is not type("string") or len(val) == 0:
+            raise ValueError, _("cpuset must be string")
+        if re.match("^[0-9,-]*$", val) is None:
+            raise ValueError, _("cpuset can only contain numeric, ',', or '-' characters")
+
+        pcpus = util.get_phy_cpus(self.conn)
+        for c in val.split(','):
+            if c.find('-') != -1:
+                (x, y) = c.split('-')
+                if int(x) > int(y):
+                    raise ValueError, _("cpuset contains invalid format.")
+                if int(x) >= pcpus or int(y) >= pcpus:
+                    raise ValueError, _("cpuset's pCPU numbers must be less than pCPUs.")
+            else:
+                if int(c) >= pcpus:
+                    raise ValueError, _("cpuset's pCPU numbers must be less than pCPUs.")
+        self._cpuset = val
+    cpuset = property(get_cpuset, set_cpuset)
 
     # graphics setup
     def get_graphics(self):
@@ -743,6 +766,11 @@ class Guest(object):
         if not osblob:
             return None
 
+        if self.cpuset is not None:
+            cpuset = " cpuset='" + self.cpuset + "'"
+        else:
+            cpuset = ""
+
         return """<domain type='%(type)s'>
   <name>%(name)s</name>
   <currentMemory>%(ramkb)s</currentMemory>
@@ -752,7 +780,7 @@ class Guest(object):
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>%(action)s</on_reboot>
   <on_crash>%(action)s</on_crash>
-  <vcpu>%(vcpus)d</vcpu>
+  <vcpu%(cpuset)s>%(vcpus)d</vcpu>
   <devices>
 %(devices)s
   </devices>
@@ -760,6 +788,7 @@ class Guest(object):
 """ % { "type": self.type,
         "name": self.name, \
         "vcpus": self.vcpus, \
+        "cpuset": cpuset, \
         "uuid": self.uuid, \
         "ramkb": self.memory * 1024, \
         "maxramkb": self.maxmemory * 1024, \
diff -r c98f26991bad virtinst/cli.py
--- a/virtinst/cli.py	Wed Dec 05 15:34:29 2007 -0800
+++ b/virtinst/cli.py	Thu Dec 06 16:02:31 2007 +0900
@@ -148,6 +148,10 @@ def get_vcpus(vcpus, check_cpu, guest, c
             guest.vcpus = vcpus
         except ValueError, e:
             print _("ERROR: "), e
+
+def get_cpuset(cpuset, guest):
+    if cpuset:
+        guest.cpuset = cpuset
 
 def get_network(mac, network, guest):
     if mac == "RANDOM":
diff -r c98f26991bad virtinst/util.py
--- a/virtinst/util.py	Wed Dec 05 15:34:29 2007 -0800
+++ b/virtinst/util.py	Thu Dec 06 16:02:31 2007 +0900
@@ -200,3 +200,9 @@ def get_max_vcpus(conn):
         #print >> stderr, _("Couldn't determine max vcpus. Using 32.")
         max = 32
     return max
+
+def get_phy_cpus(conn):
+    """Get number of physical CPUs."""
+    hostinfo = conn.getInfo()
+    pcpus = hostinfo[4] * hostinfo[5] * hostinfo[6] * hostinfo[7]
+    return pcpus
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux