render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From 5a978253cced5135a6dd01c730faea2fd21a5dc9 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <5a978253cced5135a6dd01c730faea2fd21a5dc9@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 16:32:18 +0100
c1c534
Subject: [PATCH] conf: Format cache banks in capabilities with
c1c534
 virFormatIntPretty
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
Reviewed-by: John Ferlan <jferlan@redhat.com>
c1c534
(cherry picked from commit 63d95a19cc72d120d40092c1e97235d7b9d4eb29)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 src/conf/capabilities.c                            | 50 ++++++++++++++--------
c1c534
 tests/vircaps2xmldata/vircaps-x86_64-caches.xml    |  2 +-
c1c534
 .../vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml |  4 +-
c1c534
 .../vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml |  4 +-
c1c534
 tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml   |  4 +-
c1c534
 5 files changed, 39 insertions(+), 25 deletions(-)
c1c534
c1c534
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
c1c534
index 1f7d8cdb31..798c9bdaea 100644
c1c534
--- a/src/conf/capabilities.c
c1c534
+++ b/src/conf/capabilities.c
c1c534
@@ -883,7 +883,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
c1c534
     for (i = 0; i < ncaches; i++) {
c1c534
         virCapsHostCacheBankPtr bank = caches[i];
c1c534
         char *cpus_str = virBitmapFormat(bank->cpus);
c1c534
-        bool kilos = !(bank->size % 1024);
c1c534
+        const char *unit = NULL;
c1c534
+        unsigned long long short_size = virFormatIntPretty(bank->size, &unit);
c1c534
 
c1c534
         if (!cpus_str)
c1c534
             return -1;
c1c534
@@ -897,34 +898,47 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
c1c534
                           "size='%llu' unit='%s' cpus='%s'",
c1c534
                           bank->id, bank->level,
c1c534
                           virCacheTypeToString(bank->type),
c1c534
-                          bank->size >> (kilos * 10),
c1c534
-                          kilos ? "KiB" : "B",
c1c534
-                          cpus_str);
c1c534
+                          short_size, unit, cpus_str);
c1c534
         VIR_FREE(cpus_str);
c1c534
 
c1c534
         virBufferSetChildIndent(&controlBuf, buf);
c1c534
         for (j = 0; j < bank->ncontrols; j++) {
c1c534
-            bool min_kilos = !(bank->controls[j]->granularity % 1024);
c1c534
+            const char *min_unit;
c1c534
+            virResctrlInfoPtr controls = bank->controls[j];
c1c534
+            unsigned long long gran_short_size = controls->granularity;
c1c534
+            unsigned long long min_short_size = controls->min;
c1c534
 
c1c534
-            /* Only use KiB if both values are divisible */
c1c534
-            if (bank->controls[j]->min)
c1c534
-                min_kilos = min_kilos && !(bank->controls[j]->min % 1024);
c1c534
+            gran_short_size = virFormatIntPretty(gran_short_size, &unit);
c1c534
+            min_short_size = virFormatIntPretty(min_short_size, &min_unit);
c1c534
 
c1c534
-            virBufferAsprintf(&controlBuf,
c1c534
-                              "
c1c534
-                              bank->controls[j]->granularity >> (min_kilos * 10));
c1c534
+            /* Only use the smaller unit if they are different */
c1c534
+            if (min_short_size) {
c1c534
+                unsigned long long gran_div;
c1c534
+                unsigned long long min_div;
c1c534
 
c1c534
-            if (bank->controls[j]->min) {
c1c534
-                virBufferAsprintf(&controlBuf,
c1c534
-                                  " min='%llu'",
c1c534
-                                  bank->controls[j]->min >> (min_kilos * 10));
c1c534
+                gran_div = controls->granularity / gran_short_size;
c1c534
+                min_div = controls->min / min_short_size;
c1c534
+
c1c534
+                if (min_div > gran_div) {
c1c534
+                    min_short_size *= min_div / gran_div;
c1c534
+                } else if (min_div < gran_div) {
c1c534
+                    unit = min_unit;
c1c534
+                    gran_short_size *= gran_div / min_div;
c1c534
+                }
c1c534
             }
c1c534
 
c1c534
+            virBufferAsprintf(&controlBuf,
c1c534
+                              "
c1c534
+                              gran_short_size);
c1c534
+
c1c534
+            if (min_short_size)
c1c534
+                virBufferAsprintf(&controlBuf, " min='%llu'", min_short_size);
c1c534
+
c1c534
             virBufferAsprintf(&controlBuf,
c1c534
                               " unit='%s' type='%s' maxAllocs='%u'/>\n",
c1c534
-                              min_kilos ? "KiB" : "B",
c1c534
-                              virCacheTypeToString(bank->controls[j]->scope),
c1c534
-                              bank->controls[j]->max_allocation);
c1c534
+                              unit,
c1c534
+                              virCacheTypeToString(controls->scope),
c1c534
+                              controls->max_allocation);
c1c534
         }
c1c534
 
c1c534
         if (virBufferCheckError(&controlBuf) < 0)
c1c534
diff --git a/tests/vircaps2xmldata/vircaps-x86_64-caches.xml b/tests/vircaps2xmldata/vircaps-x86_64-caches.xml
c1c534
index fe0be6d08f..0c6f3769a2 100644
c1c534
--- a/tests/vircaps2xmldata/vircaps-x86_64-caches.xml
c1c534
+++ b/tests/vircaps2xmldata/vircaps-x86_64-caches.xml
c1c534
@@ -29,7 +29,7 @@
c1c534
       </cells>
c1c534
     </topology>
c1c534
     <cache>
c1c534
-      <bank id='0' level='3' type='both' size='8192' unit='KiB' cpus='0-7'/>
c1c534
+      <bank id='0' level='3' type='both' size='8' unit='MiB' cpus='0-7'/>
c1c534
     </cache>
c1c534
   </host>
c1c534
 
c1c534
diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml
c1c534
index 7361537bfb..443917c62d 100644
c1c534
--- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml
c1c534
+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-cdp.xml
c1c534
@@ -41,11 +41,11 @@
c1c534
       </cells>
c1c534
     </topology>
c1c534
     <cache>
c1c534
-      <bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>
c1c534
+      <bank id='0' level='3' type='both' size='15' unit='MiB' cpus='0-5'>
c1c534
         <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
c1c534
         <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
c1c534
       </bank>
c1c534
-      <bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>
c1c534
+      <bank id='1' level='3' type='both' size='15' unit='MiB' cpus='6-11'>
c1c534
         <control granularity='768' unit='KiB' type='code' maxAllocs='8'/>
c1c534
         <control granularity='768' unit='KiB' type='data' maxAllocs='8'/>
c1c534
       </bank>
c1c534
diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml
c1c534
index 4e91c87de3..0cd25e59a9 100644
c1c534
--- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml
c1c534
+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl-skx.xml
c1c534
@@ -22,8 +22,8 @@
c1c534
       </cells>
c1c534
     </topology>
c1c534
     <cache>
c1c534
-      <bank id='0' level='3' type='both' size='33792' unit='KiB' cpus='0'>
c1c534
-        <control granularity='3072' unit='KiB' type='both' maxAllocs='16'/>
c1c534
+      <bank id='0' level='3' type='both' size='33' unit='MiB' cpus='0'>
c1c534
+        <control granularity='3' unit='MiB' type='both' maxAllocs='16'/>
c1c534
       </bank>
c1c534
     </cache>
c1c534
   </host>
c1c534
diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml
c1c534
index eb02ad3322..7629259294 100644
c1c534
--- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml
c1c534
+++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml
c1c534
@@ -41,10 +41,10 @@
c1c534
       </cells>
c1c534
     </topology>
c1c534
     <cache>
c1c534
-      <bank id='0' level='3' type='both' size='15360' unit='KiB' cpus='0-5'>
c1c534
+      <bank id='0' level='3' type='both' size='15' unit='MiB' cpus='0-5'>
c1c534
         <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
c1c534
       </bank>
c1c534
-      <bank id='1' level='3' type='both' size='15360' unit='KiB' cpus='6-11'>
c1c534
+      <bank id='1' level='3' type='both' size='15' unit='MiB' cpus='6-11'>
c1c534
         <control granularity='768' min='1536' unit='KiB' type='both' maxAllocs='4'/>
c1c534
       </bank>
c1c534
     </cache>
c1c534
-- 
c1c534
2.16.1
c1c534