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

Re: [virt-tools-list] [PATCH] Virt-manager CPU pinning support



Hello everybody,
this is new version of my patch. It's now showing traceback and it's working on Python 2.5 as well (I used Python 2.6 construction here before so I fixed this now).

Also, previous version had an issue of not showing Maximum allocation because of badly written .glade file. This is also fixed in this one.

Thanks,
Michal

On 07/21/2009 06:25 PM, Michal Novotny wrote:
Hi again,
sorry, there was a mistake preventing showing currently used pinning value on the Processor tab in details. This patch should have this one problem fixed...

Thanks,
Michal

On 07/21/2009 05:54 PM, Michal Novotny wrote:
Hi all,
since having virt-manager with CPU pinning support would be a nice new feature I've added this support to my virt-manager (that has been updated from hg repository today to the newest version so there should be no problem with codebase). Basically it shows "CPU Affinity string" entry on Processor tab in VM details. Apply button is not applicable when you provide bad CPU pinning string so that you should double-check the pinning string if you can't apply changes. If you want to disable CPU pinning, just delete the string to default value (zero length string) and it will unset this entry in libvirt XML file it won't be used for domain creation then.

Michal

_______________________________________________ virt-tools-list mailing list virt-tools-list redhat com https://www.redhat.com/mailman/listinfo/virt-tools-list


_______________________________________________ virt-tools-list mailing list virt-tools-list redhat com https://www.redhat.com/mailman/listinfo/virt-tools-list

# HG changeset patch
# User Michal Novotny <minovotn redhat com>
# Date 1248645844 -7200
# Node ID c1e448bd6fc8652faaf8e684b366213fcd950c5b
# Parent  0446206f5cba0e89a71a92e528da1bde4565a710
CPU Pinning support

Virt-manager doesn't consider CPU pinning settings in the Processor tab yet so
this is the patch to provide CPU pinning support for virt-manager. It's using
only CPU definition for libvirt itself and it doesn't support CPU pinning for
domains that are currently in running state since this feature will be rarely
used for already running domains in my opinion.

diff -r 0446206f5cba -r c1e448bd6fc8 src/virtManager/details.py
--- a/src/virtManager/details.py	Sun Jul 26 16:09:46 2009 -0400
+++ b/src/virtManager/details.py	Mon Jul 27 00:04:04 2009 +0200
@@ -786,6 +786,7 @@
 
         ro = vm.is_read_only()
         self.window.get_widget("config-vcpus").set_sensitive(not ro)
+        self.window.get_widget("config-vcpupin").set_sensitive(not ro)
         self.window.get_widget("config-memory").set_sensitive(not ro)
         self.window.get_widget("config-maxmem").set_sensitive(not ro)
         self.window.get_widget("details-menu-migrate").set_sensitive(not ro)
@@ -973,6 +974,7 @@
         if not(self.window.get_widget("config-apply").get_property("sensitive")):
             self.window.get_widget("config-vcpus").get_adjustment().value = self.vm.vcpu_count()
         self.window.get_widget("state-vm-vcpus").set_text("%d" % (self.vm.vcpu_count()))
+        self.window.get_widget("config-vcpupin").set_text("%s" % self.vm.vcpu_pinning() )
 
     def refresh_config_memory(self):
         self.window.get_widget("state-host-memory").set_text("%d MB" % (int(round(self.vm.get_connection().host_memory_size()/1024))))
@@ -1598,8 +1600,21 @@
 
     def config_vcpus_apply(self):
         vcpus = self.window.get_widget("config-vcpus").get_adjustment().value
-        logging.info("Setting vcpus for %s to %s" % (self.vm.get_name(),
-                                                     str(vcpus)))
+        cpuset = self.window.get_widget("config-vcpupin").get_text()
+
+        try:
+            self.vm.get_cpuset_syntax_error(cpuset)
+        except Exception, e:
+            self.err.show_err(_("Error setting CPU pinning: %s") % str(e),
+                              "".join(traceback.format_exc()))
+            return False
+
+        # Since for cpuset we require None for define_vcpus, we'll change this now
+        if len(cpuset) == 0:
+            cpuset = None
+
+        logging.info("Setting vcpus for %s to %s, cpuset is %s" % 
+                                    (self.vm.get_name(), str(vcpus), cpuset))
         hotplug_err = False
 
         try:
@@ -1611,7 +1626,7 @@
 
         # Change persistent config
         try:
-            self.vm.define_vcpus(vcpus)
+            self.vm.define_vcpus(vcpus, cpuset)
         except Exception, e:
             self.err.show_err(_("Error changing vcpu value: %s" % str(e)),
                               "".join(traceback.format_exc()))
diff -r 0446206f5cba -r c1e448bd6fc8 src/virtManager/domain.py
--- a/src/virtManager/domain.py	Sun Jul 26 16:09:46 2009 -0400
+++ b/src/virtManager/domain.py	Mon Jul 27 00:04:04 2009 +0200
@@ -24,9 +24,11 @@
 import logging
 import time
 import difflib
+import re
 
 from virtManager import util
 import virtinst.util as vutil
+import virtinst.Guest as vguest
 
 def safeint(val, fmt="%.3d"):
     try:
@@ -554,6 +556,13 @@
             return 0
         return self.record[0]["vcpuCount"]
 
+    def vcpu_pinning(self):
+        cpuset = vutil.get_xml_path(self.get_xml(), "/domain/vcpu/@cpuset")
+        # We need to set it to empty string not to show None in the entry
+        if cpuset is None:
+           cpuset = ""
+        return cpuset
+
     def vcpu_max_count(self):
         cpus = vutil.get_xml_path(self.get_xml(), "/domain/vcpu")
         return int(cpus)
@@ -1308,22 +1317,39 @@
         if vcpus != self.vcpu_count():
             self.vm.setVcpus(vcpus)
 
-    def define_vcpus(self, vcpus):
+    def get_cpuset_syntax_error(self, val):
+        # We need to allow None value and empty string so we can't get
+        # rid of this function
+        if len(val) == 0:
+            return None
+
+        guest = vguest(connection = self.get_connection().vmm)
+        guest.cpuset = val
+
+    def define_vcpus(self, vcpus, cpuset=None):
         vcpus = int(vcpus)
 
-        def set_node(doc, ctx, val, xpath):
+        def set_node(doc, ctx, vcpus, cpumask, xpath):
             node = ctx.xpathEval(xpath)
             node = (node and node[0] or None)
 
             if node:
-                node.setContent(str(val))
+                node.setContent(str(vcpus))
+
+                # If cpuset mask is not valid, don't change it
+                # If cpuset mask is None, we don't want to use cpuset
+                if cpumask is None or (cpumask is not None
+                    and len(cpumask) == 0):
+                    node.unsetProp("cpuset")
+                elif not self.get_cpuset_syntax_error(cpumask):
+                    node.setProp("cpuset", cpumask)
             return doc.serialize()
 
-        def change_vcpu_xml(xml, vcpus):
-            return util.xml_parse_wrapper(xml, set_node, vcpus,
+        def change_vcpu_xml(xml, vcpus, cpuset):
+            return util.xml_parse_wrapper(xml, set_node, vcpus, cpuset,
                                           "/domain/vcpu[1]")
 
-        self.redefine(change_vcpu_xml, vcpus)
+        self.redefine(change_vcpu_xml, vcpus, cpuset)
 
     def hotplug_memory(self, memory):
         if memory != self.get_memory():
diff -r 0446206f5cba -r c1e448bd6fc8 src/vmm-details.glade
--- a/src/vmm-details.glade	Sun Jul 26 16:09:46 2009 -0400
+++ b/src/vmm-details.glade	Mon Jul 27 00:04:04 2009 +0200
@@ -1575,14 +1575,27 @@
                                               </packing>
                                             </child>
                                             <child>
+                                              <widget class="GtkLabel" id="label336">
+                                                <property name="visible">True</property>
+                                                <property name="xalign">1</property>
+                                                <property name="label" translatable="yes">Physical CPU pinning:</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="top_attach">2</property>
+                                                <property name="bottom_attach">3</property>
+                                                <property name="x_options">GTK_FILL</property>
+                                                <property name="y_options"></property>
+                                              </packing>
+                                            </child>
+                                            <child>
                                               <widget class="GtkLabel" id="label335">
                                                 <property name="visible">True</property>
                                                 <property name="xalign">1</property>
                                                 <property name="label" translatable="yes">Maximum allocation:</property>
                                               </widget>
                                               <packing>
-                                                <property name="top_attach">2</property>
-                                                <property name="bottom_attach">3</property>
+                                                <property name="top_attach">3</property>
+                                                <property name="bottom_attach">4</property>
                                                 <property name="x_options">GTK_FILL</property>
                                                 <property name="y_options"></property>
                                               </packing>
@@ -1594,8 +1607,8 @@
                                                 <property name="label" translatable="yes">Total CPUs on host machine:</property>
                                               </widget>
                                               <packing>
-                                                <property name="top_attach">3</property>
-                                                <property name="bottom_attach">4</property>
+                                                <property name="top_attach">4</property>
+                                                <property name="bottom_attach">5</property>
                                                 <property name="x_options">GTK_FILL</property>
                                                 <property name="y_options"></property>
                                               </packing>
@@ -1609,8 +1622,8 @@
                                               <packing>
                                                 <property name="left_attach">1</property>
                                                 <property name="right_attach">2</property>
-                                                <property name="top_attach">2</property>
-                                                <property name="bottom_attach">3</property>
+                                                <property name="top_attach">3</property>
+                                                <property name="bottom_attach">4</property>
                                                 <property name="x_options">GTK_FILL</property>
                                                 <property name="y_options"></property>
                                               </packing>
@@ -1624,8 +1637,8 @@
                                               <packing>
                                                 <property name="left_attach">1</property>
                                                 <property name="right_attach">2</property>
-                                                <property name="top_attach">3</property>
-                                                <property name="bottom_attach">4</property>
+                                                <property name="top_attach">4</property>
+                                                <property name="bottom_attach">5</property>
                                                 <property name="x_options">GTK_FILL</property>
                                                 <property name="y_options"></property>
                                               </packing>
@@ -1665,6 +1678,24 @@
                                                 <property name="y_options"></property>
                                               </packing>
                                             </child>
+		                            <child>
+		                              <widget class="GtkEntry" id="config-vcpupin">
+		                                <property name="visible">True</property>
+		                                <property name="can_focus">True</property>
+		                                <property name="editable">True</property>
+		                                <accessibility>
+		                                  <atkproperty name="AtkObject::accessible-name" translatable="yes">Virtual CPU Affinity Select</atkproperty>                                    </accessibility>
+		                                <signal name="changed" handler="on_config_vcpus_changed"/>
+		                              </widget>
+		                              <packing>
+		                                <property name="left_attach">1</property>
+		                                <property name="right_attach">2</property>
+		                                <property name="top_attach">2</property>
+		                                <property name="bottom_attach">3</property>
+		                                <property name="x_options">GTK_FILL</property>
+		                                <property name="y_options"></property>
+		                              </packing>
+		                            </child>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>

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