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>
---
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 c260d603a9..6e79445abc 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -200,35 +200,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)
{
@@ -289,6 +260,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.17.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list