From nobody Fri May 3 20:16:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577961910; cv=none; d=zohomail.com; s=zohoarc; b=RyKN3Tzyu/IjA3kkKpE1LTssRVVxMS3VCSunoV6JnOWAb7/OWuKHCNWrST9WnIJMuhC6wC19rfAOci4Zp/pw8TyIc6AtNvZ4LjU3dXmEJTVEFUPxv0znnIHrS/iV4DWv/7EhvHanyfHP6PJkIEG+TE1UwuJvj/FQ/xzF8VDaWdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577961910; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JAW2RRRYmdK9Edh0K9Yd3KpbPAp3bwu5CVJ4knzBtSA=; b=kYW6VzMCpV/wsB/7fR+1RWmIOFJbH2Cc+vcRVcaBd9rAJxSG1lK47b1fCvnf1pnUh3iaJ89GHxCwxXAm9tk/+k4Ui914kqQg34YGlnAbn1P4WXv85G7FgJbPWuF5VNnu1gwPxOnt4iyzH6OYtHx+1TuWTvmxtemAK0Kyawv3OWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1577961910506286.9311587398371; Thu, 2 Jan 2020 02:45:10 -0800 (PST) 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-120-G98_S0-wOsGHcbTlegxPVQ-1; Thu, 02 Jan 2020 05:45:07 -0500 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 E2219800D41; Thu, 2 Jan 2020 10:45:01 +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 CCCAF10027A6; Thu, 2 Jan 2020 10:45:00 +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 7517E18089CF; Thu, 2 Jan 2020 10:44: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 002AiveL028976 for ; Thu, 2 Jan 2020 05:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id DB02C10D17BB; Thu, 2 Jan 2020 10:44:57 +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 D469310D18F2 for ; Thu, 2 Jan 2020 10:44:55 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B4CC0185B0C3 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-xUP8I1CCP9WWToK-u4rlTg-1; Thu, 02 Jan 2020 05:44:53 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 02:44:51 -0800 Received: from david-unc.bj.intel.com ([10.238.157.59]) by fmsmga008.fm.intel.com with ESMTP; 02 Jan 2020 02:44:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577961909; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JAW2RRRYmdK9Edh0K9Yd3KpbPAp3bwu5CVJ4knzBtSA=; b=gwPO4PxbRmWuJHSHzkXX8UecxqU768hUEMfL2EegBigCLTAkpXxwy4GE0VaOn1H+XM0VXo pyZVGmkxKxcl/+WcRUkgwJipWKE3h18BZLtyzC/Yd8rgIWBmta6MINQZZL8ni1ttQxHcJl xCP6RwCo7NLtI2BPggemofGsO2a2PTU= X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,386,1571727600"; d="scan'208";a="216477090" From: Wang Huaqiang To: libvir-list@redhat.com, berrange@redhat.com Date: Thu, 2 Jan 2020 18:45:04 +0800 Message-Id: <20200102104505.28461-2-huaqiang.wang@intel.com> In-Reply-To: <20200102104505.28461-1-huaqiang.wang@intel.com> References: <20200102104505.28461-1-huaqiang.wang@intel.com> MIME-Version: 1.0 X-MC-Unique: xUP8I1CCP9WWToK-u4rlTg-1 X-MC-Unique: G98_S0-wOsGHcbTlegxPVQ-1 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 002AiveL028976 X-loop: libvir-list@redhat.com Cc: huaqiang.wang@intel.com Subject: [libvirt] [PATCHv2 1/2] util, resctrl: using 64bit interface instead of 32bit for counters 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 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The underlying resctrl monitoring is actually using 64 bit counters, not the 32bit one. Correct this by using 64bit data type for reading hardware value. To keep the interface consistent, the result of CPU last level cache that occupied by vcpu processors of specific restrl monitor group is still reported with a truncated 32bit data type. because, in silicon world, CPU cache size will never exceed 4GB. Signed-off-by: Wang Huaqiang Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_driver.c | 15 +++++++++++++-- src/util/virfile.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/util/virfile.h | 2 ++ src/util/virresctrl.c | 6 +++--- src/util/virresctrl.h | 2 +- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7a7f388767..ad6f3130ae 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20740,8 +20740,19 @@ qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, "cpu.cache.monitor.%zu.bank.%zu.i= d", i, j) < 0) goto cleanup; =20 - if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->val= s[0], - "cpu.cache.monitor.%zu.bank.%zu.b= ytes", i, j) < 0) + /* 'resdata[i]->stats[j]->vals[0]' keeps the value of how many= last + * level cache in bank j currently occupied by the vcpus liste= d in + * resource monitor i, in bytes. This value is reported throug= h a + * 64 bit hardware counter, so it is better to be arranged with + * data type in 64 bit width, but considering the fact that + * physical cache on a CPU could never be designed to be bigger + * than 4G bytes in size, to keep the 'domstats' interface + * historically consistent, it is safe to report the value wit= h a + * truncated 'UInt' data type here. */ + if (virTypedParamListAddUInt(params, + (unsigned int)resdata[i]->stats[j= ]->vals[0], + "cpu.cache.monitor.%zu.bank.%zu.b= ytes", + i, j) < 0) goto cleanup; } } diff --git a/src/util/virfile.c b/src/util/virfile.c index 4fd865dd83..7bf33682c7 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4196,6 +4196,46 @@ virFileReadValueUint(unsigned int *value, const char= *format, ...) } =20 =20 +/** + * virFileReadValueUllong: + * @value: pointer to unsigned long long to be filled in with the value + * @format, ...: file to read from + * + * Read unsigned int from @format and put it into @value. + * + * Return -2 for non-existing file, -1 on other errors and 0 if everything= went + * fine. + */ +int +virFileReadValueUllong(unsigned long long *value, const char *format, ...) +{ + g_autofree char *str =3D NULL; + g_autofree char *path =3D NULL; + va_list ap; + + va_start(ap, format); + path =3D g_strdup_vprintf(format, ap); + va_end(ap); + + if (!virFileExists(path)) + return -2; + + if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + return -1; + + virStringTrimOptionalNewline(str); + + if (virStrToLong_ullp(str, NULL, 10, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid unsigned long long value '%s' in file '%= s'"), + str, path); + return -1; + } + + return 0; +} + + /** * virFileReadValueScaledInt: * @value: pointer to unsigned long long int to be filled in with the value diff --git a/src/util/virfile.h b/src/util/virfile.h index bcae40ee06..756c9a70b9 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -361,6 +361,8 @@ int virFileReadValueInt(int *value, const char *format,= ...) G_GNUC_PRINTF(2, 3); int virFileReadValueUint(unsigned int *value, const char *format, ...) G_GNUC_PRINTF(2, 3); +int virFileReadValueUllong(unsigned long long *value, const char *format, = ...) + G_GNUC_PRINTF(2, 3); int virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...) G_GNUC_PRINTF(2, 3); int virFileReadValueScaledInt(unsigned long long *value, const char *forma= t, ...) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index b78fded026..684d2ce398 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2678,7 +2678,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, int rv =3D -1; int ret =3D -1; size_t i =3D 0; - unsigned int val =3D 0; + unsigned long long val =3D 0; DIR *dirp =3D NULL; char *datapath =3D NULL; char *filepath =3D NULL; @@ -2734,8 +2734,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, goto cleanup; =20 for (i =3D 0; resources[i]; i++) { - rv =3D virFileReadValueUint(&val, "%s/%s/%s", datapath, - ent->d_name, resources[i]); + rv =3D virFileReadValueUllong(&val, "%s/%s/%s", datapath, + ent->d_name, resources[i]); if (rv =3D=3D -2) { virReportError(VIR_ERR_INTERNAL_ERROR, _("File '%s/%s/%s' does not exist."), diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 3dd7c96348..11f275acf4 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -204,7 +204,7 @@ struct _virResctrlMonitorStats { char **features; /* @vals store the statistical record values and @val[0] is the value = for * @features[0], @val[1] for@features[1] ... respectively */ - unsigned int *vals; + unsigned long long *vals; /* The length of @vals array */ size_t nvals; }; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 20:16:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577961910; cv=none; d=zohomail.com; s=zohoarc; b=IecnzxTOetAQ/25dhPZP8Gemw2zZ6Zf8ABzFBchmCM8dsCdKJaO+KD2b+yktEld/2scvOhUml3TAxcH0vazo6GFLdNQ3Vxn4YS03Z6iNGStF5tV4/AshRP8vKVqB4eAiCJaA8Reu+ph6R1CzCS0aiwSws/8JOujAr88/SbhYh6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577961910; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e1tqkhg07mSocZBI0yfhEJZVk1IilC2pvA5WmqmmQQA=; b=gWJTPvzcTEr9muHI9WRg2WU5KwA+tE/NFjTOZjfECZ/L3m2Qm0AjnV9sPjj8vxBWPI296acKHyHqLUYKUoAzPWbn6Pi+gN2ANgkDiXrxEuxoE+Ls3Y3LsJEI3UmKnFj4yXQS08vbkWNnK0qX7L6FSRaqIaOQh1x8AdIfYaS1KQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1577961910388124.98865295463702; Thu, 2 Jan 2020 02:45:10 -0800 (PST) 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-162-UxfBk9QZMiSACmiJlFDdvw-1; Thu, 02 Jan 2020 05:45:07 -0500 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 BFC28800EB6; Thu, 2 Jan 2020 10:45:01 +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 A134B60C05; Thu, 2 Jan 2020 10:45:00 +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 6D44C18089CE; Thu, 2 Jan 2020 10:44: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 002Aiw2b028977 for ; Thu, 2 Jan 2020 05:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD1DD10D17BC; Thu, 2 Jan 2020 10:44:57 +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 D61B610D18F3 for ; Thu, 2 Jan 2020 10:44:55 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A7998008A0 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-MKWtsu9NPCisW18MI77cjw-2; Thu, 02 Jan 2020 05:44:53 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 02:44:52 -0800 Received: from david-unc.bj.intel.com ([10.238.157.59]) by fmsmga008.fm.intel.com with ESMTP; 02 Jan 2020 02:44:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577961908; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=e1tqkhg07mSocZBI0yfhEJZVk1IilC2pvA5WmqmmQQA=; b=I9rIYAShrT9bsZLuEXpkNZRrlY+hTolUyD3ViHsVPsQWjWYeatxKsop00oNL6CBKkNkm3N ddseZtgdJU8jpHtQnkVLspAlhsJO0jn/4761XoILT9Sz8fJu/oWG+7HOtrzLQMqun7BA2+ SOwm2vUEGHoqjsmWmiFppa0bBvNxEOk= X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,386,1571727600"; d="scan'208";a="216477094" From: Wang Huaqiang To: libvir-list@redhat.com, berrange@redhat.com Date: Thu, 2 Jan 2020 18:45:05 +0800 Message-Id: <20200102104505.28461-3-huaqiang.wang@intel.com> In-Reply-To: <20200102104505.28461-1-huaqiang.wang@intel.com> References: <20200102104505.28461-1-huaqiang.wang@intel.com> MIME-Version: 1.0 X-MC-Unique: MKWtsu9NPCisW18MI77cjw-2 X-MC-Unique: UxfBk9QZMiSACmiJlFDdvw-1 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 002Aiw2b028977 X-loop: libvir-list@redhat.com Cc: huaqiang.wang@intel.com Subject: [libvirt] [PATCHv2 2/2] Introduce command 'virsh domstats --memory' for reporting memory BW 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 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Introduce an option '--memory' for showing memory related information. The memory bandwidth infomatio is listed as: Domain: 'libvirt-vm' memory.bandwidth.monitor.count=3D4 memory.bandwidth.monitor.0.name=3Dvcpus_0-4 memory.bandwidth.monitor.0.vcpus=3D0-4 memory.bandwidth.monitor.0.node.count=3D2 memory.bandwidth.monitor.0.node.0.id=3D0 memory.bandwidth.monitor.0.node.0.bytes.total=3D10208067584 memory.bandwidth.monitor.0.node.0.bytes.local=3D4807114752 memory.bandwidth.monitor.0.node.1.id=3D1 memory.bandwidth.monitor.0.node.1.bytes.total=3D8693735424 memory.bandwidth.monitor.0.node.1.bytes.local=3D5850161152 memory.bandwidth.monitor.1.name=3Dvcpus_7 memory.bandwidth.monitor.1.vcpus=3D7 memory.bandwidth.monitor.1.node.count=3D2 memory.bandwidth.monitor.1.node.0.id=3D0 memory.bandwidth.monitor.1.node.0.bytes.total=3D853811200 memory.bandwidth.monitor.1.node.0.bytes.local=3D290701312 memory.bandwidth.monitor.1.node.1.id=3D1 memory.bandwidth.monitor.1.node.1.bytes.total=3D406044672 memory.bandwidth.monitor.1.node.1.bytes.local=3D229425152 Signed-off-by: Wang Huaqiang Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/manpages/virsh.rst | 22 ++++++- include/libvirt/libvirt-domain.h | 1 + src/libvirt-domain.c | 21 +++++++ src/qemu/qemu_driver.c | 103 +++++++++++++++++++++++++++++++ tools/virsh-domain-monitor.c | 7 +++ 5 files changed, 152 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index fea0527caf..d0f9e15c38 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -2186,7 +2186,7 @@ domstats =20 domstats [--raw] [--enforce] [--backing] [--nowait] [--state] [--cpu-total] [--balloon] [--vcpu] [--interface] - [--block] [--perf] [--iothread] + [--block] [--perf] [--iothread] [--memory] [[--list-active] [--list-inactive] [--list-persistent] [--list-transient] [--list-running]y [--list-paused] [--list-shutoff] [--list-other]] | [domain ...] @@ -2205,7 +2205,7 @@ behavior use the *--raw* flag. The individual statistics groups are selectable via specific flags. By default all supported statistics groups are returned. Supported statistics groups flags are: *--state*, *--cpu-total*, *--balloon*, -*--vcpu*, *--interface*, *--block*, *--perf*, *--iothread*. +*--vcpu*, *--interface*, *--block*, *--perf*, *--iothread*, *--memory*. =20 Note that - depending on the hypervisor type and version or the domain sta= te - not all of the following statistics may be returned. @@ -2372,6 +2372,24 @@ not available for statistical purposes. * ``iothread..poll-shrink`` - polling time shrink value. A value of (zero) indicates shrink is managed by hypervisor. =20 +*--memory* returns: + +* ``memory.bandwidth.monitor.count`` - the number of memory bandwidth + monitors for this domain +* ``memory.bandwidth.monitor..name`` - the name of monitor +* ``memory.bandwidth.monitor..vcpus`` - the vcpu list of monitor +* ``memory.bandwidth.monitor..node.count`` - the number of memory + controller in monitor +* ``memory.bandwidth.monitor..node..id`` - host allocated memo= ry + controller id for controller of monitor +* ``memory.bandwidth.monitor..node..bytes.local`` - the accumu= lative + bytes consumed by @vcpus that passing through the memory controller in t= he + same processor that the scheduled host CPU belongs to. +* ``memory.bandwidth.monitor..node..bytes.total`` - the total + bytes consumed by @vcpus that passing through all memory controllers, ei= ther + local or remote controller. + + Selecting a specific statistics groups doesn't guarantee that the daemon supports the selected group of stats. Flag *--enforce* forces the command to fail if the daemon doesn't support the diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index e60003978a..78532c0eb8 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2160,6 +2160,7 @@ typedef enum { VIR_DOMAIN_STATS_BLOCK =3D (1 << 5), /* return domain block info */ VIR_DOMAIN_STATS_PERF =3D (1 << 6), /* return domain perf event info */ VIR_DOMAIN_STATS_IOTHREAD =3D (1 << 7), /* return iothread poll info */ + VIR_DOMAIN_STATS_MEMORY=3D (1 << 8), /* return domain memory info */ } virDomainStatsTypes; =20 typedef enum { diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 793eceb39f..eb66999f07 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11640,6 +11640,27 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * hypervisor to choose how to shrink the * polling time. * + * VIR_DOMAIN_STATS_MEMORY: + * Return memory bandwidth statistics and the usage information. The t= yped + * parameter keys are in this format: + * + * "memory.bandwidth.monitor.count" - the number of memory bandwidth + * monitors for this domain + * "memory.bandwidth.monitor..name" - the name of monitor + * "memory.bandwidth.monitor..vcpus" - the vcpu list of monitor <= num> + * "memory.bandwidth.monitor..node.count" - the number of memory + * controller in monitor + * "memory.bandwidth.monitor..node..id" - host allocated m= emory + * controller id for contr= oller + * of monitor + * "memory.bandwidth.monitor..node..bytes.local" - the + * accumulative bytes consumed by @vcpus that passing + * through the memory controller in the same process= or + * that the scheduled host CPU belongs to. + * "memory.bandwidth.monitor..node..bytes.total" - the tot= al + * bytes consumed by @vcpus that passing through all + * memory controllers, either local or remote contro= ller. + * * Note that entire stats groups or individual stat fields may be missing = from * the output in case they are not supported by the given hypervisor, are = not * applicable for the current state of the guest domain, or their retrieval diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ad6f3130ae..d91adcf52f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20649,6 +20649,9 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, features =3D caps->host.cache.monitor->features; break; case VIR_RESCTRL_MONITOR_TYPE_MEMBW: + if (caps->host.memBW.monitor) + features =3D caps->host.memBW.monitor->features; + break; case VIR_RESCTRL_MONITOR_TYPE_UNSUPPORT: case VIR_RESCTRL_MONITOR_TYPE_LAST: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", @@ -20701,6 +20704,94 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuDomainGetStatsMemoryBandwidth(virQEMUDriverPtr driver, + virDomainObjPtr dom, + virTypedParamListPtr params) +{ + virQEMUResctrlMonDataPtr *resdata =3D NULL; + char **features =3D NULL; + size_t nresdata =3D 0; + size_t i =3D 0; + size_t j =3D 0; + size_t k =3D 0; + int ret =3D -1; + + if (!virDomainObjIsActive(dom)) + return 0; + + if (qemuDomainGetResctrlMonData(driver, dom, &resdata, &nresdata, + VIR_RESCTRL_MONITOR_TYPE_MEMBW) < 0) + goto cleanup; + + if (nresdata =3D=3D 0) + return 0; + + if (virTypedParamListAddUInt(params, nresdata, + "memory.bandwidth.monitor.count") < 0) + goto cleanup; + + for (i =3D 0; i < nresdata; i++) { + if (virTypedParamListAddString(params, resdata[i]->name, + "memory.bandwidth.monitor.%zu.name", + i) < 0) + goto cleanup; + + if (virTypedParamListAddString(params, resdata[i]->vcpus, + "memory.bandwidth.monitor.%zu.vcpus= ", + i) < 0) + goto cleanup; + + if (virTypedParamListAddUInt(params, resdata[i]->nstats, + "memory.bandwidth.monitor.%zu.node.co= unt", + i) < 0) + goto cleanup; + + + for (j =3D 0; j < resdata[i]->nstats; j++) { + if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, + "memory.bandwidth.monitor.%zu." + "node.%zu.id", + i, j) < 0) + goto cleanup; + + + features =3D resdata[i]->stats[j]->features; + for (k =3D 0; features[k]; k++) { + if (STREQ(features[k], "mbm_local_bytes")) { + /* The accumulative data passing through local memory + * controller is recorded with 64 bit counter. */ + if (virTypedParamListAddULLong(params, + resdata[i]->stats[j]->v= als[k], + "memory.bandwidth.monit= or." + "%zu.node.%zu.bytes.loc= al", + i, j) < 0) + goto cleanup; + } + + if (STREQ(features[k], "mbm_total_bytes")) { + /* The accumulative data passing through local and rem= ote + * memory controller is recorded with 64 bit counter. = */ + if (virTypedParamListAddULLong(params, + resdata[i]->stats[j]->v= als[k], + "memory.bandwidth.monit= or." + "%zu.node.%zu.bytes.tot= al", + i, j) < 0) + goto cleanup; + } + } + } + } + + ret =3D 0; + cleanup: + for (i =3D 0; i < nresdata; i++) + qemuDomainFreeResctrlMonData(resdata[i]); + VIR_FREE(resdata); + return ret; +} + + static int qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -20809,6 +20900,17 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver, } =20 =20 +static int +qemuDomainGetStatsMemory(virQEMUDriverPtr driver, + virDomainObjPtr dom, + virTypedParamListPtr params, + unsigned int privflags G_GNUC_UNUSED) + +{ + return qemuDomainGetStatsMemoryBandwidth(driver, dom, params); +} + + static int qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -21478,6 +21580,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGe= tStatsWorkers[] =3D { { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK, true }, { qemuDomainGetStatsPerf, VIR_DOMAIN_STATS_PERF, false }, { qemuDomainGetStatsIOThread, VIR_DOMAIN_STATS_IOTHREAD, true }, + { qemuDomainGetStatsMemory, VIR_DOMAIN_STATS_MEMORY, false }, { NULL, 0, false } }; =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index c2f157ad6b..7b9b9c57b0 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2111,6 +2111,10 @@ static const vshCmdOptDef opts_domstats[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("report domain IOThread information"), }, + {.name =3D "memory", + .type =3D VSH_OT_BOOL, + .help =3D N_("report domain memory usage"), + }, {.name =3D "list-active", .type =3D VSH_OT_BOOL, .help =3D N_("list only active domains"), @@ -2227,6 +2231,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "iothread")) stats |=3D VIR_DOMAIN_STATS_IOTHREAD; =20 + if (vshCommandOptBool(cmd, "memory")) + stats |=3D VIR_DOMAIN_STATS_MEMORY; + if (vshCommandOptBool(cmd, "list-active")) flags |=3D VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list