From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921759222668.1956923109761; Sun, 29 Jul 2018 20:35:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 990173082131; Mon, 30 Jul 2018 03:35:55 +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 4D1C13001A40; Mon, 30 Jul 2018 03:35:55 +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 ED39D3FCC0; Mon, 30 Jul 2018 03:35:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZSGp002757 for ; Sun, 29 Jul 2018 23:35:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29035600C5; Mon, 30 Jul 2018 03:35:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 21382600C4 for ; Mon, 30 Jul 2018 03:35:25 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D36F881DFE for ; Mon, 30 Jul 2018 03:35:24 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:23 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:22 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613691" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:25 +0800 Message-Id: <1532920361-24737-2-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 30 Jul 2018 03:35:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 30 Jul 2018 03:35:25 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 01/17] util: Rename some functions of virresctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 30 Jul 2018 03:35:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Some functions in virresctrl are for CAT only, while some of other functions are for resource allocation, not just CAT. So change their names to reflect the reality. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 8 ++++---- src/libvirt_private.syms | 4 ++-- src/util/virresctrl.c | 30 +++++++++++++++--------------- src/util/virresctrl.h | 26 +++++++++++++------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index eff8af2..abb6c5e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19013,7 +19013,7 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, ULLONG_MAX, true) < 0) goto cleanup; =20 - if (virResctrlAllocSetSize(alloc, level, type, cache, size) < 0) + if (virResctrlAllocSetCacheSize(alloc, level, type, cache, size) < 0) goto cleanup; =20 ret =3D 0; @@ -27002,9 +27002,9 @@ virDomainCachetuneDefFormat(virBufferPtr buf, int ret =3D -1; =20 virBufferSetChildIndent(&childrenBuf, buf); - virResctrlAllocForeachSize(cachetune->alloc, - virDomainCachetuneDefFormatHelper, - &childrenBuf); + virResctrlAllocForeachCache(cachetune->alloc, + virDomainCachetuneDefFormatHelper, + &childrenBuf); =20 =20 if (virBufferCheckError(&childrenBuf) < 0) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fc386e1..bc489cb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2648,14 +2648,14 @@ virCacheTypeToString; virResctrlAllocAddPID; virResctrlAllocCreate; virResctrlAllocDeterminePath; -virResctrlAllocForeachSize; +virResctrlAllocForeachCache; virResctrlAllocFormat; virResctrlAllocGetID; virResctrlAllocGetUnused; virResctrlAllocNew; virResctrlAllocRemove; +virResctrlAllocSetCacheSize; virResctrlAllocSetID; -virResctrlAllocSetSize; virResctrlInfoGetCache; virResctrlInfoNew; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index e492a63..6d69c8d 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -754,11 +754,11 @@ virResctrlAllocCheckCollision(virResctrlAllocPtr allo= c, =20 =20 int -virResctrlAllocSetSize(virResctrlAllocPtr alloc, - unsigned int level, - virCacheType type, - unsigned int cache, - unsigned long long size) +virResctrlAllocSetCacheSize(virResctrlAllocPtr alloc, + unsigned int level, + virCacheType type, + unsigned int cache, + unsigned long long size) { if (virResctrlAllocCheckCollision(alloc, level, type, cache)) { virReportError(VIR_ERR_XML_ERROR, @@ -773,9 +773,9 @@ virResctrlAllocSetSize(virResctrlAllocPtr alloc, =20 =20 int -virResctrlAllocForeachSize(virResctrlAllocPtr alloc, - virResctrlAllocForeachSizeCallback cb, - void *opaque) +virResctrlAllocForeachCache(virResctrlAllocPtr alloc, + virResctrlAllocForeachCacheCallback cb, + void *opaque) { int ret =3D 0; unsigned int level =3D 0; @@ -939,9 +939,9 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr resc= trl, =20 =20 static int -virResctrlAllocParseProcessLine(virResctrlInfoPtr resctrl, - virResctrlAllocPtr alloc, - char *line) +virResctrlAllocParseCacheLine(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + char *line) { char **caches =3D NULL; char *tmp =3D NULL; @@ -1009,7 +1009,7 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl, =20 lines =3D virStringSplitCount(schemata, "\n", 0, &nlines); for (i =3D 0; i < nlines; i++) { - if (virResctrlAllocParseProcessLine(resctrl, alloc, lines[i]) < 0) + if (virResctrlAllocParseCacheLine(resctrl, alloc, lines[i]) < 0) goto cleanup; } =20 @@ -1401,8 +1401,8 @@ virResctrlAllocCopyMasks(virResctrlAllocPtr dst, * transforming `sizes` into `masks`. */ static int -virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, - virResctrlAllocPtr alloc) +virResctrlAllocAssign(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc) { int ret =3D -1; unsigned int level =3D 0; @@ -1526,7 +1526,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (lockfd < 0) goto cleanup; =20 - if (virResctrlAllocMasksAssign(resctrl, alloc) < 0) + if (virResctrlAllocAssign(resctrl, alloc) < 0) goto cleanup; =20 alloc_str =3D virResctrlAllocFormat(alloc); diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 9052a2b..d657c06 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -67,11 +67,11 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, typedef struct _virResctrlAlloc virResctrlAlloc; typedef virResctrlAlloc *virResctrlAllocPtr; =20 -typedef int virResctrlAllocForeachSizeCallback(unsigned int level, - virCacheType type, - unsigned int cache, - unsigned long long size, - void *opaque); +typedef int virResctrlAllocForeachCacheCallback(unsigned int level, + virCacheType type, + unsigned int cache, + unsigned long long size, + void *opaque); =20 virResctrlAllocPtr virResctrlAllocNew(void); @@ -80,16 +80,16 @@ bool virResctrlAllocIsEmpty(virResctrlAllocPtr alloc); =20 int -virResctrlAllocSetSize(virResctrlAllocPtr alloc, - unsigned int level, - virCacheType type, - unsigned int cache, - unsigned long long size); +virResctrlAllocSetCacheSize(virResctrlAllocPtr alloc, + unsigned int level, + virCacheType type, + unsigned int cache, + unsigned long long size); =20 int -virResctrlAllocForeachSize(virResctrlAllocPtr alloc, - virResctrlAllocForeachSizeCallback cb, - void *opaque); +virResctrlAllocForeachCache(virResctrlAllocPtr alloc, + virResctrlAllocForeachCacheCallback cb, + void *opaque); =20 int virResctrlAllocSetID(virResctrlAllocPtr alloc, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921738101580.4149010380906; Sun, 29 Jul 2018 20:35:38 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4FCE685543; Mon, 30 Jul 2018 03:35:35 +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 905FC4516; Mon, 30 Jul 2018 03:35:34 +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 7FE8518037ED; Mon, 30 Jul 2018 03:35:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZSF6002762 for ; Sun, 29 Jul 2018 23:35:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E89946EE3F; Mon, 30 Jul 2018 03:35:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCF5D6EE2C for ; Mon, 30 Jul 2018 03:35:26 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A09E30832DC for ; Mon, 30 Jul 2018 03:35:25 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:25 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:24 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613697" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:26 +0800 Message-Id: <1532920361-24737-3-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 30 Jul 2018 03:35:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 30 Jul 2018 03:35:25 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 02/17] util: Refactor virResctrlGetInfo in virresctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Separate resctrl common information parts from CAT specific parts, so that common information parts can be reused among different resource allocation technologies. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 6d69c8d..313f964 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -318,9 +318,9 @@ virResctrlUnlock(int fd) =20 /* virResctrlInfo-related definitions */ static int -virResctrlGetInfo(virResctrlInfoPtr resctrl) +virResctrlGetCacheInfo(virResctrlInfoPtr resctrl, + DIR *dirp) { - DIR *dirp =3D NULL; char *endptr =3D NULL; char *tmp_str =3D NULL; int ret =3D -1; @@ -332,12 +332,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) virResctrlInfoPerLevelPtr i_level =3D NULL; virResctrlInfoPerTypePtr i_type =3D NULL; =20 - rv =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); - if (rv <=3D 0) { - ret =3D rv; - goto cleanup; - } - while ((rv =3D virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0= ) { VIR_DEBUG("Parsing info type '%s'", ent->d_name); if (ent->d_name[0] !=3D 'L') @@ -443,12 +437,32 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dirp); VIR_FREE(i_type); return ret; } =20 =20 +static int +virResctrlGetInfo(virResctrlInfoPtr resctrl) +{ + DIR *dirp =3D NULL; + int ret =3D -1; + + ret =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); + if (ret <=3D 0) + goto cleanup; + + ret =3D virResctrlGetCacheInfo(resctrl, dirp); + if (ret < 0) + goto cleanup; + + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dirp); + return ret; +} + + virResctrlInfoPtr virResctrlInfoNew(void) { --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921763500683.5135433849796; Sun, 29 Jul 2018 20:36:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 496D381DF7; Mon, 30 Jul 2018 03:36:01 +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 02BF9308BDB2; Mon, 30 Jul 2018 03:36:01 +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 59A863F7FE; Mon, 30 Jul 2018 03:36:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZTMM002770 for ; Sun, 29 Jul 2018 23:35:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FC876E721; Mon, 30 Jul 2018 03:35:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCB886EE26 for ; Mon, 30 Jul 2018 03:35:28 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A1DF1555C for ; Mon, 30 Jul 2018 03:35:27 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:27 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:25 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613705" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:27 +0800 Message-Id: <1532920361-24737-4-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:27 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 03/17] util: Refactor virResctrlAllocFormat of virresctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 30 Jul 2018 03:36:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Refactor virResctrlAllocFormat so that it is easy to support other resource allocation technologies. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 313f964..a38c926 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -849,17 +849,14 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc) } =20 =20 -char * -virResctrlAllocFormat(virResctrlAllocPtr alloc) +static int +virResctrlAllocFormatCache(virResctrlAllocPtr alloc, + virBufferPtr buf) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; unsigned int level =3D 0; unsigned int type =3D 0; unsigned int cache =3D 0; =20 - if (!alloc) - return NULL; - for (level =3D 0; level < alloc->nlevels; level++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; =20 @@ -872,7 +869,7 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) if (!a_type) continue; =20 - virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToStrin= g(type)); + virBufferAsprintf(buf, "L%u%s:", level, virResctrlTypeToString= (type)); =20 for (cache =3D 0; cache < a_type->nmasks; cache++) { virBitmapPtr mask =3D a_type->masks[cache]; @@ -882,21 +879,35 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) continue; =20 mask_str =3D virBitmapToString(mask, false, true); - if (!mask_str) { - virBufferFreeAndReset(&buf); - return NULL; - } + if (!mask_str) + return -1; =20 - virBufferAsprintf(&buf, "%u=3D%s;", cache, mask_str); + virBufferAsprintf(buf, "%u=3D%s;", cache, mask_str); VIR_FREE(mask_str); } =20 - virBufferTrim(&buf, ";", 1); - virBufferAddChar(&buf, '\n'); + virBufferTrim(buf, ";", 1); + virBufferAddChar(buf, '\n'); } } =20 - virBufferCheckError(&buf); + return virBufferCheckError(buf); +} + + +char * +virResctrlAllocFormat(virResctrlAllocPtr alloc) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (!alloc) + return NULL; + + if (virResctrlAllocFormatCache(alloc, &buf) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + return virBufferContentAndReset(&buf); } =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921759447506.97273775207657; Sun, 29 Jul 2018 20:35:59 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A9F11308FB84; Mon, 30 Jul 2018 03:35:55 +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 4E762100164C; Mon, 30 Jul 2018 03:35:55 +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 EE28518037F0; Mon, 30 Jul 2018 03:35:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZUUA002775 for ; Sun, 29 Jul 2018 23:35:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D596600C5; Mon, 30 Jul 2018 03:35:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25465600C4 for ; Mon, 30 Jul 2018 03:35:30 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D369813A88 for ; Mon, 30 Jul 2018 03:35:28 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:28 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:27 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613709" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:28 +0800 Message-Id: <1532920361-24737-5-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:29 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 04/17] util: Add MBA capability information query to resctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 30 Jul 2018 03:35:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introducing virResctrlInfoMemBW for the information memory bandwidth allocation information. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 84 insertions(+) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index a38c926..b12a05c 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -80,6 +80,9 @@ typedef virResctrlInfoPerType *virResctrlInfoPerTypePtr; typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; =20 +typedef struct _virResctrlInfoMemBW virResctrlInfoMemBW; +typedef virResctrlInfoMemBW *virResctrlInfoMemBWPtr; + typedef struct _virResctrlAllocPerType virResctrlAllocPerType; typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; =20 @@ -116,11 +119,30 @@ struct _virResctrlInfoPerLevel { virResctrlInfoPerTypePtr *types; }; =20 +/* Information about memory bandwidth allocation */ +struct _virResctrlInfoMemBW { + /* minimum memory bandwidth allowed */ + unsigned int min_bandwidth; + /* bandwidth granularity */ + unsigned int bandwidth_granularity; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocation; + /* level number of last level cache */ + unsigned int last_level_cache; + /* max id of last level cache, this is used to track + * how many last level cache available in host system, + * the number of memory bandwidth allocation controller + * is identical with last level cache. */ + unsigned int max_id; +}; + struct _virResctrlInfo { virObject parent; =20 virResctrlInfoPerLevelPtr *levels; size_t nlevels; + + virResctrlInfoMemBWPtr membw_info; }; =20 =20 @@ -146,6 +168,7 @@ virResctrlInfoDispose(void *obj) VIR_FREE(level); } =20 + VIR_FREE(resctrl->membw_info); VIR_FREE(resctrl->levels); } =20 @@ -443,6 +466,60 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl, =20 =20 static int +virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr resctrl) +{ + int ret =3D -1; + int rv =3D -1; + virResctrlInfoMemBWPtr i_membw =3D NULL; + + /* query memory bandwidth allocation info */ + if (VIR_ALLOC(i_membw) < 0) + goto cleanup; + rv =3D virFileReadValueUint(&i_membw->bandwidth_granularity, + SYSFS_RESCTRL_PATH "/info/MB/bandwidth_gran"= ); + if (rv =3D=3D -2) { + /* The file doesn't exist, so it's unusable for us, + * probably memory bandwidth allocation unsupported */ + VIR_INFO("The path '" SYSFS_RESCTRL_PATH "/info/MB/bandwidth_gran'" + "does not exist"); + ret =3D 0; + goto cleanup; + } else if (rv < 0) { + /* Other failures are fatal, so just quit */ + goto cleanup; + } + + rv =3D virFileReadValueUint(&i_membw->min_bandwidth, + SYSFS_RESCTRL_PATH "/info/MB/min_bandwidth"); + if (rv =3D=3D -2) { + /* If the previous file exists, so should this one. Hence -2 is + * fatal in this case (errors out in next condition) - the kernel + * interface might've changed too much or something else is wrong.= */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get min bandwidth from resctrl memory inf= o")); + } + if (rv < 0) + goto cleanup; + + rv =3D virFileReadValueUint(&i_membw->max_allocation, + SYSFS_RESCTRL_PATH "/info/MB/num_closids"); + if (rv =3D=3D -2) { + /* Similar reasoning to min_bandwidth above. */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get max allocation from resctrl memory in= fo")); + } + if (rv < 0) + goto cleanup; + + VIR_STEAL_PTR(resctrl->membw_info, i_membw); + ret =3D 0; + cleanup: + VIR_FREE(i_membw); + return ret; +} + + +static int virResctrlGetInfo(virResctrlInfoPtr resctrl) { DIR *dirp =3D NULL; @@ -452,6 +529,10 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (ret <=3D 0) goto cleanup; =20 + ret =3D virResctrlGetMemoryBandwidthInfo(resctrl); + if (ret < 0) + goto cleanup; + ret =3D virResctrlGetCacheInfo(resctrl, dirp); if (ret < 0) goto cleanup; @@ -493,6 +574,9 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) if (!resctrl) return true; =20 + if (resctrl->membw_info) + return false; + for (i =3D 0; i < resctrl->nlevels; i++) { virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153292176305796.16212473281291; Sun, 29 Jul 2018 20:36:03 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C75F03084033; Mon, 30 Jul 2018 03:36:00 +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 8BCCE26543; Mon, 30 Jul 2018 03:36: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 2249018037F2; Mon, 30 Jul 2018 03:36:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZVR1002791 for ; Sun, 29 Jul 2018 23:35:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 591E7600C5; Mon, 30 Jul 2018 03:35:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 528F4600C4 for ; Mon, 30 Jul 2018 03:35:31 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71B5B85541 for ; Mon, 30 Jul 2018 03:35:30 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:30 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:28 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613713" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:29 +0800 Message-Id: <1532920361-24737-6-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:30 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 05/17] util: Add MBA check to virResctrlInfoGetCache 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 30 Jul 2018 03:36:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu If we have some membw_info data, then we need to calculate the number of MBA controllers on the system. The value cannot be obtained from a direct query to the RDT kernel module, but it is the same as the last level cache value which is calculated by traversing the cache hierarchy of host(/sys/bus/cpu/devices/cpuX/cache/). Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index b12a05c..f454868 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -608,6 +608,20 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, if (virResctrlInfoIsEmpty(resctrl)) return 0; =20 + /* Let's take the opportunity to update the number of last level + * cache. This number of memory bandwidth controller is same with + * last level cache */ + if (resctrl->membw_info) { + virResctrlInfoMemBWPtr membw_info =3D resctrl->membw_info; + + if (level > membw_info->last_level_cache) { + membw_info->last_level_cache =3D level; + membw_info->max_id =3D 0; + } else if (membw_info->last_level_cache =3D=3D level) { + membw_info->max_id++; + } + } + if (level >=3D resctrl->nlevels) return 0; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921770144253.7269308681307; Sun, 29 Jul 2018 20:36:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D895308FB8F; Mon, 30 Jul 2018 03:35:37 +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 CEE632010CED; Mon, 30 Jul 2018 03:35:36 +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 854A64A465; Mon, 30 Jul 2018 03:35:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZWVC002798 for ; Sun, 29 Jul 2018 23:35:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF6F76E733; Mon, 30 Jul 2018 03:35:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5A0E6E73A for ; Mon, 30 Jul 2018 03:35:32 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C49EF8553D for ; Mon, 30 Jul 2018 03:35:31 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:31 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:30 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613719" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:30 +0800 Message-Id: <1532920361-24737-7-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:31 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 06/17] util: Add MBA allocation to virresctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 30 Jul 2018 03:35:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Add memory bandwidth allocation support to virresctrl class. Introducing virResctrlAllocMemBW which is used for allocating memory bandwidth. Following virResctrlAllocPerType, it also employs a nested sparse array to indicate whether allocation is available for particular last level cache. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index f454868..8a25798 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -36,9 +36,9 @@ VIR_LOG_INIT("util.virresctrl") =20 =20 /* Resctrl is short for Resource Control. It might be implemented for var= ious - * resources, but at the time of this writing this is only supported for c= ache - * allocation technology (aka CAT). Hence the reson for leaving 'Cache' o= ut of - * all the structure and function names for now (can be added later if nee= ded. + * resources. Currently this supports cache allocation technology (aka CAT= ) and + * memory bandwidth allocation (aka MBA). More resources technologies may = be + * added in the future. */ =20 =20 @@ -89,6 +89,9 @@ typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel; typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr; =20 +typedef struct _virResctrlAllocMemBW virResctrlAllocMemBW; +typedef virResctrlAllocMemBW *virResctrlAllocMemBWPtr; + =20 /* Class definitions and initializations */ static virClassPtr virResctrlInfoClass; @@ -180,7 +183,10 @@ virResctrlInfoDispose(void *obj) * consequently a directory under /sys/fs/resctrl). Since it can have mul= tiple * parts of multiple caches allocated it is represented as bunch of nested * sparse arrays (by sparse I mean array of pointers so that each might be= NULL - * in case there is no allocation for that particular one (level, cache, .= ..)). + * in case there is no allocation for that particular cache allocation (le= vel, + * cache, ...) or memory allocation for particular node). + * + * =3D=3D=3D=3D=3DCache allocation technology (CAT)=3D=3D=3D=3D=3D * * Since one allocation can be made for caches on different levels, the fi= rst * nested sparse array is of types virResctrlAllocPerLevel. For example i= f you @@ -205,6 +211,17 @@ virResctrlInfoDispose(void *obj) * all of them. While doing that we store the bitmask in a sparse array of * virBitmaps named `masks` indexed the same way as `sizes`. The upper bo= unds * of the sparse arrays are stored in nmasks or nsizes, respectively. + + * + * =3D=3D=3D=3D=3DMemory Bandwidth allocation technology (MBA)=3D=3D=3D=3D= =3D + * + * The memory bandwidth allocation support in virResctrlAlloc works in the + * same fashion as CAT. However, memory bandwidth controller doesn't have a + * hierarchy organization as cache, each node have one memory bandwidth + * controller to memory bandwidth distribution. The number of memory bandw= idth + * controller is identical with number of last level cache. So MBA also em= ploys + * a sparse array to represent whether a memory bandwidth allocation happe= ns + * on corresponding node. The available memory controller number is collec= ted + * in 'virResctrlInfo'. */ struct _virResctrlAllocPerType { /* There could be bool saying whether this is set or not, but since ev= erything @@ -225,12 +242,24 @@ struct _virResctrlAllocPerLevel { * VIR_CACHE_TYPE_LAST number of items */ }; =20 +/* + * virResctrlAllocMemBW represents one memory bandwidth allocation. + * Since it can have several last level caches in a NUMA system, it is + * also represented as a nested sparse arrays as virRestrlAllocPerLevel. + */ +struct _virResctrlAllocMemBW { + unsigned int **bandwidths; + size_t nbandwidths; +}; + struct _virResctrlAlloc { virObject parent; =20 virResctrlAllocPerLevelPtr *levels; size_t nlevels; =20 + virResctrlAllocMemBWPtr mem_bw; + /* The identifier (any unique string for now) */ char *id; /* libvirt-generated path in /sys/fs/resctrl for this particular @@ -274,6 +303,13 @@ virResctrlAllocDispose(void *obj) VIR_FREE(level); } =20 + if (alloc->mem_bw) { + virResctrlAllocMemBWPtr mem_bw =3D alloc->mem_bw; + for (i =3D 0; i < mem_bw->nbandwidths; i++) + VIR_FREE(mem_bw->bandwidths[i]); + VIR_FREE(alloc->mem_bw); + } + VIR_FREE(alloc->id); VIR_FREE(alloc->path); VIR_FREE(alloc->levels); @@ -692,6 +728,9 @@ virResctrlAllocIsEmpty(virResctrlAllocPtr alloc) if (!alloc) return true; =20 + if (alloc->mem_bw) + return false; + for (i =3D 0; i < alloc->nlevels; i++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[i]; =20 @@ -1266,6 +1305,22 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) } } =20 + /* set default free memory bandwidth to 100%*/ + if (info->membw_info) { + if (VIR_ALLOC(ret->mem_bw) < 0) + goto error; + + if (VIR_EXPAND_N(ret->mem_bw->bandwidths, ret->mem_bw->nbandwidths, + info->membw_info->max_id + 1) < 0) + goto error; + + for (i =3D 0; i < ret->mem_bw->nbandwidths; i++) { + if (VIR_ALLOC(ret->mem_bw->bandwidths[i]) < 0) + goto error; + *(ret->mem_bw->bandwidths[i]) =3D 100; + } + } + cleanup: virBitmapFree(mask); return ret; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153292176885055.75966395126136; Sun, 29 Jul 2018 20:36:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC40B356D5; Mon, 30 Jul 2018 03:36:06 +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 7E3B7308BDB3; Mon, 30 Jul 2018 03:36:06 +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 26D3518037F4; Mon, 30 Jul 2018 03:36:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3Za5J002811 for ; Sun, 29 Jul 2018 23:35:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id C33345D6B5; Mon, 30 Jul 2018 03:35:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF325D6A3 for ; Mon, 30 Jul 2018 03:35:34 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5ED1E8553F for ; Mon, 30 Jul 2018 03:35:33 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:33 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613723" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:31 +0800 Message-Id: <1532920361-24737-8-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:33 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 07/17] util: Add MBA schemata parse and format methods 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 30 Jul 2018 03:36:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce virResctrlAllocMemoryBandwidthFormat and virResctrlAllocParseMemoryBandwidthLine which will format and parse an entry in the schemata file for MBA. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 141 insertions(+) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 8a25798..1cbf9b3 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -986,6 +986,139 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc) } =20 =20 +/* Format the Memory Bandwidth Allocation line that will be found in + * the schemata files. The line should be start with "MB:" and be + * followed by "id=3Dvalue" pairs separated by a colon such as: + * + * MB:0=3D100;1=3D100 + * + * which indicates node id 0 has 100 percent bandwith and node id 1 + * has 100 percent bandwidth + */ +static int +virResctrlAllocMemoryBandwidthFormat(virResctrlAllocPtr alloc, + virBufferPtr buf) +{ + size_t i; + + if (!alloc->mem_bw) + return 0; + + virBufferAddLit(buf, "MB:"); + + for (i =3D 0; i < alloc->mem_bw->nbandwidths; i++) { + if (alloc->mem_bw->bandwidths[i]) { + virBufferAsprintf(buf, "%zd=3D%u;", i, + *(alloc->mem_bw->bandwidths[i])); + } + } + + virBufferTrim(buf, ";", 1); + virBufferAddChar(buf, '\n'); + return virBufferCheckError(buf); +} + + +static int +virResctrlAllocParseProcessMemoryBandwidth(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + char *mem_bw) +{ + unsigned int bandwidth; + unsigned int id; + char *tmp =3D NULL; + + tmp =3D strchr(mem_bw, '=3D'); + if (!tmp) + return 0; + *tmp =3D '\0'; + tmp++; + + if (virStrToLong_uip(mem_bw, NULL, 10, &id) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid node id %u "), id); + return -1; + } + if (virStrToLong_uip(tmp, NULL, 10, &bandwidth) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid bandwidth %u"), bandwidth); + return -1; + } + if (bandwidth < resctrl->membw_info->min_bandwidth || + id > resctrl->membw_info->max_id) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing or inconsistent resctrl info for " + "memory bandwidth node '%u'"), id); + return -1; + } + if (alloc->mem_bw->nbandwidths <=3D id && + VIR_EXPAND_N(alloc->mem_bw->bandwidths, alloc->mem_bw->nbandwidths, + id - alloc->mem_bw->nbandwidths + 1) < 0) { + return -1; + } + if (!alloc->mem_bw->bandwidths[id]) { + if (VIR_ALLOC(alloc->mem_bw->bandwidths[id]) < 0) + return -1; + } + + *(alloc->mem_bw->bandwidths[id]) =3D bandwidth; + return 0; +} + + +/* Parse a schemata formatted MB: entry. Format details are described in + * virResctrlAllocMemoryBandwidthFormat. + */ +static int +virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + char *line) +{ + char **mbs =3D NULL; + char *tmp =3D NULL; + size_t nmbs =3D 0; + size_t i; + int ret =3D -1; + + /* For no reason there can be spaces */ + virSkipSpaces((const char **) &line); + + if (STRNEQLEN(line, "MB", 2)) + return 0; + + if (!resctrl || !resctrl->membw_info || + !resctrl->membw_info->min_bandwidth || + !resctrl->membw_info->bandwidth_granularity) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing or inconsistent resctrl info for " + "memory bandwidth allocation")); + } + + if (!alloc->mem_bw) { + if (VIR_ALLOC(alloc->mem_bw) < 0) + return -1; + } + + tmp =3D strchr(line, ':'); + if (!tmp) + return 0; + tmp++; + + mbs =3D virStringSplitCount(tmp, ";", 0, &nmbs); + if (nmbs =3D=3D 0) + return 0; + + for (i =3D 0; i < nmbs; i++) { + if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, mbs= [i]) < 0) + goto cleanup; + } + ret =3D 0; + cleanup: + virStringListFree(mbs); + return ret; +} + + static int virResctrlAllocFormatCache(virResctrlAllocPtr alloc, virBufferPtr buf) @@ -1045,6 +1178,11 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) return NULL; } =20 + if (virResctrlAllocMemoryBandwidthFormat(alloc, &buf) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + return virBufferContentAndReset(&buf); } =20 @@ -1173,6 +1311,9 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl, for (i =3D 0; i < nlines; i++) { if (virResctrlAllocParseCacheLine(resctrl, alloc, lines[i]) < 0) goto cleanup; + if (virResctrlAllocParseMemoryBandwidthLine(resctrl, alloc, lines[= i]) < 0) + goto cleanup; + } =20 ret =3D 0; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921783346190.32622784021964; Sun, 29 Jul 2018 20:36:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D303881F0C; Mon, 30 Jul 2018 03:36:20 +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 890653001A40; Mon, 30 Jul 2018 03:36:20 +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 18DD218037F3; Mon, 30 Jul 2018 03:36:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3Zdw2002847 for ; Sun, 29 Jul 2018 23:35:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E13017146; Mon, 30 Jul 2018 03:35:39 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 629EF5C73D for ; Mon, 30 Jul 2018 03:35:36 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E88D485541 for ; Mon, 30 Jul 2018 03:35:34 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:34 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:33 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613727" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:32 +0800 Message-Id: <1532920361-24737-9-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:35 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 08/17] util: Add support to calculate MBA utilization 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 30 Jul 2018 03:36:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce virResctrlMemoryBandwidthSubtract and virResctrlAllocMemoryBandwidth to be used as part of the virResctrlAllocAssign processing to configure the available memory bandwidth. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 105 ++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 93 insertions(+), 12 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 1cbf9b3..c22b30f 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1409,6 +1409,22 @@ virResctrlAllocSubtract(virResctrlAllocPtr dst, } =20 =20 +static void +virResctrlMemoryBandwidthSubtract(virResctrlAllocPtr free, + virResctrlAllocPtr used) +{ + size_t i; + + if (!used->mem_bw) + return; + + for (i =3D 0; i < used->mem_bw->nbandwidths; i++) { + if (used->mem_bw->bandwidths[i]) + *(free->mem_bw->bandwidths[i]) -=3D *(used->mem_bw->bandwidths= [i]); + } +} + + static virResctrlAllocPtr virResctrlAllocNewFromInfo(virResctrlInfoPtr info) { @@ -1472,14 +1488,15 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) } =20 /* - * This function creates an allocation that represents all unused parts of= all - * caches in the system. It uses virResctrlInfo for creating a new full - * allocation with all bits set (using virResctrlAllocNewFromInfo()) and t= hen - * scans for all allocations under /sys/fs/resctrl and subtracts each one = of - * them from it. That way it can then return an allocation with only bit = set - * being those that are not mentioned in any other allocation. It is used= for - * two things, a) calculating the masks when creating allocations and b) f= rom - * tests. + * This function creates an allocation that represents all unused parts of + * all caches and memory bandwidth in the system. It uses virResctrlInfo + * for creating a new full allocation with all bits set (using the + * virResctrlAllocNewFromInfo()), sets memory bandwidth 100%, and then sca= ns + * for all allocations under /sys/fs/resctrl and subtracts each one of them + * from it. That way it can then return an allocation with only bit set + * being those that are not mentioned in any other allocation for CAT and + * available memory bandwidth for MBA. It is used for two things, calculat= ing + * the masks and bandwidth available when creating allocations and from te= sts. */ virResctrlAllocPtr virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) @@ -1525,6 +1542,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto error; } =20 + virResctrlMemoryBandwidthSubtract(ret, alloc); virResctrlAllocSubtract(ret, alloc); virObjectUnref(alloc); alloc =3D NULL; @@ -1676,6 +1694,66 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, =20 =20 static int +virResctrlAllocMemoryBandwidth(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + virResctrlAllocPtr free) +{ + size_t i; + virResctrlAllocMemBWPtr mem_bw_alloc =3D alloc->mem_bw; + virResctrlAllocMemBWPtr mem_bw_free =3D free->mem_bw; + virResctrlInfoMemBWPtr mem_bw_info =3D resctrl->membw_info; + + if (!mem_bw_alloc) + return 0; + + if (mem_bw_alloc && !mem_bw_info) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("RDT Memory Bandwidth allocation unsupported")); + return -1; + } + + for (i =3D 0; i < mem_bw_alloc->nbandwidths; i++) { + if (!mem_bw_alloc->bandwidths[i]) + continue; + + if (*(mem_bw_alloc->bandwidths[i]) % mem_bw_info->bandwidth_granul= arity) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Memory Bandwidth allocation of size " + "%u is not divisible by granularity %u"), + *(mem_bw_alloc->bandwidths[i]), + mem_bw_info->bandwidth_granularity); + return -1; + } + if (*(mem_bw_alloc->bandwidths[i]) < mem_bw_info->min_bandwidth) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Memory Bandwidth allocation of size " + "%u is smaller than the minimum " + "allowed allocation %u"), + *(mem_bw_alloc->bandwidths[i]), + mem_bw_info->min_bandwidth); + return -1; + } + if (i > mem_bw_info->max_id) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("bandwidth controller id %zd does not " + "exist, max controller id %u"), + i, mem_bw_info->max_id); + return -1; + } + if (*(mem_bw_alloc->bandwidths[i]) > *(mem_bw_free->bandwidths[i])= ) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Not enough room for allocation of %u%% " + "bandwidth on node %zd, available bandwidth %= u%%"), + *(mem_bw_alloc->bandwidths[i]), i, + *(mem_bw_free->bandwidths[i])); + return -1; + } + } + return 0; +} + + +static int virResctrlAllocCopyMasks(virResctrlAllocPtr dst, virResctrlAllocPtr src) { @@ -1714,10 +1792,10 @@ virResctrlAllocCopyMasks(virResctrlAllocPtr dst, =20 =20 /* - * This function is called when creating an allocation in the system. Wha= t it - * does is that it gets all the unused bits using virResctrlAllocGetUnused= () and - * then tries to find a proper space for every requested allocation effect= ively - * transforming `sizes` into `masks`. + * This function is called when creating an allocation in the system. + * What it does is that it gets all the unused resources using + * virResctrlAllocGetUnused and then tries to find a proper space for + * every requested allocation effectively transforming `sizes` into `masks= `. */ static int virResctrlAllocAssign(virResctrlInfoPtr resctrl, @@ -1736,6 +1814,9 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, if (!alloc_default) goto cleanup; =20 + if (virResctrlAllocMemoryBandwidth(resctrl, alloc, alloc_free) < 0) + goto cleanup; + if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0) goto cleanup; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921773318335.6985611918225; Sun, 29 Jul 2018 20:36:13 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7E4A84E4C0; Mon, 30 Jul 2018 03:36:11 +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 3EB272632C; Mon, 30 Jul 2018 03:36:11 +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 E3B6F3F64B; Mon, 30 Jul 2018 03:36:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZbCT002826 for ; Sun, 29 Jul 2018 23:35:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7ED27600C6; Mon, 30 Jul 2018 03:35:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 733E5600C4 for ; Mon, 30 Jul 2018 03:35:37 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 815E98553D for ; Mon, 30 Jul 2018 03:35:36 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:36 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:35 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613731" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:33 +0800 Message-Id: <1532920361-24737-10-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:36 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 09/17] util: Introduce virResctrlAllocForeachMemory 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 30 Jul 2018 03:36:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce an API that will traverse the memory bandwidth data calling a callback function for each defined bandwidth entry. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virresctrl.c | 33 +++++++++++++++++++++++++++++++++ src/util/virresctrl.h | 9 +++++++++ 3 files changed, 43 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bc489cb..cd598f9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2649,6 +2649,7 @@ virResctrlAllocAddPID; virResctrlAllocCreate; virResctrlAllocDeterminePath; virResctrlAllocForeachCache; +virResctrlAllocForeachMemory; virResctrlAllocFormat; virResctrlAllocGetID; virResctrlAllocGetUnused; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index c22b30f..dc57c89 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -965,6 +965,39 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, } =20 =20 +/* virResctrlAllocForeachMemory + * @alloc: Pointer to an active allocation + * @cb: Callback function + * @opaque: Opaque data to be passed to @cb + * + * If available, traverse the defined memory bandwidth allocations and + * call the @cb function. + * + * Returns 0 on success, -1 and immediate failure if the @cb has any failu= re. + */ +int +virResctrlAllocForeachMemory(virResctrlAllocPtr alloc, + virResctrlAllocForeachMemoryCallback cb, + void *opaque) +{ + size_t i =3D 0; + virResctrlAllocMemBWPtr mem_bw; + + if (!alloc || !alloc->mem_bw) + return 0; + + mem_bw =3D alloc->mem_bw; + for (i =3D 0; i < mem_bw->nbandwidths; i++) { + if (mem_bw->bandwidths[i]) { + if (cb(i, *mem_bw->bandwidths[i], opaque) < 0) + return -1; + } + } + + return 0; +} + + int virResctrlAllocSetID(virResctrlAllocPtr alloc, const char *id) diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index d657c06..5ea5b27 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -73,6 +73,10 @@ typedef int virResctrlAllocForeachCacheCallback(unsigned= int level, unsigned long long size, void *opaque); =20 +typedef int virResctrlAllocForeachMemoryCallback(unsigned int id, + unsigned int size, + void *opaque); + virResctrlAllocPtr virResctrlAllocNew(void); =20 @@ -92,6 +96,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, void *opaque); =20 int +virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl, + virResctrlAllocForeachMemoryCallback cb, + void *opaque); + +int virResctrlAllocSetID(virResctrlAllocPtr alloc, const char *id); const char * --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921778231300.45117200228117; Sun, 29 Jul 2018 20:36:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D149A820EB; Mon, 30 Jul 2018 03:36:15 +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 917803083322; Mon, 30 Jul 2018 03:36:15 +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 45FF03D3BC; Mon, 30 Jul 2018 03:36:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZdoJ002842 for ; Sun, 29 Jul 2018 23:35:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 199B4D059F; Mon, 30 Jul 2018 03:35:39 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 133BA4D34C for ; Mon, 30 Jul 2018 03:35:39 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17A598553F for ; Mon, 30 Jul 2018 03:35:38 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:38 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:36 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613736" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:34 +0800 Message-Id: <1532920361-24737-11-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:38 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 10/17] util: Introduce virResctrlAllocSetMemoryBandwidth 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 30 Jul 2018 03:36:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce an API to allow setting of the MBA from domain XML. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virresctrl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virresctrl.h | 5 +++++ 3 files changed, 54 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cd598f9..0d2fc5c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2657,6 +2657,7 @@ virResctrlAllocNew; virResctrlAllocRemove; virResctrlAllocSetCacheSize; virResctrlAllocSetID; +virResctrlAllocSetMemoryBandwidth; virResctrlInfoGetCache; virResctrlInfoNew; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index dc57c89..f25e7bc 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -965,6 +965,54 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, } =20 =20 +/* virResctrlAllocSetMemoryBandwidth + * @alloc: Pointer to an active allocation + * @id: node id of MBA to be set + * @memory_bandwidth: new memory bandwidth value + * + * Set the @memory_bandwidth for the node @id entry in the @alloc. + * + * Returns 0 on success, -1 on failure with error message set. + */ +int +virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc, + unsigned int id, + unsigned int memory_bandwidth) +{ + virResctrlAllocMemBWPtr mem_bw =3D alloc->mem_bw; + + if (memory_bandwidth > 100) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Memory Bandwidth value exceeding 100 is invalid.= ")); + return -1; + } + + if (!mem_bw) { + if (VIR_ALLOC(mem_bw) < 0) + return -1; + alloc->mem_bw =3D mem_bw; + } + + if (mem_bw->nbandwidths <=3D id && + VIR_EXPAND_N(mem_bw->bandwidths, mem_bw->nbandwidths, + id - mem_bw->nbandwidths + 1) < 0) + return -1; + + if (mem_bw->bandwidths[id]) { + virReportError(VIR_ERR_XML_ERROR, + _("Memory Bandwidth already defined for node %u"), + id); + return -1; + } + + if (VIR_ALLOC(mem_bw->bandwidths[id]) < 0) + return -1; + + *(mem_bw->bandwidths[id]) =3D memory_bandwidth; + return 0; +} + + /* virResctrlAllocForeachMemory * @alloc: Pointer to an active allocation * @cb: Callback function diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 5ea5b27..8d62517 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -96,6 +96,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, void *opaque); =20 int +virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc, + unsigned int id, + unsigned int memory_bandwidth); + +int virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl, virResctrlAllocForeachMemoryCallback cb, void *opaque); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921769629930.4730618707633; Sun, 29 Jul 2018 20:36:09 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7B1F9C04AC4B; Mon, 30 Jul 2018 03:36:07 +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 AF28A26568; Mon, 30 Jul 2018 03:36:06 +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 4DD7818037F3; Mon, 30 Jul 2018 03:36:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZhBB002868 for ; Sun, 29 Jul 2018 23:35:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A6923001A5A; Mon, 30 Jul 2018 03:35:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F1673001A5F for ; Mon, 30 Jul 2018 03:35:40 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA6D48553F for ; Mon, 30 Jul 2018 03:35:39 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:39 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:38 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613740" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:35 +0800 Message-Id: <1532920361-24737-12-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:39 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 11/17] conf: Rename cachetune to resctrl 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 30 Jul 2018 03:36:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Resctrl not only supports cache tuning, but also memory bandwidth tuning. Renaming cachetune to resctrl to reflect that. With resctrl, all allocation for different resources (cache, memory bandwidth) are aggregated and represented by a virResctrlAllocPtr inside virDomainResctrlDef. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 44 ++++++++++++++++++++++---------------------- src/conf/domain_conf.h | 10 +++++----- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_process.c | 18 +++++++++--------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index abb6c5e..c1527b2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2966,14 +2966,14 @@ virDomainLoaderDefFree(virDomainLoaderDefPtr loader) =20 =20 static void -virDomainCachetuneDefFree(virDomainCachetuneDefPtr cachetune) +virDomainResctrlDefFree(virDomainResctrlDefPtr resctrl) { - if (!cachetune) + if (!resctrl) return; =20 - virObjectUnref(cachetune->alloc); - virBitmapFree(cachetune->vcpus); - VIR_FREE(cachetune); + virObjectUnref(resctrl->alloc); + virBitmapFree(resctrl->vcpus); + VIR_FREE(resctrl); } =20 =20 @@ -3163,9 +3163,9 @@ void virDomainDefFree(virDomainDefPtr def) virDomainShmemDefFree(def->shmems[i]); VIR_FREE(def->shmems); =20 - for (i =3D 0; i < def->ncachetunes; i++) - virDomainCachetuneDefFree(def->cachetunes[i]); - VIR_FREE(def->cachetunes); + for (i =3D 0; i < def->nresctrls; i++) + virDomainResctrlDefFree(def->resctrls[i]); + VIR_FREE(def->resctrls); =20 VIR_FREE(def->keywrap); =20 @@ -19034,7 +19034,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, xmlNodePtr *nodes =3D NULL; virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D virResctrlAllocNew(); - virDomainCachetuneDefPtr tmp_cachetune =3D NULL; + virDomainResctrlDefPtr tmp_resctrl =3D NULL; char *tmp =3D NULL; char *vcpus_str =3D NULL; char *alloc_id =3D NULL; @@ -19047,7 +19047,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, if (!alloc) goto cleanup; =20 - if (VIR_ALLOC(tmp_cachetune) < 0) + if (VIR_ALLOC(tmp_resctrl) < 0) goto cleanup; =20 vcpus_str =3D virXMLPropString(node, "vcpus"); @@ -19088,8 +19088,8 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 - for (i =3D 0; i < def->ncachetunes; i++) { - if (virBitmapOverlaps(def->cachetunes[i]->vcpus, vcpus)) { + for (i =3D 0; i < def->nresctrls; i++) { + if (virBitmapOverlaps(def->resctrls[i]->vcpus, vcpus)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Overlapping vcpus in cachetunes")); goto cleanup; @@ -19119,16 +19119,16 @@ virDomainCachetuneDefParse(virDomainDefPtr def, if (virResctrlAllocSetID(alloc, alloc_id) < 0) goto cleanup; =20 - VIR_STEAL_PTR(tmp_cachetune->vcpus, vcpus); - VIR_STEAL_PTR(tmp_cachetune->alloc, alloc); + VIR_STEAL_PTR(tmp_resctrl->vcpus, vcpus); + VIR_STEAL_PTR(tmp_resctrl->alloc, alloc); =20 - if (VIR_APPEND_ELEMENT(def->cachetunes, def->ncachetunes, tmp_cachetun= e) < 0) + if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0) goto cleanup; =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; - virDomainCachetuneDefFree(tmp_cachetune); + virDomainResctrlDefFree(tmp_resctrl); virObjectUnref(alloc); virBitmapFree(vcpus); VIR_FREE(alloc_id); @@ -26994,7 +26994,7 @@ virDomainCachetuneDefFormatHelper(unsigned int leve= l, =20 static int virDomainCachetuneDefFormat(virBufferPtr buf, - virDomainCachetuneDefPtr cachetune, + virDomainResctrlDefPtr resctrl, unsigned int flags) { virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; @@ -27002,7 +27002,7 @@ virDomainCachetuneDefFormat(virBufferPtr buf, int ret =3D -1; =20 virBufferSetChildIndent(&childrenBuf, buf); - virResctrlAllocForeachCache(cachetune->alloc, + virResctrlAllocForeachCache(resctrl->alloc, virDomainCachetuneDefFormatHelper, &childrenBuf); =20 @@ -27015,14 +27015,14 @@ virDomainCachetuneDefFormat(virBufferPtr buf, goto cleanup; } =20 - vcpus =3D virBitmapFormat(cachetune->vcpus); + vcpus =3D virBitmapFormat(resctrl->vcpus); if (!vcpus) goto cleanup; =20 virBufferAsprintf(buf, "alloc); + const char *alloc_id =3D virResctrlAllocGetID(resctrl->alloc); if (!alloc_id) goto cleanup; =20 @@ -27143,8 +27143,8 @@ virDomainCputuneDefFormat(virBufferPtr buf, def->iothreadids[i]->iothread_id); } =20 - for (i =3D 0; i < def->ncachetunes; i++) - virDomainCachetuneDefFormat(&childrenBuf, def->cachetunes[i], flag= s); + for (i =3D 0; i < def->nresctrls; i++) + virDomainCachetuneDefFormat(&childrenBuf, def->resctrls[i], flags); =20 if (virBufferCheckError(&childrenBuf) < 0) return -1; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1dfa37..ade60f5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2232,10 +2232,10 @@ struct _virDomainCputune { }; =20 =20 -typedef struct _virDomainCachetuneDef virDomainCachetuneDef; -typedef virDomainCachetuneDef *virDomainCachetuneDefPtr; +typedef struct _virDomainResctrlDef virDomainResctrlDef; +typedef virDomainResctrlDef *virDomainResctrlDefPtr; =20 -struct _virDomainCachetuneDef { +struct _virDomainResctrlDef { virBitmapPtr vcpus; virResctrlAllocPtr alloc; }; @@ -2413,8 +2413,8 @@ struct _virDomainDef { =20 virDomainCputune cputune; =20 - virDomainCachetuneDefPtr *cachetunes; - size_t ncachetunes; + virDomainResctrlDefPtr *resctrls; + size_t nresctrls; =20 virDomainNumaPtr numa; virDomainResourceDefPtr resource; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index de05627..c6388fd 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3999,7 +3999,7 @@ qemuDomainDefValidate(const virDomainDef *def, } } =20 - if (def->ncachetunes && + if (def->nresctrls && def->virtType !=3D VIR_DOMAIN_VIRT_KVM) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("cachetune is only supported for KVM domains")); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c4e3372..02fdc55 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2559,7 +2559,7 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver, virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 - if (!vm->def->ncachetunes) + if (!vm->def->nresctrls) return 0; =20 /* Force capability refresh since resctrl info can change @@ -2568,9 +2568,9 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver, if (!caps) return -1; =20 - for (i =3D 0; i < vm->def->ncachetunes; i++) { + for (i =3D 0; i < vm->def->nresctrls; i++) { if (virResctrlAllocCreate(caps->host.resctrl, - vm->def->cachetunes[i]->alloc, + vm->def->resctrls[i]->alloc, priv->machineName) < 0) goto cleanup; } @@ -5388,8 +5388,8 @@ qemuProcessSetupVcpu(virDomainObjPtr vm, &vcpu->sched) < 0) return -1; =20 - for (i =3D 0; i < vm->def->ncachetunes; i++) { - virDomainCachetuneDefPtr ct =3D vm->def->cachetunes[i]; + for (i =3D 0; i < vm->def->nresctrls; i++) { + virDomainResctrlDefPtr ct =3D vm->def->resctrls[i]; =20 if (virBitmapIsBitSet(ct->vcpus, vcpuid)) { if (virResctrlAllocAddPID(ct->alloc, vcpupid) < 0) @@ -7091,8 +7091,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, /* Remove resctrl allocation after cgroups are cleaned up which makes = it * kind of safer (although removing the allocation should work even wi= th * pids in tasks file */ - for (i =3D 0; i < vm->def->ncachetunes; i++) - virResctrlAllocRemove(vm->def->cachetunes[i]->alloc); + for (i =3D 0; i < vm->def->nresctrls; i++) + virResctrlAllocRemove(vm->def->resctrls[i]->alloc); =20 qemuProcessRemoveDomainStatus(driver, vm); =20 @@ -7818,8 +7818,8 @@ qemuProcessReconnect(void *opaque) if (qemuConnectAgent(driver, obj) < 0) goto error; =20 - for (i =3D 0; i < obj->def->ncachetunes; i++) { - if (virResctrlAllocDeterminePath(obj->def->cachetunes[i]->alloc, + for (i =3D 0; i < obj->def->nresctrls; i++) { + if (virResctrlAllocDeterminePath(obj->def->resctrls[i]->alloc, priv->machineName) < 0) goto error; } --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921759267562.3598670262196; Sun, 29 Jul 2018 20:35:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 627D53082135; Mon, 30 Jul 2018 03:35: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 25FCD5D9C5; Mon, 30 Jul 2018 03:35: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 B27D03FC9D; Mon, 30 Jul 2018 03:35:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZjMo002885 for ; Sun, 29 Jul 2018 23:35:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06484308BDB3; Mon, 30 Jul 2018 03:35:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF011308BDB2 for ; Mon, 30 Jul 2018 03:35:42 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BFA085541 for ; Mon, 30 Jul 2018 03:35:41 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:41 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:39 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613745" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:36 +0800 Message-Id: <1532920361-24737-13-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:41 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 12/17] conf: Factor out vcpus parsing part from virDomainCachetuneDefParse 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 30 Jul 2018 03:35:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Extract vcpus parsing part from virDomainCachetuneDefParse into one function called virDomainResctrlParseVcpus. So that vcpus parsing logic can be reused by other resource control technologies. Adjust error message and use node->name so that the error message can fit to all technologies. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 48 +++++++++++++++++++++++++++++++++-------------= -- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c1527b2..d6314de 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18951,6 +18951,38 @@ virDomainDefParseBootOptions(virDomainDefPtr def, =20 =20 static int +virDomainResctrlParseVcpus(virDomainDefPtr def, + xmlNodePtr node, + virBitmapPtr *vcpus) +{ + char *vcpus_str =3D NULL; + int ret =3D -1; + + vcpus_str =3D virXMLPropString(node, "vcpus"); + if (!vcpus_str) { + virReportError(VIR_ERR_XML_ERROR, _("Missing %s attribute 'vcpus'"= ), + node->name); + goto cleanup; + } + if (virBitmapParse(vcpus_str, vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid %s attribute 'vcpus' value '%s'"), + vcpus_str, node->name); + goto cleanup; + } + + /* We need to limit the bitmap to number of vCPUs. If there's nothing= left, + * then we can just clean up and return 0 immediately */ + virBitmapShrink(*vcpus, def->maxvcpus); + + ret =3D 0; + cleanup: + VIR_FREE(vcpus_str); + return ret; +} + + +static int virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, xmlNodePtr node, virResctrlAllocPtr alloc) @@ -19050,22 +19082,8 @@ virDomainCachetuneDefParse(virDomainDefPtr def, if (VIR_ALLOC(tmp_resctrl) < 0) goto cleanup; =20 - vcpus_str =3D virXMLPropString(node, "vcpus"); - if (!vcpus_str) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing cachetune attribute 'vcpus'")); - goto cleanup; - } - if (virBitmapParse(vcpus_str, &vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid cachetune attribute 'vcpus' value '%s'"), - vcpus_str); + if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0) goto cleanup; - } - - /* We need to limit the bitmap to number of vCPUs. If there's nothing= left, - * then we can just clean up and return 0 immediately */ - virBitmapShrink(vcpus, def->maxvcpus); =20 if (virBitmapIsAllClear(vcpus)) { ret =3D 0; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153292179330936.70795900949929; Sun, 29 Jul 2018 20:36:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EBCD4E4C3; Mon, 30 Jul 2018 03:36:25 +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 054F33083328; Mon, 30 Jul 2018 03:36:25 +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 9812B264FB; Mon, 30 Jul 2018 03:36:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3Zhmm002875 for ; Sun, 29 Jul 2018 23:35:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id C44763083322; Mon, 30 Jul 2018 03:35:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDB9B3001A40 for ; Mon, 30 Jul 2018 03:35:43 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7DFB85546 for ; Mon, 30 Jul 2018 03:35:42 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:42 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:41 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613750" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:37 +0800 Message-Id: <1532920361-24737-14-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:42 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 13/17] conf: Factor out vcpus overlapping from virDomainCachetuneDefParse 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 30 Jul 2018 03:36:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Factor out vcpus overlapping detecting part from virDomainCachetuneDefParse and introduce virDomainResctrlVcpuMatch. Instead of allocating virResctrlAllocPtr by default, allocating virResctrlAllocPtr after confirm vcpus not overlap with existing ones. And virDomainResctrlVcpuMatch can be reused by other resource control technologies. virDomainResctrlVcpuMatch can clarify old vcpus overlap error whether an overlap or a redefinition. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 51 ++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d6314de..da8681d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18983,6 +18983,31 @@ virDomainResctrlParseVcpus(virDomainDefPtr def, =20 =20 static int +virDomainResctrlVcpuMatch(virDomainDefPtr def, + virBitmapPtr vcpus, + virResctrlAllocPtr *alloc) +{ + ssize_t i =3D 0; + + for (i =3D 0; i < def->nresctrls; i++) { + /* vcpus group has been created, directly use the existing one. + * Just updating memory allocation information of that group + */ + if (virBitmapEqual(def->resctrls[i]->vcpus, vcpus)) { + *alloc =3D def->resctrls[i]->alloc; + break; + } + if (virBitmapOverlaps(def->resctrls[i]->vcpus, vcpus)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Overlapping vcpus in resctrls")); + return -1; + } + } + return 0; +} + + +static int virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, xmlNodePtr node, virResctrlAllocPtr alloc) @@ -19065,7 +19090,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, xmlNodePtr oldnode =3D ctxt->node; xmlNodePtr *nodes =3D NULL; virBitmapPtr vcpus =3D NULL; - virResctrlAllocPtr alloc =3D virResctrlAllocNew(); + virResctrlAllocPtr alloc =3D NULL; virDomainResctrlDefPtr tmp_resctrl =3D NULL; char *tmp =3D NULL; char *vcpus_str =3D NULL; @@ -19076,9 +19101,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, =20 ctxt->node =3D node; =20 - if (!alloc) - goto cleanup; - if (VIR_ALLOC(tmp_resctrl) < 0) goto cleanup; =20 @@ -19096,6 +19118,19 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 + if (virDomainResctrlVcpuMatch(def, vcpus, &alloc) < 0) + goto cleanup; + + if (!alloc) { + alloc =3D virResctrlAllocNew(); + if (!alloc) + goto cleanup; + } else { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Identical vcpus in cachetunes found")); + goto cleanup; + } + for (i =3D 0; i < n; i++) { if (virDomainCachetuneDefParseCache(ctxt, nodes[i], alloc) < 0) goto cleanup; @@ -19106,14 +19141,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 - for (i =3D 0; i < def->nresctrls; i++) { - if (virBitmapOverlaps(def->resctrls[i]->vcpus, vcpus)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Overlapping vcpus in cachetunes")); - goto cleanup; - } - } - /* We need to format it back because we need to be consistent in the n= aming * even when users specify some "sub-optimal" string there. */ VIR_FREE(vcpus_str); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921774570289.35404233522615; Sun, 29 Jul 2018 20:36:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 757DB307D842; Mon, 30 Jul 2018 03:36:12 +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 388B5D0937; Mon, 30 Jul 2018 03:36:12 +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 CCAC218037F2; Mon, 30 Jul 2018 03:36:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZlJ8002909 for ; Sun, 29 Jul 2018 23:35:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA94A6EE24; Mon, 30 Jul 2018 03:35:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E25BD6E73A for ; Mon, 30 Jul 2018 03:35:45 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60D2E8553D for ; Mon, 30 Jul 2018 03:35:44 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:44 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:42 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613754" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:38 +0800 Message-Id: <1532920361-24737-15-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:44 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 14/17] conf: Factor out virDomainResctrlDef update from virDomainCachetuneDefParse 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 30 Jul 2018 03:36:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Factor out vcpus virDomainResctrlDef update from virDomainCachetuneDefParse and introduce virDomainResctrlAppend. virDomainResctrlAppend will format vcpus string and append a new virDomainResctrlDef to virDomainDefPtr. So that this logic can be reusable. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 93 +++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index da8681d..f45def8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19082,6 +19082,58 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr= ctxt, =20 =20 static int +virDomainResctrlAppend(virDomainDefPtr def, + xmlNodePtr node, + virResctrlAllocPtr alloc, + virBitmapPtr vcpus, + unsigned int flags) +{ + char *vcpus_str =3D NULL; + char *alloc_id =3D NULL; + virDomainResctrlDefPtr tmp_resctrl =3D NULL; + int ret =3D -1; + + if (VIR_ALLOC(tmp_resctrl) < 0) + goto cleanup; + + /* We need to format it back because we need to be consistent in the n= aming + * even when users specify some "sub-optimal" string there. */ + vcpus_str =3D virBitmapFormat(vcpus); + if (!vcpus_str) + goto cleanup; + + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + alloc_id =3D virXMLPropString(node, "id"); + + if (!alloc_id) { + /* The number of allocations is limited and the directory structur= e is flat, + * not hierarchical, so we need to have all same allocations in one + * directory, so it's nice to have it named appropriately. For no= w it's + * 'vcpus_...' but it's designed in order for it to be changeable = in the + * future (it's part of the status XML). */ + if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0) + goto cleanup; + } + + if (virResctrlAllocSetID(alloc, alloc_id) < 0) + goto cleanup; + + tmp_resctrl->vcpus =3D vcpus; + tmp_resctrl->alloc =3D alloc; + + if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virDomainResctrlDefFree(tmp_resctrl); + VIR_FREE(alloc_id); + VIR_FREE(vcpus_str); + return ret; +} + + +static int virDomainCachetuneDefParse(virDomainDefPtr def, xmlXPathContextPtr ctxt, xmlNodePtr node, @@ -19091,19 +19143,12 @@ virDomainCachetuneDefParse(virDomainDefPtr def, xmlNodePtr *nodes =3D NULL; virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D NULL; - virDomainResctrlDefPtr tmp_resctrl =3D NULL; - char *tmp =3D NULL; - char *vcpus_str =3D NULL; - char *alloc_id =3D NULL; ssize_t i =3D 0; int n; int ret =3D -1; =20 ctxt->node =3D node; =20 - if (VIR_ALLOC(tmp_resctrl) < 0) - goto cleanup; - if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0) goto cleanup; =20 @@ -19141,45 +19186,17 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 - /* We need to format it back because we need to be consistent in the n= aming - * even when users specify some "sub-optimal" string there. */ - VIR_FREE(vcpus_str); - vcpus_str =3D virBitmapFormat(vcpus); - if (!vcpus_str) - goto cleanup; - - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - alloc_id =3D virXMLPropString(node, "id"); - - if (!alloc_id) { - /* The number of allocations is limited and the directory structur= e is flat, - * not hierarchical, so we need to have all same allocations in one - * directory, so it's nice to have it named appropriately. For no= w it's - * 'vcpus_...' but it's designed in order for it to be changeable = in the - * future (it's part of the status XML). */ - if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0) - goto cleanup; - } - - if (virResctrlAllocSetID(alloc, alloc_id) < 0) - goto cleanup; - - VIR_STEAL_PTR(tmp_resctrl->vcpus, vcpus); - VIR_STEAL_PTR(tmp_resctrl->alloc, alloc); - - if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0) + if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0) goto cleanup; + vcpus =3D NULL; + alloc =3D NULL; =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; - virDomainResctrlDefFree(tmp_resctrl); virObjectUnref(alloc); virBitmapFree(vcpus); - VIR_FREE(alloc_id); - VIR_FREE(vcpus_str); VIR_FREE(nodes); - VIR_FREE(tmp); return ret; } =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921916063411.2346720672508; Sun, 29 Jul 2018 20:38:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4F4F783F44; Mon, 30 Jul 2018 03:36:34 +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 13EE26EE49; Mon, 30 Jul 2018 03:36:34 +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 BA7FE24F61; Mon, 30 Jul 2018 03:36:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZpRp002936 for ; Sun, 29 Jul 2018 23:35:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F60B2638B; Mon, 30 Jul 2018 03:35:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 144112632C for ; Mon, 30 Jul 2018 03:35:47 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0018885547 for ; Mon, 30 Jul 2018 03:35:45 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:45 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:44 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613760" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:39 +0800 Message-Id: <1532920361-24737-16-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:46 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 15/17] conf: Add support for memorytune XML processing for resctrl MBA 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 30 Jul 2018 03:38:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce a new section memorytune to support memory bandwidth allocation. This is consistent with existing cachetune. As the example: below: ...... vpus --- vpus subjected to this memory bandwidth. id --- on which node memory bandwidth to be set. bandwidth --- the memory bandwidth percent to set. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- docs/formatdomain.html.in | 39 +++- docs/schemas/domaincommon.rng | 17 ++ src/conf/domain_conf.c | 200 +++++++++++++++++= ++++ .../memorytune-colliding-allocs.xml | 30 ++++ .../memorytune-colliding-cachetune.xml | 32 ++++ tests/genericxml2xmlindata/memorytune.xml | 33 ++++ tests/genericxml2xmltest.c | 5 + 7 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 tests/genericxml2xmlindata/memorytune-colliding-allocs.= xml create mode 100644 tests/genericxml2xmlindata/memorytune-colliding-cachetu= ne.xml create mode 100644 tests/genericxml2xmlindata/memorytune.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 19b7312..1ae6e98 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -759,6 +759,10 @@ <cache id=3D'0' level=3D'3' type=3D'both' size=3D'3' unit=3D'MiB'= /> <cache id=3D'1' level=3D'3' type=3D'both' size=3D'3' unit=3D'MiB'= /> </cachetune> + <memorytune vcpus=3D'0-3'> + <node id=3D'0' bandwidth=3D'60'/> + </memorytune> + </cputune> ... </domain> @@ -932,7 +936,9 @@ size and required granularity are reported as well. The required attribute vcpus specifies to which vCPUs this allocat= ion applies. A vCPU can only be member of one cachetune e= lement - allocations. Supported subelements are: + allocations. The vCPUs specified by cachetune can be identical wit= h those + in memorytune, however they are not allowed to overlap. + Supported subelements are:
cache
@@ -972,7 +978,38 @@
+ =20 +
memorytuneSince 4.7.0<= /dt> +
+ Optional memorytune element can control allocations f= or + memory bandwidth using the resctrl on the host. Whether or not is = this + supported can be gathered from capabilities where some limitations= like + minimum bandwidth and required granularity are reported as well. T= he + required attribute vcpus specifies to which vCPUs this + allocation applies. A vCPU can only be member of one + memorytune element allocations. The vcpus specified + by memorytune can be identical to those specified by + cachetune. However they are not allowed to overlap ea= ch other. + Supported subelements are: +
+
node
+
+ This element controls the allocation of CPU memory bandwidth a= nd has the + following attributes: +
+
id
+
+ Host node id from which to allocate memory bandwidth. +
+
bandwidth
+
+ The memory bandwidth to allocate from this node. The value= by default + is in percentage. +
+
+
+
=20 diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index ac04af5..48f0637 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -983,6 +983,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f45def8..d8333ad 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19290,6 +19290,129 @@ virDomainDefParseCaps(virDomainDefPtr def, } =20 =20 +static int +virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virResctrlAllocPtr alloc) +{ + xmlNodePtr oldnode =3D ctxt->node; + unsigned int id; + unsigned int bandwidth; + char *tmp =3D NULL; + int ret =3D -1; + + ctxt->node =3D node; + + tmp =3D virXMLPropString(node, "id"); + if (!tmp) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing memorytune attribute 'id'")); + goto cleanup; + } + if (virStrToLong_uip(tmp, NULL, 10, &id) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid memorytune attribute 'id' value '%s'"), + tmp); + goto cleanup; + } + VIR_FREE(tmp); + + tmp =3D virXMLPropString(node, "bandwidth"); + if (!tmp) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing memorytune attribute 'bandwidth'")); + goto cleanup; + } + if (virStrToLong_uip(tmp, NULL, 10, &bandwidth) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid memorytune attribute 'bandwidth' value '= %s'"), + tmp); + goto cleanup; + } + VIR_FREE(tmp); + if (virResctrlAllocSetMemoryBandwidth(alloc, id, bandwidth) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + ctxt->node =3D oldnode; + VIR_FREE(tmp); + return ret; +} + + +static int +virDomainMemorytuneDefParse(virDomainDefPtr def, + xmlXPathContextPtr ctxt, + xmlNodePtr node, + unsigned int flags) +{ + xmlNodePtr oldnode =3D ctxt->node; + xmlNodePtr *nodes =3D NULL; + virBitmapPtr vcpus =3D NULL; + virResctrlAllocPtr alloc =3D NULL; + ssize_t i =3D 0; + int n; + int ret =3D -1; + bool new_alloc =3D false; + + ctxt->node =3D node; + + if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0) + goto cleanup; + + if (virBitmapIsAllClear(vcpus)) { + ret =3D 0; + goto cleanup; + } + + if ((n =3D virXPathNodeSet("./node", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot extract memory nodes under memorytune")); + goto cleanup; + } + + if (virDomainResctrlVcpuMatch(def, vcpus, &alloc) < 0) + goto cleanup; + + if (!alloc) { + alloc =3D virResctrlAllocNew(); + if (!alloc) + goto cleanup; + new_alloc =3D true; + } else { + alloc =3D virObjectRef(alloc); + } + + for (i =3D 0; i < n; i++) { + if (virDomainMemorytuneDefParseMemory(ctxt, nodes[i], alloc) < 0) + goto cleanup; + } + if (virResctrlAllocIsEmpty(alloc)) { + ret =3D 0; + goto cleanup; + } + /* + * If this is a new allocation, format ID and append to resctrl, other= wise + * just update the existing alloc information, which is done in above + * virDomainMemorytuneDefParseMemory */ + if (new_alloc) { + if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0) + goto cleanup; + vcpus =3D NULL; + alloc =3D NULL; + } + + ret =3D 0; + cleanup: + ctxt->node =3D oldnode; + virObjectUnref(alloc); + virBitmapFree(vcpus); + VIR_FREE(nodes); + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19804,6 +19927,18 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 + if ((n =3D virXPathNodeSet("./cputune/memorytune", ctxt, &nodes)) < 0)= { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot extract memorytune nodes")); + goto error; + } + + for (i =3D 0; i < n; i++) { + if (virDomainMemorytuneDefParse(def, ctxt, nodes[i], flags) < 0) + goto error; + } + VIR_FREE(nodes); + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu)= < 0) goto error; =20 @@ -27104,6 +27239,68 @@ virDomainCachetuneDefFormat(virBufferPtr buf, =20 =20 static int +virDomainMemorytuneDefFormatHelper(unsigned int id, + unsigned int bandwidth, + void *opaque) +{ + virBufferPtr buf =3D opaque; + + virBufferAsprintf(buf, + "\n", + id, bandwidth); + return 0; +} + + +static int +virDomainMemorytuneDefFormat(virBufferPtr buf, + virDomainResctrlDefPtr resctrl, + unsigned int flags) +{ + virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; + char *vcpus =3D NULL; + int ret =3D -1; + + virBufferSetChildIndent(&childrenBuf, buf); + if (virResctrlAllocForeachMemory(resctrl->alloc, + virDomainMemorytuneDefFormatHelper, + &childrenBuf) < 0) + goto cleanup; + + if (virBufferCheckError(&childrenBuf) < 0) + goto cleanup; + + if (!virBufferUse(&childrenBuf)) { + ret =3D 0; + goto cleanup; + } + + vcpus =3D virBitmapFormat(resctrl->vcpus); + if (!vcpus) + goto cleanup; + + virBufferAsprintf(buf, "alloc); + if (!alloc_id) + goto cleanup; + + virBufferAsprintf(buf, " id=3D'%s'", alloc_id); + } + virBufferAddLit(buf, ">\n"); + + virBufferAddBuffer(buf, &childrenBuf); + virBufferAddLit(buf, "\n"); + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&childrenBuf); + VIR_FREE(vcpus); + return ret; +} + +static int virDomainCputuneDefFormat(virBufferPtr buf, virDomainDefPtr def, unsigned int flags) @@ -27208,6 +27405,9 @@ virDomainCputuneDefFormat(virBufferPtr buf, for (i =3D 0; i < def->nresctrls; i++) virDomainCachetuneDefFormat(&childrenBuf, def->resctrls[i], flags); =20 + for (i =3D 0; i < def->nresctrls; i++) + virDomainMemorytuneDefFormat(&childrenBuf, def->resctrls[i], flags= ); + if (virBufferCheckError(&childrenBuf) < 0) return -1; =20 diff --git a/tests/genericxml2xmlindata/memorytune-colliding-allocs.xml b/t= ests/genericxml2xmlindata/memorytune-colliding-allocs.xml new file mode 100644 index 0000000..9b8ebaa --- /dev/null +++ b/tests/genericxml2xmlindata/memorytune-colliding-allocs.xml @@ -0,0 +1,30 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 4 + + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/genericxml2xmlindata/memorytune-colliding-cachetune.xml = b/tests/genericxml2xmlindata/memorytune-colliding-cachetune.xml new file mode 100644 index 0000000..5416870 --- /dev/null +++ b/tests/genericxml2xmlindata/memorytune-colliding-cachetune.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 4 + + + + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/genericxml2xmlindata/memorytune.xml b/tests/genericxml2x= mlindata/memorytune.xml new file mode 100644 index 0000000..ea03e22 --- /dev/null +++ b/tests/genericxml2xmlindata/memorytune.xml @@ -0,0 +1,33 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 4 + + + + + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 7a4fc1e..e6d4ef2 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -140,6 +140,11 @@ mymain(void) TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_FULL("cachetune-colliding-types", false, true, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST("memorytune"); + DO_TEST_FULL("memorytune-colliding-allocs", false, true, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST_FULL("memorytune-colliding-cachetune", false, true, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); =20 DO_TEST("tseg"); =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153292181387373.4435279127091; Sun, 29 Jul 2018 20:36:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBEC75F734; Mon, 30 Jul 2018 03:36:29 +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 959F32010D59; Mon, 30 Jul 2018 03:36:29 +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 3FE5618037FE; Mon, 30 Jul 2018 03:36:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3Zp38002931 for ; Sun, 29 Jul 2018 23:35:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F24476122; Mon, 30 Jul 2018 03:35:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 079255D9C5 for ; Mon, 30 Jul 2018 03:35:48 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF18585541 for ; Mon, 30 Jul 2018 03:35:47 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:47 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613764" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:40 +0800 Message-Id: <1532920361-24737-17-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:47 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 16/17] conf: Add return value check to virResctrlAllocForeachCache 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 30 Jul 2018 03:36:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Add return value check to virResctrlAllocForeachCache in virDomainCachetuneDefFormat. The virResctrlAllocForeachCache dose have return value, so need check return value to make sure function executed without error. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d8333ad..095c903 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27199,10 +27199,10 @@ virDomainCachetuneDefFormat(virBufferPtr buf, int ret =3D -1; =20 virBufferSetChildIndent(&childrenBuf, buf); - virResctrlAllocForeachCache(resctrl->alloc, - virDomainCachetuneDefFormatHelper, - &childrenBuf); - + if (virResctrlAllocForeachCache(resctrl->alloc, + virDomainCachetuneDefFormatHelper, + &childrenBuf) < 0) + goto cleanup; =20 if (virBufferCheckError(&childrenBuf) < 0) goto cleanup; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 10:58:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921764756464.67960943218316; Sun, 29 Jul 2018 20:36:04 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 318DD13AA5; Mon, 30 Jul 2018 03:36:02 +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 C0C7F1001938; Mon, 30 Jul 2018 03:36:01 +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 50BAF3F7CB; Mon, 30 Jul 2018 03:36:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6U3ZrGH002946 for ; Sun, 29 Jul 2018 23:35:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1F7DD0930; Mon, 30 Jul 2018 03:35:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99689D0925 for ; Mon, 30 Jul 2018 03:35:50 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D9DC8553D for ; Mon, 30 Jul 2018 03:35:49 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:49 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:47 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613771" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:41 +0800 Message-Id: <1532920361-24737-18-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Jul 2018 03:35:49 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 17/17] conf: Add memory bandwidth allocation capability of host 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:36:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Add new XML section to report host's memory bandwidth allocation capability. The format as below example: ..... granularity ---- granularity of memory bandwidth, unit percentage. min ---- minimum memory bandwidth allowed, unit percentage. maxAllocs ---- maximum memory bandwidth allocation group supported. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- docs/schemas/capability.rng | 33 +++++++ src/conf/capabilities.c | 107 +++++++++++++++++= ++++ src/conf/capabilities.h | 11 +++ src/util/virresctrl.c | 20 ++++ src/util/virresctrl.h | 15 +++ .../linux-resctrl/resctrl/info/MB/bandwidth_gran | 1 + .../linux-resctrl/resctrl/info/MB/min_bandwidth | 1 + .../linux-resctrl/resctrl/info/MB/num_closids | 1 + tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml | 8 ++ tests/virresctrldata/resctrl.schemata | 1 + 10 files changed, 198 insertions(+) create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/ban= dwidth_gran create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min= _bandwidth create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num= _closids diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index 52164d5..d61515c 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -51,6 +51,9 @@ + + + @@ -326,6 +329,36 @@ =20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 0f96500..ef2ca81 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -198,6 +198,16 @@ virCapabilitiesFreeNUMAInfo(virCapsPtr caps) } =20 static void +virCapsHostMemBWNodeFree(virCapsHostMemBWNodePtr ptr) +{ + if (!ptr) + return; + + virBitmapFree(ptr->cpus); + VIR_FREE(ptr); +} + +static void virCapabilitiesClearSecModel(virCapsHostSecModelPtr secmodel) { size_t i; @@ -239,6 +249,10 @@ virCapsDispose(void *object) virCapsHostCacheBankFree(caps->host.caches[i]); VIR_FREE(caps->host.caches); =20 + for (i =3D 0; i < caps->host.nnodes; i++) + virCapsHostMemBWNodeFree(caps->host.nodes[i]); + VIR_FREE(caps->host.nodes); + VIR_FREE(caps->host.netprefix); VIR_FREE(caps->host.pagesSize); virCPUDefFree(caps->host.cpu); @@ -957,6 +971,58 @@ virCapabilitiesFormatCaches(virBufferPtr buf, return 0; } =20 +static int +virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, + size_t nnodes, + virCapsHostMemBWNodePtr *nodes) +{ + size_t i =3D 0; + virBuffer controlBuf =3D VIR_BUFFER_INITIALIZER; + + if (!nnodes) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 0; i < nnodes; i++) { + virCapsHostMemBWNodePtr node =3D nodes[i]; + virResctrlInfoMemBWPerNodePtr control =3D &node->control; + char *cpus_str =3D virBitmapFormat(node->cpus); + + if (!cpus_str) + return -1; + + virBufferAsprintf(buf, + "id, cpus_str); + VIR_FREE(cpus_str); + + virBufferSetChildIndent(&controlBuf, buf); + virBufferAsprintf(&controlBuf, + "\n", + control->granularity, control->min, + control->max_allocation); + + if (virBufferCheckError(&controlBuf) < 0) + return -1; + + if (virBufferUse(&controlBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &controlBuf); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + /** * virCapabilitiesFormatXML: * @caps: capabilities to format @@ -1060,6 +1126,10 @@ virCapabilitiesFormatXML(virCapsPtr caps) caps->host.caches) < 0) goto error; =20 + if (virCapabilitiesFormatMemoryBandwidth(&buf, caps->host.nnodes, + caps->host.nodes) < 0) + goto error; + for (i =3D 0; i < caps->host.nsecModels; i++) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -1602,6 +1672,40 @@ virCapabilitiesInitResctrl(virCapsPtr caps) } =20 =20 +static int +virCapabilitiesInitResctrlMemory(virCapsPtr caps) +{ + virCapsHostMemBWNodePtr node =3D NULL; + size_t i =3D 0; + int ret =3D -1; + + for (i =3D 0; i < caps->host.ncaches; i++) { + virCapsHostCacheBankPtr bank =3D caps->host.caches[i]; + if (VIR_ALLOC(node) < 0) + goto cleanup; + + if (virResctrlInfoGetMemoryBandwidth(caps->host.resctrl, + bank->level, &node->control) = > 0) { + node->id =3D bank->id; + if (!(node->cpus =3D virBitmapNewCopy(bank->cpus))) + goto cleanup; + + if (VIR_APPEND_ELEMENT(caps->host.nodes, + caps->host.nnodes, node) < 0) { + goto cleanup; + } + } + virCapsHostMemBWNodeFree(node); + node =3D NULL; + } + + ret =3D 0; + cleanup: + virCapsHostMemBWNodeFree(node); + return ret; +} + + int virCapabilitiesInitCaches(virCapsPtr caps) { @@ -1731,6 +1835,9 @@ virCapabilitiesInitCaches(virCapsPtr caps) qsort(caps->host.caches, caps->host.ncaches, sizeof(*caps->host.caches), virCapsHostCacheBankSorter); =20 + if (virCapabilitiesInitResctrlMemory(caps) < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_FREE(type); diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index fe1b9ea..046e275 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -151,6 +151,14 @@ struct _virCapsHostCacheBank { virResctrlInfoPerCachePtr *controls; }; =20 +typedef struct _virCapsHostMemBWNode virCapsHostMemBWNode; +typedef virCapsHostMemBWNode *virCapsHostMemBWNodePtr; +struct _virCapsHostMemBWNode { + unsigned int id; + virBitmapPtr cpus; /* All CPUs that belong to this node*/ + virResctrlInfoMemBWPerNode control; +}; + typedef struct _virCapsHost virCapsHost; typedef virCapsHost *virCapsHostPtr; struct _virCapsHost { @@ -175,6 +183,9 @@ struct _virCapsHost { size_t ncaches; virCapsHostCacheBankPtr *caches; =20 + size_t nnodes; + virCapsHostMemBWNodePtr *nodes; + size_t nsecModels; virCapsHostSecModelPtr secModels; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index f25e7bc..4d5adcc 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -630,6 +630,26 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) =20 =20 int +virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resctrl, + unsigned int level, + virResctrlInfoMemBWPerNodePtr control) +{ + virResctrlInfoMemBWPtr membw_info =3D resctrl->membw_info; + + if (!membw_info) + return 0; + + if (membw_info->last_level_cache !=3D level) + return 0; + + control->granularity =3D membw_info->bandwidth_granularity; + control->min =3D membw_info->min_bandwidth; + control->max_allocation =3D membw_info->max_allocation; + return 1; +} + + +int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, unsigned long long size, diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 8d62517..cfd56dd 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -50,6 +50,17 @@ struct _virResctrlInfoPerCache { unsigned int max_allocation; }; =20 +typedef struct _virResctrlInfoMemBWPerNode virResctrlInfoMemBWPerNode; +typedef virResctrlInfoMemBWPerNode *virResctrlInfoMemBWPerNodePtr; +struct _virResctrlInfoMemBWPerNode { + /* Smallest possible increase of the allocation bandwidth in percentag= e */ + unsigned int granularity; + /* Minimal allocatable bandwidth in percentage */ + unsigned int min; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocation; +}; + typedef struct _virResctrlInfo virResctrlInfo; typedef virResctrlInfo *virResctrlInfoPtr; =20 @@ -63,6 +74,10 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, size_t *ncontrols, virResctrlInfoPerCachePtr **controls); =20 +int +virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resctrl, + unsigned int level, + virResctrlInfoMemBWPerNodePtr control); /* Alloc-related things */ typedef struct _virResctrlAlloc virResctrlAlloc; typedef virResctrlAlloc *virResctrlAllocPtr; diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/bandwidth_= gran b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/bandwidth_gran new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/bandwidth_gran @@ -0,0 +1 @@ +10 diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min_bandwi= dth b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min_bandwidth new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min_bandwidth @@ -0,0 +1 @@ +10 diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num_closid= s b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num_closids new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num_closids @@ -0,0 +1 @@ +4 diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml b/tests/virca= ps2xmldata/vircaps-x86_64-resctrl.xml index 4840614..9b00cf0 100644 --- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml +++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml @@ -49,6 +49,14 @@ + + + + + + + + =20 diff --git a/tests/virresctrldata/resctrl.schemata b/tests/virresctrldata/r= esctrl.schemata index fa980e5..2578822 100644 --- a/tests/virresctrldata/resctrl.schemata +++ b/tests/virresctrldata/resctrl.schemata @@ -1 +1,2 @@ L3:0=3D000ff;1=3D000f0 +MB:0=3D100;1=3D100 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list