]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Report more correct information for cache control
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 5 Jun 2017 12:00:45 +0000 (14:00 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 16 Jun 2017 11:09:41 +0000 (13:09 +0200)
On some platforms the number of bits in the cbm_mask might not be
divisible by 4 (and not even by 2), so we need to properly count the
bits.  Similar file, min_cbm_bits, is properly parsed and used, but if
the number is greater than one, we lose the information about
granularity when reporting the data in capabilities.  For that matter
always report granularity, but if it is not the same as the minimum,
add that information in there as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
31 files changed:
docs/schemas/capability.rng
src/conf/capabilities.c
src/conf/capabilities.h
tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_mask [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bits [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closids [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schemata [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/id [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/level [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_list [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_map [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/size [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/online [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_id [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_list [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_id [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_list [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/online [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/present [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0 [new symlink]
tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulist [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumap [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distance [new file with mode: 0644]
tests/vircaps2xmldata/linux-resctrl-skx/system/node/online [new file with mode: 0644]
tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml
tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml [new file with mode: 0644]
tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml
tests/vircaps2xmltest.c

index e5cbfa362ec00c44e1dd2e6578e78747dc80cff1..071090c2d9916971ca7e20f86772dea4b63d2801 100644 (file)
           </attribute>
           <zeroOrMore>
             <element name='control'>
-              <attribute name='min'>
+              <attribute name='granularity'>
                 <ref name='unsignedInt'/>
               </attribute>
+              <optional>
+                <attribute name='min'>
+                  <ref name='unsignedInt'/>
+                </attribute>
+              </optional>
               <attribute name='unit'>
                 <ref name='unit'/>
               </attribute>
index 3becc7e18c62937febdfbe449a5ff0bf77615459..0f99f3096292c572d0f1efa459a086e568baacbb 100644 (file)
@@ -31,6 +31,7 @@
 #include <unistd.h>
 
 #include "capabilities.h"
+#include "c-ctype.h"
 #include "count-one-bits.h"
 #include "cpu_conf.h"
 #include "domain_conf.h"
@@ -906,11 +907,24 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
 
         virBufferAdjustIndent(&controlBuf, indent + 4);
         for (j = 0; j < bank->ncontrols; j++) {
-            bool min_kilos = !(bank->controls[j]->min % 1024);
+            bool min_kilos = !(bank->controls[j]->granularity % 1024);
+
+            /* Only use KiB if both values are divisible */
+            if (bank->controls[j]->min)
+                min_kilos = min_kilos && !(bank->controls[j]->min % 1024);
+
+            virBufferAsprintf(&controlBuf,
+                              "<control granularity='%llu'",
+                              bank->controls[j]->granularity >> (min_kilos * 10));
+
+            if (bank->controls[j]->min) {
+                virBufferAsprintf(&controlBuf,
+                                  " min='%llu'",
+                                  bank->controls[j]->min >> (min_kilos * 10));
+            }
+
             virBufferAsprintf(&controlBuf,
-                              "<control min='%llu' unit='%s' "
-                              "type='%s' maxAllocs='%u'/>\n",
-                              bank->controls[j]->min >> (min_kilos * 10),
+                              " unit='%s' type='%s' maxAllocs='%u'/>\n",
                               min_kilos ? "KiB" : "B",
                               virCacheTypeToString(bank->controls[j]->scope),
                               bank->controls[j]->max_allocation);
@@ -1598,9 +1612,11 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,
                                virCacheType scope)
 {
     int ret = -1;
+    char *tmp = NULL;
     char *path = NULL;
     char *cbm_mask = NULL;
     char *type_upper = NULL;
+    unsigned int bits = 0;
     unsigned int min_cbm_bits = 0;
     virCapsHostCacheControlPtr control;
 
@@ -1632,8 +1648,14 @@ virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank,
 
     virStringTrimOptionalNewline(cbm_mask);
 
-    /* cbm_mask: cache bit mask, it's in hex, eg: fffff */
-    control->min = min_cbm_bits * bank->size / (strlen(cbm_mask) * 4);
+    for (tmp = cbm_mask; *tmp != '\0'; tmp++) {
+        if (c_isxdigit(*tmp))
+            bits += count_one_bits(virHexToBin(*tmp));
+    }
+
+    control->granularity = bank->size / bits;
+    if (min_cbm_bits != 1)
+        control->min = min_cbm_bits * control->granularity;
 
     control->scope = scope;
 
index ee87d598ef66274b981b9e4a49450ac26a4e9919..39a9bc689279c911ede664a1d53d8d86522657ef 100644 (file)
@@ -151,9 +151,14 @@ VIR_ENUM_DECL(virCache);
 typedef struct _virCapsHostCacheControl virCapsHostCacheControl;
 typedef virCapsHostCacheControl *virCapsHostCacheControlPtr;
 struct _virCapsHostCacheControl {
-    unsigned long long min; /* minimum cache control size in B */
-    virCacheType scope;  /* data, code or both */
-    unsigned int max_allocation; /* max number of supported allocations */
+    /* Smallest possible increase of the allocation size in bytes */
+    unsigned long long granularity;
+    /* Minimal allocatable size in bytes (if different from granularity) */
+    unsigned long long min;
+    /* Type of the allocation */
+    virCacheType scope;
+    /* Maximum number of simultaneous allocations */
+    unsigned int max_allocation;
 };
 
 typedef struct _virCapsHostCacheBank virCapsHostCacheBank;
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_mask b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/cbm_mask
new file mode 100644 (file)
index 0000000..d482bbb
--- /dev/null
@@ -0,0 +1 @@
+7ff
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bits b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/min_cbm_bits
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closids b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/info/L3/num_closids
new file mode 100644 (file)
index 0000000..b6a7d89
--- /dev/null
@@ -0,0 +1 @@
+16
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schemata b/tests/vircaps2xmldata/linux-resctrl-skx/resctrl/schemata
new file mode 100644 (file)
index 0000000..4a49137
--- /dev/null
@@ -0,0 +1 @@
+L3:0=7ff;1=7ff
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/id
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/level b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/level
new file mode 100644 (file)
index 0000000..00750ed
--- /dev/null
@@ -0,0 +1 @@
+3
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_list
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_map b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/shared_cpu_map
new file mode 100644 (file)
index 0000000..5325a8d
--- /dev/null
@@ -0,0 +1 @@
+001
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/size b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/size
new file mode 100644 (file)
index 0000000..d23da60
--- /dev/null
@@ -0,0 +1 @@
+33M
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/cache/index0/type
new file mode 100644 (file)
index 0000000..e4fd9dc
--- /dev/null
@@ -0,0 +1 @@
+Unified
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/online
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_id
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings
new file mode 100644 (file)
index 0000000..5325a8d
--- /dev/null
@@ -0,0 +1 @@
+001
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/core_siblings_list
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_id b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/physical_package_id
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings
new file mode 100644 (file)
index 0000000..5325a8d
--- /dev/null
@@ -0,0 +1 @@
+001
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_list b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/cpu0/topology/thread_siblings_list
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/online
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/present b/tests/vircaps2xmldata/linux-resctrl-skx/system/cpu/present
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0 b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpu0
new file mode 120000 (symlink)
index 0000000..c841bea
--- /dev/null
@@ -0,0 +1 @@
+../../cpu/cpu0
\ No newline at end of file
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulist b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpulist
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumap b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/cpumap
new file mode 100644 (file)
index 0000000..5325a8d
--- /dev/null
@@ -0,0 +1 @@
+001
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distance b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/node0/distance
new file mode 100644 (file)
index 0000000..f599e28
--- /dev/null
@@ -0,0 +1 @@
+10
diff --git a/tests/vircaps2xmldata/linux-resctrl-skx/system/node/online b/tests/vircaps2xmldata/linux-resctrl-skx/system/node/online
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
index 49aa0b98ca88ebe4951422221bd075708305462c..7361537bfb56307d2d5fb8975225808c8f27e9bd 100644 (file)
     </topology>
     <cache>
       <bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>
-        <control min='768' unit='KiB' type='code' maxAllocs='8'/>
-        <control min='768' unit='KiB' type='data' maxAllocs='8'/>
+        <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
+        <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
       </bank>
       <bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>
-        <control min='768' unit='KiB' type='code' maxAllocs='8'/>
-        <control min='768' unit='KiB' type='data' maxAllocs='8'/>
+        <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
+        <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
       </bank>
     </cache>
   </host>
diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml
new file mode 100644 (file)
index 0000000..4e91c87
--- /dev/null
@@ -0,0 +1,31 @@
+<capabilities>
+
+  <host>
+    <cpu>
+      <arch>x86_64</arch>
+    </cpu>
+    <power_management/>
+    <migration_features>
+      <live/>
+    </migration_features>
+    <topology>
+      <cells num='1'>
+        <cell id='0'>
+          <memory unit='KiB'>1048576</memory>
+          <pages unit='KiB' size='4'>2048</pages>
+          <pages unit='KiB' size='2048'>4096</pages>
+          <pages unit='KiB' size='1048576'>6144</pages>
+          <cpus num='1'>
+            <cpu id='0' socket_id='0' core_id='0' siblings='0'/>
+          </cpus>
+        </cell>
+      </cells>
+    </topology>
+    <cache>
+      <bank id='0' level='3' type='both' size='33792' unit='KiB' cpus='0'>
+        <control granularity='3072' unit='KiB' type='both' maxAllocs='16'/>
+      </bank>
+    </cache>
+  </host>
+
+</capabilities>
index cb78b4ab788dcb90d0dc2f457008a1479087ed01..eb02ad3322a26d39249e55a758984daa1e2078b4 100644 (file)
     </topology>
     <cache>
       <bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>
-        <control min='1536' unit='KiB' type='both' maxAllocs='4'/>
+        <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
       </bank>
       <bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>
-        <control min='1536' unit='KiB' type='both' maxAllocs='4'/>
+        <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
       </bank>
     </cache>
   </host>
index ae1cd521111eab5d821f6affcc4307db02462726..c0a67858fec3d88b323f56abc3817cdf66030e61 100644 (file)
@@ -120,6 +120,7 @@ mymain(void)
 
     DO_TEST_FULL("resctrl", VIR_ARCH_X86_64, true, true, true);
     DO_TEST_FULL("resctrl-cdp", VIR_ARCH_X86_64, true, true, true);
+    DO_TEST_FULL("resctrl-skx", VIR_ARCH_X86_64, true, true, true);
 
     return ret;
 }