virhostcpu.c: introduce virHostCPUGetAvailableCPUsBitmap()

The idea is to have a function that calls virHostCPUGetOnlineBitmap()
but, instead of returning NULL if the host does not have CPU
offlining capabilities,  fall back to a bitmap containing all
present CPUs.

Next patch will use this helper in two other places.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-06-26 19:10:43 -03:00 committed by Michal Privoznik
parent bc07020511
commit 42036650c6
3 changed files with 33 additions and 0 deletions

View File

@ -2223,6 +2223,7 @@ virHookPresent;
# util/virhostcpu.h
virHostCPUGetAvailableCPUsBitmap;
virHostCPUGetCount;
virHostCPUGetInfo;
virHostCPUGetKVMMaxVCPUs;

View File

@ -1099,6 +1099,36 @@ virHostCPUGetMap(unsigned char **cpumap,
}
/* virHostCPUGetAvailableCPUsBitmap():
*
* Returns a virBitmap object with all available host CPUs.
*
* This is a glorified wrapper of virHostCPUGetOnlineBitmap()
* that, instead of returning NULL when 'ifndef __linux__' and
* the caller having to handle it outside the function, returns
* a virBitmap with all the possible CPUs in the host, up to
* virHostCPUGetCount(). */
virBitmapPtr
virHostCPUGetAvailableCPUsBitmap(void)
{
g_autoptr(virBitmap) bitmap = NULL;
if (!(bitmap = virHostCPUGetOnlineBitmap())) {
int hostcpus;
if ((hostcpus = virHostCPUGetCount()) < 0)
return NULL;
if (!(bitmap = virBitmapNew(hostcpus)))
return NULL;
virBitmapSetAll(bitmap);
}
return g_steal_pointer(&bitmap);
}
#if HAVE_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT)
/* Get the number of threads per subcore.

View File

@ -43,6 +43,8 @@ int virHostCPUGetStats(int cpuNum,
bool virHostCPUHasBitmap(void);
virBitmapPtr virHostCPUGetPresentBitmap(void);
virBitmapPtr virHostCPUGetOnlineBitmap(void);
virBitmapPtr virHostCPUGetAvailableCPUsBitmap(void);
int virHostCPUGetCount(void);
int virHostCPUGetThreadsPerSubcore(virArch arch) G_GNUC_NO_INLINE;