]> xenbits.xensource.com Git - libvirt.git/commitdiff
virhostcpu: Introduce virHostCPUGetIsolated()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 22 Apr 2024 09:07:13 +0000 (11:07 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 6 May 2024 13:36:17 +0000 (15:36 +0200)
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>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/libvirt_private.syms
src/util/virhostcpu.c
src/util/virhostcpu.h

index 661b560ffe33da452ef9ab0829f0b2426dfbdaf2..947294cb2b83ddff220eceb4b2167014319360c9 100644 (file)
@@ -2505,6 +2505,7 @@ virHostCPUGetCount;
 virHostCPUGetCPUID;
 virHostCPUGetHaltPollTime;
 virHostCPUGetInfo;
+virHostCPUGetIsolated;
 virHostCPUGetKVMMaxVCPUs;
 virHostCPUGetMap;
 virHostCPUGetMicrocodeVersion;
index 01de69c0d17753c07139b79d07ec99fd3d9a7402..3b4a11effb7ba1ed090be325ecaf24f7736875cf 100644 (file)
@@ -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 and 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.
index d7e09bff229522d038247e88f0759d79a4b267bf..1f47634c33370cc7d2ab61348738d26c68502093 100644 (file)
@@ -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;