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