From nobody Sun Apr 28 00:38:29 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 1535373567581375.3196007668481; Mon, 27 Aug 2018 05:39:27 -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 358C4308624E; Mon, 27 Aug 2018 12:39:25 +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 066125C2E0; Mon, 27 Aug 2018 12:39:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ACB55180610F; Mon, 27 Aug 2018 12:39:22 +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 w7RBNxfa024628 for ; Mon, 27 Aug 2018 07:23:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4A866308BDA4; Mon, 27 Aug 2018 11:23:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 419CF308BE72 for ; Mon, 27 Aug 2018 11:23:57 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 63E8330842A7 for ; Mon, 27 Aug 2018 11:23:56 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:55 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:40 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804956" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:04 +0800 Message-Id: <1535368993-24901-2-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:23:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:23:56 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 01/10] conf: Renamed 'controlBuf' to 'childrenBuf' 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.49]); Mon, 27 Aug 2018 12:39:26 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To add CMT/MBM feature and let code be consistent in later patches, renaming variable name from 'controlBuf' to 'childrenBuf', locates in functions 'virCapabilitiesFormatCaches' and 'virCapabilitiesFormatMemoryBandwidth'. Signed-off-by: Wang Huaqiang Reviewed-by: John Ferlan --- .gnulib | 1 - src/conf/capabilities.c | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) delete mode 160000 .gnulib diff --git a/.gnulib b/.gnulib deleted file mode 160000 index 68df637..0000000 --- a/.gnulib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 68df637b5f1b5c10370f6981d2a43a5cf74368df diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 6b60fbc..326bd15 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -873,7 +873,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf, { size_t i =3D 0; size_t j =3D 0; - virBuffer controlBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; =20 if (!ncaches) return 0; @@ -902,7 +902,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf, short_size, unit, cpus_str); VIR_FREE(cpus_str); =20 - virBufferSetChildIndent(&controlBuf, buf); + virBufferSetChildIndent(&childrenBuf, buf); for (j =3D 0; j < bank->ncontrols; j++) { const char *min_unit; virResctrlInfoPerCachePtr controls =3D bank->controls[j]; @@ -928,26 +928,26 @@ virCapabilitiesFormatCaches(virBufferPtr buf, } } =20 - virBufferAsprintf(&controlBuf, + virBufferAsprintf(&childrenBuf, "= \n", unit, virCacheTypeToString(controls->scope), controls->max_allocation); } =20 - if (virBufferCheckError(&controlBuf) < 0) + if (virBufferCheckError(&childrenBuf) < 0) return -1; =20 - if (virBufferUse(&controlBuf)) { + if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &controlBuf); + virBufferAddBuffer(buf, &childrenBuf); virBufferAddLit(buf, "\n"); } else { virBufferAddLit(buf, "/>\n"); @@ -966,7 +966,7 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, virCapsHostMemBWNodePtr *nodes) { size_t i =3D 0; - virBuffer controlBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; =20 if (!nnodes) return 0; @@ -987,19 +987,19 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, node->id, cpus_str); VIR_FREE(cpus_str); =20 - virBufferSetChildIndent(&controlBuf, buf); - virBufferAsprintf(&controlBuf, + virBufferSetChildIndent(&childrenBuf, buf); + virBufferAsprintf(&childrenBuf, "\n", control->granularity, control->min, control->max_allocation); =20 - if (virBufferCheckError(&controlBuf) < 0) + if (virBufferCheckError(&childrenBuf) < 0) return -1; =20 - if (virBufferUse(&controlBuf)) { + if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &controlBuf); + virBufferAddBuffer(buf, &childrenBuf); virBufferAddLit(buf, "\n"); } else { virBufferAddLit(buf, "/>\n"); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 15353735678981008.5198268113543; Mon, 27 Aug 2018 05:39:27 -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 354CE4E33A; Mon, 27 Aug 2018 12:39: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 C12805D9CC; Mon, 27 Aug 2018 12:39:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BE3924BB75; Mon, 27 Aug 2018 12:39:22 +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 w7RBO1hj024638 for ; Mon, 27 Aug 2018 07:24:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CF373091329; Mon, 27 Aug 2018 11:24:01 +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 527A13091323 for ; Mon, 27 Aug 2018 11:23:58 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 CED7E7F6A0 for ; Mon, 27 Aug 2018 11:23:57 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23: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.53,295,1531810800"; d="scan'208";a="84804959" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:05 +0800 Message-Id: <1535368993-24901-3-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:23:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:23:58 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 02/10] util: add interface retrieving CMT capability 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.38]); Mon, 27 Aug 2018 12:39:26 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce function for reporting CMT capability through going through files under /sys/fs/info/L3_MON. This patch is co-work with later patches and report these information to domain. Signed-off-by: Wang Huaqiang --- src/conf/capabilities.c | 6 ++- src/conf/capabilities.h | 1 + src/util/virresctrl.c | 120 ++++++++++++++++++++++++++++++++++++++++++++= ++-- src/util/virresctrl.h | 17 ++++++- 4 files changed, 137 insertions(+), 7 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 326bd15..5280348 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1626,6 +1626,9 @@ virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr) virBitmapFree(ptr->cpus); for (i =3D 0; i < ptr->ncontrols; i++) VIR_FREE(ptr->controls[i]); + if (ptr->monitor && ptr->monitor->features) + virStringListFree(ptr->monitor->features); + VIR_FREE(ptr->monitor); VIR_FREE(ptr->controls); VIR_FREE(ptr); } @@ -1801,7 +1804,8 @@ virCapabilitiesInitCaches(virCapsPtr caps) bank->level, bank->size, &bank->ncontrols, - &bank->controls) < 0) + &bank->controls, + &bank->monitor) < 0) goto cleanup; =20 if (VIR_APPEND_ELEMENT(caps->host.caches, diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 046e275..3ed2523 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -149,6 +149,7 @@ struct _virCapsHostCacheBank { virBitmapPtr cpus; /* All CPUs that share this bank */ size_t ncontrols; virResctrlInfoPerCachePtr *controls; + virResctrlInfoMonPtr monitor; }; =20 typedef struct _virCapsHostMemBWNode virCapsHostMemBWNode; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 4b5442f..2f6923a 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -146,6 +146,8 @@ struct _virResctrlInfo { size_t nlevels; =20 virResctrlInfoMemBWPtr membw_info; + + virResctrlInfoMonPtr monitor_info; }; =20 =20 @@ -171,6 +173,9 @@ virResctrlInfoDispose(void *obj) VIR_FREE(level); } =20 + if (resctrl->monitor_info) + virStringListFree(resctrl->monitor_info->features); + VIR_FREE(resctrl->monitor_info); VIR_FREE(resctrl->membw_info); VIR_FREE(resctrl->levels); } @@ -556,6 +561,81 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr res= ctrl) =20 =20 static int +virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) +{ + int rv =3D -1; + char *featurestr =3D NULL; + char **lines =3D NULL; + size_t nlines =3D 0; + size_t i =3D 0; + int ret =3D -1; + virResctrlInfoMonPtr info =3D NULL; + + if (VIR_ALLOC(info) < 0) + return -1; + + rv =3D virFileReadValueUint(&info->max_allocation, + SYSFS_RESCTRL_PATH "/info/L3_MON/num_rmids"); + if (rv =3D=3D -2) { + /* The file doesn't exist, so it's unusable for us, + * probably resource monitoring feature unsupported */ + VIR_WARN("The path '" SYSFS_RESCTRL_PATH "/info/L3_MON/num_rmids' " + "does not exist"); + + ret =3D 0; + goto cleanup; + } else if (rv < 0) { + /* Other failures are fatal, so just quit */ + goto cleanup; + } + + rv =3D virFileReadValueUint(&info->cache_threshold, + SYSFS_RESCTRL_PATH + "/info/L3_MON/max_threshold_occupancy"); + + if (rv =3D=3D -2) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get max_threshold_occupancy from resctrl" + " info")); + } + if (rv < 0) + goto cleanup; + + rv =3D virFileReadValueString(&featurestr, + SYSFS_RESCTRL_PATH + "/info/L3_MON/mon_features"); + if (rv =3D=3D -2) + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get mon_features from resctrl info")); + if (rv < 0) + goto cleanup; + + lines =3D virStringSplitCount(featurestr, "\n", 0, &nlines); + + for (i =3D 0; i < nlines; i++) { + if (STREQLEN(lines[i], "llc_", strlen("llc_")) || + STREQLEN(lines[i], "mbm_", strlen("mbm_"))) { + if (virStringListAdd(&info->features, lines[i]) < 0) + goto cleanup; + info->nfeatures++; + } + } + + VIR_FREE(featurestr); + virStringListFree(lines); + resctrl->monitor_info =3D info; + return 0; + + cleanup: + VIR_FREE(featurestr); + virStringListFree(lines); + virStringListFree(info->features); + VIR_FREE(info); + return ret; +} + + +static int virResctrlGetInfo(virResctrlInfoPtr resctrl) { DIR *dirp =3D NULL; @@ -569,6 +649,10 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (ret < 0) goto cleanup; =20 + ret =3D virResctrlGetMonitorInfo(resctrl); + if (ret < 0) + goto cleanup; + ret =3D virResctrlGetCacheInfo(resctrl, dirp); if (ret < 0) goto cleanup; @@ -654,16 +738,21 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, unsigned long long size, size_t *ncontrols, - virResctrlInfoPerCachePtr **controls) + virResctrlInfoPerCachePtr **controls, + virResctrlInfoMonPtr *monitor) { virResctrlInfoPerLevelPtr i_level =3D NULL; virResctrlInfoPerTypePtr i_type =3D NULL; + virResctrlInfoMonPtr cachemon =3D NULL; size_t i =3D 0; int ret =3D -1; =20 if (virResctrlInfoIsEmpty(resctrl)) return 0; =20 + if (VIR_ALLOC(cachemon) < 0) + return -1; + /* 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 */ @@ -716,14 +805,35 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_typ= e->control)); } =20 - ret =3D 0; - cleanup: - return ret; + cachemon->max_allocation =3D 0; + + if (resctrl->monitor_info) { + virResctrlInfoMonPtr info =3D resctrl->monitor_info; + + cachemon->max_allocation =3D info->max_allocation; + cachemon->cache_threshold =3D info->cache_threshold; + for (i =3D 0; i < info->nfeatures; i++) { + /* Only cares about last level cache */ + if (STREQLEN(info->features[i], "llc_", strlen("llc_"))) { + if (virStringListAdd(&cachemon->features, + info->features[i]) < 0) + goto error; + cachemon->nfeatures++; + } + } + } + + if (cachemon->features) + *monitor =3D cachemon; + + return 0; error: while (*ncontrols) VIR_FREE((*controls)[--*ncontrols]); VIR_FREE(*controls); - goto cleanup; + virStringListFree(cachemon->features); + VIR_FREE(cachemon); + return ret; } =20 =20 diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index cfd56dd..51bb68b 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -61,6 +61,19 @@ struct _virResctrlInfoMemBWPerNode { unsigned int max_allocation; }; =20 +typedef struct _virResctrlInfoMon virResctrlInfoMon; +typedef virResctrlInfoMon *virResctrlInfoMonPtr; +/* Information about resource monitoring group */ +struct _virResctrlInfoMon { + /* null-terminal string list for hw supported monitor feature */ + char **features; + size_t nfeatures; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocation; + /* determines the occupancy at which an RMID can be freed */ + unsigned int cache_threshold; +}; + typedef struct _virResctrlInfo virResctrlInfo; typedef virResctrlInfo *virResctrlInfoPtr; =20 @@ -72,7 +85,9 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, unsigned long long size, size_t *ncontrols, - virResctrlInfoPerCachePtr **controls); + virResctrlInfoPerCachePtr **controls, + virResctrlInfoMonPtr *monitor); + =20 int virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resctrl, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373577634619.7659003937781; Mon, 27 Aug 2018 05:39:37 -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 4323B308424B; Mon, 27 Aug 2018 12:39:35 +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 07FEA2010CF1; Mon, 27 Aug 2018 12:39: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 2885D24F64; Mon, 27 Aug 2018 12:39:34 +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 w7RBO1AZ024648 for ; Mon, 27 Aug 2018 07:24:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6B76A1F38; Mon, 27 Aug 2018 11:24:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD884A1F37 for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 0A790308424B for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:43 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804964" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:06 +0800 Message-Id: <1535368993-24901-4-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 03/10] conf: Add CMT capability to 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 12:39:36 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" CMT capability for each cache bank, includes -. Maximum CMT monitoring groups(sharing with MBM) could be created, which reflects the maximum hardware RMID count. -. 'cache threshold'. -. Statistical information of last level cache, the actual cache occupancy. cache is splitted into 'bank's, each bank MAY have different cache configuration, report cache monitoring capability in unit of cache bank. cache monitor capability is shown as below: + + + + + + Signed-off-by: Wang Huaqiang --- docs/schemas/capability.rng | 28 ++++++++++++++++++++++++++++ src/conf/capabilities.c | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index d61515c..67498f1 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -314,6 +314,24 @@ + + + + + + + + + + + + + + + + + + @@ -329,6 +347,16 @@ =20 + + + + llc_occupancy + mbm_total_bytes + mbm_local_bytes + + + + diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 5280348..7932088 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -942,6 +942,23 @@ virCapabilitiesFormatCaches(virBufferPtr buf, controls->max_allocation); } =20 + if (bank->monitor && + bank->monitor->nfeatures) { + virBufferAsprintf(&childrenBuf, + "\n", + bank->monitor->cache_threshold, + bank->monitor->max_allocation); + for (j =3D 0; j < bank->monitor->nfeatures; j++) { + virBufferAdjustIndent(&childrenBuf, 2); + virBufferAsprintf(&childrenBuf, + "\n", + bank->monitor->features[j]); + virBufferAdjustIndent(&childrenBuf, -2); + } + virBufferAddLit(&childrenBuf, "\n"); + } + if (virBufferCheckError(&childrenBuf) < 0) return -1; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373567273636.1795386368119; Mon, 27 Aug 2018 05:39:27 -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 4B8A8356C5; Mon, 27 Aug 2018 12:39:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12134A1F35; Mon, 27 Aug 2018 12:39:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CF1C4181A12D; Mon, 27 Aug 2018 12:39:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7RBO1MV024643 for ; Mon, 27 Aug 2018 07:24:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC211106A790; Mon, 27 Aug 2018 11:24:01 +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 B37A710001BC for ; Mon, 27 Aug 2018 11:23:59 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 0698781DEB for ; Mon, 27 Aug 2018 11:23:59 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23: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.53,295,1531810800"; d="scan'208";a="84804965" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:07 +0800 Message-Id: <1535368993-24901-5-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 04/10] test: add test case for resctrl monitor 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.30]); Mon, 27 Aug 2018 12:39:25 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Wang Huaqiang --- .../linux-resctrl/resctrl/info/L3_MON/max_threshold_occupancy | 1 + .../vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/mon_features | 3 +++ tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/num_rmids | 1 + tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml | 6 ++= ++++ 4 files changed, 11 insertions(+) create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON= /max_threshold_occupancy create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON= /mon_features create mode 100644 tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON= /num_rmids diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/max_th= reshold_occupancy b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON= /max_threshold_occupancy new file mode 100644 index 0000000..77f05e2 --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/max_threshold= _occupancy @@ -0,0 +1 @@ +270336 diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/mon_fe= atures b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/mon_featur= es new file mode 100644 index 0000000..0c57b8d --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/mon_features @@ -0,0 +1,3 @@ +llc_occupancy +mbm_total_bytes +mbm_local_bytes diff --git a/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/num_rm= ids b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/num_rmids new file mode 100644 index 0000000..1057e9a --- /dev/null +++ b/tests/vircaps2xmldata/linux-resctrl/resctrl/info/L3_MON/num_rmids @@ -0,0 +1 @@ +176 diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml b/tests/virca= ps2xmldata/vircaps-x86_64-resctrl.xml index 9b00cf0..678fdc9 100644 --- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml +++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml @@ -44,9 +44,15 @@ + + + + + + --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373576762481.3170418040054; Mon, 27 Aug 2018 05:39:36 -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 AF9E73DD47; Mon, 27 Aug 2018 12:39: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 0F7FCA23B8; Mon, 27 Aug 2018 12:39: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 BE5C024F63; Mon, 27 Aug 2018 12:39:33 +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 w7RBO0tR024633 for ; Mon, 27 Aug 2018 07:24:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 12255308BDA2; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 073EE308BE72 for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 CCC3830842AA for ; Mon, 27 Aug 2018 11:23:58 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23: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.53,295,1531810800"; d="scan'208";a="84804967" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:08 +0800 Message-Id: <1535368993-24901-6-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 05/10] util: resctrl: refactoring some functions 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.29]); Mon, 27 Aug 2018 12:39:35 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some code, in virresctrl.c, manupulating the file objects of resctrlfs could be reused for cache monitor interfaces. This patch refactor these functions for purpose of reusing code in later patch: virResctrlAllocDeterminePath virResctrlAllocCreate virResctrlAddPID Signed-off-by: Wang Huaqiang --- src/util/virresctrl.c | 126 +++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 93 insertions(+), 33 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 2f6923a..b3bae6e 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2082,25 +2082,94 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, } =20 =20 -int -virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, - const char *machinename) +static int +virResctrlDeterminePath(const char *id, + const char *root, + const char *parentpath, + const char *prefix, + char **path) { - if (!alloc->id) { + if (!id) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Resctrl Allocation ID must be set before creatio= n")); + _("Resctrl resource ID must be set before creation"= )); return -1; } =20 - if (!alloc->path && - virAsprintf(&alloc->path, "%s/%s-%s", - SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0) + if (*path) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Resctrl group (%s) already created, path=3D%s."), + id, *path); return -1; + } + + if (!parentpath && !root) { + if (virAsprintf(path, "%s/%s-%s", + SYSFS_RESCTRL_PATH, prefix, id) < 0) + return -1; + } else if (!parentpath) { + if (virAsprintf(path, "%s/%s/%s-%s", + SYSFS_RESCTRL_PATH, parentpath, prefix, id) < 0) + return -1; + } else { + if (virAsprintf(path, "%s/%s/%s-%s", + root, parentpath, prefix, id) < 0) + return -1; + } =20 return 0; } =20 =20 +int +virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, + const char *machinename) +{ + return virResctrlDeterminePath(alloc->id, NULL, NULL, + machinename, &alloc->path); +} + +static int +virResctrlCreateGroup(virResctrlInfoPtr resctrl, + char *path) +{ + int ret =3D -1; + int lockfd =3D -1; + + if (!path) + return -1; + + if (virResctrlInfoIsEmpty(resctrl)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Resource control is not supported on this host")= ); + return -1; + } + + if (STREQ(path, SYSFS_RESCTRL_PATH)) + return 0; + + if (virFileExists(path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Path '%s' for resctrl resource group exists"), p= ath); + goto cleanup; + } + + lockfd =3D virResctrlLockWrite(); + if (lockfd < 0) + goto cleanup; + + if (virFileMakePath(path) < 0) { + virReportSystemError(errno, + _("Cannot create resctrl directory '%s'"), pa= th); + goto cleanup; + } + + ret =3D 0; + cleanup: + virResctrlUnlock(lockfd); + return ret; +} + + /* This checks if the directory for the alloc exists. If not it tries to = create * it and apply appropriate alloc settings. */ int @@ -2116,21 +2185,11 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (!alloc) return 0; =20 - if (virResctrlInfoIsEmpty(resctrl)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Resource control is not supported on this host")= ); - return -1; - } - if (virResctrlAllocDeterminePath(alloc, machinename) < 0) return -1; =20 - if (virFileExists(alloc->path)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Path '%s' for resctrl allocation exists"), - alloc->path); - goto cleanup; - } + if (virResctrlCreateGroup(resctrl, alloc->path) < 0) + return -1; =20 lockfd =3D virResctrlLockWrite(); if (lockfd < 0) @@ -2146,13 +2205,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (virAsprintf(&schemata_path, "%s/schemata", alloc->path) < 0) goto cleanup; =20 - if (virFileMakePath(alloc->path) < 0) { - virReportSystemError(errno, - _("Cannot create resctrl directory '%s'"), - alloc->path); - goto cleanup; - } - VIR_DEBUG("Writing resctrl schemata '%s' into '%s'", alloc_str, schema= ta_path); if (virFileWriteStr(schemata_path, alloc_str, 0) < 0) { rmdir(alloc->path); @@ -2171,21 +2223,21 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, } =20 =20 -int -virResctrlAllocAddPID(virResctrlAllocPtr alloc, - pid_t pid) +static int +virResctrlAddPID(char *path, + pid_t pid) { char *tasks =3D NULL; char *pidstr =3D NULL; int ret =3D 0; =20 - if (!alloc->path) { + if (!path) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot add pid to non-existing resctrl allocatio= n")); + _("Cannot add pid to non-existing resctrl group")); return -1; } =20 - if (virAsprintf(&tasks, "%s/tasks", alloc->path) < 0) + if (virAsprintf(&tasks, "%s/tasks", path) < 0) return -1; =20 if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0) @@ -2207,6 +2259,14 @@ virResctrlAllocAddPID(virResctrlAllocPtr alloc, =20 =20 int +virResctrlAllocAddPID(virResctrlAllocPtr alloc, + pid_t pid) +{ + return virResctrlAddPID(alloc->path, pid); +} + + +int virResctrlAllocRemove(virResctrlAllocPtr alloc) { int 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 Sun Apr 28 00:38:29 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 1535373580627497.15347127336884; Mon, 27 Aug 2018 05:39:40 -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 BE17930832D2; Mon, 27 Aug 2018 12:39:38 +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 8627F100190E; Mon, 27 Aug 2018 12:39:38 +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 3F97F181A13C; Mon, 27 Aug 2018 12:39:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7RBO2Mv024658 for ; Mon, 27 Aug 2018 07:24:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7832460A9A; Mon, 27 Aug 2018 11:24:02 +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 684F9608FA for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 2B9C83083391 for ; Mon, 27 Aug 2018 11:23:59 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23: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.53,295,1531810800"; d="scan'208";a="84804970" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:09 +0800 Message-Id: <1535368993-24901-7-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 27 Aug 2018 11:23:59 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 06/10] util: Introduce resctrl monitor for CMT 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.44]); Mon, 27 Aug 2018 12:39:39 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 'virResctrlAllocMon' denotes a resctrl monitor reporting the resource consumption information. This patch introduced the interfaces for resctrl monitor. Relationship of 'resctrl allocation' and 'resctrl monitor': 1. resctrl monitor monitors resources (cache or memory bandwidth) of particular allocation. 2. resctrl allocation may refer to the 'default' allocation if no dedicated resource 'control' applied to it. The 'default' allocation enjoys remaining resource that not allocated. 3. resctrl monitor belongs to 'default' allocation if no 'cachetune' specified in XML file. 4. one resctrl allocation may have several monitors. It is also permitted that there is no resctrl monitor associated with an allocation. Key data structures: + struct _virResctrlAllocMon { + char *id; + char *path; + }; struct _virResctrlAlloc { virObject parent; @@ -276,6 +289,12 @@ struct _virResctrlAlloc { virResctrlAllocMemBWPtr mem_bw; + virResctrlAllocMonPtr *monitors; + size_t nmonitors; } Signed-off-by: Wang Huaqiang --- src/libvirt_private.syms | 6 + src/util/virresctrl.c | 361 +++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virresctrl.h | 31 ++++ 3 files changed, 394 insertions(+), 4 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 47ea35f..1439327 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2645,12 +2645,17 @@ virCacheKernelTypeFromString; virCacheKernelTypeToString; virCacheTypeFromString; virCacheTypeToString; +virResctrlAllocAddMonitorPID; virResctrlAllocAddPID; virResctrlAllocCreate; +virResctrlAllocCreateMonitor; +virResctrlAllocDeleteMonitor; +virResctrlAllocDetermineMonitorPath; virResctrlAllocDeterminePath; virResctrlAllocForeachCache; virResctrlAllocForeachMemory; virResctrlAllocFormat; +virResctrlAllocGetCacheOccupancy; virResctrlAllocGetID; virResctrlAllocGetUnused; virResctrlAllocNew; @@ -2658,6 +2663,7 @@ virResctrlAllocRemove; virResctrlAllocSetCacheSize; virResctrlAllocSetID; virResctrlAllocSetMemoryBandwidth; +virResctrlAllocSetMonitor; virResctrlInfoGetCache; virResctrlInfoNew; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index b3bae6e..7215a47 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -257,6 +257,19 @@ struct _virResctrlAllocMemBW { size_t nbandwidths; }; =20 + +typedef struct _virResctrlAllocMon virResctrlAllocMon; +typedef virResctrlAllocMon *virResctrlAllocMonPtr; +/* virResctrlAllocMon denotes a resctrl monitoring group reporting the res= ource + * consumption information for resource of either cache or memory + * bandwidth. */ +struct _virResctrlAllocMon { + /* monitoring group identifier, should be unique in scope of allocatio= n */ + char *id; + /* directory path under /sys/fs/resctrl*/ + char *path; +}; + struct _virResctrlAlloc { virObject parent; =20 @@ -265,11 +278,21 @@ struct _virResctrlAlloc { =20 virResctrlAllocMemBWPtr mem_bw; =20 + /* monintoring groups associated with current resource allocation + * it might report resource consumption information at a finer + * granularity */ + virResctrlAllocMonPtr *monitors; + size_t nmonitors; + /* The identifier (any unique string for now) */ char *id; /* libvirt-generated path in /sys/fs/resctrl for this particular * allocation */ char *path; + /* is this a default resctrl group? + * true : default group, directory path equals '/sys/fs/resctrl' + * false: non-default group */ + bool default_group; }; =20 =20 @@ -315,6 +338,13 @@ virResctrlAllocDispose(void *obj) VIR_FREE(alloc->mem_bw); } =20 + for (i =3D 0; i < alloc->nmonitors; i++) { + virResctrlAllocMonPtr monitor =3D alloc->monitors[i]; + VIR_FREE(monitor->id); + VIR_FREE(monitor->path); + VIR_FREE(monitor); + } + VIR_FREE(alloc->monitors); VIR_FREE(alloc->id); VIR_FREE(alloc->path); VIR_FREE(alloc->levels); @@ -805,6 +835,7 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_typ= e->control)); } =20 + cachemon->nfeatures =3D 0; cachemon->max_allocation =3D 0; =20 if (resctrl->monitor_info) { @@ -817,7 +848,7 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, if (STREQLEN(info->features[i], "llc_", strlen("llc_"))) { if (virStringListAdd(&cachemon->features, info->features[i]) < 0) - goto error; + goto error; cachemon->nfeatures++; } } @@ -841,10 +872,19 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, virResctrlAllocPtr virResctrlAllocNew(void) { + virResctrlAllocPtr ret =3D NULL; + if (virResctrlInitialize() < 0) return NULL; =20 - return virObjectNew(virResctrlAllocClass); + ret =3D virObjectNew(virResctrlAllocClass); + if (!ret) + return NULL; + + /* By default, a resource group is a default group */ + ret->default_group =3D true; + + return ret; } =20 =20 @@ -861,6 +901,9 @@ virResctrlAllocIsEmpty(virResctrlAllocPtr alloc) if (alloc->mem_bw) return false; =20 + if (alloc->nmonitors) + return false; + for (i =3D 0; i < alloc->nlevels; i++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[i]; =20 @@ -2124,10 +2167,18 @@ int virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, const char *machinename) { - return virResctrlDeterminePath(alloc->id, NULL, NULL, - machinename, &alloc->path); + if (alloc->default_group) { + if (VIR_STRDUP(alloc->path, SYSFS_RESCTRL_PATH) < 0) + return -1; + return 0; + } else { + + return virResctrlDeterminePath(alloc->id, NULL, NULL, + machinename, &alloc->path); + } } =20 + static int virResctrlCreateGroup(virResctrlInfoPtr resctrl, char *path) @@ -2169,6 +2220,27 @@ virResctrlCreateGroup(virResctrlInfoPtr resctrl, return ret; } =20 + /* In case of no explicit requirement for allocating cache and memory + * bandwidth, set 'alloc->default' to 'true', then the monitoring + * group will be created under '/sys/fs/resctrl/mon_groups' in later + * invocation of virResctrlAllocCreate. + * Otherwise, set 'alloc->default' to false, create a new directory + * under '/sys/fs/resctrl/'. This is will cost a hardware 'COSID'.*/ +static int +virResctrlAllocCheckDefault(virResctrlAllocPtr alloc) +{ + bool default_group =3D true; + if (!alloc) + return -1; + + if (alloc->nlevels) + default_group =3D false; + if (alloc->mem_bw && alloc->mem_bw->nbandwidths) + default_group =3D false; + + alloc->default_group =3D default_group; + return 0; +} =20 /* This checks if the directory for the alloc exists. If not it tries to = create * it and apply appropriate alloc settings. */ @@ -2185,6 +2257,8 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (!alloc) return 0; =20 + virResctrlAllocCheckDefault(alloc); + if (virResctrlAllocDeterminePath(alloc, machinename) < 0) return -1; =20 @@ -2275,10 +2349,289 @@ virResctrlAllocRemove(virResctrlAllocPtr alloc) return 0; =20 VIR_DEBUG("Removing resctrl allocation %s", alloc->path); + + while (alloc->nmonitors > 0) { + ret =3D virResctrlAllocDeleteMonitor(alloc, alloc->monitors[0]->id= ); + if (ret < 0) + goto cleanup; + } + if (rmdir(alloc->path) !=3D 0 && errno !=3D ENOENT) { ret =3D -errno; VIR_ERROR(_("Unable to remove %s (%d)"), alloc->path, errno); } =20 + ret =3D 0; + cleanup: + return ret; +} + + +static int +virResctrlAllocGetMonitor(virResctrlAllocPtr alloc, + const char *id, + virResctrlAllocMonPtr *monitor, + size_t *pos) +{ + size_t i =3D 0; + + if (!alloc || !id) + return -1; + + for (i =3D 0; i < alloc->nmonitors; i++) { + if (alloc->monitors[i]->id && + STREQ(id, (alloc->monitors[i])->id)) { + if (monitor) + *monitor =3D alloc->monitors[i]; + if (pos) + *pos =3D i; + return 0; + } + } + + return -1; +} + + +int +virResctrlAllocDetermineMonitorPath(virResctrlAllocPtr alloc, + const char *id, + const char *machinename) +{ + virResctrlAllocMonPtr monitor =3D NULL; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, NULL) < 0) + return -1; + + + return virResctrlDeterminePath(monitor->id, + alloc->path, + "mon_groups", + machinename, + &monitor->path); +} + + +int +virResctrlAllocAddMonitorPID(virResctrlAllocPtr alloc, + const char *id, + pid_t pid) +{ + virResctrlAllocMonPtr monitor =3D NULL; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, NULL) < 0) + return -1; + + return virResctrlAddPID(monitor->path, pid); +} + + +int +virResctrlAllocSetMonitor(virResctrlAllocPtr alloc, + const char *id) +{ + virResctrlAllocMonPtr monitor =3D NULL; + + if (!alloc || !id) + return - 1; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, NULL) < 0) { + if (VIR_ALLOC(monitor) < 0) + return -1; + } + + if (VIR_STRDUP(monitor->id, (char*)id) < 0) + return -1; + + if (VIR_APPEND_ELEMENT(alloc->monitors, alloc->nmonitors, monitor) < 0) + return -1; + + return 0; +} + +int +virResctrlAllocCreateMonitor(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + const char *machinename, + const char *id) +{ + virResctrlAllocMonPtr monitor =3D NULL; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, NULL) < 0) + return - 1; + + if (virResctrlAllocDetermineMonitorPath(alloc, id, machinename) < 0) + return -1; + + VIR_DEBUG("Creating resctrl monitor %s", monitor->path); + if (virResctrlCreateGroup(resctrl, monitor->path) < 0) + return -1; + + return 0; +} + + +int +virResctrlAllocDeleteMonitor(virResctrlAllocPtr alloc, + const char *id) +{ + int ret =3D 0; + + virResctrlAllocMonPtr monitor =3D NULL; + size_t pos =3D 0; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, &pos) < 0) + return -1; + + VIR_DELETE_ELEMENT(alloc->monitors, pos, alloc->nmonitors); + + VIR_DEBUG("Deleting resctrl monitor %s ", monitor->path); + if (rmdir(monitor->path) !=3D 0 && errno !=3D ENOENT) { + ret =3D -errno; + VIR_ERROR(_("Unable to remove %s (%d)"), monitor->path, errno); + } + + VIR_FREE(monitor->id); + VIR_FREE(monitor->path); + VIR_FREE(monitor); + return ret; +} + + +static int +virResctrlAllocGetStatistic(virResctrlAllocPtr alloc, + const char *id, + const char *resfile, + unsigned int *nnodes, + unsigned int **nodeids, + unsigned int **nodevals) +{ + DIR *dirp =3D NULL; + int ret =3D -1; + int rv =3D -1; + struct dirent *ent =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *mondatapath =3D NULL; + size_t ntmpid =3D 0; + size_t ntmpval =3D 0; + virResctrlAllocMonPtr monitor =3D NULL; + + if (!nnodes || !nodeids || !nodevals) + return -1; + + if (virResctrlAllocGetMonitor(alloc, id, &monitor, NULL) < 0) + goto cleanup; + + if (!monitor || !monitor->path) + goto cleanup; + + rv =3D virDirOpenIfExists(&dirp, monitor->path); + if (rv <=3D 0) + goto cleanup; + + *nnodes =3D 0; + + virBufferAsprintf(&buf, "%s/mon_data", monitor->path); + + mondatapath =3D virBufferContentAndReset(&buf); + if (!mondatapath) + goto cleanup; + + if (virDirOpen(&dirp, mondatapath) < 0) + goto cleanup; + + while ((rv =3D virDirRead(dirp, &ent, mondatapath)) > 0) { + char *pstrid =3D NULL; + size_t i =3D 0; + unsigned int len =3D 0; + unsigned int counter =3D 0; + unsigned int cacheid =3D 0; + unsigned int cur_cacheid =3D 0; + unsigned int val =3D 0; + int tmpnodeid =3D 0; + int tmpnodeval =3D 0; + + if (ent->d_type !=3D DT_DIR) + continue; + + /* mon_L3(|CODE|DATA)_xx, xx is cache id */ + if (STRNEQLEN(ent->d_name, "mon_L", 5)) + continue; + + len =3D strlen(ent->d_name); + pstrid =3D ent->d_name; + /* locating the cache id string: 'xx' */ + for (i =3D 0; i < len; i++) { + if (*(pstrid + i) =3D=3D '_') + counter ++; + if (counter =3D=3D 2) + break; + } + i++; + + if (i >=3D len) + goto cleanup; + + if (virStrToLong_uip(pstrid + i, NULL, 0, &cacheid) < 0) { + VIR_DEBUG("Cannot parse id from folder '%s'", ent->d_name); + goto cleanup; + } + + rv =3D virFileReadValueUint(&val, + "%s/%s/%s", + mondatapath, ent->d_name, resfile); + + if (rv =3D=3D -2) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("file %s/%s/%s does not exist"), + mondatapath, ent->d_name, resfile); + goto cleanup; + } else { + if (rv < 0) + goto cleanup; + } + + /* The ultimate caller will be responiblefor free memory of + * 'nodeids' an 'nodevals' */ + if (VIR_APPEND_ELEMENT(*nodeids, ntmpid, cacheid) < 0) + goto cleanup; + if (VIR_APPEND_ELEMENT(*nodevals, ntmpval, val) < 0) + goto cleanup; + + cur_cacheid =3D ntmpval - 1; + /* sort the cache information in caach bank id's ascending order */ + for (i =3D 0; i < cur_cacheid; i++) { + if ((*nodeids)[cur_cacheid] < (*nodeids)[i]) { + tmpnodeid =3D (*nodeids)[cur_cacheid]; + tmpnodeval =3D (*nodevals)[cur_cacheid]; + (*nodeids)[cur_cacheid] =3D (*nodeids)[i]; + (*nodevals)[cur_cacheid] =3D (*nodevals)[i]; + (*nodeids)[i] =3D tmpnodeid; + (*nodevals)[i] =3D tmpnodeval; + } + } + } + + (*nnodes) =3D ntmpval; + ret =3D 0; + cleanup: + VIR_FREE(mondatapath); + VIR_DIR_CLOSE(dirp); + return ret; +} + + +int +virResctrlAllocGetCacheOccupancy(virResctrlAllocPtr alloc, + const char *id, + unsigned int *nbank, + unsigned int **bankids, + unsigned int **bankcaches) +{ + int ret =3D - 1; + + ret =3D virResctrlAllocGetStatistic(alloc, id, "llc_occupancy", + nbank, bankids, bankcaches); + return ret; } diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 51bb68b..0f63997 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -160,4 +160,35 @@ virResctrlAllocAddPID(virResctrlAllocPtr alloc, int virResctrlAllocRemove(virResctrlAllocPtr alloc); =20 +int +virResctrlAllocDetermineMonitorPath(virResctrlAllocPtr alloc, + const char *id, + const char *machinename); + +int +virResctrlAllocAddMonitorPID(virResctrlAllocPtr alloc, + const char *id, + pid_t pid); + +int +virResctrlAllocSetMonitor(virResctrlAllocPtr alloc, + const char *id); + +int +virResctrlAllocCreateMonitor(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc, + const char *machinename, + const char *id); + +int +virResctrlAllocDeleteMonitor(virResctrlAllocPtr alloc, + const char *id); + +int +virResctrlAllocGetCacheOccupancy(virResctrlAllocPtr alloc, + const char *id, + unsigned int *nbank, + unsigned int **bankids, + unsigned int **bankcaches); + #endif /* __VIR_RESCTRL_H__ */ --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373584597501.67948147977256; Mon, 27 Aug 2018 05:39:44 -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 5B344307D85F; Mon, 27 Aug 2018 12:39:42 +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 1E0B518814; Mon, 27 Aug 2018 12:39:42 +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 BD38B24F5F; Mon, 27 Aug 2018 12:39:41 +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 w7RBO44x024671 for ; Mon, 27 Aug 2018 07:24:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2856A5FC3B; Mon, 27 Aug 2018 11:24:04 +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 1F2AB5F701 for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 E3C9581DE5 for ; Mon, 27 Aug 2018 11:23:59 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:49 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804973" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:10 +0800 Message-Id: <1535368993-24901-8-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 07/10] conf: refactor virDomainResctrlAppend 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.48]); Mon, 27 Aug 2018 12:39:43 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Changed the interface from virDomainResctrlAppend(virDomainDefPtr def, xmlNodePtr node, virResctrlAllocPtr alloc, virBitmapPtr vcpus, unsigned int flags); to virDomainResctrlAppend(virDomainDefPtr def, xmlNodePtr node, virDomainResctrlDefPtr resctrl, unsigned int flags); Changes will let virDomainRestrlAppend pass through more information with virDomainResctrlDefPtr, such as monitoring groups associated with the allocation. Signed-off-by: Wang Huaqiang --- src/conf/domain_conf.c | 48 ++++++++++++++++++++++++++++++++++------------= -- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bde9fef..9a65655 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19247,17 +19247,21 @@ virDomainCachetuneDefParseCache(xmlXPathContextPt= r ctxt, static int virDomainResctrlAppend(virDomainDefPtr def, xmlNodePtr node, - virResctrlAllocPtr alloc, - virBitmapPtr vcpus, + virDomainResctrlDefPtr resctrl, unsigned int flags) { char *vcpus_str =3D NULL; char *alloc_id =3D NULL; - virDomainResctrlDefPtr tmp_resctrl =3D NULL; + virResctrlAllocPtr alloc =3D NULL; + virBitmapPtr vcpus =3D NULL; + int ret =3D -1; =20 - if (VIR_ALLOC(tmp_resctrl) < 0) - goto cleanup; + if (!resctrl) + return -1; + + alloc =3D virObjectRef(resctrl->alloc); + vcpus =3D resctrl->vcpus; =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. */ @@ -19281,15 +19285,12 @@ virDomainResctrlAppend(virDomainDefPtr def, if (virResctrlAllocSetID(alloc, alloc_id) < 0) goto cleanup; =20 - tmp_resctrl->vcpus =3D vcpus; - tmp_resctrl->alloc =3D alloc; - - if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0) + if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, resctrl) < 0) goto cleanup; =20 ret =3D 0; cleanup: - virDomainResctrlDefFree(tmp_resctrl); + virObjectUnref(alloc); VIR_FREE(alloc_id); VIR_FREE(vcpus_str); return ret; @@ -19306,6 +19307,8 @@ virDomainCachetuneDefParse(virDomainDefPtr def, xmlNodePtr *nodes =3D NULL; virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D NULL; + virDomainResctrlDefPtr tmp_resctrl =3D NULL; + ssize_t i =3D 0; int n; int ret =3D -1; @@ -19349,15 +19352,24 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 - if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0) + if (VIR_ALLOC(tmp_resctrl) < 0) goto cleanup; - vcpus =3D NULL; + + tmp_resctrl->vcpus =3D vcpus; + tmp_resctrl->alloc =3D virObjectRef(alloc); + + if (virDomainResctrlAppend(def, node, tmp_resctrl, flags) < 0) + goto cleanup; + alloc =3D NULL; + vcpus =3D NULL; + tmp_resctrl =3D NULL; =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; virObjectUnref(alloc); + VIR_FREE(tmp_resctrl); virBitmapFree(vcpus); VIR_FREE(nodes); return ret; @@ -19514,6 +19526,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, xmlNodePtr *nodes =3D NULL; virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D NULL; + virDomainResctrlDefPtr tmp_resctrl =3D NULL; ssize_t i =3D 0; int n; int ret =3D -1; @@ -19560,17 +19573,24 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, * just update the existing alloc information, which is done in above * virDomainMemorytuneDefParseMemory */ if (new_alloc) { - if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0) + if (VIR_ALLOC(tmp_resctrl) < 0) + goto cleanup; + + tmp_resctrl->alloc =3D virObjectRef(alloc); + tmp_resctrl->vcpus =3D vcpus; + if (virDomainResctrlAppend(def, node, tmp_resctrl, flags) < 0) goto cleanup; vcpus =3D NULL; alloc =3D NULL; + tmp_resctrl =3D NULL; } =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; - virObjectUnref(alloc); virBitmapFree(vcpus); + virObjectUnref(alloc); + VIR_FREE(tmp_resctrl); VIR_FREE(nodes); return ret; } --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373580294619.6078210714195; Mon, 27 Aug 2018 05:39:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D1008553C; Mon, 27 Aug 2018 12:39:38 +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 1829C19E1C; Mon, 27 Aug 2018 12:39:38 +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 BACC124F5A; Mon, 27 Aug 2018 12:39:37 +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 w7RBO3Ll024666 for ; Mon, 27 Aug 2018 07:24:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id BDDF860157; Mon, 27 Aug 2018 11:24:03 +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 B6A4619CBA for ; Mon, 27 Aug 2018 11:24:01 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 8E9FB30832C8 for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:51 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804975" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:11 +0800 Message-Id: <1535368993-24901-9-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 27 Aug 2018 11:24:00 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 08/10] conf: introduce resctrl monitor group in domain 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 27 Aug 2018 12:39:39 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce resource monitoring group in domain configuration file to support CPU cache monitoring technology (CMT). Domain rng file changes, supporting following types of resource monitoring group regarding the allocation regin it belongs to: 1. monitoring group that working for partial working thread of current allocation: e.g. "" creates monitoring group special for vcpu '0' while an allocation group is created for vcpus of '0' *and* '1'. 2. monitoring group for whole vcpu set of current allocation: e.g. "" creates monitoring group for all vcpus belonging to current allocation. 3. monitoring group for vcpu(s) that does not have dedicated allocation group: e.g. "" creates a monitoring group but no resource control applied to it. + + + + Signed-off-by: Wang Huaqiang --- docs/formatdomain.html.in | 14 ++- docs/schemas/domaincommon.rng | 11 +- src/conf/domain_conf.c | 131 +++++++++++++++++= +--- src/conf/domain_conf.h | 20 ++++ tests/genericxml2xmlindata/cachetune-cdp.xml | 2 + .../cachetune-colliding-monitors.xml | 36 ++++++ tests/genericxml2xmlindata/cachetune-small.xml | 1 + tests/genericxml2xmlindata/cachetune.xml | 3 + tests/genericxml2xmltest.c | 4 + 9 files changed, 204 insertions(+), 18 deletions(-) create mode 100644 tests/genericxml2xmlindata/cachetune-colliding-monitors= .xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0cbf570..33d2890 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -758,6 +758,7 @@ <cachetune vcpus=3D'0-3'> <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'= /> + <monitor vcpus=3D'0-1'/> </cachetune> <memorytune vcpus=3D'0-3'> <node id=3D'0' bandwidth=3D'60'/> @@ -942,8 +943,8 @@
cache
- This element controls the allocation of CPU cache and has the - following attributes: + This optional element controls the allocation of CPU cache and= has + the following attributes:
level
@@ -977,6 +978,15 @@
+
monitor
+
+ The optional element monitor creates the cahce + monitoring group(s) for current cache allocation group. The re= quired + attribute vcpus specifies to which vCPUs this + monitoring group applies. A vCPU can only be member of one + cachetune element allocation. And no overlap is + permitted. +
=20 diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index f176538..83fb9b7 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -956,7 +956,7 @@ - + @@ -980,7 +980,14 @@ - + + + + + + + +
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9a65655..304a94e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2969,13 +2969,30 @@ virDomainLoaderDefFree(virDomainLoaderDefPtr loader) =20 =20 static void +virDomainResctrlMonFree(virDomainResctrlMonitorPtr monitor) +{ + if (!monitor) + return; + + VIR_FREE(monitor->id); + virBitmapFree(monitor->vcpus); + VIR_FREE(monitor); +} + + +static void virDomainResctrlDefFree(virDomainResctrlDefPtr resctrl) { + size_t i =3D 0; + if (!resctrl) return; =20 virObjectUnref(resctrl->alloc); virBitmapFree(resctrl->vcpus); + for (i =3D 0; i < resctrl->nmonitors; i++) + virDomainResctrlMonFree(resctrl->monitors[i]); + VIR_FREE(resctrl->monitors); VIR_FREE(resctrl); } =20 @@ -19298,6 +19315,71 @@ virDomainResctrlAppend(virDomainDefPtr def, =20 =20 static int +virDomainResctrlParseMonitor(virDomainDefPtr def, + xmlXPathContextPtr ctxt, + xmlNodePtr node, + virDomainResctrlDefPtr resctrl) +{ + xmlNodePtr oldnode =3D ctxt->node; + virBitmapPtr vcpus =3D NULL; + char *id =3D NULL; + int vcpu =3D -1; + char *vcpus_str =3D NULL; + virDomainResctrlMonitorPtr tmp_domresmon =3D NULL; + int ret =3D -1; + + if (!resctrl || !resctrl->vcpus || !resctrl->alloc) + return -1; + + ctxt->node =3D node; + + if (VIR_ALLOC(tmp_domresmon) < 0) + goto cleanup; + + if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0) + goto cleanup; + + /* empty monitoring group is not allowed */ + if (virBitmapIsAllClear(vcpus)) + goto cleanup; + + while ((vcpu =3D virBitmapNextSetBit(vcpus, vcpu)) >=3D 0) { + if (!virBitmapIsBitSet(resctrl->vcpus, vcpu)) + goto cleanup; + } + + vcpus_str =3D virBitmapFormat(vcpus); + if (!vcpus_str) + goto cleanup; + + if (virAsprintf(&id, "vcpus_%s", vcpus_str) < 0) + goto cleanup; + + if (VIR_STRDUP(tmp_domresmon->id, id) < 0) + goto cleanup; + + tmp_domresmon->vcpus =3D vcpus; + + if (VIR_APPEND_ELEMENT(resctrl->monitors, + resctrl->nmonitors, + tmp_domresmon) < 0) + goto cleanup; + + if (virResctrlAllocSetMonitor(resctrl->alloc, id) < 0) + goto cleanup; + + tmp_domresmon =3D NULL; + ret =3D 0; + cleanup: + ctxt->node =3D oldnode; + VIR_FREE(id); + VIR_FREE(vcpus_str); + virDomainResctrlMonFree(tmp_domresmon); + return ret; +} + + +static int virDomainCachetuneDefParse(virDomainDefPtr def, xmlXPathContextPtr ctxt, xmlNodePtr node, @@ -19313,6 +19395,9 @@ virDomainCachetuneDefParse(virDomainDefPtr def, int n; int ret =3D -1; =20 + if (VIR_ALLOC(tmp_resctrl) < 0) + return -1; + ctxt->node =3D node; =20 if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0) @@ -19347,30 +19432,40 @@ virDomainCachetuneDefParse(virDomainDefPtr def, goto cleanup; } =20 - if (virResctrlAllocIsEmpty(alloc)) { - ret =3D 0; + tmp_resctrl->vcpus =3D vcpus; + tmp_resctrl->alloc =3D virObjectRef(alloc); + + VIR_FREE(nodes); + ctxt->node =3D node; + + if ((n =3D virXPathNodeSet("./monitor", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot extract monitor nodes under cachetune")); goto cleanup; } =20 - if (VIR_ALLOC(tmp_resctrl) < 0) - goto cleanup; + for (i =3D 0; i < n; i++) { + if (virDomainResctrlParseMonitor(def, ctxt, + nodes[i], tmp_resctrl) < 0) =20 - tmp_resctrl->vcpus =3D vcpus; - tmp_resctrl->alloc =3D virObjectRef(alloc); + goto cleanup; + } + + if (virResctrlAllocIsEmpty(alloc)) { + VIR_WARN("cachetune: resctrl alloc is empty"); + ret =3D 0; + goto cleanup; + } =20 if (virDomainResctrlAppend(def, node, tmp_resctrl, flags) < 0) goto cleanup; =20 - alloc =3D NULL; - vcpus =3D NULL; tmp_resctrl =3D NULL; =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; - virObjectUnref(alloc); - VIR_FREE(tmp_resctrl); - virBitmapFree(vcpus); + virDomainResctrlDefFree(tmp_resctrl); VIR_FREE(nodes); return ret; } @@ -19588,10 +19683,8 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ret =3D 0; cleanup: ctxt->node =3D oldnode; - virBitmapFree(vcpus); - virObjectUnref(alloc); - VIR_FREE(tmp_resctrl); VIR_FREE(nodes); + virDomainResctrlDefFree(tmp_resctrl); return ret; } =20 @@ -27394,6 +27487,7 @@ virDomainCachetuneDefFormat(virBufferPtr buf, { virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; char *vcpus =3D NULL; + size_t i =3D 0; int ret =3D -1; =20 virBufferSetChildIndent(&childrenBuf, buf); @@ -27405,6 +27499,15 @@ virDomainCachetuneDefFormat(virBufferPtr buf, if (virBufferCheckError(&childrenBuf) < 0) goto cleanup; =20 + for (i =3D 0; i < resctrl->nmonitors; i++) { + vcpus =3D virBitmapFormat(resctrl->monitors[i]->vcpus); + if (!vcpus) + goto cleanup; + + virBufferAsprintf(&childrenBuf, "\n", vcpus= ); + VIR_FREE(vcpus); + } + if (!virBufferUse(&childrenBuf)) { ret =3D 0; goto cleanup; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c0ad072..797b4bd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2235,12 +2235,31 @@ struct _virDomainCputune { }; =20 =20 +typedef enum { + VIR_DOMAIN_RESCTRL_MONITOR_CACHE, + VIR_DOMAIN_RESCTRL_MONITOR_MEMBW, + VIR_DOMAIN_RESCTRL_MONITOR_CACHE_MEMBW, + + VIR_DOMAIN_RESCTRL_MONITOR_LAST +} virDomainResctrlMonType; + +typedef struct _virDomainResctrlMonitor virDomainResctrlMonitor; +typedef virDomainResctrlMonitor *virDomainResctrlMonitorPtr; +struct _virDomainResctrlMonitor { + int type; /* virDomainResctrlMonType*/ + char *id; + virBitmapPtr vcpus; +}; + + typedef struct _virDomainResctrlDef virDomainResctrlDef; typedef virDomainResctrlDef *virDomainResctrlDefPtr; =20 struct _virDomainResctrlDef { virBitmapPtr vcpus; virResctrlAllocPtr alloc; + virDomainResctrlMonitorPtr *monitors; + size_t nmonitors; }; =20 =20 @@ -3455,6 +3474,7 @@ VIR_ENUM_DECL(virDomainIOMMUModel) VIR_ENUM_DECL(virDomainVsockModel) VIR_ENUM_DECL(virDomainShmemModel) VIR_ENUM_DECL(virDomainLaunchSecurity) +VIR_ENUM_DECL(virDomainResctrlMonType) /* from libvirt.h */ VIR_ENUM_DECL(virDomainState) VIR_ENUM_DECL(virDomainNostateReason) diff --git a/tests/genericxml2xmlindata/cachetune-cdp.xml b/tests/genericxm= l2xmlindata/cachetune-cdp.xml index 9718f06..b257fd5 100644 --- a/tests/genericxml2xmlindata/cachetune-cdp.xml +++ b/tests/genericxml2xmlindata/cachetune-cdp.xml @@ -8,9 +8,11 @@ + + diff --git a/tests/genericxml2xmlindata/cachetune-colliding-monitors.xml b/= tests/genericxml2xmlindata/cachetune-colliding-monitors.xml new file mode 100644 index 0000000..7526070 --- /dev/null +++ b/tests/genericxml2xmlindata/cachetune-colliding-monitors.xml @@ -0,0 +1,36 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 4 + + + + + + + + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/genericxml2xmlindata/cachetune-small.xml b/tests/generic= xml2xmlindata/cachetune-small.xml index ab2d9cf..aa7b2c3 100644 --- a/tests/genericxml2xmlindata/cachetune-small.xml +++ b/tests/genericxml2xmlindata/cachetune-small.xml @@ -7,6 +7,7 @@ + diff --git a/tests/genericxml2xmlindata/cachetune.xml b/tests/genericxml2xm= lindata/cachetune.xml index 645cab7..52e95bc 100644 --- a/tests/genericxml2xmlindata/cachetune.xml +++ b/tests/genericxml2xmlindata/cachetune.xml @@ -8,9 +8,12 @@ + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index e6d4ef2..bc2fc50 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -140,11 +140,15 @@ 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_FULL("cachetune-colliding-monitors", 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); + DO_TEST_FULL("cachetune-colliding-monitors", 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 Sun Apr 28 00:38:29 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 1535373588213931.5923415248418; Mon, 27 Aug 2018 05:39:48 -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 35BCBC059B8B; Mon, 27 Aug 2018 12:39:46 +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 EAA275D964; Mon, 27 Aug 2018 12:39:45 +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 9FBC024BC3; Mon, 27 Aug 2018 12:39:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7RBO4rQ024679 for ; Mon, 27 Aug 2018 07:24:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id C74A22010D04; Mon, 27 Aug 2018 11:24:04 +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 BEFE52010CBC for ; Mon, 27 Aug 2018 11:24:01 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 DBF5288E4F for ; Mon, 27 Aug 2018 11:24:00 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:52 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804977" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:12 +0800 Message-Id: <1535368993-24901-10-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:24:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Aug 2018 11:24:01 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 09/10] qemu: Introduce resctrl monitoring group 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.32]); Mon, 27 Aug 2018 12:39:46 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Resource monitoring group monitors the resource consumption, cache and memory bandwidth, of particular resctrl allocation. Introduce the resctrl monitoring group. Signed-off-by: Wang Huaqiang --- src/qemu/qemu_process.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 960c3ed..e70aa5e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2593,6 +2593,7 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver, { int ret =3D -1; size_t i =3D 0; + size_t j =3D 0; virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 @@ -2610,6 +2611,20 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver, vm->def->resctrls[i]->alloc, priv->machineName) < 0) goto cleanup; + + /* Create resctrl monitoring groups associated with allocation */ + for (j =3D 0; j < vm->def->resctrls[i]->nmonitors; j++) { + virDomainResctrlMonitorPtr monitor =3D NULL; + monitor =3D vm->def->resctrls[i]->monitors[j]; + + if (virResctrlAllocCreateMonitor(caps->host.resctrl, + vm->def->resctrls[i]->alloc, + priv->machineName, + monitor->id) < 0) + + goto cleanup; + + } } =20 ret =3D 0; @@ -5419,7 +5434,9 @@ qemuProcessSetupVcpu(virDomainObjPtr vm, { pid_t vcpupid =3D qemuDomainGetVcpuPid(vm, vcpuid); virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(vm->def, vcpuid); + virDomainResctrlMonitorPtr mon =3D NULL; size_t i =3D 0; + size_t j =3D 0; =20 if (qemuProcessSetupPid(vm, vcpupid, VIR_CGROUP_THREAD_VCPU, vcpuid, vcpu->cpumask, @@ -5434,7 +5451,15 @@ qemuProcessSetupVcpu(virDomainObjPtr vm, if (virBitmapIsBitSet(ct->vcpus, vcpuid)) { if (virResctrlAllocAddPID(ct->alloc, vcpupid) < 0) return -1; - break; + } + + for (j =3D 0; j < vm->def->resctrls[i]->nmonitors; j++) { + mon =3D vm->def->resctrls[i]->monitors[j]; + if (virBitmapIsBitSet(mon->vcpus, vcpuid)) { + if (virResctrlAllocAddMonitorPID(ct->alloc, + mon->id, vcpupid) < 0) + return -1; + } } } =20 @@ -7747,10 +7772,12 @@ qemuProcessReconnect(void *opaque) int reason; virQEMUDriverConfigPtr cfg; size_t i; + size_t j; unsigned int stopFlags =3D 0; bool jobStarted =3D false; virCapsPtr caps =3D NULL; bool retry =3D true; + virDomainResctrlDefPtr resctrl =3D NULL; =20 VIR_FREE(data); =20 @@ -7934,9 +7961,18 @@ qemuProcessReconnect(void *opaque) goto error; =20 for (i =3D 0; i < obj->def->nresctrls; i++) { - if (virResctrlAllocDeterminePath(obj->def->resctrls[i]->alloc, + resctrl =3D obj->def->resctrls[i]; + + if (virResctrlAllocDeterminePath(resctrl->alloc, priv->machineName) < 0) goto error; + + for (j =3D 0; j < resctrl->nmonitors; j++) { + if (virResctrlAllocDetermineMonitorPath(resctrl->alloc, + resctrl->monitors[j]->= id, + priv->machineName) < 0) + goto error; + } } =20 /* update domain state XML with possibly updated state in virDomainObj= */ --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:38:29 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 1535373592403997.0279200458021; Mon, 27 Aug 2018 05:39:52 -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 1F9D036A5E6; Mon, 27 Aug 2018 12:39:50 +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 DB32A70BA3; Mon, 27 Aug 2018 12:39:49 +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 81DDC181A55B; Mon, 27 Aug 2018 12:39:49 +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 w7RBO66t024696 for ; Mon, 27 Aug 2018 07:24:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E21A5D9CC; Mon, 27 Aug 2018 11:24:06 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6373B5D9CD for ; Mon, 27 Aug 2018 11:24:02 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 031AE30842AD for ; Mon, 27 Aug 2018 11:24:01 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2018 04:23:56 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 27 Aug 2018 04:23:54 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,295,1531810800"; d="scan'208";a="84804981" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 19:23:13 +0800 Message-Id: <1535368993-24901-11-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> References: <1535368993-24901-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:24:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 27 Aug 2018 11:24:01 +0000 (UTC) for IP:'134.134.136.20' DOMAIN:'mga02.intel.com' HELO:'mga02.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.20 mga02.intel.com 134.134.136.20 mga02.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 27 Aug 2018 08:39:21 -0400 Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCH 10/10] qemu: Report cache occupancy (CMT) with domstats 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.29]); Mon, 27 Aug 2018 12:39:51 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Intel x86 RDT CMT is the technology to tell the last level cache occupancy information. Adding the interface in qemu to report this information for resource monitor group through command 'virsh domstats --cpu-total'. Below is a typical output: # virsh domstats 1 --cpu-total Domain: 'ubuntu16.04-base' ... cpu.cache.monitor.count=3D2 cpu.cache.0.name=3Dvcpus_1 cpu.cache.0.vcpus=3D1 cpu.cache.0.bank.count=3D2 cpu.cache.0.bank.0.id=3D0 cpu.cache.0.bank.0.bytes=3D4505600 cpu.cache.0.bank.1.id=3D1 cpu.cache.0.bank.1.bytes=3D5586944 cpu.cache.1.name=3Dvcpus_4-6 cpu.cache.1.vcpus=3D4,5,6 cpu.cache.1.bank.count=3D2 cpu.cache.1.bank.0.id=3D0 cpu.cache.1.bank.0.bytes=3D17571840 cpu.cache.1.bank.1.id=3D1 cpu.cache.1.bank.1.bytes=3D29106176 Signed-off-by: Wang Huaqiang --- src/libvirt-domain.c | 9 ++ src/qemu/qemu_driver.c | 265 +++++++++++++++++++++++++++++++++++++++++++++= ---- 2 files changed, 253 insertions(+), 21 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index ef46027..a88e94a 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11337,6 +11337,15 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * "cpu.user" - user cpu time spent in nanoseconds as unsigned long lo= ng. * "cpu.system" - system cpu time spent in nanoseconds as unsigned long * long. + * "cpu.cache.monitor.count" - tocal cache monitoring groups + * "cpu.cache.M.name" - name for cache monitoring group 'M' + * "cpu.cache.M.vcpus" - vcpus for cache monitoring group 'M' + * "cpu.cache.M.bank.count" - total bank number for cache monitoring + * group 'M' + * "cpu.cache.M.bank.N.id" - OS assigned cache bank id for cache 'N' in + * cache monitoring group 'M' + * "cpu.cache.M.bank.N.bytes" - cache occupancy of cache bank 'N' in + * cache monitoring group 'M' * * VIR_DOMAIN_STATS_BALLOON: * Return memory balloon device information. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index da8c4e8..193f606 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -107,6 +107,7 @@ #include "virnuma.h" #include "dirname.h" #include "netdev_bandwidth_conf.h" +#include "c-ctype.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -19660,6 +19661,225 @@ typedef enum { #define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB) =20 =20 +/* + * qemuDomainVcpuFormatHelper + * For vcpu string, both '1-3' and '1,3' are valid format and + * representing different vcpu set, but it is not easy to + * differentiate them at first galance, to avoid this case + * substituting all '-' with ',', e.g. substitute string '1-3' + * with '1,2,3'. + */ +static int +qemuDomainVcpuFormatHelper(char **vcpus) +{ + const char *cur =3D NULL; + size_t i =3D 0; + char *tmp =3D NULL; + int start, last; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + bool firstnum =3D 1; + + if (!*vcpus) + goto error; + + cur =3D *vcpus; + + virSkipSpaces(&cur); + + if (*cur =3D=3D '\0') + goto error; + + while (*cur !=3D 0) { + if (!c_isdigit(*cur)) + goto error; + + if (virStrToLong_i(cur, &tmp, 10, &start) < 0) + goto error; + if (start < 0) + goto error; + + cur =3D tmp; + + virSkipSpaces(&cur); + + if (*cur =3D=3D ',' || *cur =3D=3D 0) { + if (!firstnum) + virBufferAddChar(&buf, ','); + virBufferAsprintf(&buf, "%d", start); + firstnum =3D 0; + } else if (*cur =3D=3D '-') { + cur++; + virSkipSpaces(&cur); + + if (virStrToLong_i(cur, &tmp, 10, &last) < 0) + + goto error; + if (last < start) + goto error; + cur =3D tmp; + + for (i =3D start; i <=3D last; i++) { + if (!firstnum) + + virBufferAddChar(&buf, ','); + virBufferAsprintf(&buf, "%ld", i); + firstnum =3D 0; + } + + virSkipSpaces(&cur); + } + + if (*cur =3D=3D ',') { + cur++; + virSkipSpaces(&cur); + } else if (*cur =3D=3D 0) { + break; + } else { + goto error; + } + } + VIR_FREE(*vcpus); + *vcpus =3D virBufferContentAndReset(&buf); + return 0; + error: + virBufferFreeAndReset(&buf); + return -1; +} + +static int +qemuDomainGetStatsCpuResource(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, + virDomainObjPtr dom, + virDomainStatsRecordPtr record, + int *maxparams, + unsigned int privflags ATTRIBUTE_UNUSED) +{ + size_t i =3D 0; + size_t j =3D 0; + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + virDomainResctrlDefPtr resctrl =3D NULL; + virDomainResctrlMonitorPtr monitor =3D NULL; + unsigned int nvals =3D 0; + unsigned int *ids =3D NULL; + unsigned int *vals =3D NULL; + unsigned int nmonitor =3D NULL; + char *vcpustr =3D NULL; + int ret =3D -1; + + for (i =3D 0; i < dom->def->nresctrls; i++) { + resctrl =3D dom->def->resctrls[i]; + + for (j =3D 0; j < resctrl->nmonitors; j++) { + monitor =3D resctrl->monitors[j]; + if (monitor->vcpus) + nmonitor++; + } + } + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.count"); + if (virTypedParamsAddUInt(&record->params, + &record->nparams, + maxparams, + param_name, + nmonitor) < 0) + goto cleanup; + + for (i =3D 0; i < dom->def->nresctrls; i++) { + resctrl =3D dom->def->resctrls[i]; + + for (j =3D 0; j < resctrl->nmonitors; j++) { + size_t l =3D 0; + + monitor =3D resctrl->monitors[j]; + + if (!(vcpustr =3D virBitmapFormat(monitor->vcpus))) + goto cleanup; + + if (qemuDomainVcpuFormatHelper(&vcpustr) < 0) + goto cleanup; + + switch ((virDomainResctrlMonType) monitor->type) { + case VIR_DOMAIN_RESCTRL_MONITOR_CACHE: + case VIR_DOMAIN_RESCTRL_MONITOR_CACHE_MEMBW: + if (!monitor->vcpus) + continue; + + if (virResctrlAllocGetCacheOccupancy(resctrl->alloc, + monitor->id, &nvals, + &ids, &vals) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.%ld.name", i); + if (virTypedParamsAddString(&record->params, + &record->nparams, + maxparams, + param_name, + monitor->id) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.%ld.vcpus", i); + + if (virTypedParamsAddString(&record->params, + &record->nparams, + maxparams, + param_name, + vcpustr) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.%ld.bank.count", i); + if (virTypedParamsAddUInt(&record->params, + &record->nparams, + maxparams, + param_name, + nvals) < 0) + goto cleanup; + + for (l =3D 0; l < nvals; l++) { + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.%ld.bank.%ld.id", i, l); + if (virTypedParamsAddUInt(&record->params, + &record->nparams, + maxparams, + param_name, + ids[l]) < 0) + goto cleanup; + + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.%ld.bank.%ld.bytes", i, l); + if (virTypedParamsAddUInt(&record->params, + &record->nparams, + maxparams, + param_name, + vals[l]) < 0) + goto cleanup; + } + break; + + case VIR_DOMAIN_RESCTRL_MONITOR_MEMBW: + case VIR_DOMAIN_RESCTRL_MONITOR_LAST: + default: + break; + } + + VIR_FREE(ids); + VIR_FREE(vals); + VIR_FREE(vcpustr); + nvals =3D 0; + } + } + + ret =3D 0; + cleanup: + VIR_FREE(ids); + VIR_FREE(vals); + VIR_FREE(vcpustr); + return ret; +} + static int qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr dom, @@ -19673,29 +19893,32 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATT= RIBUTE_UNUSED, unsigned long long sys_time =3D 0; int err =3D 0; =20 - if (!priv->cgroup) - return 0; + if (priv->cgroup) { + err =3D virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time); + if (!err && virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + "cpu.time", + cpu_time) < 0) + return -1; =20 - err =3D virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time); - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.time", - cpu_time) < 0) - return -1; + err =3D virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_tim= e); + if (!err && virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + "cpu.user", + user_time) < 0) + return -1; + if (!err && virTypedParamsAddULLong(&record->params, + &record->nparams, + maxparams, + "cpu.system", + sys_time) < 0) + return -1; + } =20 - err =3D virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time); - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.user", - user_time) < 0) - return -1; - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.system", - sys_time) < 0) + if (qemuDomainGetStatsCpuResource(driver, dom, + record, maxparams, privflags) < 0) return -1; =20 return 0; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list