Re: [PATCH 2/3] qemu: add hypervisor feature cpu-pm support for kvm

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

 



On Mon, Aug 19, 2019 at 10:32:25AM +0200, Menno Lageman wrote:
From: Wim ten Have <wim.ten.have@xxxxxxxxxx>

QEMU introduced a CPU power management feature with commit 6f131f13e68d
("kvm: support -overcommit cpu-pm=on|off").

This patch series adds support for controlling QEMU's "-overcommit"
command line switch: "-overcommit cpu-pm=[on|off]". By default "cpu-pm" is off.

To turn the CPU power management feature on, the following
XML needs to be added to the guest's domain description:

 <features>
   <kvm>
     <cpu-pm state='on'/>
   </kvm>
 </features>

Note that the "cpu-pm" element is only available if the CPU
mode is set to "host-passthrough":

 <cpu mode='host-passthrough ... />

Signed-off-by: Wim ten Have <wim.ten.have@xxxxxxxxxx>
Signed-off-by: Menno Lageman <menno.lageman@xxxxxxxxxx>
---
docs/formatdomain.html.in     |  7 +++++++
docs/schemas/domaincommon.rng |  5 +++++
src/conf/domain_conf.c        |  4 ++++
src/conf/domain_conf.h        |  1 +
src/libvirt_private.syms      |  1 +
src/qemu/qemu_command.c       | 16 +++++++++++++++-
src/qemu/qemu_domain.c        | 25 ++++++++++++++++++-------
7 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a18119f9a08e..7ea819ef6fb2 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2045,6 +2045,7 @@
  &lt;kvm&gt;
    &lt;hidden state='on'/&gt;
    &lt;hint-dedicated state='on'/&gt;
+    &lt;cpu-pm state='on'/&gt;
  &lt;/kvm&gt;
  &lt;pvspinlock state='on'/&gt;
  &lt;gic version='2'/&gt;
@@ -2224,6 +2225,12 @@
          <td>on, off</td>
          <td><span class="since">5.7.0 (QEMU 2.12.1)</span></td>
        </tr>

Hmm, seems we did not bother to document hint-dedicated

+        <tr>
+          <td>cpu-pm</td>
+          <td>Enable guest management of the host CPU's power state.  Note that enabling this will increase latency for other processes running on the same host CPU.</td>
+          <td>on, off</td>
+          <td><span class="since">5.7.0 (QEMU 2.12.1)</span></td>
+        </tr>
      </table>
      </dd>
      <dt><code>pmu</code></dt>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 08853f9d9e92..51c9e434aa35 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5970,6 +5970,11 @@
            <ref name="featurestate"/>
          </element>
        </optional>
+        <optional>
+          <element name="cpu-pm">
+            <ref name="featurestate"/>
+          </element>
+        </optional>
      </interleave>
    </element>
  </define>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8642927d6bf3..e348aa0bcb5f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -203,6 +203,7 @@ VIR_ENUM_IMPL(virDomainKVM,
              VIR_DOMAIN_KVM_LAST,
              "hidden",
              "hint-dedicated",
+              "cpu-pm",
);

VIR_ENUM_IMPL(virDomainMsrsUnknown,
@@ -20412,6 +20413,7 @@ virDomainDefParseXML(xmlDocPtr xml,
            switch ((virDomainKVM) feature) {
                case VIR_DOMAIN_KVM_HIDDEN:
                case VIR_DOMAIN_KVM_DEDICATED:
+                case VIR_DOMAIN_KVM_CPU_PM:
                    if (!(tmp = virXMLPropString(nodes[i], "state"))) {
                        virReportError(VIR_ERR_XML_ERROR,
                                       _("missing 'state' attribute for "
@@ -22625,6 +22627,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
            switch ((virDomainKVM) i) {
            case VIR_DOMAIN_KVM_HIDDEN:
            case VIR_DOMAIN_KVM_DEDICATED:
+            case VIR_DOMAIN_KVM_CPU_PM:
                if (src->kvm_features[i] != dst->kvm_features[i]) {
                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                   _("State of KVM feature '%s' differs: "
@@ -28126,6 +28129,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
                switch ((virDomainKVM) j) {
                case VIR_DOMAIN_KVM_HIDDEN:
                case VIR_DOMAIN_KVM_DEDICATED:
+                case VIR_DOMAIN_KVM_CPU_PM:
                    if (def->kvm_features[j])
                        virBufferAsprintf(&childBuf, "<%s state='%s'/>\n",
                                          virDomainKVMTypeToString(j),
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f7423b1b6f89..b5a4cee46c1e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1766,6 +1766,7 @@ typedef enum {
typedef enum {
    VIR_DOMAIN_KVM_HIDDEN = 0,
    VIR_DOMAIN_KVM_DEDICATED,
+    VIR_DOMAIN_KVM_CPU_PM,

    VIR_DOMAIN_KVM_LAST
} virDomainKVM;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9db4ac7933e5..67a3a14c9b36 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -446,6 +446,7 @@ virDomainIOThreadIDDel;
virDomainIOThreadIDFind;
virDomainKeyWrapCipherNameTypeFromString;
virDomainKeyWrapCipherNameTypeToString;
+virDomainKVMTypeToString;
virDomainLeaseDefFree;
virDomainLeaseIndex;
virDomainLeaseInsert;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 922456ec679e..163c98bc7d0f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7217,6 +7217,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
                    virBufferAddLit(&buf, ",kvm-hint-dedicated=on");
                break;

+            /* Not a -cpu option */
+            case VIR_DOMAIN_KVM_CPU_PM:
            /* coverity[dead_error_begin] */
            case VIR_DOMAIN_KVM_LAST:
                break;
@@ -7852,8 +7854,20 @@ qemuBuildOvercommitCommandLine(virCommandPtr cmd,
                               virQEMUCapsPtr qemuCaps)
{
    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OVERCOMMIT)) {
+        virBuffer buf = VIR_BUFFER_INITIALIZER;
+        char *overcommit;
+
+        virBufferAsprintf(&buf, "mem-lock=%s", def->mem.locked ? "on" : "off");
+
+        if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON)
+            virBufferAsprintf(&buf, ",cpu-pm=%s",
+                              def->kvm_features[VIR_DOMAIN_KVM_CPU_PM] == VIR_TRISTATE_SWITCH_ON ? "on" : "off");

const char *cpu_pm = NULL;

if (def->kvm_features[VIR_DOMAIN_KVM_CPU_PM] != VIR_TRISTATE_SWITCH_DEFAULT)
   cpu_pm = virTristateBoolTypeToString(def->kvm_features[VIR_DOMAIN_KVM_CPU_PM])

if (cpu_pm)
   virBufferAsprintf...

to avoid the super long line.

+
+        overcommit = virBufferContentAndReset(&buf);
        virCommandAddArg(cmd, "-overcommit");
-        virCommandAddArgFormat(cmd, "mem-lock=%s", def->mem.locked ? "on" : "off");
+        virCommandAddArgFormat(cmd, "%s", overcommit);

You can use virCommandAddArgBuffer and avoid the temporary char*
variable

+
+        VIR_FREE(overcommit);
    }
    return 0;
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a06672333cf7..5571f52fec47 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4442,7 +4442,7 @@ static int
qemuDomainDefValidateFeatures(const virDomainDef *def,
                              virQEMUCapsPtr qemuCaps)
{
-    size_t i;
+    size_t i, j;

    for (i = 0; i < VIR_DOMAIN_FEATURE_LAST; i++) {
        const char *featureName = virDomainFeatureTypeToString(i);
@@ -4499,12 +4499,23 @@ qemuDomainDefValidateFeatures(const virDomainDef *def,
            break;

        case VIR_DOMAIN_FEATURE_KVM:
-            if (def->kvm_features[VIR_DOMAIN_KVM_DEDICATED] == VIR_TRISTATE_SWITCH_ON &&
-                (!def->cpu || def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("kvm-hint-dedicated=on is only applicable "
-                                 "for cpu host-passthrough"));
-                return -1;
+            for (j = 0; j < VIR_DOMAIN_KVM_LAST; j++) {
+                switch ((virDomainKVM) j) {
+                case VIR_DOMAIN_KVM_DEDICATED:
+                case VIR_DOMAIN_KVM_CPU_PM:
+                    if (def->kvm_features[j] == VIR_TRISTATE_SWITCH_ON &&
+                        (!def->cpu || def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH)) {
+                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                       _("%s=on is only applicable for cpu host-passthrough"),
+                                       virDomainKVMTypeToString(j));
+                        return -1;
+                    }

What if the user asks for cpu-pm but QEMU_CAPS_OVERCOMMIT is not
available?

Jano

+                    break;
+
+                case VIR_DOMAIN_KVM_HIDDEN:
+                case VIR_DOMAIN_KVM_LAST:
+                    break;
+                }
            }
            break;

--
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux