From nobody Fri May 3 17:47:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1626265834098409.15758709893043; Wed, 14 Jul 2021 05:30:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-535-6cwA93xlNJGeNqiwUyZZhQ-1; Wed, 14 Jul 2021 08:30:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 508B519057A1; Wed, 14 Jul 2021 12:30:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 208F426E51; Wed, 14 Jul 2021 12:30:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D2F9B1832E78; Wed, 14 Jul 2021 12:30:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16ECTCTT023953 for ; Wed, 14 Jul 2021 08:29:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8A6F2200E49B; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 842112012E34 for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33A8996B04D for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-TGiiixuYMl-5W0MJSScLrg-1; Wed, 14 Jul 2021 08:29:07 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GPxY12hpzz7BH1; Wed, 14 Jul 2021 20:25:25 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:28:58 +0800 Received: from 90078.china.huawei.com (10.174.187.199) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:28:58 +0800 X-MC-Unique: 6cwA93xlNJGeNqiwUyZZhQ-1 X-MC-Unique: TGiiixuYMl-5W0MJSScLrg-1 From: Yang Fei To: Subject: [PATCH v2 1/3] util: Move virGetCgroupValueRaw to vircgroup.c and rename it virGetValueRaw Date: Wed, 14 Jul 2021 20:28:52 +0800 Message-ID: <20210714122854.46848-2-yangfei85@huawei.com> In-Reply-To: <20210714122854.46848-1-yangfei85@huawei.com> References: <20210714122854.46848-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 16ECTCTT023953 X-loop: libvir-list@redhat.com Cc: liangpeng10@huawei.com, yubihong@huawei.com, yangfei85@huawei.com, pkrempa@redhat.com, xiexiangyou@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1626265834784100004 Content-Type: text/plain; charset="utf-8" Move virGetCgroupValueRaw from vircgroup.c, so that we can call it more appropriately at any where. And change it to a more generic name virGetValueRaw. Replace virGetCgroupValueRaw by virGetValueRaw in cgroup data obtain. Signed-off-by: Yang Fei --- src/util/vircgroup.c | 29 ++--------------------------- src/util/vircgrouppriv.h | 3 --- src/util/vircgroupv1.c | 5 +++-- src/util/vircgroupv2.c | 5 +++-- src/util/virutil.c | 23 +++++++++++++++++++++++ src/util/virutil.h | 3 +++ 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 65a81e8d6f..80a06c78b9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -48,6 +48,7 @@ #include "virtypedparam.h" #include "virhostcpu.h" #include "virthread.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -539,31 +540,6 @@ virCgroupSetValueRaw(const char *path, return 0; } =20 - -int -virCgroupGetValueRaw(const char *path, - char **value) -{ - int rc; - - *value =3D NULL; - - VIR_DEBUG("Get value %s", path); - - if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { - virReportSystemError(errno, - _("Unable to read from '%s'"), path); - return -1; - } - - /* Terminated with '\n' has sometimes harmful effects to the caller */ - if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') - (*value)[rc - 1] =3D '\0'; - - return 0; -} - - int virCgroupSetValueStr(virCgroup *group, int controller, @@ -590,10 +566,9 @@ virCgroupGetValueStr(virCgroup *group, if (virCgroupPathOfController(group, controller, key, &keypath) < 0) return -1; =20 - return virCgroupGetValueRaw(keypath, value); + return virGetValueRaw(keypath, value); } =20 - int virCgroupGetValueForBlkDev(const char *str, const char *path, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index caf7ed84db..627308d995 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -76,9 +76,6 @@ int virCgroupSetValueDBus(const char *unitName, int virCgroupSetValueRaw(const char *path, const char *value); =20 -int virCgroupGetValueRaw(const char *path, - char **value); - int virCgroupSetValueStr(virCgroup *group, int controller, const char *key, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8a04bb2e4a..2a40de51a0 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -42,6 +42,7 @@ #include "virerror.h" #include "viralloc.h" #include "virthread.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -1042,7 +1043,7 @@ virCgroupV1GetBlkioWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virStrToLong_ui(value, NULL, 10, weight) < 0) { @@ -1297,7 +1298,7 @@ virCgroupV1GetBlkioDeviceWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8881d3a88a..1c444d58f2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -41,6 +41,7 @@ #include "virlog.h" #include "virstring.h" #include "virsystemd.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -701,7 +702,7 @@ virCgroupV2GetBlkioWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if ((tmp =3D strstr(value, "default "))) { @@ -907,7 +908,7 @@ virCgroupV2GetBlkioDeviceWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/virutil.c b/src/util/virutil.c index 311cbbf93a..c0d25fe247 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1936,3 +1936,26 @@ virPipeNonBlock(int fds[2]) { return virPipeImpl(fds, true, true); } + +int +virGetValueRaw(const char *path, + char **value) +{ + int rc; + + *value =3D NULL; + + VIR_DEBUG("Get value %s", path); + + if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { + virReportSystemError(errno, + _("Unable to read from '%s'"), path); + return -1; + } + + /* Terminated with '\n' has sometimes harmful effects to the caller */ + if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') + (*value)[rc - 1] =3D '\0'; + + return 0; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 854b494890..851b421476 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -225,3 +225,6 @@ int virPipeQuiet(int fds[2]); * Returns: -1 on error, 0 on success */ int virPipeNonBlock(int fds[2]); + +int virGetValueRaw(const char *path, + char **value); --=20 2.23.0 From nobody Fri May 3 17:47:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1626265813067165.02361807085197; Wed, 14 Jul 2021 05:30:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-Fk6RrgbJNnSRHdCrtJAAlA-1; Wed, 14 Jul 2021 08:30:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9C411084F4B; Wed, 14 Jul 2021 12:30:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D06D69FAE; Wed, 14 Jul 2021 12:30:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DD3164EA2A; Wed, 14 Jul 2021 12:29:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16ECTBsQ023943 for ; Wed, 14 Jul 2021 08:29:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8111D101B880; Wed, 14 Jul 2021 12:29:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BB8A10EE967 for ; Wed, 14 Jul 2021 12:29:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EDDE866DF9 for ; Wed, 14 Jul 2021 12:29:08 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-0MrcvgaJMwyiDPr6v08ysA-1; Wed, 14 Jul 2021 08:29:05 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GPxVf2f5zzXt3N; Wed, 14 Jul 2021 20:23:22 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:29:00 +0800 Received: from 90078.china.huawei.com (10.174.187.199) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:28:59 +0800 X-MC-Unique: Fk6RrgbJNnSRHdCrtJAAlA-1 X-MC-Unique: 0MrcvgaJMwyiDPr6v08ysA-1 From: Yang Fei To: Subject: [PATCH v2 2/3] util: Add virGetCpuHaltPollTime and virGetDebugFsKvmValue Date: Wed, 14 Jul 2021 20:28:53 +0800 Message-ID: <20210714122854.46848-3-yangfei85@huawei.com> In-Reply-To: <20210714122854.46848-1-yangfei85@huawei.com> References: <20210714122854.46848-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 16ECTBsQ023943 X-loop: libvir-list@redhat.com Cc: liangpeng10@huawei.com, yubihong@huawei.com, yangfei85@huawei.com, pkrempa@redhat.com, xiexiangyou@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1626265815145100004 Content-Type: text/plain; charset="utf-8" Add helper function virGetCpuHaltPollTime and virGetDebugFsKvmValue to obtain the halt polling time. If system mount debugfs, and the kernel support halt polling time statistic, it will work. Signed-off-by: Yang Fei --- src/libvirt_private.syms | 2 ++ src/util/virutil.c | 78 ++++++++++++++++++++++++++++++++++++++++ src/util/virutil.h | 9 +++++ 3 files changed, 89 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 68e4b6aab8..f92213b8c2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3479,6 +3479,8 @@ virDoesUserExist; virDoubleToStr; virFormatIntDecimal; virFormatIntPretty; +virGetCpuHaltPollTime; +virGetDebugFsKvmValue; virGetDeviceID; virGetDeviceUnprivSGIO; virGetGroupID; diff --git a/src/util/virutil.c b/src/util/virutil.c index c0d25fe247..7e4531b4b4 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1959,3 +1959,81 @@ virGetValueRaw(const char *path, =20 return 0; } + +int +virGetDebugFsKvmValue(struct dirent *ent, + const char *path, + const char *filename, + unsigned long long *value) +{ + g_autofree char *valToStr =3D NULL; + g_autofree char *valPath =3D NULL; + + valPath =3D g_strdup_printf("%s/%s/%s", path, ent->d_name, filename); + + if (virGetValueRaw(valPath, &valToStr) < 0) { + return -1; + } + + /* 10 is a Cardinality, must be between 2 and 36 inclusive, + * or special value 0. Used in fuction strtoull() + */ + if (virStrToLong_ull(valToStr, NULL, 10, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), valToStr); + return -1; + } + + return 0; +} + +int +virGetCpuHaltPollTime(pid_t pid, + unsigned long long *haltPollSuccess, + unsigned long long *haltPollFail) +{ + g_autofree char *pidToStr =3D NULL; + g_autofree char *debugFsPath =3D NULL; + g_autofree char *completePath =3D NULL; + struct dirent *ent =3D NULL; + DIR *dir =3D NULL; + int ret =3D -1; + int flag =3D 0; + + if (!(debugFsPath =3D virFileFindMountPoint("debugfs"))) { + virReportSystemError(errno, "%s", + _("unable to find debugfs mountpoint")); + return ret; + } + + completePath =3D g_strdup_printf("%s/%s", debugFsPath, "kvm"); + if (virDirOpen(&dir, completePath) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s %s", "Can not open directory", completePath); + return ret; + } + + pidToStr =3D g_strdup_printf("%lld%c", (unsigned long long)pid, '-'); + while (virDirRead(dir, &ent, NULL) > 0) { + if (STRPREFIX(ent->d_name, pidToStr)) { + flag =3D 1; + break; + } + } + + if (flag =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find VM(Pid %s) in '%s'"), pidToStr, c= ompletePath); + goto cleanup; + } + + if (virGetDebugFsKvmValue(ent, completePath, "halt_poll_success_ns", h= altPollSuccess) < 0 || + virGetDebugFsKvmValue(ent, completePath, "halt_poll_fail_ns", halt= PollFail) < 0) { + goto cleanup; + } + + ret =3D 0; +cleanup: + closedir(dir); + return ret; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 851b421476..00cef47208 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -228,3 +228,12 @@ int virPipeNonBlock(int fds[2]); =20 int virGetValueRaw(const char *path, char **value); + +int virGetDebugFsKvmValue(struct dirent *ent, + const char *path, + const char *filename, + unsigned long long *value); + +int virGetCpuHaltPollTime(pid_t pid, + unsigned long long *haltPollSuccess, + unsigned long long *haltPollFail); --=20 2.23.0 From nobody Fri May 3 17:47:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1626265813020385.9553419280428; Wed, 14 Jul 2021 05:30:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-371-511MbOAnMvyn2JHraBC66Q-1; Wed, 14 Jul 2021 08:30:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8434D1054F93; Wed, 14 Jul 2021 12:30:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61155100F49F; Wed, 14 Jul 2021 12:30:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DD3121832E6F; Wed, 14 Jul 2021 12:29:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16ECTEJ3023973 for ; Wed, 14 Jul 2021 08:29:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E678EE380; Wed, 14 Jul 2021 12:29:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 998A7EAF91 for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1DB25800963 for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-bWB9PTUQNUu9nG01IpROkg-1; Wed, 14 Jul 2021 08:29:07 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4GPxVg6Pnpz1CJRb; Wed, 14 Jul 2021 20:23:23 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:29:01 +0800 Received: from 90078.china.huawei.com (10.174.187.199) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:29:01 +0800 X-MC-Unique: 511MbOAnMvyn2JHraBC66Q-1 X-MC-Unique: bWB9PTUQNUu9nG01IpROkg-1 From: Yang Fei To: Subject: [PATCH v2 3/3] qemu: Introduce qemuDomainGetStatsCpuHaltPollTime Date: Wed, 14 Jul 2021 20:28:54 +0800 Message-ID: <20210714122854.46848-4-yangfei85@huawei.com> In-Reply-To: <20210714122854.46848-1-yangfei85@huawei.com> References: <20210714122854.46848-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 16ECTEJ3023973 X-loop: libvir-list@redhat.com Cc: liangpeng10@huawei.com, yubihong@huawei.com, yangfei85@huawei.com, pkrempa@redhat.com, xiexiangyou@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1626265815145100005 Content-Type: text/plain; charset="utf-8" This function is used to obtain the halt polling time. The kernel provides statistics about haltpollsuccess.time and haltpollfail.time. We add it in domstats, so that we can use command 'virsh domstats VM' to get it if system support. Signed-off-by: Yang Fei --- src/qemu/qemu_driver.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 235f575901..6163037ec3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17839,6 +17839,31 @@ qemuDomainGetStatsCpuCgroup(virDomainObj *dom, return 0; } =20 +#ifdef __linux__ +static int +qemuDomainGetStatsCpuHaltPollTime(virDomainObj *dom, + virTypedParamList *params) +{ + unsigned long long haltPollSuccess =3D 0; + unsigned long long haltPollFail =3D 0; + pid_t pid =3D dom->pid; + int err =3D 0; + + err =3D virGetCpuHaltPollTime(pid, &haltPollSuccess, &haltPollFail); + if (!err && virTypedParamListAddULLong(params, haltPollSuccess, "haltp= ollsuccess.time") < 0) + return -1; + if (!err && virTypedParamListAddULLong(params, haltPollFail, "haltpoll= fail.time") < 0) + return -1; + return 0; +} +#else +static int +qemuDomainGetStatsCpuHaltPollTime(virDomainObj *dom, + virTypedParamList *params) +{ + return 0; +} +#endif =20 static int qemuDomainGetStatsCpu(virQEMUDriver *driver, @@ -17852,6 +17877,9 @@ qemuDomainGetStatsCpu(virQEMUDriver *driver, if (qemuDomainGetStatsCpuCache(driver, dom, params) < 0) return -1; =20 + if (qemuDomainGetStatsCpuHaltPollTime(dom, params) < 0) + return -1; + return 0; } =20 --=20 2.23.0