From nobody Sun May 5 10:16:21 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 1626432176566731.2156036492777; Fri, 16 Jul 2021 03:42:56 -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-478-s0Lx_mmmNn-SfC8nC-uKPA-1; Fri, 16 Jul 2021 06:42:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B83F4804140; Fri, 16 Jul 2021 10:42:48 +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 6E30460C05; Fri, 16 Jul 2021 10:42:48 +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 E19941809C99; Fri, 16 Jul 2021 10:42:44 +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 16GAghbC009128 for ; Fri, 16 Jul 2021 06:42:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 017EB205B12E; Fri, 16 Jul 2021 10:42:43 +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 EE32A205B133 for ; Fri, 16 Jul 2021 10:42:38 +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 C942280018D for ; Fri, 16 Jul 2021 10:42:38 +0000 (UTC) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-En-B5SUNOuCiu-wQGEJVeQ-1; Fri, 16 Jul 2021 06:42:33 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GR7466KmQz7tdT; Fri, 16 Jul 2021 18:37:58 +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; Fri, 16 Jul 2021 18:42:29 +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; Fri, 16 Jul 2021 18:42:29 +0800 X-MC-Unique: s0Lx_mmmNn-SfC8nC-uKPA-1 X-MC-Unique: En-B5SUNOuCiu-wQGEJVeQ-1 From: Yang Fei To: Subject: [PATCH v3 1/2] util: Add virGetCpuHaltPollTime Date: Fri, 16 Jul 2021 18:42:22 +0800 Message-ID: <20210716104223.39176-2-yangfei85@huawei.com> In-Reply-To: <20210716104223.39176-1-yangfei85@huawei.com> References: <20210716104223.39176-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 16GAghbC009128 X-loop: libvir-list@redhat.com Cc: yubihong@huawei.com, pkrempa@redhat.com, mprivozn@redhat.com, yangfei85@huawei.com, xiexiangyou@huawei.com, liangpeng10@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.12 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: 1626432179169100001 Content-Type: text/plain; charset="utf-8" Add helper function virGetCpuHaltPollTime 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 --- src/libvirt_private.syms | 1 + src/util/virutil.c | 43 ++++++++++++++++++++++++++++++++++++++++ src/util/virutil.h | 4 ++++ 3 files changed, 48 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 68e4b6aab8..64aff4eca4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3479,6 +3479,7 @@ virDoesUserExist; virDoubleToStr; virFormatIntDecimal; virFormatIntPretty; +virGetCpuHaltPollTime; virGetDeviceID; virGetDeviceUnprivSGIO; virGetGroupID; diff --git a/src/util/virutil.c b/src/util/virutil.c index 311cbbf93a..f5304644c0 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1936,3 +1936,46 @@ virPipeNonBlock(int fds[2]) { return virPipeImpl(fds, true, true); } + +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; + g_autoptr(DIR) dir =3D NULL; + int ret =3D -1; + bool found =3D false; + + if (!(debugFsPath =3D virFileFindMountPoint("debugfs"))) + return ret; + + completePath =3D g_strdup_printf("%s/%s", debugFsPath, "kvm"); + if (virDirOpenIfExists(&dir, completePath) !=3D 1) + return ret; + + pidToStr =3D g_strdup_printf("%d%c", pid, '-'); + while (virDirRead(dir, &ent, NULL) > 0) { + if (STRPREFIX(ent->d_name, pidToStr)) { + found =3D true; + break; + } + } + + if (!found) + return ret; + + if (virFileReadValueUllong(haltPollSuccess, "%s/%s/%s", completePath, + ent->d_name, "halt_poll_success_ns") < 0 + || virFileReadValueUllong(haltPollFail, "%s/%s/%s", completePath, + ent->d_name, "halt_poll_fail_ns") < 0) { + return ret; + } + + ret =3D 0; + + return ret; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 854b494890..03b225185f 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -225,3 +225,7 @@ int virPipeQuiet(int fds[2]); * Returns: -1 on error, 0 on success */ int virPipeNonBlock(int fds[2]); + +int virGetCpuHaltPollTime(pid_t pid, + unsigned long long *haltPollSuccess, + unsigned long long *haltPollFail); --=20 2.23.0 From nobody Sun May 5 10:16:21 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 1626432184886137.54059613952347; Fri, 16 Jul 2021 03:43:04 -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-219-ScwSDPENOvyw5mYIr969CQ-1; Fri, 16 Jul 2021 06:43:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E045019200C3; Fri, 16 Jul 2021 10:42:56 +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 980056090F; Fri, 16 Jul 2021 10:42:56 +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 597144EA2F; Fri, 16 Jul 2021 10:42:56 +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 16GAgh6E009127 for ; Fri, 16 Jul 2021 06:42:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id F13142052DDA; Fri, 16 Jul 2021 10:42:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC2BC205B131 for ; Fri, 16 Jul 2021 10:42:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 C5487185A79C for ; Fri, 16 Jul 2021 10:42:39 +0000 (UTC) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-dIIsDLRBPgeGyNEQpRSjyw-1; Fri, 16 Jul 2021 06:42:35 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GR7485rldz7tc4; Fri, 16 Jul 2021 18:38:00 +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; Fri, 16 Jul 2021 18:42:31 +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; Fri, 16 Jul 2021 18:42:31 +0800 X-MC-Unique: ScwSDPENOvyw5mYIr969CQ-1 X-MC-Unique: dIIsDLRBPgeGyNEQpRSjyw-1 From: Yang Fei To: Subject: [PATCH v3 2/2] qemu: Introduce qemuDomainGetStatsCpuHaltPollTime Date: Fri, 16 Jul 2021 18:42:23 +0800 Message-ID: <20210716104223.39176-3-yangfei85@huawei.com> In-Reply-To: <20210716104223.39176-1-yangfei85@huawei.com> References: <20210716104223.39176-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 16GAgh6E009127 X-loop: libvir-list@redhat.com Cc: yubihong@huawei.com, pkrempa@redhat.com, mprivozn@redhat.com, yangfei85@huawei.com, xiexiangyou@huawei.com, liangpeng10@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.13 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: 1626432185470100001 Content-Type: text/plain; charset="utf-8" This function add halt polling time interface in domstats. So that we can use command 'virsh domstats VM' to get the data if system support. Signed-off-by: Yang Fei --- src/libvirt-domain.c | 7 +++++++ src/qemu/qemu_driver.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 750e32f0ca..8e58c1b43f 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11625,6 +11625,13 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * "cpu.user" - user cpu time spent in nanoseconds as unsigned long lo= ng. * "cpu.system" - system cpu time spent in nanoseconds as unsigned long * long. + * "haltpollsuccess.time" - halt-polling cpu usage about the VCPU poll= ed + * until a virtual interrupt was delivered in + * nanoseconds as unsigned long long. + * "haltpollfail.time" - halt-polling cpu usage about the VCPU had to = schedule + * out (either because the maximum poll time was= reached + * or it needed to yield the CPU) in nanoseconds= as + * unsigned long long. * "cpu.cache.monitor.count" - the number of cache monitors for this d= omain * "cpu.cache.monitor..name" - the name of cache monitor * "cpu.cache.monitor..vcpus" - vcpu list of cache monitor diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 235f575901..adb4628558 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17839,6 +17839,23 @@ qemuDomainGetStatsCpuCgroup(virDomainObj *dom, return 0; } =20 +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; + + if (virGetCpuHaltPollTime(pid, &haltPollSuccess, &haltPollFail) < 0) + return 0; + + if (virTypedParamListAddULLong(params, haltPollSuccess, "haltpollsucce= ss.time") < 0 || + virTypedParamListAddULLong(params, haltPollFail, "haltpollfail.tim= e") < 0) + return -1; + + return 0; +} =20 static int qemuDomainGetStatsCpu(virQEMUDriver *driver, @@ -17852,6 +17869,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