[PATCH 2/2] capabilities: Add total number of cores and threads to the XML

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

 



Management applications may want to limit the maximum number of vCPUs
the guest has assigned based on the number of physical cores in the
system (excluding threads) for performance reasons.

This patch adds output of the total number of cores and total number of
threads present in the system as this information couldn't be reliably
determined in all cases by the data provided by libvirt.

The new output looks like this on a system with HyperThreading:
<capabilities>
  <host>
    <cpu>
      <arch>x86_64</arch>
      <model>SandyBridge</model>
      <vendor>Intel</vendor>
      <topology sockets='1' cores='2' threads='2' totalcores='2' totalthreads='4'/>
---
 docs/formatcaps.html.in      | 2 +-
 docs/schemas/capability.rng  | 8 ++++++++
 src/conf/cpu_conf.c          | 4 ++++
 src/conf/cpu_conf.h          | 2 ++
 src/qemu/qemu_capabilities.c | 3 ++-
 tests/testutilsqemu.c        | 2 ++
 6 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in
index 9d42426..c16267c 100644
--- a/docs/formatcaps.html.in
+++ b/docs/formatcaps.html.in
@@ -23,7 +23,7 @@ BIOS you will see</p>
       &lt;/features&gt;
       &lt;model&gt;core2duo&lt;/model&gt;
       &lt;vendor&gt;Intel&lt;/vendor&gt;
-      &lt;topology sockets="1" cores="2" threads="1"/&gt;
+      &lt;topology sockets="1" cores="2" threads="2" totalcores="2" totalthreads="4" /&gt;
       &lt;feature name="lahf_lm"/&gt;
       &lt;feature name='xtpr'/&gt;
       ...
diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng
index 8c928bc..0fb7d6a 100644
--- a/docs/schemas/capability.rng
+++ b/docs/schemas/capability.rng
@@ -100,6 +100,14 @@
       <attribute name='threads'>
         <ref name='positiveInteger'/>
       </attribute>
+      <optional>
+        <attribute name='totalthreads'>
+          <ref name='positiveInteger'/>
+        </attribute>
+        <attribute name='totalcores'>
+          <ref name='positiveInteger'/>
+        </attribute>
+      </optional>
     </element>
     <zeroOrMore>
       <element name='feature'>
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index bdc5f1d..753a6dd 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -626,6 +626,10 @@ virCPUDefFormatBuf(virBufferPtr buf,
         virBufferAsprintf(buf, " sockets='%u'", def->sockets);
         virBufferAsprintf(buf, " cores='%u'", def->cores);
         virBufferAsprintf(buf, " threads='%u'", def->threads);
+        if (def->totalcores) {
+            virBufferAsprintf(buf, " totalcores='%u'", def->totalcores);
+            virBufferAsprintf(buf, " totalthreads='%u'", def->totalthreads);
+        }
         virBufferAddLit(buf, "/>\n");
     }

diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 23ea455..7a881a1 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -113,6 +113,8 @@ struct _virCPUDef {
     unsigned int sockets;
     unsigned int cores;
     unsigned int threads;
+    unsigned int totalcores;
+    unsigned int totalthreads;
     size_t nfeatures;
     size_t nfeatures_max;
     virCPUFeatureDefPtr features;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b166dd6..6920ea8 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -842,13 +842,14 @@ qemuCapsInitCPU(virCapsPtr caps,

     cpu->arch = arch;

-    if (nodeGetInfo(NULL, &nodeinfo))
+    if (nodeGetInfoCores(&nodeinfo, &cpu->totalcores))
         goto error;

     cpu->type = VIR_CPU_TYPE_HOST;
     cpu->sockets = nodeinfo.sockets;
     cpu->cores = nodeinfo.cores;
     cpu->threads = nodeinfo.threads;
+    cpu->totalthreads = nodeinfo.cpus;
     caps->host.cpu = cpu;

     if (!(data = cpuNodeData(arch))
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 573927d..f95ba05 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -155,6 +155,8 @@ virCapsPtr testQemuCapsInit(void) {
         1,                      /* sockets */
         2,                      /* cores */
         1,                      /* threads */
+        2,                      /* totalcores */
+        2,                      /* totalthreads */
         ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */
         ARRAY_CARDINALITY(host_cpu_features), /* nfeatures_max */
         host_cpu_features,      /* features */
-- 
1.8.1

--
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]