From nobody Sun Feb 8 19:44:11 2026 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 14931461533385.940617357868518; Tue, 25 Apr 2017 11:49:13 -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 4ACAE61B86; Tue, 25 Apr 2017 18:49:11 +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 22CAF179E3; Tue, 25 Apr 2017 18:49:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C5E7E18523D4; Tue, 25 Apr 2017 18:49:10 +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 v3PImokA030792 for ; Tue, 25 Apr 2017 14:48:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE00817C28; Tue, 25 Apr 2017 18:48:50 +0000 (UTC) Received: from mamuti.net (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40F46179E3 for ; Tue, 25 Apr 2017 18:48:47 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 809D2103EA1; Tue, 25 Apr 2017 20:48:46 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4ACAE61B86 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 4ACAE61B86 From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 20:48:44 +0200 Message-Id: <54acae7550eb24a1a0329d9e6bbe8b590064708b.1493145823.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] Add support for CPU cache specification 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.39]); Tue, 25 Apr 2017 18:49:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch introduces sub element of /domain/cpu. Currently only a single element is allowed. Signed-off-by: Jiri Denemark --- docs/formatdomain.html.in | 35 ++++++++++++ docs/schemas/cputypes.rng | 21 ++++++++ docs/schemas/domaincommon.rng | 3 ++ src/conf/cpu_conf.c | 62 ++++++++++++++++++= ++++ src/conf/cpu_conf.h | 19 +++++++ src/libvirt_private.syms | 2 + .../generic-cpu-cache-disable.xml | 20 +++++++ .../generic-cpu-cache-emulate.xml | 20 +++++++ .../generic-cpu-cache-passthrough.xml | 20 +++++++ .../generic-cpu-cache-disable.xml | 20 +++++++ .../generic-cpu-cache-emulate.xml | 20 +++++++ .../generic-cpu-cache-passthrough.xml | 20 +++++++ tests/genericxml2xmltest.c | 4 ++ 13 files changed, 266 insertions(+) create mode 100644 tests/genericxml2xmlindata/generic-cpu-cache-disable.xml create mode 100644 tests/genericxml2xmlindata/generic-cpu-cache-emulate.xml create mode 100644 tests/genericxml2xmlindata/generic-cpu-cache-passthroug= h.xml create mode 100644 tests/genericxml2xmloutdata/generic-cpu-cache-disable.x= ml create mode 100644 tests/genericxml2xmloutdata/generic-cpu-cache-emulate.x= ml create mode 100644 tests/genericxml2xmloutdata/generic-cpu-cache-passthrou= gh.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index e31a271a5..03961fb4b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1198,6 +1198,7 @@ <model fallback=3D'allow'>core2duo</model> <vendor>Intel</vendor> <topology sockets=3D'1' cores=3D'2' threads=3D'1'/> + <cache level=3D'3' mode=3D'emulate'/> <feature policy=3D'disable' name=3D'lahf_lm'/> </cpu> ... @@ -1211,6 +1212,7 @@ =20
 <cpu mode=3D'host-passthrough'>
+  <cache mode=3D'passthrough'/>
   <feature policy=3D'disable' name=3D'lahf_lm'/>
 ...
=20 @@ -1434,6 +1436,39 @@ Since 0.8.5 the policy attribute can be omitted and will default to require. + +
cache
+
Since 3.3.0 the cache + element describes the virtual CPU cache. If the element is missing, + the hypervisor will use a sensible default. + +
+
level
+
This optional attribute specifies which cache level is descr= ibed + by the element. Missing attribute means the element describes = all + CPU cache levels at once. Mixing cache elements w= ith + the level attribute set and those without the + attribute is forbidden.
+ +
mode
+
+ The following values are supported: +
+
emulate
+
The hypervisor will provide a fake CPU cache data.
+ +
passthrough
+
The real CPU cache data reported by the host CPU will be + passed through to the virtual CPU.
+ +
disable
+
The virtual CPU will report no CPU cache of the specified + level (or no cache at all if the level attrib= ute + is missing).
+
+
+
+
=20

diff --git a/docs/schemas/cputypes.rng b/docs/schemas/cputypes.rng index 8189114e3..3eef16abc 100644 --- a/docs/schemas/cputypes.rng +++ b/docs/schemas/cputypes.rng @@ -142,4 +142,25 @@ =20 + + + + + + 1 + 2 + 3 + + + + + + emulate + passthrough + disable + + + + + diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index eb4b0f743..7a9b4b702 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4548,6 +4548,9 @@ + + + diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 623b1699f..1b098c476 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -62,6 +62,12 @@ VIR_ENUM_IMPL(virCPUFeaturePolicy, VIR_CPU_FEATURE_LAST, "disable", "forbid") =20 +VIR_ENUM_IMPL(virCPUCacheMode, VIR_CPU_CACHE_MODE_LAST, + "emulate", + "passthrough", + "disable") + + void virCPUDefFreeFeatures(virCPUDefPtr def) { @@ -92,6 +98,7 @@ virCPUDefFree(virCPUDefPtr def) return; =20 virCPUDefFreeModel(def); + VIR_FREE(def->cache); VIR_FREE(def); } =20 @@ -204,7 +211,18 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu) copy->threads =3D cpu->threads; copy->arch =3D cpu->arch; =20 + if (cpu->cache) { + if (VIR_ALLOC(copy->cache) < 0) + goto error; + + *copy->cache =3D *cpu->cache; + } + return copy; + + error: + virCPUDefFree(copy); + return NULL; } =20 =20 @@ -489,6 +507,41 @@ virCPUDefParseXML(xmlNodePtr node, def->features[i].policy =3D policy; } =20 + if (virXPathInt("count(./cache)", ctxt, &n) < 0) { + goto cleanup; + } else if (n > 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("at most one CPU cache element may be specified")= ); + goto cleanup; + } else if (n =3D=3D 1) { + int level =3D -1; + char *strmode; + int mode; + + if (virXPathBoolean("boolean(./cache[1]/@level)", ctxt) =3D=3D 1 && + (virXPathInt("string(./cache[1]/@level)", ctxt, &level) < 0 || + level < 1 || level > 3)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("invalid CPU cache level, must be in range [1= ,3]")); + goto cleanup; + } + + if (!(strmode =3D virXPathString("string(./cache[1]/@mode)", ctxt)= ) || + (mode =3D virCPUCacheModeTypeFromString(strmode)) < 0) { + VIR_FREE(strmode); + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing or invalid CPU cache mode")); + goto cleanup; + } + VIR_FREE(strmode); + + if (VIR_ALLOC(def->cache) < 0) + goto cleanup; + + def->cache->level =3D level; + def->cache->mode =3D mode; + } + cleanup: ctxt->node =3D oldnode; VIR_FREE(fallback); @@ -662,6 +715,15 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 + if (def->cache) { + virBufferAddLit(buf, "cache->level !=3D -1) + virBufferAsprintf(buf, "level=3D'%d' ", def->cache->level); + virBufferAsprintf(buf, "mode=3D'%s'", + virCPUCacheModeTypeToString(def->cache->mode)); + virBufferAddLit(buf, "/>\n"); + } + for (i =3D 0; i < def->nfeatures; i++) { virCPUFeatureDefPtr feature =3D def->features + i; =20 diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 3e02deed4..09438b68b 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -103,6 +103,24 @@ struct _virCPUFeatureDef { }; =20 =20 +typedef enum { + VIR_CPU_CACHE_MODE_EMULATE, + VIR_CPU_CACHE_MODE_PASSTHROUGH, + VIR_CPU_CACHE_MODE_DISABLE, + + VIR_CPU_CACHE_MODE_LAST +} virCPUCacheMode; + +VIR_ENUM_DECL(virCPUCacheMode); + +typedef struct _virCPUCacheDef virCPUCacheDef; +typedef virCPUCacheDef *virCPUCacheDefPtr; +struct _virCPUCacheDef { + int level; /* -1 for unspecified */ + virCPUCacheMode mode; +}; + + typedef struct _virCPUDef virCPUDef; typedef virCPUDef *virCPUDefPtr; struct _virCPUDef { @@ -121,6 +139,7 @@ struct _virCPUDef { size_t nfeatures; size_t nfeatures_max; virCPUFeatureDefPtr features; + virCPUCacheDefPtr cache; }; =20 =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 83e979a2b..882abc8ef 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -67,6 +67,8 @@ virCapabilitiesSetNetPrefix; =20 =20 # conf/cpu_conf.h +virCPUCacheModeTypeFromString; +virCPUCacheModeTypeToString; virCPUDefAddFeature; virCPUDefCopy; virCPUDefCopyModel; diff --git a/tests/genericxml2xmlindata/generic-cpu-cache-disable.xml b/tes= ts/genericxml2xmlindata/generic-cpu-cache-disable.xml new file mode 100644 index 000000000..25f65cc6e --- /dev/null +++ b/tests/genericxml2xmlindata/generic-cpu-cache-disable.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmlindata/generic-cpu-cache-emulate.xml b/tes= ts/genericxml2xmlindata/generic-cpu-cache-emulate.xml new file mode 100644 index 000000000..6ea57cbf6 --- /dev/null +++ b/tests/genericxml2xmlindata/generic-cpu-cache-emulate.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmlindata/generic-cpu-cache-passthrough.xml b= /tests/genericxml2xmlindata/generic-cpu-cache-passthrough.xml new file mode 100644 index 000000000..8d4c186c9 --- /dev/null +++ b/tests/genericxml2xmlindata/generic-cpu-cache-passthrough.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmloutdata/generic-cpu-cache-disable.xml b/te= sts/genericxml2xmloutdata/generic-cpu-cache-disable.xml new file mode 100644 index 000000000..25f65cc6e --- /dev/null +++ b/tests/genericxml2xmloutdata/generic-cpu-cache-disable.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmloutdata/generic-cpu-cache-emulate.xml b/te= sts/genericxml2xmloutdata/generic-cpu-cache-emulate.xml new file mode 100644 index 000000000..6ea57cbf6 --- /dev/null +++ b/tests/genericxml2xmloutdata/generic-cpu-cache-emulate.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmloutdata/generic-cpu-cache-passthrough.xml = b/tests/genericxml2xmloutdata/generic-cpu-cache-passthrough.xml new file mode 100644 index 000000000..8d4c186c9 --- /dev/null +++ b/tests/genericxml2xmloutdata/generic-cpu-cache-passthrough.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 1cda18cd9..5bce00e21 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -100,6 +100,10 @@ mymain(void) =20 DO_TEST("vcpus-individual"); =20 + DO_TEST("cpu-cache-emulate"); + DO_TEST("cpu-cache-passthrough"); + DO_TEST("cpu-cache-disable"); + virObjectUnref(caps); virObjectUnref(xmlopt); =20 --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list