加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vcpustat-modify-vcpu-info-acquirement-from-debugfs.patch 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
From 3e17cc136a1cb2a2ae5798448c553b16694ec408 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Sun, 27 Sep 2020 15:25:41 +0800
Subject: [PATCH] vcpustat: modify vcpu info acquirement from debugfs
Previous judgement to determine whether the vcpustat info matches the process is:
strstr(buf, pid) == buf + 1
But there is an exception that the kvm exit times may contain process pid string.
And then, we will calculate the delta between two defferent process.
So, modify this judgement codition.
---
src/vcpu_stat.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/vcpu_stat.c b/src/vcpu_stat.c
index 2076563..7ec2371 100644
--- a/src/vcpu_stat.c
+++ b/src/vcpu_stat.c
@@ -15,7 +15,6 @@
#include "type.h"
#include "vcpu_stat.h"
-#define PID_STRING_SIZE 20
#define KVM_VCPU_STAT_PATH "/sys/kernel/debug/kvm/vcpu_stat"
struct file_item vcpu_stat_stab[] = {
@@ -57,12 +56,9 @@ const int vcpu_stat_size = sizeof(vcpu_stat_stab) / sizeof(struct file_item);
int get_vcpu_stat(struct domain *dom)
{
char buf[BUF_SIZE];
- char pid[PID_STRING_SIZE];
+ unsigned int pid;
FILE *fp = NULL;
- if (snprintf(pid, PID_STRING_SIZE, "%u", dom->pid) < 0) {
- return -1;
- }
fp = fopen(KVM_VCPU_STAT_PATH, "r");
if (!fp) {
return -1;
@@ -72,7 +68,9 @@ int get_vcpu_stat(struct domain *dom)
char *p_next = NULL;
int i = 0;
- if (strstr(buf, pid) == NULL) {
+ /* judge whether vcpu pid is match */
+ sscanf(buf, "%u", &pid);
+ if (pid != dom->pid) {
continue;
}
for (p = strtok_r(buf, " \t\r\n", &p_next); p && i < vcpu_stat_size;
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化