render / rpms / libvirt

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