This is a helper that parses /sys/devices/system/cpu/isolated
into a virBitmap. It's going to be needed soon.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virhostcpu.c | 31 +++++++++++++++++++++++++++++++
src/util/virhostcpu.h | 1 +
3 files changed, 33 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2c7e4b45d3..0f2d5db883 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2504,6 +2504,7 @@ virHostCPUGetCount;
virHostCPUGetCPUID;
virHostCPUGetHaltPollTime;
virHostCPUGetInfo;
+virHostCPUGetIsolated;
virHostCPUGetKVMMaxVCPUs;
virHostCPUGetMap;
virHostCPUGetMicrocodeVersion;
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 01de69c0d1..b6d1db2302 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1152,6 +1152,37 @@ virHostCPUGetAvailableCPUsBitmap(void)
}
+/**
+ * virHostCPUGetIsolated:
+ * @isolated: returned bitmap of isolated CPUs
+ *
+ * Sets @isolated to point to a bitmap of isolated CPUs (e.g. those passed to
+ * isolcpus= kernel cmdline). If the file doesn't exist, @isolated is set to
+ * NULL and success is returned. If the file does exist but it's empty,
+ * @isolated is set to an empty bitmap an success is returned.
+ *
+ * Returns: 0 on success,
+ * -1 otherwise (with error reported).
+ */
+int
+virHostCPUGetIsolated(virBitmap **isolated)
+{
+ g_autoptr(virBitmap) bitmap = NULL;
+ int rc;
+
+ rc = virFileReadValueBitmapAllowEmpty(&bitmap, "%s/cpu/isolated", SYSFS_SYSTEM_PATH);
+ if (rc == -2) {
+ *isolated = NULL;
+ return 0;
+ } else if (rc < 0) {
+ return -1;
+ }
+
+ *isolated = g_steal_pointer(&bitmap);
+ return 0;
+}
+
+
#if WITH_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT)
/* Get the number of threads per subcore.
diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h
index d7e09bff22..1f47634c33 100644
--- a/src/util/virhostcpu.h
+++ b/src/util/virhostcpu.h
@@ -43,6 +43,7 @@ bool virHostCPUHasBitmap(void);
virBitmap *virHostCPUGetPresentBitmap(void);
virBitmap *virHostCPUGetOnlineBitmap(void);
virBitmap *virHostCPUGetAvailableCPUsBitmap(void);
+int virHostCPUGetIsolated(virBitmap **isolated);
int virHostCPUGetCount(void);
int virHostCPUGetThreadsPerSubcore(virArch arch) G_NO_INLINE;
--
2.43.2
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
On Tue, Apr 23, 2024 at 04:16:23PM +0200, Michal Privoznik wrote:
> This is a helper that parses /sys/devices/system/cpu/isolated
> into a virBitmap. It's going to be needed soon.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> src/libvirt_private.syms | 1 +
> src/util/virhostcpu.c | 31 +++++++++++++++++++++++++++++++
> src/util/virhostcpu.h | 1 +
> 3 files changed, 33 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 2c7e4b45d3..0f2d5db883 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -2504,6 +2504,7 @@ virHostCPUGetCount;
> virHostCPUGetCPUID;
> virHostCPUGetHaltPollTime;
> virHostCPUGetInfo;
> +virHostCPUGetIsolated;
> virHostCPUGetKVMMaxVCPUs;
> virHostCPUGetMap;
> virHostCPUGetMicrocodeVersion;
> diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
> index 01de69c0d1..b6d1db2302 100644
> --- a/src/util/virhostcpu.c
> +++ b/src/util/virhostcpu.c
> @@ -1152,6 +1152,37 @@ virHostCPUGetAvailableCPUsBitmap(void)
> }
>
>
> +/**
> + * virHostCPUGetIsolated:
> + * @isolated: returned bitmap of isolated CPUs
> + *
> + * Sets @isolated to point to a bitmap of isolated CPUs (e.g. those passed to
> + * isolcpus= kernel cmdline). If the file doesn't exist, @isolated is set to
> + * NULL and success is returned. If the file does exist but it's empty,
> + * @isolated is set to an empty bitmap an success is returned.
s/an success/and success/
> + *
> + * Returns: 0 on success,
> + * -1 otherwise (with error reported).
> + */
> +int
> +virHostCPUGetIsolated(virBitmap **isolated)
> +{
> + g_autoptr(virBitmap) bitmap = NULL;
> + int rc;
> +
> + rc = virFileReadValueBitmapAllowEmpty(&bitmap, "%s/cpu/isolated", SYSFS_SYSTEM_PATH);
> + if (rc == -2) {
> + *isolated = NULL;
> + return 0;
> + } else if (rc < 0) {
> + return -1;
> + }
> +
> + *isolated = g_steal_pointer(&bitmap);
> + return 0;
> +}
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
© 2016 - 2026 Red Hat, Inc.