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>
This commit is contained in:
parent
37e64f6508
commit
794513e89d
@ -200,35 +200,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
|
|||||||
|
|
||||||
# define LINUX_NB_CPU_STATS 4
|
# 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
|
int
|
||||||
virHostCPUGetSocket(unsigned int cpu, unsigned int *socket)
|
virHostCPUGetSocket(unsigned int cpu, unsigned int *socket)
|
||||||
{
|
{
|
||||||
@ -289,6 +260,22 @@ virHostCPUGetSiblingsList(unsigned int cpu)
|
|||||||
return ret;
|
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
|
/* parses a node entry, returning number of processors in the node and
|
||||||
* filling arguments */
|
* filling arguments */
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user