From nobody Fri May 3 08:39:40 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1491481123241550.8248977624601; Thu, 6 Apr 2017 05:18:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F07AAC054918; Thu, 6 Apr 2017 12:18:41 +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 C492BA482F; Thu, 6 Apr 2017 12:18:41 +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 7BCFE18523C7; Thu, 6 Apr 2017 12:18: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 v36CIaR3003036 for ; Thu, 6 Apr 2017 08:18:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 76452171D5; Thu, 6 Apr 2017 12:18:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66BB81719F; Thu, 6 Apr 2017 12:18:34 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 126E2C04B956; Thu, 6 Apr 2017 12:18:32 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Apr 2017 05:18:21 -0700 Received: from s2600wt.sh.intel.com ([10.239.48.158]) by orsmga003.jf.intel.com with ESMTP; 06 Apr 2017 05:18:20 -0700 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F07AAC054918 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F07AAC054918 Authentication-Results: mx1.redhat.com; dkim=fail reason="key not found in DNS" (0-bit key) header.d=intel.com header.i=@intel.com header.b="lOIaWNbU" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 126E2C04B956 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=liyong.qiao@intel.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 126E2C04B956 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491481112; x=1523017112; h=from:to:cc:subject:date:message-id; bh=InRpeC+kqEoqalg/TZIK7eOHObsoscVNyN7Uj9Ss6UA=; b=lOIaWNbUgPbDR70zBz4B2giIvsHjPl6ZVirDiBe3DozDFNhxp/+YQJ5c AE+rNTm3X/k/EBwsVyc+TZYLQ4nxUA==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,159,1488873600"; d="scan'208";a="952636791" From: Eli Qiao To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 20:20:56 +0800 Message-Id: <1491481256-21742-1-git-send-email-liyong.qiao@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 06 Apr 2017 12:18:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 06 Apr 2017 12:18:32 +0000 (UTC) for IP:'134.134.136.24' DOMAIN:'mga09.intel.com' HELO:'mga09.intel.com' FROM:'liyong.qiao@intel.com' RCPT:'' X-RedHat-Spam-Score: -4.212 (BAYES_50, DCC_REPUT_13_19, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RP_MATCHES_RCVD, SPF_PASS, T_DKIM_INVALID) 134.134.136.24 mga09.intel.com 134.134.136.24 mga09.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, liyong.qiao@intel.com Subject: [libvirt] [PATCH V3] Expose resource control capabilites on cache bank 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 06 Apr 2017 12:18:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch is based on Martin's cache branch. This patch amends the cache bank capability as follow: Along with vircaps2xmltest case updated. Signed-off-by: Eli Qiao --- src/conf/capabilities.c | 120 +++++++++++++++++++= +++- src/conf/capabilities.h | 13 ++- tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml | 8 +- tests/vircaps2xmltest.c | 13 +++ 4 files changed, 148 insertions(+), 6 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 416dd1a..3094e48 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -52,6 +52,7 @@ #define VIR_FROM_THIS VIR_FROM_CAPABILITIES =20 #define SYSFS_SYSTEM_PATH "/sys/devices/system/" +#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl/" =20 VIR_LOG_INIT("conf.capabilities") =20 @@ -873,6 +874,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf, virCapsHostCacheBankPtr *caches) { size_t i =3D 0; + size_t j =3D 0; =20 if (!ncaches) return 0; @@ -894,13 +896,32 @@ virCapabilitiesFormatCaches(virBufferPtr buf, */ virBufferAsprintf(buf, "\n", + "size=3D'%llu' unit=3D'%s' cpus=3D'%s'", bank->id, bank->level, virCacheTypeToString(bank->type), bank->size >> (kilos * 10), kilos ? "KiB" : "B", cpus_str); =20 + if (bank->ncontrol > 0) { + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + for (j =3D 0; j < bank->ncontrol; j++) { + bool min_kilos =3D !(bank->controls[j]->min % 1024); + virBufferAsprintf(buf, + "\n", + bank->controls[j]->min >> (min_kilos * 1= 0), + min_kilos ? "KiB" : "B", + virCacheTypeToString(bank->controls[j]->= type), + bank->controls[j]->nallocations); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + VIR_FREE(cpus_str); } =20 @@ -1513,13 +1534,97 @@ virCapsHostCacheBankEquals(virCapsHostCacheBankPtr = a, void virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr) { + size_t i; + if (!ptr) return; =20 virBitmapFree(ptr->cpus); + for (i =3D 0; i < ptr->ncontrol; i++) + VIR_FREE(ptr->controls[i]); + VIR_FREE(ptr->controls); VIR_FREE(ptr); } =20 +/* test which kinds of cache control supported + * -1: don't support + * 0: cat + * 1: cdp + */ +static int +virCapabilitiesGetCacheControlType(virCapsHostCacheBankPtr bank) +{ + int ret =3D -1; + char *path =3D NULL; + if (virAsprintf(&path, SYSFS_RESCTRL_PATH "info/L%u", bank->level) < 0) + return -1; + + if (virFileExists(path)) { + ret =3D 0; + } else { + VIR_FREE(path); + if (virAsprintf(&path, SYSFS_RESCTRL_PATH "info/L%uCODE", bank->le= vel) < 0) + return -1; + if (virFileExists(path)) + ret =3D 1; + } + + VIR_FREE(path); + return ret; +} + +static int +virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank, const char* t= ype) +{ + int ret =3D -1; + char *path =3D NULL; + char *cbm_mask =3D NULL; + virCapsHostCacheControlPtr control; + + if (VIR_ALLOC(control) < 0) + goto cleanup; + + if (virFileReadValueUint(&control->nallocations, + SYSFS_RESCTRL_PATH "info/L%u%s/num_closids", + bank->level, + type) < 0) + goto cleanup; + + if (virFileReadValueString(&cbm_mask, + SYSFS_RESCTRL_PATH + "info/L%u%s/cbm_mask", + bank->level, + type) < 0) + goto cleanup; + + virStringTrimOptionalNewline(cbm_mask); + + control->min =3D bank->size / (strlen(cbm_mask) * 4); + + if (STREQ("", type)) + control->type =3D VIR_CACHE_TYPE_UNIFIED; + else if (STREQ("CODE", type)) + control->type =3D VIR_CACHE_TYPE_INSTRUCTION; + else if (STREQ("DATA", type)) + control->type =3D VIR_CACHE_TYPE_DATA; + else + goto cleanup; + + if (VIR_APPEND_ELEMENT(bank->controls, + bank->ncontrol, + control) < 0) + goto error; + + ret =3D 0; + + cleanup: + VIR_FREE(path); + return ret; + error: + VIR_FREE(control); + return -1; +} + int virCapabilitiesInitCaches(virCapsPtr caps) { @@ -1595,7 +1700,18 @@ virCapabilitiesInitCaches(virCapsPtr caps) pos, ent->d_name) < 0) goto cleanup; =20 - if (bank->level < cache_min_level) { + ret =3D virCapabilitiesGetCacheControlType(bank); + + if ((bank->level >=3D cache_min_level) || (ret >=3D 0)) { + if (ret =3D=3D 0) { + if (virCapabilitiesGetCacheControl(bank, "") < 0) + goto cleanup; + } else if (ret =3D=3D 1) { + if ((virCapabilitiesGetCacheControl(bank, "CODE") < 0)= || + (virCapabilitiesGetCacheControl(bank, "DATA") = < 0)) + goto cleanup; + } + } else { virCapsHostCacheBankFree(bank); bank =3D NULL; continue; diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index e099ccc..1007c30 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -139,15 +139,22 @@ struct _virCapsHostSecModel { }; =20 typedef enum { - VIR_CACHE_TYPE_DATA, - VIR_CACHE_TYPE_INSTRUCTION, VIR_CACHE_TYPE_UNIFIED, + VIR_CACHE_TYPE_INSTRUCTION, + VIR_CACHE_TYPE_DATA, =20 VIR_CACHE_TYPE_LAST } virCacheType; =20 VIR_ENUM_DECL(virCache); =20 +typedef struct _virCapsHostCacheControl virCapsHostCacheControl; +typedef virCapsHostCacheControl *virCapsHostCacheControlPtr; +struct _virCapsHostCacheControl { + unsigned long long min; /* B */ + virCacheType type; /* Data, Instruction or Unified */ + unsigned int nallocations; /* number of supported allocation */ +}; typedef struct _virCapsHostCacheBank virCapsHostCacheBank; typedef virCapsHostCacheBank *virCapsHostCacheBankPtr; struct _virCapsHostCacheBank { @@ -156,6 +163,8 @@ struct _virCapsHostCacheBank { unsigned long long size; /* B */ virCacheType type; /* Data, Instruction or Unified */ virBitmapPtr cpus; /* All CPUs that share this bank */ + size_t ncontrol; + virCapsHostCacheControlPtr *controls; }; =20 typedef struct _virCapsHost virCapsHost; diff --git a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml b/tests/virca= ps2xmldata/vircaps-x86_64-resctrl.xml index c30ea87..32a9549 100644 --- a/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml +++ b/tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml @@ -41,8 +41,12 @@ - - + + + + + + =20 diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c index f590249..3d1ad43 100644 --- a/tests/vircaps2xmltest.c +++ b/tests/vircaps2xmltest.c @@ -47,6 +47,7 @@ test_virCapabilities(const void *opaque) char *capsXML =3D NULL; char *path =3D NULL; char *dir =3D NULL; + char *resctrl_dir =3D NULL; int ret =3D -1; =20 /* @@ -58,6 +59,17 @@ test_virCapabilities(const void *opaque) data->resctrl ? "/system" : "") < 0) goto cleanup; =20 + if (data->resctrl) { + if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl= ", + abs_srcdir, data->filename) < 0) + goto cleanup; + } else { + /* Mock to bad directory to avoid using /sys/fs/resctrl */ + if (VIR_STRDUP(resctrl_dir, "") < 0) + goto cleanup; + } + + virFileMockAddPrefix("/sys/fs/resctrl", resctrl_dir); virFileMockAddPrefix("/sys/devices/system", dir); caps =3D virCapabilitiesNew(data->arch, data->offlineMigrate, data->li= veMigrate); =20 @@ -84,6 +96,7 @@ test_virCapabilities(const void *opaque) =20 cleanup: VIR_FREE(dir); + VIR_FREE(resctrl_dir); VIR_FREE(path); VIR_FREE(capsXML); virObjectUnref(caps); --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list