render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
edecca
From 60e8b0492c1412f03188453cae1b9b8729d69745 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <60e8b0492c1412f03188453cae1b9b8729d69745@dist-git>
edecca
From: Andrea Bolognani <abologna@redhat.com>
edecca
Date: Wed, 15 Aug 2018 14:04:42 +0200
edecca
Subject: [PATCH] util: Rewrite virHostCPUCountThreadSiblings()
edecca
edecca
We already have a function which parses
edecca
thread_siblings_list for a CPU and returns the
edecca
corresponding bitmap, and a bunch of utility functions
edecca
that perform operations on bitmaps such as counting
edecca
the number of set bits: use those to implement the
edecca
function instead of having an additional ad-hoc parser
edecca
for thread_siblings.
edecca
edecca
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
edecca
(cherry picked from commit 794513e89d0dbd9a1b30f3745007bcfdb740d890)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1608479
edecca
edecca
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
edecca
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
edecca
---
edecca
 src/util/virhostcpu.c | 45 +++++++++++++++----------------------------
edecca
 1 file changed, 16 insertions(+), 29 deletions(-)
edecca
edecca
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
edecca
index 013c95bb56..b644398e00 100644
edecca
--- a/src/util/virhostcpu.c
edecca
+++ b/src/util/virhostcpu.c
edecca
@@ -201,35 +201,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
edecca
 
edecca
 # define LINUX_NB_CPU_STATS 4
edecca
 
edecca
-
edecca
-static unsigned long
edecca
-virHostCPUCountThreadSiblings(unsigned int cpu)
edecca
-{
edecca
-    unsigned long ret = 0;
edecca
-    int rv = -1;
edecca
-    char *str = NULL;
edecca
-    size_t i;
edecca
-
edecca
-    rv = virFileReadValueString(&str,
edecca
-                                "%s/cpu/cpu%u/topology/thread_siblings",
edecca
-                                SYSFS_SYSTEM_PATH, cpu);
edecca
-    if (rv == -2) {
edecca
-        ret = 1;
edecca
-        goto cleanup;
edecca
-    }
edecca
-    if (rv < 0)
edecca
-        goto cleanup;
edecca
-
edecca
-    for (i = 0; str[i] != '\0'; i++) {
edecca
-        if (c_isxdigit(str[i]))
edecca
-            ret += count_one_bits(virHexToBin(str[i]));
edecca
-    }
edecca
-
edecca
- cleanup:
edecca
-    VIR_FREE(str);
edecca
-    return ret;
edecca
-}
edecca
-
edecca
 int
edecca
 virHostCPUGetSocket(unsigned int cpu, unsigned int *socket)
edecca
 {
edecca
@@ -290,6 +261,22 @@ virHostCPUGetSiblingsList(unsigned int cpu)
edecca
     return ret;
edecca
 }
edecca
 
edecca
+static unsigned long
edecca
+virHostCPUCountThreadSiblings(unsigned int cpu)
edecca
+{
edecca
+    virBitmapPtr siblings_map;
edecca
+    unsigned long ret = 0;
edecca
+
edecca
+    if (!(siblings_map = virHostCPUGetSiblingsList(cpu)))
edecca
+        goto cleanup;
edecca
+
edecca
+    ret = virBitmapCountBits(siblings_map);
edecca
+
edecca
+ cleanup:
edecca
+    virBitmapFree(siblings_map);
edecca
+    return ret;
edecca
+}
edecca
+
edecca
 /* parses a node entry, returning number of processors in the node and
edecca
  * filling arguments */
edecca
 static int
edecca
-- 
edecca
2.18.0
edecca