From nobody Thu May 2 08:54:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1485931882563111.52489296817305; Tue, 31 Jan 2017 22:51:22 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v116lUaJ060750; Wed, 1 Feb 2017 01:47:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v116lTaO024254 for ; Wed, 1 Feb 2017 01:47:29 -0500 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v116lTOj007384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 1 Feb 2017 01:47:29 -0500 Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A69BF5277F for ; Wed, 1 Feb 2017 06:47:26 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v116lNxT030019 for ; Wed, 1 Feb 2017 09:47:23 +0300 (MSK) From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Wed, 1 Feb 2017 09:47:20 +0300 Message-Id: <1485931640-619301-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 47:32:41 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 01 Feb 2017 06:47:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 01 Feb 2017 06:47:28 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.799 (BAYES_50, SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: add host per cpu info to all domain stats 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Info provided in virDomainGetCPUStats is now missed in all domain stats. This patch removes this discrepancy. Output example: cpu.count=3D2 cpu.0.time=3D536163399467 cpu.1.time=3D453846564946 cpu.0.vtime=3D530053197220 cpu.1.vtime=3D446078894510 --- src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 71 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/vircgroup.c | 2 +- src/util/vircgroup.h | 5 ++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2866a3..40f284c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1343,6 +1343,7 @@ virCgroupGetMemoryUsage; virCgroupGetMemSwapHardLimit; virCgroupGetMemSwapUsage; virCgroupGetPercpuStats; +virCgroupGetPercpuVcpuSum; virCgroupHasController; virCgroupHasEmptyTasks; virCgroupKill; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 16b435a..61ae60e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18768,7 +18768,16 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, unsigned long long cpu_time =3D 0; unsigned long long user_time =3D 0; unsigned long long sys_time =3D 0; + unsigned long long *sum_cpu_time =3D NULL; + virBitmapPtr cpumap =3D NULL; + virBitmapPtr guestvcpus =3D NULL; + char *buf =3D NULL; + char *pos; + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + int ncpu; int err =3D 0; + int ret =3D -1; + size_t i; =20 if (!priv->cgroup) return 0; @@ -18795,7 +18804,67 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, sys_time) < 0) return -1; =20 - return 0; + if ((cpumap =3D virHostCPUGetPresentBitmap())) { + ncpu =3D virBitmapSize(cpumap); + + if (virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + "cpu.count", + ncpu) < 0) + goto cleanup; + + if (!virCgroupGetCpuacctPercpuUsage(priv->cgroup, &buf)) { + pos =3D buf; + for (i =3D 0; i < ncpu; i++) { + unsigned long long time =3D 0; + + if (virBitmapIsBitSet(cpumap, i) && + virStrToLong_ull(pos, &pos, 10, &time) < 0) { + VIR_WARN("cpuacct parse error"); + continue; + } + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%zu.time", i); + if (virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + param_name, + time) < 0) + goto cleanup; + } + } + + if (qemuDomainHasVcpuPids(dom) && + (guestvcpus =3D virDomainDefGetOnlineVcpumap(dom->def)) && + !VIR_ALLOC_N(sum_cpu_time, ncpu) && + !virCgroupGetPercpuVcpuSum(priv->cgroup, guestvcpus, + sum_cpu_time, ncpu, cpumap)) { + for (i =3D 0; i < ncpu; i++) { + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%zu.vtime", i); + if (virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + param_name, + sum_cpu_time[i]) < 0) + goto cleanup; + } + } + } + + ret =3D 0; + + cleanup: + if (!ret && virGetLastError()) + virResetLastError(); + virBitmapFree(cpumap); + virBitmapFree(guestvcpus); + VIR_FREE(sum_cpu_time); + VIR_FREE(buf); + + return ret; } =20 static int diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5aa1db5..0b36609 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3122,7 +3122,7 @@ virCgroupDenyDevicePath(virCgroupPtr group, * s2 =3D t02 + t12 * s3 =3D t03 + t13 */ -static int +int virCgroupGetPercpuVcpuSum(virCgroupPtr group, virBitmapPtr guestvcpus, unsigned long long *sum_cpu_time, diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 2de1bf2..5f71618 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -297,4 +297,9 @@ int virCgroupSetOwner(virCgroupPtr cgroup, int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller); =20 bool virCgroupControllerAvailable(int controller); +int virCgroupGetPercpuVcpuSum(virCgroupPtr group, + virBitmapPtr guestvcpus, + unsigned long long *sum_cpu_time, + size_t nsum, + virBitmapPtr cpumap); #endif /* __VIR_CGROUP_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list