libvirt/SOURCES/libvirt-util-Rewrite-virHostCPUCountThreadSiblings.patch
2021-09-10 11:57:18 +00:00

92 lines
2.4 KiB
Diff

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