render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From e40f868e4f974ea0bd7224f5d49e602cf2947570 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <e40f868e4f974ea0bd7224f5d49e602cf2947570@dist-git>
6ae9ed
From: John Ferlan <jferlan@redhat.com>
6ae9ed
Date: Tue, 6 Sep 2016 16:43:13 -0400
6ae9ed
Subject: [PATCH] conf: Add IOThread quota and period scheduler/cputune defs
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1356937
6ae9ed
6ae9ed
Add the definitions to allow for viewing/setting cgroup period and quota
6ae9ed
limits for IOThreads.
6ae9ed
6ae9ed
This is similar to the work done for emulator quota and period by
6ae9ed
commit ids 'b65dafa' and 'e051c482'.
6ae9ed
6ae9ed
Being able to view/set the IOThread specific values is related to more
6ae9ed
recent changes adding global period (commmit id '4d92d58f') and global
6ae9ed
quota (commit id '55ecdae') definitions and qemu support (commit id
6ae9ed
'4e17ff79' and 'fbcbd1b2'). With a global setting though, if somehow
6ae9ed
the IOThread value in the cgroup hierarchy was set "outside of libvirt"
6ae9ed
to a value that is incompatible with the global value.
6ae9ed
6ae9ed
Allowing control over IOThread specific values provides the capability
6ae9ed
to alter the IOThread values as necessary.
6ae9ed
6ae9ed
(cherry picked from commit 2197ea56d77ad3da2e838115eed71d2ad393a082)
6ae9ed
Signed-off-by: John Ferlan <jferlan@redhat.com>
6ae9ed
---
6ae9ed
 docs/formatdomain.html.in                          | 25 +++++++++++++
6ae9ed
 docs/schemas/domaincommon.rng                      | 10 ++++++
6ae9ed
 include/libvirt/libvirt-domain.h                   | 32 +++++++++++++++++
6ae9ed
 src/conf/domain_conf.c                             | 42 ++++++++++++++++++++++
6ae9ed
 src/conf/domain_conf.h                             |  2 ++
6ae9ed
 tests/qemuxml2argvdata/qemuxml2argv-cputune.xml    |  2 ++
6ae9ed
 .../qemuxml2xmloutdata/qemuxml2xmlout-cputune.xml  |  2 ++
6ae9ed
 tools/virsh.pod                                    |  9 ++---
6ae9ed
 8 files changed, 120 insertions(+), 4 deletions(-)
6ae9ed
6ae9ed
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
6ae9ed
index c080bdf..5b4f83e 100644
6ae9ed
--- a/docs/formatdomain.html.in
6ae9ed
+++ b/docs/formatdomain.html.in
6ae9ed
@@ -665,6 +665,8 @@
6ae9ed
     <quota>-1</quota>
6ae9ed
     <emulator_period>1000000</emulator_period>
6ae9ed
     <emulator_quota>-1</emulator_quota>
6ae9ed
+    <iothread_period>1000000</iothread_period>
6ae9ed
+    <iothread_quota>-1</iothread_quota>
6ae9ed
     <vcpusched vcpus='0-4,^3' scheduler='fifo' priority='1'/>
6ae9ed
     <iothreadsched iothreads='2' scheduler='batch'/>
6ae9ed
   </cputune>
6ae9ed
@@ -769,6 +771,29 @@
6ae9ed
         Only QEMU driver support since 0.10.0
6ae9ed
       
6ae9ed
 
6ae9ed
+      
iothread_period
6ae9ed
+      
6ae9ed
+        The optional iothread_period element specifies the
6ae9ed
+        enforcement interval(unit: microseconds) for IOThreads. Within
6ae9ed
+        iothread_period, each IOThread of the domain will
6ae9ed
+        not be allowed to consume more than iothread_quota
6ae9ed
+        worth of runtime. The value should be in range [1000, 1000000].
6ae9ed
+        An iothread_period with value 0 means no value.
6ae9ed
+        Only QEMU driver support since 2.1.0
6ae9ed
+      
6ae9ed
+      
iothread_quota
6ae9ed
+      
6ae9ed
+        The optional iothread_quota element specifies the maximum
6ae9ed
+        allowed bandwidth(unit: microseconds) for IOThreads. A domain with
6ae9ed
+        iothread_quota as any negative value indicates that the
6ae9ed
+        domain IOThreads have infinite bandwidth, which means that it is
6ae9ed
+        not bandwidth controlled. The value should be in range
6ae9ed
+        [1000, 18446744073709551] or less than 0. An iothread_quota
6ae9ed
+        with value 0 means no value. You can use this feature to ensure that
6ae9ed
+        all IOThreads run at the same speed.
6ae9ed
+        Only QEMU driver support since 2.1.0
6ae9ed
+      
6ae9ed
+
6ae9ed
       
vcpusched and iothreadsched
6ae9ed
       
6ae9ed
         The optional vcpusched elements specifies the scheduler
6ae9ed
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
6ae9ed
index bf4d795..44e39c8 100644
6ae9ed
--- a/docs/schemas/domaincommon.rng
6ae9ed
+++ b/docs/schemas/domaincommon.rng
6ae9ed
@@ -764,6 +764,16 @@
6ae9ed
             <ref name="cpuquota"/>
6ae9ed
           </element>
6ae9ed
         </optional>
6ae9ed
+        <optional>
6ae9ed
+          <element name="iothread_period">
6ae9ed
+            <ref name="cpuperiod"/>
6ae9ed
+          </element>
6ae9ed
+        </optional>
6ae9ed
+        <optional>
6ae9ed
+          <element name="iothread_quota">
6ae9ed
+            <ref name="cpuquota"/>
6ae9ed
+          </element>
6ae9ed
+        </optional>
6ae9ed
         <zeroOrMore>
6ae9ed
           <element name="vcpupin">
6ae9ed
             <attribute name="vcpu">
6ae9ed
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
6ae9ed
index 7ea93aa..af3ecae 100644
6ae9ed
--- a/include/libvirt/libvirt-domain.h
6ae9ed
+++ b/include/libvirt/libvirt-domain.h
6ae9ed
@@ -365,6 +365,22 @@ typedef enum {
6ae9ed
 # define VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA "emulator_quota"
6ae9ed
 
6ae9ed
 /**
6ae9ed
+ * VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD:
6ae9ed
+ *
6ae9ed
+ * Macro represents the enforcement period for a quota, in microseconds,
6ae9ed
+ * for IOThreads only, when using the posix scheduler, as a ullong.
6ae9ed
+ */
6ae9ed
+# define VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD "iothread_period"
6ae9ed
+
6ae9ed
+/**
6ae9ed
+ * VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA:
6ae9ed
+ *
6ae9ed
+ * Macro represents the maximum bandwidth to be used within a period for
6ae9ed
+ * IOThreads only, when using the posix scheduler, as an llong.
6ae9ed
+ */
6ae9ed
+# define VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA "iothread_quota"
6ae9ed
+
6ae9ed
+/**
6ae9ed
  * VIR_DOMAIN_SCHEDULER_WEIGHT:
6ae9ed
  *
6ae9ed
  * Macro represents the relative weight,  when using the credit
6ae9ed
@@ -3604,6 +3620,22 @@ typedef void (*virConnectDomainEventJobCompletedCallback)(virConnectPtr conn,
6ae9ed
 # define VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA "cputune.emulator_quota"
6ae9ed
 
6ae9ed
 /**
6ae9ed
+ * VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD:
6ae9ed
+ *
6ae9ed
+ * Macro represents the enforcement period for a quota, in microseconds, for
6ae9ed
+ * iothreads only, when using the posix scheduler, as VIR_TYPED_PARAM_ULLONG.
6ae9ed
+ */
6ae9ed
+# define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD "cputune.iothread_period"
6ae9ed
+
6ae9ed
+/**
6ae9ed
+ * VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA:
6ae9ed
+ *
6ae9ed
+ * Macro represents the maximum bandwidth to be used within a period for
6ae9ed
+ * iothreads only, when using the posix scheduler, as VIR_TYPED_PARAM_LLONG.
6ae9ed
+ */
6ae9ed
+# define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA "cputune.iothread_quota"
6ae9ed
+
6ae9ed
+/**
6ae9ed
  * VIR_DOMAIN_TUNABLE_BLKDEV_DISK:
6ae9ed
  *
6ae9ed
  * Macro represents the name of guest disk for which the values are updated,
6ae9ed
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6ae9ed
index 261684e..67c7971 100644
6ae9ed
--- a/src/conf/domain_conf.c
6ae9ed
+++ b/src/conf/domain_conf.c
6ae9ed
@@ -16343,6 +16343,38 @@ virDomainDefParseXML(xmlDocPtr xml,
6ae9ed
         goto error;
6ae9ed
     }
6ae9ed
 
6ae9ed
+    if (virXPathULongLong("string(./cputune/iothread_period[1])", ctxt,
6ae9ed
+                          &def->cputune.iothread_period) < -1) {
6ae9ed
+        virReportError(VIR_ERR_XML_ERROR, "%s",
6ae9ed
+                       _("can't parse cputune iothread period value"));
6ae9ed
+        goto error;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (def->cputune.iothread_period > 0 &&
6ae9ed
+        (def->cputune.iothread_period < 1000 ||
6ae9ed
+         def->cputune.iothread_period > 1000000)) {
6ae9ed
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
+                       _("Value of cputune iothread_period must be in range "
6ae9ed
+                         "[1000, 1000000]"));
6ae9ed
+        goto error;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt,
6ae9ed
+                         &def->cputune.iothread_quota) < -1) {
6ae9ed
+        virReportError(VIR_ERR_XML_ERROR, "%s",
6ae9ed
+                       _("can't parse cputune iothread quota value"));
6ae9ed
+        goto error;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (def->cputune.iothread_quota > 0 &&
6ae9ed
+        (def->cputune.iothread_quota < 1000 ||
6ae9ed
+         def->cputune.iothread_quota > 18446744073709551LL)) {
6ae9ed
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
+                       _("Value of cputune iothread_quota must be in range "
6ae9ed
+                         "[1000, 18446744073709551]"));
6ae9ed
+        goto error;
6ae9ed
+    }
6ae9ed
+
6ae9ed
     if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
6ae9ed
         goto error;
6ae9ed
 
6ae9ed
@@ -22975,6 +23007,16 @@ virDomainCputuneDefFormat(virBufferPtr buf,
6ae9ed
                           "</emulator_quota>\n",
6ae9ed
                           def->cputune.emulator_quota);
6ae9ed
 
6ae9ed
+    if (def->cputune.iothread_period)
6ae9ed
+        virBufferAsprintf(&childrenBuf, "<iothread_period>%llu"
6ae9ed
+                          "</iothread_period>\n",
6ae9ed
+                          def->cputune.iothread_period);
6ae9ed
+
6ae9ed
+    if (def->cputune.iothread_quota)
6ae9ed
+        virBufferAsprintf(&childrenBuf, "<iothread_quota>%lld"
6ae9ed
+                          "</iothread_quota>\n",
6ae9ed
+                          def->cputune.iothread_quota);
6ae9ed
+
6ae9ed
     for (i = 0; i < def->maxvcpus; i++) {
6ae9ed
         char *cpumask;
6ae9ed
         virDomainVcpuDefPtr vcpu = def->vcpus[i];
6ae9ed
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
6ae9ed
index 34da54c..61ca8bd 100644
6ae9ed
--- a/src/conf/domain_conf.h
6ae9ed
+++ b/src/conf/domain_conf.h
6ae9ed
@@ -2031,6 +2031,8 @@ struct _virDomainCputune {
6ae9ed
     long long global_quota;
6ae9ed
     unsigned long long emulator_period;
6ae9ed
     long long emulator_quota;
6ae9ed
+    unsigned long long iothread_period;
6ae9ed
+    long long iothread_quota;
6ae9ed
     virBitmapPtr emulatorpin;
6ae9ed
 };
6ae9ed
 
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
6ae9ed
index 9595903..e6ef51d 100644
6ae9ed
--- a/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune.xml
6ae9ed
@@ -10,6 +10,8 @@
6ae9ed
     <quota>-1</quota>
6ae9ed
     <global_period>1000000</global_period>
6ae9ed
     <global_quota>-1</global_quota>
6ae9ed
+    <iothread_period>1000000</iothread_period>
6ae9ed
+    <iothread_quota>-1</iothread_quota>
6ae9ed
     <vcpupin vcpu='0' cpuset='0'/>
6ae9ed
     <vcpupin vcpu='1' cpuset='1'/>
6ae9ed
     <emulatorpin cpuset='1'/>
6ae9ed
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cputune.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cputune.xml
6ae9ed
index baf1779..7a1f50d 100644
6ae9ed
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cputune.xml
6ae9ed
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cputune.xml
6ae9ed
@@ -10,6 +10,8 @@
6ae9ed
     <quota>-1</quota>
6ae9ed
     <global_period>1000000</global_period>
6ae9ed
     <global_quota>-1</global_quota>
6ae9ed
+    <iothread_period>1000000</iothread_period>
6ae9ed
+    <iothread_quota>-1</iothread_quota>
6ae9ed
     <vcpupin vcpu='0' cpuset='0'/>
6ae9ed
     <vcpupin vcpu='1' cpuset='1'/>
6ae9ed
     <emulatorpin cpuset='1'/>
6ae9ed
diff --git a/tools/virsh.pod b/tools/virsh.pod
6ae9ed
index 601cb44..5fef86b 100644
6ae9ed
--- a/tools/virsh.pod
6ae9ed
+++ b/tools/virsh.pod
6ae9ed
@@ -1906,7 +1906,7 @@ available for each hypervisor are:
6ae9ed
 LXC (posix scheduler) : cpu_shares, vcpu_period, vcpu_quota
6ae9ed
 
6ae9ed
 QEMU/KVM (posix scheduler): cpu_shares, vcpu_period, vcpu_quota,
6ae9ed
-emulator_period, emulator_quota
6ae9ed
+emulator_period, emulator_quota, iothread_quota, iothread_period
6ae9ed
 
6ae9ed
 Xen (credit scheduler): weight, cap
6ae9ed
 
6ae9ed
@@ -1924,9 +1924,10 @@ values 0 and 1 are automatically converted to a minimal value of 2.
6ae9ed
 B<Note>: The weight and cap parameters are defined only for the
6ae9ed
 XEN_CREDIT scheduler and are now I<DEPRECATED>.
6ae9ed
 
6ae9ed
-B<Note>: The vcpu_period/emulator_period parameters have a valid value range
6ae9ed
-of 1000-1000000 or 0, and the vcpu_quota/emulator_quota parameters have a
6ae9ed
-valid value range of 1000-18446744073709551 or less than 0. The value 0 for
6ae9ed
+B<Note>: The vcpu_period, emulator_period, and iothread_period parameters
6ae9ed
+have a valid value range of 1000-1000000 or 0, and the vcpu_quota,
6ae9ed
+emulator_quota, and iothread_quota parameters have a valid value range of
6ae9ed
+1000-18446744073709551 or less than 0. The value 0 for
6ae9ed
 either parameter is the same as not specifying that parameter.
6ae9ed
 
6ae9ed
 =item B<screenshot> I<domain> [I<imagefilepath>] [I<--screen> B<screenID>]
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed