]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add virHostCPUGetHaltPollTime
authorYang Fei <yangfei85@huawei.com>
Thu, 22 Jul 2021 08:05:01 +0000 (16:05 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 27 Jul 2021 08:29:23 +0000 (10:29 +0200)
Add helper function virHostCPUGetHaltPollTime to obtain halt polling
time. If the kernel support halt polling time statistic, and mount
debugfs. This function will take effect on KVM VMs.

Signed-off-by: Yang Fei <yangfei85@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virhostcpu.c
src/util/virhostcpu.h

index 5c7f6bf8092a0c45b8d7267a9ec1c5cdffa5a979..43493ea76e33e94e334ceed59c48942c894097e7 100644 (file)
@@ -2376,6 +2376,7 @@ virHookPresent;
 # util/virhostcpu.h
 virHostCPUGetAvailableCPUsBitmap;
 virHostCPUGetCount;
+virHostCPUGetHaltPollTime;
 virHostCPUGetInfo;
 virHostCPUGetKVMMaxVCPUs;
 virHostCPUGetMap;
index bf7fda23af3d4e3b5eb738629c5dc7ade875c56f..7aa92ad11d2052fea6eb8a0055feccd150fbcf99 100644 (file)
@@ -1535,3 +1535,42 @@ virHostCPUGetSignature(char **signature)
 }
 
 #endif /* __linux__ */
+
+int
+virHostCPUGetHaltPollTime(pid_t pid,
+                      unsigned long long *haltPollSuccess,
+                      unsigned long long *haltPollFail)
+{
+    g_autofree char *pidToStr = NULL;
+    g_autofree char *debugFsPath = NULL;
+    g_autofree char *kvmPath = NULL;
+    struct dirent *ent = NULL;
+    g_autoptr(DIR) dir = NULL;
+    bool found = false;
+
+    if (!(debugFsPath = virFileFindMountPoint("debugfs")))
+        return -1;
+
+    kvmPath = g_strdup_printf("%s/%s", debugFsPath, "kvm");
+    if (virDirOpenQuiet(&dir, kvmPath) != 1)
+        return -1;
+
+    pidToStr = g_strdup_printf("%lld-", (long long)pid);
+    while (virDirRead(dir, &ent, NULL) > 0) {
+        if (STRPREFIX(ent->d_name, pidToStr)) {
+            found = true;
+            break;
+        }
+    }
+
+    if (!found)
+        return -1;
+
+    if (virFileReadValueUllongQuiet(haltPollSuccess, "%s/%s/%s", kvmPath,
+                                    ent->d_name, "halt_poll_success_ns") < 0 ||
+        virFileReadValueUllongQuiet(haltPollFail, "%s/%s/%s", kvmPath,
+                                    ent->d_name, "halt_poll_fail_ns") < 0)
+        return -1;
+
+    return 0;
+}
index fc717250d93e573f7d54ccd773c07b604822d385..d98385d53fb4d7b371e16f220fbc57bef4d4864b 100644 (file)
@@ -83,3 +83,7 @@ int virHostCPUGetMSR(unsigned long index,
 virHostCPUTscInfo *virHostCPUGetTscInfo(void);
 
 int virHostCPUGetSignature(char **signature);
+
+int virHostCPUGetHaltPollTime(pid_t pid,
+                              unsigned long long *haltPollSuccess,
+                              unsigned long long *haltPollFail);